Skip to content

Commit a4597f5

Browse files
authored
Merge pull request #5237 from stacks-network/chore/fix-multiple-miners
Fix multiple_miners* tests
2 parents 3bd42e0 + db105e0 commit a4597f5

File tree

7 files changed

+154
-234
lines changed

7 files changed

+154
-234
lines changed

stacks-signer/src/client/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ pub enum ClientError {
8989
/// Invalid response from the stacks node
9090
#[error("Invalid response from the stacks node: {0}")]
9191
InvalidResponse(String),
92-
/// A successful sortition has not occurred yet
93-
#[error("The Stacks chain has not processed any successful sortitions yet")]
94-
NoSortitionOnChain,
9592
/// A successful sortition's info response should be parseable into a SortitionState
9693
#[error("A successful sortition's info response should be parseable into a SortitionState")]
9794
UnexpectedSortitionInfo,

stacks-signer/src/client/stacks_client.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use blockstack_lib::net::api::get_tenures_fork_info::{
3232
use blockstack_lib::net::api::getaccount::AccountEntryResponse;
3333
use blockstack_lib::net::api::getpoxinfo::RPCPoxInfoData;
3434
use blockstack_lib::net::api::getsortition::{SortitionInfo, RPC_SORTITION_INFO_PATH};
35-
use blockstack_lib::net::api::getstackers::{GetStackersErrors, GetStackersResponse};
35+
use blockstack_lib::net::api::getstackers::GetStackersResponse;
3636
use blockstack_lib::net::api::postblock::StacksBlockAcceptedData;
3737
use blockstack_lib::net::api::postblock_proposal::NakamotoBlockProposal;
3838
use blockstack_lib::net::api::postblock_v3;
@@ -80,7 +80,6 @@ pub struct StacksClient {
8080

8181
#[derive(Deserialize)]
8282
struct GetStackersErrorResp {
83-
err_type: String,
8483
err_msg: String,
8584
}
8685

@@ -485,14 +484,11 @@ impl StacksClient {
485484
warn!("Failed to parse the GetStackers error response: {e}");
486485
backoff::Error::permanent(e.into())
487486
})?;
488-
if error_data.err_type == GetStackersErrors::NOT_AVAILABLE_ERR_TYPE {
489-
Err(backoff::Error::permanent(ClientError::NoSortitionOnChain))
490-
} else {
491-
warn!("Got error response ({status}): {}", error_data.err_msg);
492-
Err(backoff::Error::permanent(ClientError::RequestFailure(
493-
status,
494-
)))
495-
}
487+
488+
warn!("Got error response ({status}): {}", error_data.err_msg);
489+
Err(backoff::Error::permanent(ClientError::RequestFailure(
490+
status,
491+
)))
496492
};
497493
let stackers_response =
498494
retry_with_exponential_backoff::<_, ClientError, GetStackersResponse>(send_request)?;

stacks-signer/src/v0/signer.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,16 @@ impl Signer {
512512
.signer_db
513513
.block_lookup(self.reward_cycle, &signer_signature_hash)
514514
{
515-
Ok(Some(block_info)) => block_info,
515+
Ok(Some(block_info)) => {
516+
if block_info.state == BlockState::GloballyRejected
517+
|| block_info.state == BlockState::GloballyAccepted
518+
{
519+
debug!("{self}: Received block validation for a block that is already marked as {}. Ignoring...", block_info.state);
520+
return None;
521+
} else {
522+
block_info
523+
}
524+
}
516525
Ok(None) => {
517526
// We have not seen this block before. Why are we getting a response for it?
518527
debug!("{self}: Received a block validate response for a block we have not seen before. Ignoring...");

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,12 @@ fn microblocks_disabled() {
211211
);
212212
assert_eq!(account.nonce, 1);
213213

214-
info!(
215-
"Microblocks assembled: {}",
216-
test_observer::get_microblocks().len()
214+
let microblocks_assembled = test_observer::get_microblocks().len();
215+
info!("Microblocks assembled: {microblocks_assembled}",);
216+
assert!(
217+
microblocks_assembled > 0,
218+
"There should be at least 1 microblock assembled"
217219
);
218-
assert_eq!(test_observer::get_microblocks().len(), 1);
219220

220221
let miner_nonce_before_microblock_assembly = get_account(&http_origin, &miner_account).nonce;
221222

@@ -244,8 +245,8 @@ fn microblocks_disabled() {
244245
);
245246
assert_eq!(account.nonce, 1);
246247

247-
// but we should have assembled and announced at least 1 to the observer
248-
assert!(test_observer::get_microblocks().len() >= 2);
248+
// but we should have assembled and announced at least 1 more block to the observer
249+
assert!(test_observer::get_microblocks().len() > microblocks_assembled);
249250
info!(
250251
"Microblocks assembled: {}",
251252
test_observer::get_microblocks().len()

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

Lines changed: 1 addition & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,69 +1155,6 @@ pub fn is_key_set_for_cycle(
11551155
Ok(key.is_some())
11561156
}
11571157

1158-
fn signer_vote_if_needed(
1159-
btc_regtest_controller: &BitcoinRegtestController,
1160-
naka_conf: &Config,
1161-
signer_sks: &[StacksPrivateKey], // TODO: Is there some way to get this from the TestSigners?
1162-
signers: &TestSigners,
1163-
) {
1164-
// When we reach the next prepare phase, submit new voting transactions
1165-
let block_height = btc_regtest_controller.get_headers_height();
1166-
let reward_cycle = btc_regtest_controller
1167-
.get_burnchain()
1168-
.block_height_to_reward_cycle(block_height)
1169-
.unwrap();
1170-
let prepare_phase_start = btc_regtest_controller
1171-
.get_burnchain()
1172-
.pox_constants
1173-
.prepare_phase_start(
1174-
btc_regtest_controller.get_burnchain().first_block_height,
1175-
reward_cycle,
1176-
);
1177-
1178-
if block_height >= prepare_phase_start {
1179-
// If the key is already set, do nothing.
1180-
if is_key_set_for_cycle(
1181-
reward_cycle + 1,
1182-
naka_conf.is_mainnet(),
1183-
&naka_conf.node.rpc_bind,
1184-
)
1185-
.unwrap_or(false)
1186-
{
1187-
return;
1188-
}
1189-
1190-
// If we are self-signing, then we need to vote on the aggregate public key
1191-
let http_origin = format!("http://{}", &naka_conf.node.rpc_bind);
1192-
1193-
// Get the aggregate key
1194-
let aggregate_key = signers.clone().generate_aggregate_key(reward_cycle + 1);
1195-
let aggregate_public_key = clarity::vm::Value::buff_from(aggregate_key)
1196-
.expect("Failed to serialize aggregate public key");
1197-
1198-
for (i, signer_sk) in signer_sks.iter().enumerate() {
1199-
let signer_nonce = get_account(&http_origin, &to_addr(signer_sk)).nonce;
1200-
1201-
// Vote on the aggregate public key
1202-
let voting_tx = tests::make_contract_call(
1203-
&signer_sk,
1204-
signer_nonce,
1205-
300,
1206-
&StacksAddress::burn_address(false),
1207-
SIGNERS_VOTING_NAME,
1208-
"vote-for-aggregate-public-key",
1209-
&[
1210-
clarity::vm::Value::UInt(i as u128),
1211-
aggregate_public_key.clone(),
1212-
clarity::vm::Value::UInt(0),
1213-
clarity::vm::Value::UInt(reward_cycle as u128 + 1),
1214-
],
1215-
);
1216-
submit_tx(&http_origin, &voting_tx);
1217-
}
1218-
}
1219-
}
1220-
12211158
pub fn setup_epoch_3_reward_set(
12221159
naka_conf: &Config,
12231160
blocks_processed: &Arc<AtomicU64>,
@@ -1553,13 +1490,6 @@ fn simple_neon_integration() {
15531490
&commits_submitted,
15541491
)
15551492
.unwrap();
1556-
1557-
signer_vote_if_needed(
1558-
&btc_regtest_controller,
1559-
&naka_conf,
1560-
&[sender_signer_sk],
1561-
&signers,
1562-
);
15631493
}
15641494

15651495
// Submit a TX
@@ -1595,13 +1525,6 @@ fn simple_neon_integration() {
15951525
&commits_submitted,
15961526
)
15971527
.unwrap();
1598-
1599-
signer_vote_if_needed(
1600-
&btc_regtest_controller,
1601-
&naka_conf,
1602-
&[sender_signer_sk],
1603-
&signers,
1604-
);
16051528
}
16061529

16071530
// load the chain tip, and assert that it is a nakamoto block and at least 30 blocks have advanced in epoch 3
@@ -1805,13 +1728,6 @@ fn simple_neon_integration_with_flash_blocks_on_epoch_3() {
18051728
&commits_submitted,
18061729
)
18071730
.unwrap();
1808-
1809-
signer_vote_if_needed(
1810-
&btc_regtest_controller,
1811-
&naka_conf,
1812-
&[sender_signer_sk],
1813-
&signers,
1814-
);
18151731
}
18161732

18171733
// Submit a TX
@@ -1847,13 +1763,6 @@ fn simple_neon_integration_with_flash_blocks_on_epoch_3() {
18471763
&commits_submitted,
18481764
)
18491765
.unwrap();
1850-
1851-
signer_vote_if_needed(
1852-
&btc_regtest_controller,
1853-
&naka_conf,
1854-
&[sender_signer_sk],
1855-
&signers,
1856-
);
18571766
}
18581767

18591768
// load the chain tip, and assert that it is a nakamoto block and at least 30 blocks have advanced in epoch 3
@@ -2144,6 +2053,7 @@ fn multiple_miners() {
21442053
let node_2_p2p = 51025;
21452054
let http_origin = format!("http://{}", &naka_conf.node.rpc_bind);
21462055
naka_conf.miner.wait_on_interim_blocks = Duration::from_secs(1);
2056+
naka_conf.node.pox_sync_sample_secs = 5;
21472057
let sender_sk = Secp256k1PrivateKey::new();
21482058
let sender_signer_sk = Secp256k1PrivateKey::new();
21492059
let sender_signer_addr = tests::to_addr(&sender_signer_sk);
@@ -2579,13 +2489,6 @@ fn correct_burn_outs() {
25792489
&naka_conf,
25802490
);
25812491

2582-
signer_vote_if_needed(
2583-
&btc_regtest_controller,
2584-
&naka_conf,
2585-
&[sender_signer_sk],
2586-
&signers,
2587-
);
2588-
25892492
run_until_burnchain_height(
25902493
&mut btc_regtest_controller,
25912494
&blocks_processed,
@@ -2645,13 +2548,6 @@ fn correct_burn_outs() {
26452548
tip_sn.block_height > prior_tip,
26462549
"The new burnchain tip must have been processed"
26472550
);
2648-
2649-
signer_vote_if_needed(
2650-
&btc_regtest_controller,
2651-
&naka_conf,
2652-
&[sender_signer_sk],
2653-
&signers,
2654-
);
26552551
}
26562552

26572553
coord_channel
@@ -4751,13 +4647,6 @@ fn forked_tenure_is_ignored() {
47514647
})
47524648
.unwrap();
47534649

4754-
signer_vote_if_needed(
4755-
&btc_regtest_controller,
4756-
&naka_conf,
4757-
&[sender_signer_sk],
4758-
&signers,
4759-
);
4760-
47614650
info!("Commit op is submitted; unpause Tenure B's block");
47624651

47634652
// Unpause the broadcast of Tenure B's block, do not submit commits, and do not allow blocks to
@@ -6198,13 +6087,6 @@ fn signer_chainstate() {
61986087
make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt);
61996088
submit_tx(&http_origin, &transfer_tx);
62006089

6201-
signer_vote_if_needed(
6202-
&btc_regtest_controller,
6203-
&naka_conf,
6204-
&[sender_signer_sk],
6205-
&signers,
6206-
);
6207-
62086090
let timer = Instant::now();
62096091
while proposals_submitted.load(Ordering::SeqCst) <= before {
62106092
thread::sleep(Duration::from_millis(5));
@@ -6681,13 +6563,6 @@ fn continue_tenure_extend() {
66816563
)
66826564
.unwrap();
66836565

6684-
signer_vote_if_needed(
6685-
&btc_regtest_controller,
6686-
&naka_conf,
6687-
&[sender_signer_sk],
6688-
&signers,
6689-
);
6690-
66916566
wait_for(5, || {
66926567
let blocks_processed = coord_channel
66936568
.lock()
@@ -6707,13 +6582,6 @@ fn continue_tenure_extend() {
67076582

67086583
next_block_and(&mut btc_regtest_controller, 60, || Ok(true)).unwrap();
67096584

6710-
signer_vote_if_needed(
6711-
&btc_regtest_controller,
6712-
&naka_conf,
6713-
&[sender_signer_sk],
6714-
&signers,
6715-
);
6716-
67176585
wait_for(5, || {
67186586
let blocks_processed = coord_channel
67196587
.lock()
@@ -6755,13 +6623,6 @@ fn continue_tenure_extend() {
67556623
next_block_and_process_new_stacks_block(&mut btc_regtest_controller, 60, &coord_channel)
67566624
.unwrap();
67576625

6758-
signer_vote_if_needed(
6759-
&btc_regtest_controller,
6760-
&naka_conf,
6761-
&[sender_signer_sk],
6762-
&signers,
6763-
);
6764-
67656626
wait_for(5, || {
67666627
let blocks_processed = coord_channel
67676628
.lock()
@@ -6778,13 +6639,6 @@ fn continue_tenure_extend() {
67786639

67796640
next_block_and(&mut btc_regtest_controller, 60, || Ok(true)).unwrap();
67806641

6781-
signer_vote_if_needed(
6782-
&btc_regtest_controller,
6783-
&naka_conf,
6784-
&[sender_signer_sk],
6785-
&signers,
6786-
);
6787-
67886642
wait_for(5, || {
67896643
let blocks_processed = coord_channel
67906644
.lock()
@@ -6810,13 +6664,6 @@ fn continue_tenure_extend() {
68106664
})
68116665
.unwrap();
68126666

6813-
signer_vote_if_needed(
6814-
&btc_regtest_controller,
6815-
&naka_conf,
6816-
&[sender_signer_sk],
6817-
&signers,
6818-
);
6819-
68206667
wait_for(5, || {
68216668
let blocks_processed = coord_channel
68226669
.lock()

0 commit comments

Comments
 (0)