Skip to content

Commit 4f6b190

Browse files
committed
chore: force require anchor blocks
1 parent fb306ea commit 4f6b190

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

stackslib/src/chainstate/coordinator/mod.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ pub trait BlockEventDispatcher {
198198
}
199199

200200
pub struct ChainsCoordinatorConfig {
201+
/// true: assume all anchor blocks are present, and block chain sync until they arrive
202+
/// false: process sortitions in reward cycles without anchor blocks
203+
pub assume_present_anchor_blocks: bool,
201204
/// true: use affirmation maps before 2.1
202205
/// false: only use affirmation maps in 2.1 or later
203206
pub always_use_affirmation_maps: bool,
@@ -209,8 +212,9 @@ pub struct ChainsCoordinatorConfig {
209212
impl ChainsCoordinatorConfig {
210213
pub fn new() -> ChainsCoordinatorConfig {
211214
ChainsCoordinatorConfig {
212-
always_use_affirmation_maps: false,
215+
always_use_affirmation_maps: true,
213216
require_affirmed_anchor_blocks: true,
217+
assume_present_anchor_blocks: true,
214218
}
215219
}
216220
}
@@ -2336,6 +2340,20 @@ impl<
23362340
panic!("BUG: no epoch defined at height {}", header.block_height)
23372341
});
23382342

2343+
if self.config.assume_present_anchor_blocks {
2344+
// anchor blocks are always assumed to be present in the chain history,
2345+
// so report its absence if we don't have it.
2346+
if let PoxAnchorBlockStatus::SelectedAndUnknown(missing_anchor_block, _) =
2347+
&rc_info.anchor_status
2348+
{
2349+
info!(
2350+
"Currently missing PoX anchor block {}, which is assumed to be present",
2351+
&missing_anchor_block
2352+
);
2353+
return Ok(Some(missing_anchor_block.clone()));
2354+
}
2355+
}
2356+
23392357
if cur_epoch.epoch_id >= StacksEpochId::Epoch21 || self.config.always_use_affirmation_maps {
23402358
// potentially have an anchor block, but only process the next reward cycle (and
23412359
// subsequent reward cycles) with it if the prepare-phase block-commits affirm its

testnet/stacks-node/src/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,7 @@ pub struct NodeConfig {
16381638
pub use_test_genesis_chainstate: Option<bool>,
16391639
pub always_use_affirmation_maps: bool,
16401640
pub require_affirmed_anchor_blocks: bool,
1641+
pub assume_present_anchor_blocks: bool,
16411642
/// Fault injection for failing to push blocks
16421643
pub fault_injection_block_push_fail_probability: Option<u8>,
16431644
// fault injection for hiding blocks.
@@ -1921,6 +1922,7 @@ impl Default for NodeConfig {
19211922
use_test_genesis_chainstate: None,
19221923
always_use_affirmation_maps: true,
19231924
require_affirmed_anchor_blocks: true,
1925+
assume_present_anchor_blocks: true,
19241926
fault_injection_block_push_fail_probability: None,
19251927
fault_injection_hide_blocks: false,
19261928
chain_liveness_poll_time_secs: 300,
@@ -2393,6 +2395,7 @@ pub struct NodeConfigFile {
23932395
pub use_test_genesis_chainstate: Option<bool>,
23942396
pub always_use_affirmation_maps: Option<bool>,
23952397
pub require_affirmed_anchor_blocks: Option<bool>,
2398+
pub assume_present_anchor_blocks: Option<bool>,
23962399
/// At most, how often should the chain-liveness thread
23972400
/// wake up the chains-coordinator. Defaults to 300s (5 min).
23982401
pub chain_liveness_poll_time_secs: Option<u64>,
@@ -2474,6 +2477,10 @@ impl NodeConfigFile {
24742477
// miners should always try to mine, even if they don't have the anchored
24752478
// blocks in the canonical affirmation map. Followers, however, can stall.
24762479
require_affirmed_anchor_blocks: self.require_affirmed_anchor_blocks.unwrap_or(!miner),
2480+
// as of epoch 3.0, all prepare phases have anchor blocks.
2481+
// at the start of epoch 3.0, the chain stalls without anchor blocks.
2482+
// only set this to false if you're doing some very extreme testing.
2483+
assume_present_anchor_blocks: true,
24772484
// chainstate fault_injection activation for hide_blocks.
24782485
// you can't set this in the config file.
24792486
fault_injection_hide_blocks: false,

testnet/stacks-node/src/run_loop/nakamoto.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ impl RunLoop {
319319
let mut fee_estimator = moved_config.make_fee_estimator();
320320

321321
let coord_config = ChainsCoordinatorConfig {
322+
assume_present_anchor_blocks: moved_config.node.assume_present_anchor_blocks,
322323
always_use_affirmation_maps: moved_config.node.always_use_affirmation_maps,
323324
require_affirmed_anchor_blocks: moved_config
324325
.node

testnet/stacks-node/src/run_loop/neon.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ impl RunLoop {
625625
let mut fee_estimator = moved_config.make_fee_estimator();
626626

627627
let coord_config = ChainsCoordinatorConfig {
628+
assume_present_anchor_blocks: moved_config.node.assume_present_anchor_blocks,
628629
always_use_affirmation_maps: moved_config.node.always_use_affirmation_maps,
629630
require_affirmed_anchor_blocks: moved_config
630631
.node

0 commit comments

Comments
 (0)