From 790c1e1db2bc85accccb4ba0b1fa500de2a30fdb Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Fri, 31 Jan 2025 10:39:36 +0000 Subject: [PATCH] merged with develop, reintroduces old logic for condition variables, improved rejections comparison --- .../src/nakamoto_node/signer_coordinator.rs | 19 +++++++------------ .../src/nakamoto_node/stackerdb_listener.rs | 16 ++++++++++++---- testnet/stacks-node/src/tests/signer/mod.rs | 4 ---- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/testnet/stacks-node/src/nakamoto_node/signer_coordinator.rs b/testnet/stacks-node/src/nakamoto_node/signer_coordinator.rs index 1fdb609ad1..ec827033ba 100644 --- a/testnet/stacks-node/src/nakamoto_node/signer_coordinator.rs +++ b/testnet/stacks-node/src/nakamoto_node/signer_coordinator.rs @@ -40,9 +40,7 @@ use stacks::util_lib::boot::boot_code_id; use super::stackerdb_listener::StackerDBListenerComms; use super::Error as NakamotoNodeError; use crate::event_dispatcher::StackerDBChannel; -use crate::nakamoto_node::stackerdb_listener::{ - BlockStatus, StackerDBListener, EVENT_RECEIVER_POLL, -}; +use crate::nakamoto_node::stackerdb_listener::{StackerDBListener, EVENT_RECEIVER_POLL}; use crate::neon::Counters; use crate::Config; @@ -320,8 +318,6 @@ impl SignerCoordinator { "Invalid rejection timeout step function definition".into(), ) })?; - // this is used for comparing block_status to identify if it has been changed from the previous event - let mut block_status_tracker = BlockStatus::default(); // this is used to track the start of the waiting cycle let rejections_timer = Instant::now(); @@ -333,20 +329,19 @@ impl SignerCoordinator { block_signer_sighash, EVENT_RECEIVER_POLL, |status| { + // rejections-based timeout expired? if rejections_timer.elapsed() > *rejections_timeout { return false; } - if *status != block_status_tracker { + // number or rejections changed? + if status.total_reject_weight as u64 != rejections { return false; } - return true; + // enough signatures? + return status.total_weight_signed < self.weight_threshold; }, )? { - Some(status) => { - // keep track of the last status - block_status_tracker = status.clone(); - status - } + Some(status) => status, None => { // If we just received a timeout, we should check if the burnchain // tip has changed or if we received this signed block already in diff --git a/testnet/stacks-node/src/nakamoto_node/stackerdb_listener.rs b/testnet/stacks-node/src/nakamoto_node/stackerdb_listener.rs index ddaa14a8fd..cf9ce4b6d7 100644 --- a/testnet/stacks-node/src/nakamoto_node/stackerdb_listener.rs +++ b/testnet/stacks-node/src/nakamoto_node/stackerdb_listener.rs @@ -337,8 +337,10 @@ impl StackerDBListener { block.gathered_signatures.insert(slot_id, signature); block.responded_signers.insert(signer_pubkey); - // Signal to anyone waiting on this block that we have a new status - cvar.notify_all(); + if block.total_weight_signed >= self.weight_threshold { + // Signal to anyone waiting on this block that we have enough signatures + cvar.notify_all(); + } // Update the idle timestamp for this signer self.update_idle_timestamp( @@ -394,8 +396,14 @@ impl StackerDBListener { "server_version" => rejected_data.metadata.server_version, ); - // Signal to anyone waiting on this block that we have a new status - cvar.notify_all(); + if block + .total_reject_weight + .saturating_add(self.weight_threshold) + > self.total_weight + { + // Signal to anyone waiting on this block that we have enough rejections + cvar.notify_all(); + } // Update the idle timestamp for this signer self.update_idle_timestamp( diff --git a/testnet/stacks-node/src/tests/signer/mod.rs b/testnet/stacks-node/src/tests/signer/mod.rs index 836a9eee0a..a68a4c77fb 100644 --- a/testnet/stacks-node/src/tests/signer/mod.rs +++ b/testnet/stacks-node/src/tests/signer/mod.rs @@ -86,7 +86,6 @@ pub struct RunningNodes { pub counters: Counters, pub coord_channel: Arc>, pub conf: NeonConfig, - pub counters: Counters, } /// A test harness for running a v0 or v1 signer integration test @@ -939,8 +938,6 @@ fn setup_stx_btc_node( let coord_channel = run_loop.coordinator_channels(); - let run_loop_counters = run_loop.counters(); - let run_loop_thread = thread::spawn(move || run_loop.start(None, 0)); // Give the run loop some time to start up! @@ -978,6 +975,5 @@ fn setup_stx_btc_node( coord_channel, counters, conf: naka_conf, - counters: run_loop_counters, } }