Skip to content

Commit 5614112

Browse files
committed
Do not count received valid signatures towards threshold weight when ignore flag set
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 4e0bf1c commit 5614112

File tree

2 files changed

+37
-35
lines changed

2 files changed

+37
-35
lines changed

testnet/stacks-node/src/nakamoto_node/sign_coordinator.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -886,11 +886,6 @@ impl SignCoordinator {
886886
);
887887
continue;
888888
}
889-
if !gathered_signatures.contains_key(&slot_id) {
890-
total_weight_signed = total_weight_signed
891-
.checked_add(signer_entry.weight)
892-
.expect("FATAL: total weight signed exceeds u32::MAX");
893-
}
894889

895890
if Self::fault_injection_ignore_signatures() {
896891
warn!("SignCoordinator: fault injection: ignoring well-formed signature for block";
@@ -906,6 +901,12 @@ impl SignCoordinator {
906901
continue;
907902
}
908903

904+
if !gathered_signatures.contains_key(&slot_id) {
905+
total_weight_signed = total_weight_signed
906+
.checked_add(signer_entry.weight)
907+
.expect("FATAL: total weight signed exceeds u32::MAX");
908+
}
909+
909910
info!("SignCoordinator: Signature Added to block";
910911
"block_signer_sighash" => %block_sighash,
911912
"signer_pubkey" => signer_pubkey.to_hex(),
@@ -986,7 +987,6 @@ impl SignCoordinator {
986987
}
987988
};
988989
}
989-
990990
// After gathering all signatures, return them if we've hit the threshold
991991
if total_weight_signed >= self.weight_threshold {
992992
info!("SignCoordinator: Received enough signatures. Continuing.";

testnet/stacks-node/src/tests/signer/v0.rs

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,53 +2227,56 @@ fn signers_broadcast_signed_blocks() {
22272227
let http_origin = format!("http://{}", &signer_test.running_nodes.conf.node.rpc_bind);
22282228

22292229
signer_test.boot_to_epoch_3();
2230-
sleep_ms(10_000);
2231-
2230+
let info_before = get_chain_info(&signer_test.running_nodes.conf);
2231+
let blocks_before = signer_test
2232+
.running_nodes
2233+
.nakamoto_blocks_mined
2234+
.load(Ordering::SeqCst);
22322235
signer_test.mine_nakamoto_block(Duration::from_secs(30));
2233-
sleep_ms(10_000);
22342236

2235-
TEST_IGNORE_SIGNERS.lock().unwrap().replace(true);
2237+
wait_for(30, || {
2238+
let blocks_mined = signer_test
2239+
.running_nodes
2240+
.nakamoto_blocks_mined
2241+
.load(Ordering::SeqCst);
2242+
let info = get_chain_info(&signer_test.running_nodes.conf);
2243+
debug!(
2244+
"blocks_mined: {},{}, stacks_tip_height: {},{}",
2245+
blocks_mined, blocks_before, info.stacks_tip_height, info_before.stacks_tip_height
2246+
);
2247+
Ok(blocks_mined > blocks_before && info.stacks_tip_height > info_before.stacks_tip_height)
2248+
})
2249+
.expect("Timed out waiting for first nakamoto block to be mined");
22362250

2251+
TEST_IGNORE_SIGNERS.lock().unwrap().replace(true);
22372252
let blocks_before = signer_test
22382253
.running_nodes
22392254
.nakamoto_blocks_mined
22402255
.load(Ordering::SeqCst);
2241-
22422256
let signer_pushed_before = signer_test
22432257
.running_nodes
22442258
.nakamoto_blocks_signer_pushed
22452259
.load(Ordering::SeqCst);
2246-
22472260
let info_before = get_chain_info(&signer_test.running_nodes.conf);
22482261

2249-
// submit a tx so that the miner will mine a block
2262+
// submit a tx so that the miner will mine a blockn
22502263
let sender_nonce = 0;
22512264
let transfer_tx =
22522265
make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt);
22532266
submit_tx(&http_origin, &transfer_tx);
22542267

22552268
debug!("Transaction sent; waiting for block-mining");
22562269

2257-
let start = Instant::now();
2258-
let duration = 60;
2259-
loop {
2260-
let blocks_mined = signer_test
2261-
.running_nodes
2262-
.nakamoto_blocks_mined
2263-
.load(Ordering::SeqCst);
2270+
wait_for(30, || {
22642271
let signer_pushed = signer_test
22652272
.running_nodes
22662273
.nakamoto_blocks_signer_pushed
22672274
.load(Ordering::SeqCst);
2268-
2275+
let blocks_mined = signer_test
2276+
.running_nodes
2277+
.nakamoto_blocks_mined
2278+
.load(Ordering::SeqCst);
22692279
let info = get_chain_info(&signer_test.running_nodes.conf);
2270-
if blocks_mined > blocks_before
2271-
&& signer_pushed > signer_pushed_before
2272-
&& info.stacks_tip_height > info_before.stacks_tip_height
2273-
{
2274-
break;
2275-
}
2276-
22772280
debug!(
22782281
"blocks_mined: {},{}, signers_pushed: {},{}, stacks_tip_height: {},{}",
22792282
blocks_mined,
@@ -2283,12 +2286,11 @@ fn signers_broadcast_signed_blocks() {
22832286
info.stacks_tip_height,
22842287
info_before.stacks_tip_height
22852288
);
2286-
2287-
std::thread::sleep(Duration::from_millis(100));
2288-
if start.elapsed() >= Duration::from_secs(duration) {
2289-
panic!("Timed out");
2290-
}
2291-
}
2289+
Ok(blocks_mined > blocks_before
2290+
&& info.stacks_tip_height > info_before.stacks_tip_height
2291+
&& signer_pushed > signer_pushed_before)
2292+
})
2293+
.expect("Timed out waiting for second nakamoto block to be mined");
22922294

22932295
signer_test.shutdown();
22942296
}
@@ -4754,7 +4756,7 @@ fn miner_recovers_when_broadcast_block_delay_across_tenures_occurs() {
47544756

47554757
info!("Allowing miner to accept block responses again. ");
47564758
TEST_IGNORE_SIGNERS.lock().unwrap().replace(false);
4757-
info!("Allowing singers to broadcast block N+1 to the miner");
4759+
info!("Allowing signers to broadcast block N+1 to the miner");
47584760
TEST_PAUSE_BLOCK_BROADCAST.lock().unwrap().replace(false);
47594761

47604762
// Assert the N+1' block was rejected

0 commit comments

Comments
 (0)