From b7186d8518dc44f093daea7accf10602efe29d2d Mon Sep 17 00:00:00 2001 From: Hamdi Allam Date: Tue, 17 Feb 2026 13:15:48 -0500 Subject: [PATCH 1/4] scoped metrics --- Cargo.lock | 42 +++++++------------ Cargo.toml | 25 ++++++----- .../commonware-node/src/consensus/engine.rs | 16 ++++--- .../src/dkg/manager/actor/mod.rs | 8 +++- .../src/dkg/manager/actor/state.rs | 24 ++++++----- crates/commonware-node/src/dkg/manager/mod.rs | 4 +- .../src/epoch/manager/actor.rs | 8 ++-- .../commonware-node/src/epoch/manager/mod.rs | 6 +-- 8 files changed, 65 insertions(+), 68 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3c7fd9a5cb..dd53efa0bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2394,8 +2394,7 @@ dependencies = [ [[package]] name = "commonware-broadcast" version = "2026.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ffa29e885815ceb4e9ac4e1cb840aa96fb5493ad0c3ea5ac401212385137736" +source = "git+https://github.com/commonwarexyz/monorepo?rev=540b008ebeb2c94518d9d32adcb0c2a027bee66a#540b008ebeb2c94518d9d32adcb0c2a027bee66a" dependencies = [ "commonware-codec", "commonware-cryptography", @@ -2411,8 +2410,7 @@ dependencies = [ [[package]] name = "commonware-codec" version = "2026.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52f6cacfdaad565ab6565b7c896cdf9d6d58a528e162150c2697d4d925a9938e" +source = "git+https://github.com/commonwarexyz/monorepo?rev=540b008ebeb2c94518d9d32adcb0c2a027bee66a#540b008ebeb2c94518d9d32adcb0c2a027bee66a" dependencies = [ "bytes", "cfg-if", @@ -2426,8 +2424,7 @@ dependencies = [ [[package]] name = "commonware-consensus" version = "2026.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ec7c97f3cb71e54a24a12af393d063d4daacf17ffcb69d79b9b519e5d19bafe" +source = "git+https://github.com/commonwarexyz/monorepo?rev=540b008ebeb2c94518d9d32adcb0c2a027bee66a#540b008ebeb2c94518d9d32adcb0c2a027bee66a" dependencies = [ "bytes", "cfg-if", @@ -2455,8 +2452,7 @@ dependencies = [ [[package]] name = "commonware-cryptography" version = "2026.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea20d380b73eb74eb977c40b0ef3df88ad7a428a582c38ada2d64fd7a1ef909b" +source = "git+https://github.com/commonwarexyz/monorepo?rev=540b008ebeb2c94518d9d32adcb0c2a027bee66a#540b008ebeb2c94518d9d32adcb0c2a027bee66a" dependencies = [ "anyhow", "aws-lc-rs", @@ -2490,8 +2486,7 @@ dependencies = [ [[package]] name = "commonware-macros" version = "2026.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "241d65be9575e6de767236514985c9906e8ef0f6f6a5ce8faa6719886bf23270" +source = "git+https://github.com/commonwarexyz/monorepo?rev=540b008ebeb2c94518d9d32adcb0c2a027bee66a#540b008ebeb2c94518d9d32adcb0c2a027bee66a" dependencies = [ "commonware-macros-impl", "tokio", @@ -2500,8 +2495,7 @@ dependencies = [ [[package]] name = "commonware-macros-impl" version = "2026.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6b7bdc304661c89e6d294c5581367db81a16cf161b27c036a9f855e317b21b8" +source = "git+https://github.com/commonwarexyz/monorepo?rev=540b008ebeb2c94518d9d32adcb0c2a027bee66a#540b008ebeb2c94518d9d32adcb0c2a027bee66a" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2513,8 +2507,7 @@ dependencies = [ [[package]] name = "commonware-math" version = "2026.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2c6de52eb60c386ad2376d44ff247c41e2e7b03a436041e7065a2054799e31e" +source = "git+https://github.com/commonwarexyz/monorepo?rev=540b008ebeb2c94518d9d32adcb0c2a027bee66a#540b008ebeb2c94518d9d32adcb0c2a027bee66a" dependencies = [ "bytes", "commonware-codec", @@ -2527,8 +2520,7 @@ dependencies = [ [[package]] name = "commonware-p2p" version = "2026.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b3035f95ed50d7c440f0fbab6593409226bb42dfe105235975f6751e44051bf" +source = "git+https://github.com/commonwarexyz/monorepo?rev=540b008ebeb2c94518d9d32adcb0c2a027bee66a#540b008ebeb2c94518d9d32adcb0c2a027bee66a" dependencies = [ "commonware-codec", "commonware-cryptography", @@ -2553,8 +2545,7 @@ dependencies = [ [[package]] name = "commonware-parallel" version = "2026.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "757b851e79eef082156ab7e33e354bda406ba9abbbc614fe3c92145d23a102fc" +source = "git+https://github.com/commonwarexyz/monorepo?rev=540b008ebeb2c94518d9d32adcb0c2a027bee66a#540b008ebeb2c94518d9d32adcb0c2a027bee66a" dependencies = [ "cfg-if", "commonware-macros", @@ -2564,8 +2555,7 @@ dependencies = [ [[package]] name = "commonware-resolver" version = "2026.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "247e2bca77b21f598178b0194b519560616136222f8b10d4aa8cf801a6de91eb" +source = "git+https://github.com/commonwarexyz/monorepo?rev=540b008ebeb2c94518d9d32adcb0c2a027bee66a#540b008ebeb2c94518d9d32adcb0c2a027bee66a" dependencies = [ "bytes", "commonware-codec", @@ -2585,8 +2575,7 @@ dependencies = [ [[package]] name = "commonware-runtime" version = "2026.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68f3c41066ea741c799381b31df729c572705cd27925601db577cd44f9cf0358" +source = "git+https://github.com/commonwarexyz/monorepo?rev=540b008ebeb2c94518d9d32adcb0c2a027bee66a#540b008ebeb2c94518d9d32adcb0c2a027bee66a" dependencies = [ "async-lock", "axum", @@ -2623,8 +2612,7 @@ dependencies = [ [[package]] name = "commonware-storage" version = "2026.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31db25d40fcdf233e93dfec1749e0d7ee7b1dcdd9507f31f9f445fa98972ab8c" +source = "git+https://github.com/commonwarexyz/monorepo?rev=540b008ebeb2c94518d9d32adcb0c2a027bee66a#540b008ebeb2c94518d9d32adcb0c2a027bee66a" dependencies = [ "anyhow", "bytes", @@ -2647,8 +2635,7 @@ dependencies = [ [[package]] name = "commonware-stream" version = "2026.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30e6e61b311c4d65b16cfc70076e1d560fa1cf8975cc9afbe293501bf4814aad" +source = "git+https://github.com/commonwarexyz/monorepo?rev=540b008ebeb2c94518d9d32adcb0c2a027bee66a#540b008ebeb2c94518d9d32adcb0c2a027bee66a" dependencies = [ "chacha20poly1305", "commonware-codec", @@ -2667,8 +2654,7 @@ dependencies = [ [[package]] name = "commonware-utils" version = "2026.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d350ec4edcf243e8f746f8d6011956910c705325b295df3d686e77067b8b381b" +source = "git+https://github.com/commonwarexyz/monorepo?rev=540b008ebeb2c94518d9d32adcb0c2a027bee66a#540b008ebeb2c94518d9d32adcb0c2a027bee66a" dependencies = [ "bytes", "cfg-if", diff --git a/Cargo.toml b/Cargo.toml index 7df0047535..02a297c8f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -325,16 +325,15 @@ vergen-git2 = "9.1.0" # reth-trie-sparse = { path = "../reth/crates/trie/sparse" } # reth-trie-sparse-parallel = { path = "../reth/crates/trie/sparse-parallel" } -# [patch.crates-io] -# # Commonware right after after PR #3018 was merged -# commonware-broadcast = { git = "https://github.com/commonwarexyz/monorepo", rev = "a1b60388c0bbc9126aa9934ec6ebade6ec344552" } -# commonware-codec = { git = "https://github.com/commonwarexyz/monorepo", rev = "a1b60388c0bbc9126aa9934ec6ebade6ec344552" } -# commonware-consensus = { git = "https://github.com/commonwarexyz/monorepo", rev = "a1b60388c0bbc9126aa9934ec6ebade6ec344552" } -# commonware-cryptography = { git = "https://github.com/commonwarexyz/monorepo", rev = "a1b60388c0bbc9126aa9934ec6ebade6ec344552" } -# commonware-macros = { git = "https://github.com/commonwarexyz/monorepo", rev = "a1b60388c0bbc9126aa9934ec6ebade6ec344552" } -# commonware-math = { git = "https://github.com/commonwarexyz/monorepo", rev = "a1b60388c0bbc9126aa9934ec6ebade6ec344552" } -# commonware-p2p = { git = "https://github.com/commonwarexyz/monorepo", rev = "a1b60388c0bbc9126aa9934ec6ebade6ec344552" } -# commonware-parallel = { git = "https://github.com/commonwarexyz/monorepo", rev = "a1b60388c0bbc9126aa9934ec6ebade6ec344552" } -# commonware-runtime = { git = "https://github.com/commonwarexyz/monorepo", rev = "a1b60388c0bbc9126aa9934ec6ebade6ec344552" } -# commonware-storage = { git = "https://github.com/commonwarexyz/monorepo", rev = "a1b60388c0bbc9126aa9934ec6ebade6ec344552" } -# commonware-utils = { git = "https://github.com/commonwarexyz/monorepo", rev = "a1b60388c0bbc9126aa9934ec6ebade6ec344552" } +[patch.crates-io] +commonware-broadcast = { git = "https://github.com/commonwarexyz/monorepo", rev = "540b008ebeb2c94518d9d32adcb0c2a027bee66a" } +commonware-codec = { git = "https://github.com/commonwarexyz/monorepo", rev = "540b008ebeb2c94518d9d32adcb0c2a027bee66a" } +commonware-consensus = { git = "https://github.com/commonwarexyz/monorepo", rev = "540b008ebeb2c94518d9d32adcb0c2a027bee66a" } +commonware-cryptography = { git = "https://github.com/commonwarexyz/monorepo", rev = "540b008ebeb2c94518d9d32adcb0c2a027bee66a" } +commonware-macros = { git = "https://github.com/commonwarexyz/monorepo", rev = "540b008ebeb2c94518d9d32adcb0c2a027bee66a" } +commonware-math = { git = "https://github.com/commonwarexyz/monorepo", rev = "540b008ebeb2c94518d9d32adcb0c2a027bee66a" } +commonware-p2p = { git = "https://github.com/commonwarexyz/monorepo", rev = "540b008ebeb2c94518d9d32adcb0c2a027bee66a" } +commonware-parallel = { git = "https://github.com/commonwarexyz/monorepo", rev = "540b008ebeb2c94518d9d32adcb0c2a027bee66a" } +commonware-runtime = { git = "https://github.com/commonwarexyz/monorepo", rev = "540b008ebeb2c94518d9d32adcb0c2a027bee66a" } +commonware-storage = { git = "https://github.com/commonwarexyz/monorepo", rev = "540b008ebeb2c94518d9d32adcb0c2a027bee66a" } +commonware-utils = { git = "https://github.com/commonwarexyz/monorepo", rev = "540b008ebeb2c94518d9d32adcb0c2a027bee66a" } diff --git a/crates/commonware-node/src/consensus/engine.rs b/crates/commonware-node/src/consensus/engine.rs index 5ff1639bba..9d713d7d1d 100644 --- a/crates/commonware-node/src/consensus/engine.rs +++ b/crates/commonware-node/src/consensus/engine.rs @@ -22,8 +22,8 @@ use commonware_cryptography::{ use commonware_p2p::{AddressableManager, Blocker, Receiver, Sender}; use commonware_parallel::Sequential; use commonware_runtime::{ - Clock, ContextCell, Handle, Metrics, Network, Pacer, Spawner, Storage, buffer::paged::CacheRef, - spawn_cell, + BufferPooler, Clock, ContextCell, Handle, Metrics, Network, Pacer, Spawner, Storage, + buffer::paged::CacheRef, spawn_cell, }; use commonware_storage::archive::immutable; use commonware_utils::NZU64; @@ -118,7 +118,8 @@ where + Spawner + Storage + Metrics - + Network, + + Network + + BufferPooler, { let execution_node = self .execution_node @@ -152,7 +153,8 @@ where }, ); - let page_cache_ref = CacheRef::new(BUFFER_POOL_PAGE_SIZE, BUFFER_POOL_CAPACITY); + let page_cache_ref = + CacheRef::from_pooler(&context, BUFFER_POOL_PAGE_SIZE, BUFFER_POOL_CAPACITY); // XXX: All hard-coded values here are the same as prior to commonware // making the resolver configurable in @@ -413,7 +415,8 @@ where pub struct Engine where - TContext: Clock + TContext: BufferPooler + + Clock + governor::clock::Clock + Rng + CryptoRng @@ -465,7 +468,8 @@ where impl Engine where - TContext: Clock + TContext: BufferPooler + + Clock + governor::clock::Clock + Rng + CryptoRng diff --git a/crates/commonware-node/src/dkg/manager/actor/mod.rs b/crates/commonware-node/src/dkg/manager/actor/mod.rs index 4e0c5a9e93..68a8b35135 100644 --- a/crates/commonware-node/src/dkg/manager/actor/mod.rs +++ b/crates/commonware-node/src/dkg/manager/actor/mod.rs @@ -125,8 +125,12 @@ where impl Actor where - TContext: - Clock + CryptoRngCore + commonware_runtime::Metrics + Spawner + commonware_runtime::Storage, + TContext: commonware_runtime::BufferPooler + + Clock + + CryptoRngCore + + commonware_runtime::Metrics + + Spawner + + commonware_runtime::Storage, TPeerManager: AddressableManager + Sync, { pub(super) async fn new( diff --git a/crates/commonware-node/src/dkg/manager/actor/state.rs b/crates/commonware-node/src/dkg/manager/actor/state.rs index 91bbe19d10..c7e654919e 100644 --- a/crates/commonware-node/src/dkg/manager/actor/state.rs +++ b/crates/commonware-node/src/dkg/manager/actor/state.rs @@ -20,9 +20,9 @@ use commonware_cryptography::{ transcript::{Summary, Transcript}, }; use commonware_parallel::Strategy; -use commonware_runtime::{Clock, Metrics, buffer::paged::CacheRef}; +use commonware_runtime::{BufferPooler, Clock, Metrics, buffer::paged::CacheRef}; use commonware_storage::{ - journal::{contiguous, segmented}, + journal::{contiguous, contiguous::Reader as _, segmented}, metadata, }; use commonware_utils::{N3f1, NZU16, NZU32, NZU64, NZUsize, ordered}; @@ -495,7 +495,7 @@ impl Builder { #[instrument(skip_all, err)] pub(super) async fn init(self, context: TContext) -> eyre::Result> where - TContext: commonware_runtime::Storage + Clock + Metrics, + TContext: BufferPooler + commonware_runtime::Storage + Clock + Metrics, { let Self { initial_state, @@ -504,7 +504,7 @@ impl Builder { let partition_prefix = partition_prefix.ok_or_eyre("DKG actors state must have its partition prefix set")?; - let page_cache = CacheRef::new(PAGE_SIZE, POOL_CAPACITY); + let page_cache = CacheRef::from_pooler(&context, PAGE_SIZE, POOL_CAPACITY); let states_partition = format!("{partition_prefix}_states"); let states_metadata_partition = format!("{partition_prefix}_states_metadata"); @@ -604,7 +604,7 @@ async fn migrate_journal_to_metadata_if_necessary( page_cache: &CacheRef, ) -> eyre::Result<()> where - TContext: commonware_runtime::Storage + Clock + Metrics, + TContext: BufferPooler + commonware_runtime::Storage + Clock + Metrics, { if states.keys().next().is_some() { debug!("states already exists in new format; not migrating"); @@ -625,14 +625,15 @@ where .await .wrap_err("unable to initialize legacy DKG states journal for migration")?; - if let Some(latest_segment) = legacy_journal.size().checked_sub(1) { + if let Some(latest_segment) = legacy_journal.size().await.checked_sub(1) { info!( latest_segment, "legacy journal contains states; migrating last 2 segments", ); + let reader = legacy_journal.reader().await; for segment in latest_segment.saturating_sub(1)..=latest_segment { - let legacy_state = legacy_journal + let legacy_state = reader .read(segment) .await .wrap_err("unable to read state from legacy journal")?; @@ -1413,7 +1414,7 @@ mod tests { let partition_prefix = "test_dkg"; let states_partition = format!("{partition_prefix}_states"); let states_metadata_partition = format!("{partition_prefix}_states_metadata"); - let page_cache = CacheRef::new(PAGE_SIZE, POOL_CAPACITY); + let page_cache = CacheRef::from_pooler(&context, PAGE_SIZE, POOL_CAPACITY); let ancient_legacy = make_legacy_state(&mut context, 1); let previous_legacy = make_legacy_state(&mut context, 2); @@ -1490,7 +1491,8 @@ mod tests { ) .await .unwrap(); - assert_eq!(reopened.size(), 0); + + assert_eq!(reopened.size().await, 0); // Metadata persists across reopens. drop(states); @@ -1521,7 +1523,7 @@ mod tests { let partition_prefix = "test_dkg_single"; let states_partition = format!("{partition_prefix}_states"); let states_metadata_partition = format!("{partition_prefix}_states_metadata"); - let page_cache = CacheRef::new(PAGE_SIZE, POOL_CAPACITY); + let page_cache = CacheRef::from_pooler(&context, PAGE_SIZE, POOL_CAPACITY); let only_legacy = make_legacy_state(&mut context, 5); let only_expected: State = only_legacy.clone().into(); @@ -1581,7 +1583,7 @@ mod tests { let partition_prefix = "test_dkg_noop"; let states_partition = format!("{partition_prefix}_states"); let states_metadata_partition = format!("{partition_prefix}_states_metadata"); - let page_cache = CacheRef::new(PAGE_SIZE, POOL_CAPACITY); + let page_cache = CacheRef::from_pooler(&context, PAGE_SIZE, POOL_CAPACITY); let existing_state = make_test_state(&mut context, 10); let journal_legacy = make_legacy_state(&mut context, 20); diff --git a/crates/commonware-node/src/dkg/manager/mod.rs b/crates/commonware-node/src/dkg/manager/mod.rs index 62db325f66..b0f400a6ad 100644 --- a/crates/commonware-node/src/dkg/manager/mod.rs +++ b/crates/commonware-node/src/dkg/manager/mod.rs @@ -3,7 +3,7 @@ use commonware_cryptography::{ bls12381::primitives::group::Share, ed25519::{PrivateKey, PublicKey}, }; -use commonware_runtime::{Clock, Metrics, Spawner, Storage}; +use commonware_runtime::{BufferPooler, Clock, Metrics, Spawner, Storage}; use eyre::WrapErr as _; use futures::channel::mpsc; use rand_core::CryptoRngCore; @@ -25,7 +25,7 @@ pub(crate) async fn init( config: Config, ) -> eyre::Result<(Actor, Mailbox)> where - TContext: Clock + CryptoRngCore + Metrics + Spawner + Storage, + TContext: BufferPooler + Clock + CryptoRngCore + Metrics + Spawner + Storage, TPeerManager: commonware_p2p::AddressableManager + Sync, { let (tx, rx) = mpsc::unbounded(); diff --git a/crates/commonware-node/src/epoch/manager/actor.rs b/crates/commonware-node/src/epoch/manager/actor.rs index 67f0a09777..790080cf9d 100644 --- a/crates/commonware-node/src/epoch/manager/actor.rs +++ b/crates/commonware-node/src/epoch/manager/actor.rs @@ -59,7 +59,7 @@ use commonware_p2p::{ }; use commonware_parallel::Sequential; use commonware_runtime::{ - Clock, ContextCell, Handle, Metrics as _, Network, Spawner, Storage, spawn_cell, + BufferPooler, Clock, ContextCell, Handle, Metrics as _, Network, Spawner, Storage, spawn_cell, telemetry::metrics::status::GaugeExt as _, }; use commonware_utils::{Acknowledgement as _, vec::NonEmptyVec}; @@ -92,7 +92,8 @@ impl Actor where TBlocker: Blocker, // TODO(janis): are all of these bounds necessary? - TContext: Spawner + TContext: BufferPooler + + Spawner + commonware_runtime::Metrics + Rng + CryptoRng @@ -322,7 +323,8 @@ where let engine = simplex::Engine::new( self.context .with_label("simplex") - .with_attribute("epoch", epoch), + .with_attribute("epoch", epoch) + .with_scope(), simplex::Config { scheme, elector: elector::Random, diff --git a/crates/commonware-node/src/epoch/manager/mod.rs b/crates/commonware-node/src/epoch/manager/mod.rs index 95560dcdc8..15e32c3afd 100644 --- a/crates/commonware-node/src/epoch/manager/mod.rs +++ b/crates/commonware-node/src/epoch/manager/mod.rs @@ -13,7 +13,7 @@ use commonware_consensus::{ types::{FixedEpocher, ViewDelta}, }; use commonware_p2p::Blocker; -use commonware_runtime::{Clock, Metrics, Network, Spawner, Storage, buffer::paged::CacheRef}; +use commonware_runtime::{BufferPooler, Clock, Metrics, Network, Spawner, Storage, buffer::paged::CacheRef}; use rand_08::{CryptoRng, Rng}; use crate::{consensus::block::Block, epoch::scheme_provider::SchemeProvider, feed, subblocks}; @@ -43,8 +43,8 @@ pub(crate) fn init( ) -> (Actor, Mailbox) where TBlocker: Blocker, - TContext: - Spawner + Metrics + Rng + CryptoRng + Clock + governor::clock::Clock + Storage + Network, + TContext: BufferPooler + + Spawner + Metrics + Rng + CryptoRng + Clock + governor::clock::Clock + Storage + Network, { let (tx, rx) = futures::channel::mpsc::unbounded(); let actor = Actor::new(config, context, rx); From 5e3277abbbeb72351aded6f2fc8bccf1ab9690db Mon Sep 17 00:00:00 2001 From: Hamdi Allam Date: Tue, 17 Feb 2026 16:04:20 -0500 Subject: [PATCH 2/4] feedback --- Cargo.toml | 1 + .../src/epoch/manager/actor.rs | 23 +++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 02a297c8f6..7505c6961d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -326,6 +326,7 @@ vergen-git2 = "9.1.0" # reth-trie-sparse-parallel = { path = "../reth/crates/trie/sparse-parallel" } [patch.crates-io] +# Commonware right after after PR #3127 was merged commonware-broadcast = { git = "https://github.com/commonwarexyz/monorepo", rev = "540b008ebeb2c94518d9d32adcb0c2a027bee66a" } commonware-codec = { git = "https://github.com/commonwarexyz/monorepo", rev = "540b008ebeb2c94518d9d32adcb0c2a027bee66a" } commonware-consensus = { git = "https://github.com/commonwarexyz/monorepo", rev = "540b008ebeb2c94518d9d32adcb0c2a027bee66a" } diff --git a/crates/commonware-node/src/epoch/manager/actor.rs b/crates/commonware-node/src/epoch/manager/actor.rs index 790080cf9d..1f705f00df 100644 --- a/crates/commonware-node/src/epoch/manager/actor.rs +++ b/crates/commonware-node/src/epoch/manager/actor.rs @@ -80,7 +80,7 @@ const REPLAY_BUFFER: NonZeroUsize = NonZeroUsize::new(8 * 1024 * 1024).expect("v const WRITE_BUFFER: NonZeroUsize = NonZeroUsize::new(1024 * 1024).expect("value is not zero"); // 1MB pub(crate) struct Actor { - active_epochs: BTreeMap>, + active_epochs: BTreeMap, ContextCell)>, config: super::Config, context: ContextCell, confirmed_latest_network_epoch: Option, @@ -320,11 +320,16 @@ where }; self.config.scheme_provider.register(epoch, scheme.clone()); + // Manage the context so we can explictly drop during cleanup, releasing + // all metrics associated with this context. + let engine_ctx = self + .context + .with_label("simplex") + .with_attribute("epoch", epoch) + .with_scope(); + let engine = simplex::Engine::new( - self.context - .with_label("simplex") - .with_attribute("epoch", epoch) - .with_scope(), + engine_ctx.clone(), simplex::Config { scheme, elector: elector::Random, @@ -365,7 +370,10 @@ where assert!( self.active_epochs - .insert(epoch, engine.start(vote, certificate, resolver)) + .insert( + epoch, + (engine.start(vote, certificate, resolver), engine_ctx) + ) .is_none(), "there must be no other active engine running: this was ensured at \ the beginning of this method", @@ -387,7 +395,8 @@ where #[instrument(parent = &cause, skip_all, fields(epoch))] fn exit(&mut self, cause: Span, Exit { epoch }: Exit) { - if let Some(engine) = self.active_epochs.remove(&epoch) { + if let Some((engine, engine_ctx)) = self.active_epochs.remove(&epoch) { + drop(engine_ctx); engine.abort(); info!("stopped engine backing epoch"); } else { From 1b8f3582abe269ac7d949b345ae3e3eb2f46cb1e Mon Sep 17 00:00:00 2001 From: Hamdi Allam Date: Tue, 17 Feb 2026 16:35:21 -0500 Subject: [PATCH 3/4] fmt+typo --- crates/commonware-node/src/epoch/manager/actor.rs | 2 +- crates/commonware-node/src/epoch/manager/mod.rs | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/commonware-node/src/epoch/manager/actor.rs b/crates/commonware-node/src/epoch/manager/actor.rs index 1f705f00df..276c53b558 100644 --- a/crates/commonware-node/src/epoch/manager/actor.rs +++ b/crates/commonware-node/src/epoch/manager/actor.rs @@ -320,7 +320,7 @@ where }; self.config.scheme_provider.register(epoch, scheme.clone()); - // Manage the context so we can explictly drop during cleanup, releasing + // Manage the context so we can explicitly drop during cleanup, releasing // all metrics associated with this context. let engine_ctx = self .context diff --git a/crates/commonware-node/src/epoch/manager/mod.rs b/crates/commonware-node/src/epoch/manager/mod.rs index 15e32c3afd..acf22580d5 100644 --- a/crates/commonware-node/src/epoch/manager/mod.rs +++ b/crates/commonware-node/src/epoch/manager/mod.rs @@ -13,7 +13,9 @@ use commonware_consensus::{ types::{FixedEpocher, ViewDelta}, }; use commonware_p2p::Blocker; -use commonware_runtime::{BufferPooler, Clock, Metrics, Network, Spawner, Storage, buffer::paged::CacheRef}; +use commonware_runtime::{ + BufferPooler, Clock, Metrics, Network, Spawner, Storage, buffer::paged::CacheRef, +}; use rand_08::{CryptoRng, Rng}; use crate::{consensus::block::Block, epoch::scheme_provider::SchemeProvider, feed, subblocks}; @@ -44,7 +46,14 @@ pub(crate) fn init( where TBlocker: Blocker, TContext: BufferPooler - + Spawner + Metrics + Rng + CryptoRng + Clock + governor::clock::Clock + Storage + Network, + + Spawner + + Metrics + + Rng + + CryptoRng + + Clock + + governor::clock::Clock + + Storage + + Network, { let (tx, rx) = futures::channel::mpsc::unbounded(); let actor = Actor::new(config, context, rx); From d8e946e8d2e56929018af367879b36b876dd0a45 Mon Sep 17 00:00:00 2001 From: Hamdi Allam Date: Tue, 17 Feb 2026 16:44:00 -0500 Subject: [PATCH 4/4] clippy --- crates/commonware-node/src/dkg/manager/actor/state.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/commonware-node/src/dkg/manager/actor/state.rs b/crates/commonware-node/src/dkg/manager/actor/state.rs index c7e654919e..1743ac1d7e 100644 --- a/crates/commonware-node/src/dkg/manager/actor/state.rs +++ b/crates/commonware-node/src/dkg/manager/actor/state.rs @@ -1424,7 +1424,7 @@ mod tests { // Populate the legacy journal with three entries. { - let mut journal = contiguous::variable::Journal::<_, LegacyState>::init( + let journal = contiguous::variable::Journal::<_, LegacyState>::init( context.with_label("journal_setup"), contiguous::variable::Config { partition: states_partition.clone(), @@ -1530,7 +1530,7 @@ mod tests { // Populate the legacy journal with a single entry. { - let mut journal = contiguous::variable::Journal::<_, LegacyState>::init( + let journal = contiguous::variable::Journal::<_, LegacyState>::init( context.with_label("journal_setup"), contiguous::variable::Config { partition: states_partition.clone(), @@ -1604,7 +1604,7 @@ mod tests { // Populate a legacy journal with different data. { - let mut journal = contiguous::variable::Journal::<_, LegacyState>::init( + let journal = contiguous::variable::Journal::<_, LegacyState>::init( context.with_label("journal_setup"), contiguous::variable::Config { partition: states_partition.clone(),