Skip to content

Commit

Permalink
merged with develop, reintroduces old logic for condition variables, …
Browse files Browse the repository at this point in the history
…improved rejections comparison
  • Loading branch information
rdeioris committed Jan 31, 2025
1 parent 33642c3 commit 790c1e1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
19 changes: 7 additions & 12 deletions testnet/stacks-node/src/nakamoto_node/signer_coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down
16 changes: 12 additions & 4 deletions testnet/stacks-node/src/nakamoto_node/stackerdb_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 0 additions & 4 deletions testnet/stacks-node/src/tests/signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ pub struct RunningNodes {
pub counters: Counters,
pub coord_channel: Arc<Mutex<CoordinatorChannels>>,
pub conf: NeonConfig,
pub counters: Counters,
}

/// A test harness for running a v0 or v1 signer integration test
Expand Down Expand Up @@ -939,8 +938,6 @@ fn setup_stx_btc_node<G: FnMut(&mut NeonConfig)>(

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!
Expand Down Expand Up @@ -978,6 +975,5 @@ fn setup_stx_btc_node<G: FnMut(&mut NeonConfig)>(
coord_channel,
counters,
conf: naka_conf,
counters: run_loop_counters,
}
}

0 comments on commit 790c1e1

Please sign in to comment.