Skip to content

Commit

Permalink
Merge pull request #5299 from stacks-network/chore/fix-multiple-miners-2
Browse files Browse the repository at this point in the history
Fix boot to epoch 3 calls to retrieve the stacker set and fix multple miners test
  • Loading branch information
kantai authored Oct 10, 2024
2 parents f9e735b + e7a8fff commit 6d60dad
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
38 changes: 25 additions & 13 deletions testnet/stacks-node/src/tests/nakamoto_integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,18 +255,17 @@ pub fn check_nakamoto_empty_block_heuristics() {
}
}

pub fn get_stacker_set(http_origin: &str, cycle: u64) -> GetStackersResponse {
pub fn get_stacker_set(http_origin: &str, cycle: u64) -> Result<GetStackersResponse, String> {
let client = reqwest::blocking::Client::new();
let path = format!("{http_origin}/v3/stacker_set/{cycle}");
let res = client
.get(&path)
.send()
.unwrap()
.json::<serde_json::Value>()
.unwrap();
.map_err(|e| format!("{e}"))?;
info!("Stacker set response: {res}");
let res = serde_json::from_value(res).unwrap();
res
serde_json::from_value(res).map_err(|e| format!("{e}"))
}

pub fn get_stackerdb_slot_version(
Expand Down Expand Up @@ -886,19 +885,21 @@ pub fn boot_to_epoch_3(
signers.signer_keys = signer_sks.to_vec();
}

let prepare_phase_start = btc_regtest_controller
// the reward set is generally calculated in the first block of the prepare phase hence the + 1
let reward_set_calculation = btc_regtest_controller
.get_burnchain()
.pox_constants
.prepare_phase_start(
btc_regtest_controller.get_burnchain().first_block_height,
reward_cycle,
);
)
+ 1;

// Run until the prepare phase
run_until_burnchain_height(
btc_regtest_controller,
&blocks_processed,
prepare_phase_start,
reward_set_calculation,
&naka_conf,
);

Expand All @@ -909,7 +910,11 @@ pub fn boot_to_epoch_3(
let aggregate_public_key = clarity::vm::Value::buff_from(aggregate_key)
.expect("Failed to serialize aggregate public key");
let signer_sks_unique: HashMap<_, _> = signer_sks.iter().map(|x| (x.to_hex(), x)).collect();
let signer_set = get_stacker_set(&http_origin, reward_cycle + 1);
wait_for(30, || {
Ok(get_stacker_set(&http_origin, reward_cycle + 1).is_ok())
})
.expect("Timed out waiting for stacker set");
let signer_set = get_stacker_set(&http_origin, reward_cycle + 1).unwrap();
// Vote on the aggregate public key
for signer_sk in signer_sks_unique.values() {
let signer_index =
Expand Down Expand Up @@ -1040,19 +1045,21 @@ pub fn boot_to_pre_epoch_3_boundary(
signers.signer_keys = signer_sks.to_vec();
}

let prepare_phase_start = btc_regtest_controller
// the reward set is generally calculated in the first block of the prepare phase hence the + 1
let reward_set_calculation = btc_regtest_controller
.get_burnchain()
.pox_constants
.prepare_phase_start(
btc_regtest_controller.get_burnchain().first_block_height,
reward_cycle,
);
)
+ 1;

// Run until the prepare phase
run_until_burnchain_height(
btc_regtest_controller,
&blocks_processed,
prepare_phase_start,
reward_set_calculation,
&naka_conf,
);

Expand All @@ -1063,7 +1070,11 @@ pub fn boot_to_pre_epoch_3_boundary(
let aggregate_public_key = clarity::vm::Value::buff_from(aggregate_key)
.expect("Failed to serialize aggregate public key");
let signer_sks_unique: HashMap<_, _> = signer_sks.iter().map(|x| (x.to_hex(), x)).collect();
let signer_set = get_stacker_set(&http_origin, reward_cycle + 1);
wait_for(30, || {
Ok(get_stacker_set(&http_origin, reward_cycle + 1).is_ok())
})
.expect("Timed out waiting for stacker set");
let signer_set = get_stacker_set(&http_origin, reward_cycle + 1).unwrap();
// Vote on the aggregate public key
for signer_sk in signer_sks_unique.values() {
let signer_index =
Expand Down Expand Up @@ -2566,7 +2577,7 @@ fn correct_burn_outs() {
info!("first_epoch_3_cycle: {:?}", first_epoch_3_cycle);

let http_origin = format!("http://{}", &naka_conf.node.rpc_bind);
let stacker_response = get_stacker_set(&http_origin, first_epoch_3_cycle);
let stacker_response = get_stacker_set(&http_origin, first_epoch_3_cycle).unwrap();
assert!(stacker_response.stacker_set.signers.is_some());
assert_eq!(
stacker_response.stacker_set.signers.as_ref().unwrap().len(),
Expand Down Expand Up @@ -8179,6 +8190,7 @@ fn mock_mining() {

let (mut naka_conf, _miner_account) = naka_neon_integration_conf(None);
naka_conf.miner.wait_on_interim_blocks = Duration::from_secs(1);
naka_conf.node.pox_sync_sample_secs = 5;
let sender_sk = Secp256k1PrivateKey::new();
let sender_signer_sk = Secp256k1PrivateKey::new();
let sender_signer_addr = tests::to_addr(&sender_signer_sk);
Expand Down
11 changes: 0 additions & 11 deletions testnet/stacks-node/src/tests/neon_integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ use stacks::net::api::getaccount::AccountEntryResponse;
use stacks::net::api::getcontractsrc::ContractSrcResponse;
use stacks::net::api::getinfo::RPCPeerInfoData;
use stacks::net::api::getpoxinfo::RPCPoxInfoData;
use stacks::net::api::getstackers::GetStackersResponse;
use stacks::net::api::gettransaction_unconfirmed::UnconfirmedTransactionResponse;
use stacks::net::api::postblock::StacksBlockAcceptedData;
use stacks::net::api::postfeerate::RPCFeeEstimateResponse;
Expand Down Expand Up @@ -1437,16 +1436,6 @@ pub fn get_contract_src(
}
}

pub fn get_stacker_set(http_origin: &str, reward_cycle: u64) -> GetStackersResponse {
let client = reqwest::blocking::Client::new();
let path = format!("{}/v3/stacker_set/{}", http_origin, reward_cycle);
let res = client.get(&path).send().unwrap();

info!("Got stacker_set response {:?}", &res);
let res = res.json::<GetStackersResponse>().unwrap();
res
}

#[test]
#[ignore]
fn deep_contract() {
Expand Down

0 comments on commit 6d60dad

Please sign in to comment.