Skip to content

Commit 69eb7ac

Browse files
committed
fix: use a real signer to verify that we can resume mining atop shadow blocks
1 parent 439abdb commit 69eb7ac

File tree

3 files changed

+14
-81
lines changed

3 files changed

+14
-81
lines changed

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

Lines changed: 11 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ use stacks_common::util::secp256k1::{MessageSignature, Secp256k1PrivateKey, Secp
9191
use stacks_common::util::{get_epoch_time_secs, sleep_ms};
9292
use stacks_signer::chainstate::{ProposalEvalConfig, SortitionsView};
9393
use stacks_signer::signerdb::{BlockInfo, BlockState, ExtraBlockInfo, SignerDb};
94+
use stacks_signer::v0::SpawnedSigner;
9495

9596
use super::bitcoin_regtest::BitcoinCoreController;
9697
use crate::config::{EventKeyType, InitialBalance};
@@ -105,6 +106,7 @@ use crate::tests::neon_integrations::{
105106
get_neighbors, get_pox_info, next_block_and_wait, run_until_burnchain_height, submit_tx,
106107
test_observer, wait_for_runloop,
107108
};
109+
use crate::tests::signer::SignerTest;
108110
use crate::tests::{
109111
gen_random_port, get_chain_info, make_contract_publish, make_contract_publish_versioned,
110112
make_stacks_transfer, to_addr,
@@ -9605,87 +9607,19 @@ fn test_shadow_recovery() {
96059607
return;
96069608
}
96079609

9608-
let (mut naka_conf, _miner_account) = naka_neon_integration_conf(None);
9609-
let http_origin = format!("http://{}", &naka_conf.node.rpc_bind);
9610-
naka_conf.miner.wait_on_interim_blocks = Duration::from_secs(1);
9611-
let sender_sk = Secp256k1PrivateKey::new();
9612-
let sender_signer_sk = Secp256k1PrivateKey::new();
9613-
let sender_signer_addr = tests::to_addr(&sender_signer_sk);
9614-
// setup sender + recipient for some test stx transfers
9615-
// these are necessary for the interim blocks to get mined at all
9616-
let sender_addr = tests::to_addr(&sender_sk);
9617-
let send_amt = 100;
9618-
let send_fee = 180;
9619-
naka_conf.add_initial_balance(PrincipalData::from(sender_addr.clone()).to_string(), 100000);
9620-
naka_conf.add_initial_balance(
9621-
PrincipalData::from(sender_signer_addr.clone()).to_string(),
9622-
100000,
9623-
);
9624-
let recipient = PrincipalData::from(StacksAddress::burn_address(false));
9625-
let stacker_sk = setup_stacker(&mut naka_conf);
9610+
let mut signer_test: SignerTest<SpawnedSigner> = SignerTest::new(1, vec![]);
9611+
signer_test.boot_to_epoch_3();
96269612

9627-
test_observer::spawn();
9628-
test_observer::register_any(&mut naka_conf);
9629-
9630-
let mut btcd_controller = BitcoinCoreController::new(naka_conf.clone());
9631-
btcd_controller
9632-
.start_bitcoind()
9633-
.expect("Failed starting bitcoind");
9634-
let mut btc_regtest_controller = BitcoinRegtestController::new(naka_conf.clone(), None);
9635-
btc_regtest_controller.bootstrap_chain(201);
9636-
9637-
let mut run_loop = boot_nakamoto::BootRunLoop::new(naka_conf.clone()).unwrap();
9638-
let run_loop_stopper = run_loop.get_termination_switch();
9639-
let Counters {
9640-
blocks_processed,
9641-
naka_submitted_commits: commits_submitted,
9642-
naka_proposed_blocks: proposals_submitted,
9643-
..
9644-
} = run_loop.counters();
9645-
9646-
let coord_channel = run_loop.coordinator_channels();
9647-
9648-
let run_loop_thread = thread::Builder::new()
9649-
.name("run_loop".into())
9650-
.spawn(move || run_loop.start(None, 0))
9651-
.unwrap();
9652-
wait_for_runloop(&blocks_processed);
9653-
let mut signers = TestSigners::new(vec![sender_signer_sk.clone()]);
9654-
boot_to_epoch_3(
9655-
&naka_conf,
9656-
&blocks_processed,
9657-
&[stacker_sk],
9658-
&[sender_signer_sk],
9659-
&mut Some(&mut signers),
9660-
&mut btc_regtest_controller,
9661-
);
9662-
9663-
info!("Bootstrapped to Epoch-3.0 boundary, starting nakamoto miner");
9613+
let naka_conf = signer_test.running_nodes.conf.clone();
9614+
let btc_regtest_controller = &mut signer_test.running_nodes.btc_regtest_controller;
9615+
let coord_channel = signer_test.running_nodes.coord_channel.clone();
9616+
let commits_submitted = signer_test.running_nodes.commits_submitted.clone();
96649617

96659618
let burnchain = naka_conf.get_burnchain();
9666-
let sortdb = burnchain.open_sortition_db(true).unwrap();
9667-
let (chainstate, _) = StacksChainState::open(
9668-
naka_conf.is_mainnet(),
9669-
naka_conf.burnchain.chain_id,
9670-
&naka_conf.get_chainstate_path_str(),
9671-
None,
9672-
)
9673-
.unwrap();
9674-
9675-
let block_height_pre_3_0 =
9676-
NakamotoChainState::get_canonical_block_header(chainstate.db(), &sortdb)
9677-
.unwrap()
9678-
.unwrap()
9679-
.stacks_block_height;
9680-
9681-
info!("Nakamoto miner started...");
9682-
blind_signer(&naka_conf, &signers, proposals_submitted);
9683-
9684-
wait_for_first_naka_block_commit(60, &commits_submitted);
96859619

96869620
// make another tenure
96879621
next_block_and_mine_commit(
9688-
&mut btc_regtest_controller,
9622+
btc_regtest_controller,
96899623
60,
96909624
&coord_channel,
96919625
&commits_submitted,
@@ -9736,7 +9670,6 @@ fn test_shadow_recovery() {
97369670
})
97379671
.unwrap();
97389672

9739-
let burn_height_after = get_chain_info(&naka_conf).burn_block_height;
97409673
let stacks_height_before = get_chain_info(&naka_conf).stacks_tip_height;
97419674

97429675
// fix node
@@ -9753,14 +9686,14 @@ fn test_shadow_recovery() {
97539686
.unwrap();
97549687

97559688
// revive ATC-C by waiting for commits
9756-
for i in 0..4 {
9689+
for _i in 0..4 {
97579690
btc_regtest_controller.bootstrap_chain(1);
97589691
sleep_ms(30_000);
97599692
}
97609693

97619694
// make another tenure
97629695
next_block_and_mine_commit(
9763-
&mut btc_regtest_controller,
9696+
btc_regtest_controller,
97649697
60,
97659698
&coord_channel,
97669699
&commits_submitted,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub struct SignerTest<S> {
112112
}
113113

114114
impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<SpawnedSigner<S, T>> {
115-
fn new(num_signers: usize, initial_balances: Vec<(StacksAddress, u64)>) -> Self {
115+
pub fn new(num_signers: usize, initial_balances: Vec<(StacksAddress, u64)>) -> Self {
116116
Self::new_with_config_modifications(
117117
num_signers,
118118
initial_balances,
@@ -123,7 +123,7 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
123123
)
124124
}
125125

126-
fn new_with_config_modifications<
126+
pub fn new_with_config_modifications<
127127
F: FnMut(&mut SignerConfig) -> (),
128128
G: FnMut(&mut NeonConfig) -> (),
129129
>(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl SignerTest<SpawnedSigner> {
227227
}
228228

229229
/// Run the test until the epoch 3 boundary
230-
fn boot_to_epoch_3(&mut self) {
230+
pub fn boot_to_epoch_3(&mut self) {
231231
boot_to_epoch_3_reward_set(
232232
&self.running_nodes.conf,
233233
&self.running_nodes.blocks_processed,

0 commit comments

Comments
 (0)