From 3a1b4fbaf8af3767056944f3d0a259a06b6e69ae Mon Sep 17 00:00:00 2001 From: Ash Manning Date: Wed, 1 Jul 2026 23:57:56 +0800 Subject: [PATCH 1/2] Update deny.toml, deps --- Cargo.lock | 144 +++++++------------------------------ Cargo.toml | 10 +-- deny.toml | 8 ++- lib/archive.rs | 5 +- lib/mempool.rs | 5 +- lib/net/mod.rs | 6 +- lib/net/peer/mod.rs | 2 +- lib/node/mainchain_task.rs | 6 +- lib/node/mod.rs | 10 +-- lib/node/net_task.rs | 6 +- lib/state/bitnames.rs | 9 ++- lib/state/mod.rs | 5 +- lib/wallet/mod.rs | 10 +-- 13 files changed, 72 insertions(+), 154 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8ff2fca..8878f27 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -304,9 +304,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.102" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" +checksum = "2a4385e2e34eb35d6b3efe798b9eb88096925d87726c0798709bf56d9ed84af3" [[package]] name = "arboard" @@ -772,7 +772,7 @@ dependencies = [ "dotenvy", "either", "futures", - "hex 0.4.3", + "hex", "http", "indicatif", "jsonrpsee 0.26.0", @@ -819,9 +819,9 @@ dependencies = [ "fallible-iterator", "futures", "hashlink 0.12.0", - "heed 0.22.0", + "heed", "heed-types", - "hex 0.4.3", + "hex", "http-body", "jiff", "jsonrpsee 0.26.0", @@ -838,7 +838,7 @@ dependencies = [ "rusty-leveldb", "serde", "serde_json", - "sneed 0.0.22", + "sneed", "thiserror 2.0.18", "tokio", "tokio-rusqlite", @@ -932,7 +932,7 @@ dependencies = [ "bitcoin", "educe", "hashlink 0.11.0", - "hex 0.4.3", + "hex", "http", "jsonrpsee 0.26.0", "monostate", @@ -1734,7 +1734,7 @@ dependencies = [ "tracing", "typewit", "ulid", - "zeromq 0.6.0", + "zeromq", ] [[package]] @@ -3082,15 +3082,6 @@ dependencies = [ "serde", ] -[[package]] -name = "heck" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "heck" version = "0.4.1" @@ -3103,25 +3094,6 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" -[[package]] -name = "heed" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd54745cfacb7b97dee45e8fdb91814b62bccddb481debb7de0f9ee6b7bf5b43" -dependencies = [ - "bitflags 2.10.0", - "byteorder", - "heed-traits", - "heed-types", - "libc", - "lmdb-master-sys", - "once_cell", - "page_size", - "serde", - "synchronoise", - "url", -] - [[package]] name = "heed" version = "0.22.0" @@ -3166,12 +3138,6 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" -[[package]] -name = "hex" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" - [[package]] name = "hex" version = "0.4.3" @@ -5429,8 +5395,8 @@ dependencies = [ "futures", "governor", "hashlink 0.10.0", - "heed 0.21.0", - "hex 0.4.3", + "heed", + "hex", "jsonrpsee 0.25.1", "libes", "nonempty 0.11.0", @@ -5448,8 +5414,8 @@ dependencies = [ "serde", "serde_json", "serde_with", - "sneed 0.0.19", - "strum 0.27.2", + "sneed", + "strum 0.28.0", "thiserror 2.0.18", "tiny-bip39", "tokio", @@ -5462,7 +5428,7 @@ dependencies = [ "transitive", "utoipa", "x25519-dalek", - "zeromq 0.5.0", + "zeromq", ] [[package]] @@ -5480,7 +5446,7 @@ dependencies = [ "either", "fallible-iterator", "futures", - "hex 0.4.3", + "hex", "http", "human-size", "include_path", @@ -5495,7 +5461,7 @@ dependencies = [ "poll-promise", "serde", "shlex", - "strum 0.27.2", + "strum 0.28.0", "thiserror 2.0.18", "tiny-bip39", "tokio", @@ -5520,7 +5486,7 @@ dependencies = [ "bitcoin", "blake3", "clap", - "hex 0.4.3", + "hex", "http", "jsonrpsee 0.25.1", "plain_bitnames", @@ -5589,8 +5555,8 @@ dependencies = [ "ed25519-dalek", "educe", "generic-array 1.3.5", - "heed 0.21.0", - "hex 0.4.3", + "heed", + "hex", "hex-literal", "libes", "merkle-cbt", @@ -5601,7 +5567,7 @@ dependencies = [ "serde_json", "serde_with", "smallvec", - "strum 0.27.2", + "strum 0.28.0", "thiserror 2.0.18", "typenum", "utoipa", @@ -5819,7 +5785,7 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "343d3bd7056eda839b03204e68deff7d1b13aba7af2b2fd16890697274262ee7" dependencies = [ - "heck 0.5.0", + "heck 0.4.1", "itertools 0.14.0", "log", "multimap", @@ -6819,7 +6785,7 @@ checksum = "4fa237f2807440d238e0364a218270b98f767a00d3dada77b1c53ae88940e2e7" dependencies = [ "base64 0.22.1", "chrono", - "hex 0.4.3", + "hex", "serde_core", "serde_json", "serde_with_macros", @@ -7026,23 +6992,6 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b6b67fb9a61334225b5b790716f609cd58395f895b3fe8b328786812a40bc3b" -[[package]] -name = "sneed" -version = "0.0.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f611ea5d3b6bc4669514cd971708fed12c89c1689f5f6d1a240cc2cb84be00a" -dependencies = [ - "educe", - "enum-ordinalize", - "fallible-iterator", - "heed 0.21.0", - "hex 0.3.2", - "strum 0.20.0", - "syn 1.0.109", - "thiserror 1.0.69", - "tokio", -] - [[package]] name = "sneed" version = "0.0.22" @@ -7052,8 +7001,8 @@ dependencies = [ "educe", "enum-ordinalize", "fallible-iterator", - "heed 0.22.0", - "hex 0.4.3", + "heed", + "hex", "strum 0.27.2", "syn 1.0.109", "thiserror 2.0.18", @@ -7138,15 +7087,6 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" -[[package]] -name = "strum" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7318c509b5ba57f18533982607f24070a55d353e90d4cae30c467cdb2ad5ac5c" -dependencies = [ - "strum_macros 0.20.1", -] - [[package]] name = "strum" version = "0.27.2" @@ -7165,18 +7105,6 @@ dependencies = [ "strum_macros 0.28.0", ] -[[package]] -name = "strum_macros" -version = "0.20.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee8bc6b87a5112aeeab1f4a9f7ab634fe6cbefc4850006df31267f4cfb9e3149" -dependencies = [ - "heck 0.3.3", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "strum_macros" version = "0.27.2" @@ -9172,7 +9100,7 @@ dependencies = [ "event-listener", "futures-core", "futures-lite", - "hex 0.4.3", + "hex", "libc", "ordered-stream", "rustix 1.1.3", @@ -9311,30 +9239,6 @@ dependencies = [ "syn 2.0.117", ] -[[package]] -name = "zeromq" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b32e1e46c4e278efd0c1153f2db0113924b9bc5fff9f9221853d035e2d26fadf" -dependencies = [ - "async-trait", - "asynchronous-codec", - "bytes", - "crossbeam-queue", - "futures", - "log", - "num-traits", - "once_cell", - "parking_lot", - "rand 0.9.4", - "regex", - "scc", - "thiserror 1.0.69", - "tokio", - "tokio-util", - "uuid", -] - [[package]] name = "zeromq" version = "0.6.0" diff --git a/Cargo.toml b/Cargo.toml index f21c673..eadf8f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ futures = { version = "0.3.30", default-features = false } generic-array = "1.3.3" governor = { version = "0.8.1", default-features = false } hashlink = "0.10.0" -heed = "0.21.0" +heed = "0.22.0" hex = "0.4.3" hex-literal = "0.4.1" human-size = "0.4.3" @@ -66,8 +66,8 @@ serde_json_canonicalizer = "0.3.0" serde_with = { version = "3.4.0", default-features = false } shlex = "1.3.0" smallvec = "1.13.2" -sneed = "0.0.19" -strum = { version = "0.27.2", default-features = false } +sneed = "0.0.22" +strum = { version = "0.28.0", default-features = false } thiserror = "2.0.16" tiny-bip39 = "2.0.0" tokio = { version = "1.50.0", default-features = false } @@ -90,7 +90,7 @@ url = "2.5.4" utoipa = { version = "5.2.0", default-features = false } uuid = "1.13.1" x25519-dalek = "2.0.0" -zeromq = "0.5.0" +zeromq = "0.6.0" [workspace.dependencies.bip300301_enforcer_lib] default-features = false @@ -130,4 +130,4 @@ git = "https://github.com/torkelrogstad/tokio-tracing.git" branch = "log-rotation-size" [profile.release] -# lto = "fat" \ No newline at end of file +# lto = "fat" diff --git a/deny.toml b/deny.toml index ccfd0e9..cd09dd2 100644 --- a/deny.toml +++ b/deny.toml @@ -74,11 +74,13 @@ ignore = [ #{ id = "RUSTSEC-0000-0000", reason = "you can specify a reason the advisory is ignored" }, #"a-crate-that-is-yanked@0.1.1", # you can also ignore yanked crate versions if you wish #{ crate = "a-crate-that-is-yanked@0.1.1", reason = "you can specify why you are ignoring the yanked crate" }, - { id = "RUSTSEC-2024-0370", reason = "Temporary ignore until the ouroboros branch gets updated"}, + { id = "RUSTSEC-2024-0370", reason = "Temporary ignore until the ouroboros branch gets updated" }, # paste (via aws-lc-rs) is unmaintained # https://github.com/aws/aws-lc-rs/issues/722 - { id = "RUSTSEC-2024-0436", reason = "Temporary ignore until aws-lc-rs and rustls-webpki get updated"}, - { id = "RUSTSEC-2025-0141", reason = "Temporary ignore until heed migrates to wincode"}, + { id = "RUSTSEC-2024-0436", reason = "Temporary ignore until aws-lc-rs and rustls-webpki get updated" }, + { id = "RUSTSEC-2025-0141", reason = "Temporary ignore until heed migrates to wincode" }, + # ttf-parser (via egui) is unmaintained + { id = "RUSTSEC-2026-0192", reason = "Temporary ignore until ttf-parser is replaced by skrifa etc." }, ] # If this is true, then cargo deny will use the git executable to fetch advisory database. # If this is false, then it uses a built-in git library. diff --git a/lib/archive.rs b/lib/archive.rs index 7ea64b7..133006c 100644 --- a/lib/archive.rs +++ b/lib/archive.rs @@ -160,7 +160,10 @@ pub struct Archive { impl Archive { pub const NUM_DBS: u32 = 14; - pub fn new(env: &sneed::Env) -> Result { + pub fn new(env: &sneed::Env) -> Result + where + Tls: heed::TlsUsage, + { let mut rwtxn = env.write_txn()?; let version = DatabaseUnique::create(env, &mut rwtxn, "archive_version")?; diff --git a/lib/mempool.rs b/lib/mempool.rs index 4345b95..8cc673a 100644 --- a/lib/mempool.rs +++ b/lib/mempool.rs @@ -53,7 +53,10 @@ pub struct MemPool { impl MemPool { pub const NUM_DBS: u32 = 3; - pub fn new(env: &sneed::Env) -> Result { + pub fn new(env: &sneed::Env) -> Result + where + Tls: heed::TlsUsage, + { let mut rwtxn = env.write_txn()?; let transactions = DatabaseUnique::create(env, &mut rwtxn, "transactions")?; diff --git a/lib/net/mod.rs b/lib/net/mod.rs index cda84e8..12f7153 100644 --- a/lib/net/mod.rs +++ b/lib/net/mod.rs @@ -252,7 +252,7 @@ impl Net { #[instrument(skip_all, fields(addr), err(Debug))] pub fn connect_peer( &self, - env: sneed::Env, + env: sneed::Env, addr: SocketAddr, ) -> Result<(), Error> { if self.active_peers.read().contains_key(&addr) { @@ -309,7 +309,7 @@ impl Net { } pub fn new( - env: &sneed::Env, + env: &sneed::Env, archive: Archive, network: Network, state: State, @@ -389,7 +389,7 @@ impl Net { /// and a new peer was added. pub async fn accept_incoming( &self, - env: sneed::Env, + env: sneed::Env, ) -> Result, error::AcceptConnection> { tracing::debug!( "listening for connections on `{}`", diff --git a/lib/net/peer/mod.rs b/lib/net/peer/mod.rs index e2b4fbf..9795658 100644 --- a/lib/net/peer/mod.rs +++ b/lib/net/peer/mod.rs @@ -334,7 +334,7 @@ impl Connection { } pub struct ConnectionContext { - pub env: sneed::Env, + pub env: sneed::Env, pub archive: Archive, pub network: Network, pub state: State, diff --git a/lib/node/mainchain_task.rs b/lib/node/mainchain_task.rs index 51b76c2..92301ac 100644 --- a/lib/node/mainchain_task.rs +++ b/lib/node/mainchain_task.rs @@ -71,7 +71,7 @@ enum Error { } struct MainchainTask { - env: sneed::Env, + env: sneed::Env, archive: Archive, mainchain: proto::mainchain::ValidatorClient, // receive a request, and optional oneshot sender to send the result to @@ -88,7 +88,7 @@ where /// including the specified header. /// Returns `false` if the specified block was not available. async fn request_ancestor_infos( - env: &sneed::Env, + env: &sneed::Env, archive: &Archive, cusf_mainchain: &mut proto::mainchain::ValidatorClient, block_hash: bitcoin::BlockHash, @@ -213,7 +213,7 @@ pub(super) struct MainchainTaskHandle { impl MainchainTaskHandle { pub fn new( - env: sneed::Env, + env: sneed::Env, archive: Archive, mainchain: mainchain::ValidatorClient, ) -> (Self, mpsc::UnboundedReceiver) diff --git a/lib/node/mod.rs b/lib/node/mod.rs index 14a1c15..b052172 100644 --- a/lib/node/mod.rs +++ b/lib/node/mod.rs @@ -122,7 +122,7 @@ pub struct Node { cusf_mainchain: Arc>>, cusf_mainchain_wallet: Option>>>, - env: sneed::Env, + env: sneed::Env, mainchain_task: MainchainTaskHandle, mempool: MemPool, net: Net, @@ -159,7 +159,8 @@ where // let _ = std::fs::remove_dir_all(&env_path); std::fs::create_dir_all(&env_path)?; let env = { - let mut env_open_opts = heed::EnvOpenOptions::new(); + let mut env_open_opts = + heed::EnvOpenOptions::new().read_txn_without_tls(); env_open_opts .map_size(128 * 1024 * 1024 * 1024) // 128 GB .max_dbs( @@ -187,8 +188,7 @@ where | EnvFlags::MAP_ASYNC | EnvFlags::NO_SYNC | EnvFlags::NO_META_SYNC - | EnvFlags::NO_READ_AHEAD - | EnvFlags::NO_TLS; + | EnvFlags::NO_READ_AHEAD; unsafe { env_open_opts.flags(fast_flags) }; unsafe { Env::open(&env_open_opts, &env_path) }? }; @@ -235,7 +235,7 @@ where }) } - pub fn env(&self) -> &Env { + pub fn env(&self) -> &Env { &self.env } diff --git a/lib/node/net_task.rs b/lib/node/net_task.rs index 9b61f78..2573e27 100644 --- a/lib/node/net_task.rs +++ b/lib/node/net_task.rs @@ -261,7 +261,7 @@ fn disconnect_tip_( /// A result of `Ok(true)` indicates a successful re-org. /// A result of `Ok(false)` indicates that no re-org was attempted. fn reorg_to_tip( - env: &sneed::Env, + env: &sneed::Env, archive: &Archive, mempool: &MemPool, state: &State, @@ -440,7 +440,7 @@ fn reorg_to_tip( #[derive(Clone)] struct NetTaskContext { - env: sneed::Env, + env: sneed::Env, archive: Archive, mainchain_task: MainchainTaskHandle, mempool: MemPool, @@ -1184,7 +1184,7 @@ impl NetTaskHandle { #[allow(clippy::too_many_arguments)] pub fn new( runtime: &tokio::runtime::Runtime, - env: sneed::Env, + env: sneed::Env, archive: Archive, mainchain_task: MainchainTaskHandle, mainchain_task_response_rx: UnboundedReceiver, diff --git a/lib/state/bitnames.rs b/lib/state/bitnames.rs index 3981e9f..2d1818f 100644 --- a/lib/state/bitnames.rs +++ b/lib/state/bitnames.rs @@ -294,10 +294,13 @@ impl Dbs { pub const NUM_DBS: u32 = 3; /// Create / Open DBs. Does not commit the RwTxn. - pub(in crate::state) fn new( - env: &sneed::Env, + pub(in crate::state) fn new( + env: &sneed::Env, rwtxn: &mut RwTxn, - ) -> Result { + ) -> Result + where + Tls: heed::TlsUsage, + { let bitnames = DatabaseUnique::create(env, rwtxn, "bitnames")?; let reservations = DatabaseUnique::create(env, rwtxn, "bitname_reservations")?; diff --git a/lib/state/mod.rs b/lib/state/mod.rs index 6fa3d03..24b0376 100644 --- a/lib/state/mod.rs +++ b/lib/state/mod.rs @@ -96,7 +96,10 @@ pub struct State { impl State { pub const NUM_DBS: u32 = bitnames::Dbs::NUM_DBS + 10; - pub fn new(env: &sneed::Env) -> Result { + pub fn new(env: &sneed::Env) -> Result + where + Tls: heed::TlsUsage, + { let mut rwtxn = env.write_txn()?; let tip = DatabaseUnique::create(env, &mut rwtxn, "tip")?; let height = DatabaseUnique::create(env, &mut rwtxn, "height")?; diff --git a/lib/wallet/mod.rs b/lib/wallet/mod.rs index f8303a8..f7fe125 100644 --- a/lib/wallet/mod.rs +++ b/lib/wallet/mod.rs @@ -61,11 +61,11 @@ pub struct VkDoesNotExistError { pub struct WalletEnv; type DatabaseUnique = sneed::DatabaseUnique; -type RoTxn<'a> = sneed::RoTxn<'a, WalletEnv>; +type RoTxn<'a> = sneed::RoTxn<'a, heed::AnyTls, WalletEnv>; #[derive(Clone)] pub struct Wallet { - pub env: sneed::Env, + pub env: sneed::Env, // Seed is always [u8; 64], but due to serde not implementing serialize // for [T; 64], use heed's `Bytes` // TODO: Don't store the seed in plaintext. @@ -100,7 +100,8 @@ impl Wallet { std::fs::create_dir_all(path)?; let env = { use heed::EnvFlags; - let mut env_open_options = heed::EnvOpenOptions::new(); + let mut env_open_options = + heed::EnvOpenOptions::new().read_txn_without_tls(); env_open_options .map_size(10 * 1024 * 1024) // 10MB .max_dbs(Self::NUM_DBS); @@ -123,8 +124,7 @@ impl Wallet { | EnvFlags::MAP_ASYNC | EnvFlags::NO_SYNC | EnvFlags::NO_META_SYNC - | EnvFlags::NO_READ_AHEAD - | EnvFlags::NO_TLS; + | EnvFlags::NO_READ_AHEAD; unsafe { env_open_options.flags(fast_flags) }; unsafe { Env::open(&env_open_options, path) }? }; From 6709c6fc6f5186373976bfcbef8736f49f72c74e Mon Sep 17 00:00:00 2001 From: Ash Manning Date: Wed, 1 Jul 2026 22:07:24 +0800 Subject: [PATCH 2/2] Enforce consensus block size limit --- lib/state/block.rs | 13 +++++++++++++ lib/state/error.rs | 2 ++ types/lib.rs | 3 +++ 3 files changed, 18 insertions(+) diff --git a/lib/state/block.rs b/lib/state/block.rs index 09d5708..16241b2 100644 --- a/lib/state/block.rs +++ b/lib/state/block.rs @@ -26,6 +26,12 @@ pub fn validate( header: &Header, body: &Body, ) -> Result<(bitcoin::Amount, MerkleRoot), Error> { + let body_size = + borsh::object_length(&body).map_err(Error::BorshSerialize)?; + if body_size > Body::MAX_SIZE { + return Err(Error::BodyTooLarge); + } + let tip_hash = state.try_get_tip(rotxn)?; if header.prev_side_hash != tip_hash { let err = error::InvalidHeader::PrevSideHash { @@ -123,6 +129,12 @@ pub fn prevalidate( header: &Header, body: &Body, ) -> Result { + let body_size = + borsh::object_length(&body).map_err(Error::BorshSerialize)?; + if body_size > Body::MAX_SIZE { + return Err(Error::BodyTooLarge); + } + let tip_hash = state.try_get_tip(rotxn)?; if header.prev_side_hash != tip_hash { let err = error::InvalidHeader::PrevSideHash { @@ -131,6 +143,7 @@ pub fn prevalidate( }; return Err(Error::InvalidHeader(err)); }; + let mut coinbase_value = bitcoin::Amount::ZERO; for output in &body.coinbase { coinbase_value = coinbase_value diff --git a/lib/state/error.rs b/lib/state/error.rs index 0f2834b..5d9213e 100644 --- a/lib/state/error.rs +++ b/lib/state/error.rs @@ -180,6 +180,8 @@ pub enum Error { BitName(#[from] BitName), #[error("bitname {name_hash} already registered")] BitNameAlreadyRegistered { name_hash: BitNameId }, + #[error("body too large")] + BodyTooLarge, #[error("bundle too heavy {weight} > {max_weight}")] BundleTooHeavy { weight: u64, max_weight: u64 }, #[error(transparent)] diff --git a/types/lib.rs b/types/lib.rs index 1a986bb..c9ac2dc 100644 --- a/types/lib.rs +++ b/types/lib.rs @@ -572,6 +572,9 @@ impl Body { } } + /// Size limit in bytes + pub const MAX_SIZE: usize = 8 * 1024 * 1024; + pub fn authorized_transactions(&self) -> Vec { let mut authorizations_iter = self.authorizations.iter(); self.transactions