Skip to content

Commit d0c8871

Browse files
committed
Fix test
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 8f6af15 commit d0c8871

File tree

3 files changed

+34
-28
lines changed

3 files changed

+34
-28
lines changed

stacks-signer/src/runloop.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,16 @@ impl SignerRunLoop<Vec<OperationResult>, RunLoopCommand> for RunLoop {
415415
signer.commands.push_back(command.command);
416416
}
417417
}
418+
// Check if we missed any DKG messages due to a restart or being late to the party
419+
// Note: We currently only check for DKG specific messages as we cannot rejoin a sign
420+
// round due to a miner overwriting its own message slots (impossible to recover without every message)
421+
if let Err(e) = signer.read_dkg_stackerdb_messages(
422+
&self.stacks_client,
423+
res.clone(),
424+
current_reward_cycle,
425+
) {
426+
error!("{signer}: failed to read stackerdb messages: {e}");
427+
}
418428
// After processing event, run the next command for each signer
419429
signer.process_next_command(&self.stacks_client, current_reward_cycle);
420430
}

stacks-signer/src/signer.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1418,11 +1418,15 @@ impl Signer {
14181418
// TODO: this will never work as is. We need to have stored our party shares on the side etc for this particular aggregate key.
14191419
// Need to update state to store the necessary info, check against it to see if we have participated in the winning round and
14201420
// then overwrite our value accordingly. Otherwise, we will be locked out of the round and should not participate.
1421+
let internal_dkg = self.coordinator.aggregate_public_key;
1422+
if internal_dkg != self.approved_aggregate_public_key {
1423+
warn!("{self}: we do not support changing the internal DKG key yet. Expected {internal_dkg:?} got {:?}", self.approved_aggregate_public_key);
1424+
}
14211425
self.coordinator
14221426
.set_aggregate_public_key(self.approved_aggregate_public_key);
14231427
if old_dkg != self.approved_aggregate_public_key {
14241428
warn!(
1425-
"{self}: updated DKG value to {:?}.",
1429+
"{self}: updated DKG value from {old_dkg:?} to {:?}.",
14261430
self.approved_aggregate_public_key
14271431
);
14281432
}
@@ -1432,6 +1436,9 @@ impl Signer {
14321436
self.coordinator.current_dkg_id
14331437
);
14341438
self.finish_operation();
1439+
} else if self.state == State::Uninitialized {
1440+
// If we successfully load the DKG value, we are fully initialized
1441+
self.state = State::Idle;
14351442
}
14361443
} else if should_queue {
14371444
if self.commands.front() != Some(&Command::Dkg) {

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

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use crate::tests::bitcoin_regtest::BitcoinCoreController;
5959
use crate::tests::nakamoto_integrations::{
6060
boot_to_epoch_3_reward_set, boot_to_epoch_3_reward_set_calculation_boundary,
6161
naka_neon_integration_conf, next_block_and, next_block_and_mine_commit,
62-
POX_4_DEFAULT_STACKER_BALANCE,
62+
next_block_and_process_new_stacks_block, POX_4_DEFAULT_STACKER_BALANCE,
6363
};
6464
use crate::tests::neon_integrations::{
6565
next_block_and_wait, run_until_burnchain_height, test_observer, wait_for_runloop,
@@ -1162,44 +1162,33 @@ fn stackerdb_delayed_dkg() {
11621162
);
11631163

11641164
info!("------------------------- Start DKG -------------------------");
1165-
let height = signer_test
1166-
.running_nodes
1167-
.btc_regtest_controller
1168-
.get_headers_height();
1165+
info!("Waiting for DKG to start...");
11691166
// Advance one more to trigger DKG
1170-
run_until_burnchain_height(
1167+
next_block_and(
11711168
&mut signer_test.running_nodes.btc_regtest_controller,
1172-
&signer_test.running_nodes.blocks_processed,
1173-
height.wrapping_add(1),
1174-
&signer_test.running_nodes.conf,
1175-
);
1169+
timeout.as_secs(),
1170+
|| Ok(true),
1171+
)
1172+
.expect("Failed to mine bitcoin block");
11761173
// Wait a bit so DKG is actually triggered and signers are not available to respond
11771174
std::thread::sleep(Duration::from_secs(5));
11781175

1179-
// Make sure DKG did not get set
1180-
assert!(signer_test
1181-
.stacks_client
1182-
.get_approved_aggregate_key(reward_cycle)
1183-
.expect("Failed to get approved aggregate key")
1184-
.is_none());
1185-
11861176
info!("------------------------- Restart Stopped Signer -------------------------");
11871177

11881178
signer_test.restart_signer(signer_idx, signer_key);
11891179

11901180
info!("------------------------- Wait for DKG -------------------------");
11911181
let key = signer_test.wait_for_dkg(timeout);
1192-
let height = signer_test
1193-
.running_nodes
1194-
.btc_regtest_controller
1195-
.get_headers_height();
1196-
// Advance one more to mine dkg transactions
1197-
run_until_burnchain_height(
1182+
// Sleep a bit to make sure the transactions are broadcast.
1183+
std::thread::sleep(Duration::from_secs(1));
1184+
// Mine a block and make sure the votes were mined
1185+
next_block_and_process_new_stacks_block(
11981186
&mut signer_test.running_nodes.btc_regtest_controller,
1199-
&signer_test.running_nodes.blocks_processed,
1200-
height.wrapping_add(1),
1201-
&signer_test.running_nodes.conf,
1202-
);
1187+
timeout.as_secs(),
1188+
&signer_test.running_nodes.coord_channel,
1189+
)
1190+
.unwrap();
1191+
12031192
// Make sure DKG did get set
12041193
assert_eq!(
12051194
key,

0 commit comments

Comments
 (0)