Skip to content

Commit 284945b

Browse files
authored
Merge pull request #4561 from stacks-network/feat/2.5-no-microblocks
Disable Microblocks in Epoch 2.5
2 parents d5414a2 + c9a97cb commit 284945b

File tree

11 files changed

+443
-59
lines changed

11 files changed

+443
-59
lines changed

.github/workflows/bitcoin-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ jobs:
7272
- tests::neon_integrations::confirm_unparsed_ongoing_ops
7373
- tests::neon_integrations::min_txs
7474
- tests::neon_integrations::vote_for_aggregate_key_burn_op_test
75+
- tests::epoch_25::microblocks_disabled
7576
- tests::should_succeed_handling_malformed_and_valid_txs
7677
- tests::nakamoto_integrations::simple_neon_integration
7778
- tests::nakamoto_integrations::mine_multiple_per_tenure_integration

stackslib/src/chainstate/burn/db/sortdb.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5088,6 +5088,18 @@ impl SortitionDB {
50885088
query_row(conn, sql, args)
50895089
}
50905090

5091+
/// Are microblocks disabled by Epoch 2.5 at the height specified
5092+
/// in `at_burn_height`?
5093+
pub fn are_microblocks_disabled(conn: &DBConn, at_burn_height: u64) -> Result<bool, db_error> {
5094+
match Self::get_stacks_epoch_by_epoch_id(conn, &StacksEpochId::Epoch25)? {
5095+
Some(epoch_25) => Ok(at_burn_height >= epoch_25.start_height),
5096+
None => {
5097+
// Epoch 2.5 is not defined, so it cannot disable microblocks
5098+
Ok(false)
5099+
}
5100+
}
5101+
}
5102+
50915103
/// Get the last reward cycle in epoch 2.05
50925104
pub fn get_last_epoch_2_05_reward_cycle(&self) -> Result<u64, db_error> {
50935105
Self::static_get_last_epoch_2_05_reward_cycle(

stackslib/src/chainstate/coordinator/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ fn make_genesis_block_with_recipients(
663663
.unwrap();
664664

665665
let iconn = sort_db.index_conn();
666-
let mut miner_epoch_info = builder.pre_epoch_begin(state, &iconn).unwrap();
666+
let mut miner_epoch_info = builder.pre_epoch_begin(state, &iconn, true).unwrap();
667667
let ast_rules = miner_epoch_info.ast_rules.clone();
668668
let mut epoch_tx = builder
669669
.epoch_begin(&iconn, &mut miner_epoch_info)
@@ -926,7 +926,7 @@ fn make_stacks_block_with_input(
926926
next_hash160(),
927927
)
928928
.unwrap();
929-
let mut miner_epoch_info = builder.pre_epoch_begin(state, &iconn).unwrap();
929+
let mut miner_epoch_info = builder.pre_epoch_begin(state, &iconn, true).unwrap();
930930
let ast_rules = miner_epoch_info.ast_rules.clone();
931931
let mut epoch_tx = builder
932932
.epoch_begin(&iconn, &mut miner_epoch_info)

stackslib/src/chainstate/stacks/db/blocks.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6075,6 +6075,40 @@ impl StacksChainState {
60756075
}
60766076
};
60776077

6078+
let microblocks_disabled_by_epoch_25 =
6079+
SortitionDB::are_microblocks_disabled(sort_tx.tx(), u64::from(burn_header_height))?;
6080+
6081+
// microblocks are not allowed after Epoch 2.5 starts
6082+
if microblocks_disabled_by_epoch_25 {
6083+
if next_staging_block.parent_microblock_seq != 0
6084+
|| next_staging_block.parent_microblock_hash != BlockHeaderHash([0; 32])
6085+
{
6086+
let msg = format!(
6087+
"Invalid stacks block {}/{} ({}). Confirms microblocks after Epoch 2.5 start.",
6088+
&next_staging_block.consensus_hash,
6089+
&next_staging_block.anchored_block_hash,
6090+
&StacksBlockId::new(
6091+
&next_staging_block.consensus_hash,
6092+
&next_staging_block.anchored_block_hash
6093+
),
6094+
);
6095+
warn!("{msg}");
6096+
6097+
// clear out
6098+
StacksChainState::set_block_processed(
6099+
chainstate_tx.deref_mut(),
6100+
None,
6101+
&blocks_path,
6102+
&next_staging_block.consensus_hash,
6103+
&next_staging_block.anchored_block_hash,
6104+
false,
6105+
)?;
6106+
chainstate_tx.commit().map_err(Error::DBError)?;
6107+
6108+
return Err(Error::InvalidStacksBlock(msg));
6109+
}
6110+
}
6111+
60786112
debug!(
60796113
"Process staging block {}/{} in burn block {}, parent microblock {}",
60806114
next_staging_block.consensus_hash,

stackslib/src/chainstate/stacks/miner.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ pub struct BlockBuilderSettings {
165165
pub max_miner_time_ms: u64,
166166
pub mempool_settings: MemPoolWalkSettings,
167167
pub miner_status: Arc<Mutex<MinerStatus>>,
168+
/// Should the builder attempt to confirm any parent microblocks
169+
pub confirm_microblocks: bool,
168170
}
169171

170172
impl BlockBuilderSettings {
@@ -173,6 +175,7 @@ impl BlockBuilderSettings {
173175
max_miner_time_ms: u64::MAX,
174176
mempool_settings: MemPoolWalkSettings::default(),
175177
miner_status: Arc::new(Mutex::new(MinerStatus::make_ready(0))),
178+
confirm_microblocks: true,
176179
}
177180
}
178181

@@ -181,6 +184,7 @@ impl BlockBuilderSettings {
181184
max_miner_time_ms: u64::MAX,
182185
mempool_settings: MemPoolWalkSettings::zero(),
183186
miner_status: Arc::new(Mutex::new(MinerStatus::make_ready(0))),
187+
confirm_microblocks: true,
184188
}
185189
}
186190
}
@@ -1800,6 +1804,7 @@ impl StacksBlockBuilder {
18001804
&mut self,
18011805
chainstate: &'a mut StacksChainState,
18021806
burn_dbconn: &'a SortitionDBConn,
1807+
confirm_microblocks: bool,
18031808
) -> Result<MinerEpochInfo<'a>, Error> {
18041809
debug!(
18051810
"Miner epoch begin";
@@ -1830,7 +1835,10 @@ impl StacksBlockBuilder {
18301835
)
18311836
.expect("FATAL: more than 2^32 sortitions");
18321837

1833-
let parent_microblocks = if StacksChainState::block_crosses_epoch_boundary(
1838+
let parent_microblocks = if !confirm_microblocks {
1839+
debug!("Block assembly invoked with confirm_microblocks = false. Will not confirm any microblocks.");
1840+
vec![]
1841+
} else if StacksChainState::block_crosses_epoch_boundary(
18341842
chainstate.db(),
18351843
&self.parent_consensus_hash,
18361844
&self.parent_header_hash,
@@ -1991,7 +1999,7 @@ impl StacksBlockBuilder {
19911999
) -> Result<(StacksBlock, u64, ExecutionCost, Option<StacksMicroblock>), Error> {
19922000
debug!("Build anchored block from {} transactions", txs.len());
19932001
let (mut chainstate, _) = chainstate_handle.reopen()?;
1994-
let mut miner_epoch_info = builder.pre_epoch_begin(&mut chainstate, burn_dbconn)?;
2002+
let mut miner_epoch_info = builder.pre_epoch_begin(&mut chainstate, burn_dbconn, true)?;
19952003
let ast_rules = miner_epoch_info.ast_rules;
19962004
let (mut epoch_tx, _) = builder.epoch_begin(burn_dbconn, &mut miner_epoch_info)?;
19972005
for tx in txs.drain(..) {
@@ -2416,9 +2424,14 @@ impl StacksBlockBuilder {
24162424
pubkey_hash,
24172425
)?;
24182426

2427+
if !settings.confirm_microblocks {
2428+
builder.parent_microblock_hash = None;
2429+
}
2430+
24192431
let ts_start = get_epoch_time_ms();
24202432

2421-
let mut miner_epoch_info = builder.pre_epoch_begin(&mut chainstate, burn_dbconn)?;
2433+
let mut miner_epoch_info =
2434+
builder.pre_epoch_begin(&mut chainstate, burn_dbconn, settings.confirm_microblocks)?;
24222435
let ast_rules = miner_epoch_info.ast_rules;
24232436
if ast_rules != ASTRules::Typical {
24242437
builder.header.version = cmp::max(

stackslib/src/chainstate/stacks/tests/chain_histories.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ where
152152

153153
let sort_iconn = sortdb.index_conn();
154154
let mut miner_epoch_info = builder
155-
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn)
155+
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn, true)
156156
.unwrap();
157157
let mut epoch = builder
158158
.epoch_begin(&sort_iconn, &mut miner_epoch_info)
@@ -338,7 +338,7 @@ where
338338

339339
let sort_iconn = sortdb.index_conn();
340340
let mut miner_epoch_info = builder
341-
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn)
341+
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn, true)
342342
.unwrap();
343343
let mut epoch = builder
344344
.epoch_begin(&sort_iconn, &mut miner_epoch_info)
@@ -485,7 +485,7 @@ where
485485

486486
let sort_iconn = sortdb.index_conn();
487487
let mut miner_epoch_info = builder
488-
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn)
488+
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn, true)
489489
.unwrap();
490490
let mut epoch = builder
491491
.epoch_begin(&sort_iconn, &mut miner_epoch_info)
@@ -533,7 +533,7 @@ where
533533

534534
let sort_iconn = sortdb.index_conn();
535535
let mut miner_epoch_info = builder
536-
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn)
536+
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn, true)
537537
.unwrap();
538538
let mut epoch = builder
539539
.epoch_begin(&sort_iconn, &mut miner_epoch_info)
@@ -822,7 +822,7 @@ where
822822

823823
let sort_iconn = sortdb.index_conn();
824824
let mut miner_epoch_info = builder
825-
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn)
825+
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn, true)
826826
.unwrap();
827827
let mut epoch = builder
828828
.epoch_begin(&sort_iconn, &mut miner_epoch_info)
@@ -870,7 +870,7 @@ where
870870

871871
let sort_iconn = sortdb.index_conn();
872872
let mut miner_epoch_info = builder
873-
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn)
873+
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn, true)
874874
.unwrap();
875875
let mut epoch = builder
876876
.epoch_begin(&sort_iconn, &mut miner_epoch_info)
@@ -1087,7 +1087,7 @@ where
10871087

10881088
let sort_iconn = sortdb.index_conn();
10891089
let mut miner_epoch_info = builder
1090-
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn)
1090+
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn, true)
10911091
.unwrap();
10921092
let mut epoch = builder
10931093
.epoch_begin(&sort_iconn, &mut miner_epoch_info)
@@ -1136,7 +1136,7 @@ where
11361136

11371137
let sort_iconn = sortdb.index_conn();
11381138
let mut miner_epoch_info = builder
1139-
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn)
1139+
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn, true)
11401140
.unwrap();
11411141
let mut epoch = builder
11421142
.epoch_begin(&sort_iconn, &mut miner_epoch_info)
@@ -1435,7 +1435,7 @@ where
14351435

14361436
let sort_iconn = sortdb.index_conn();
14371437
let mut miner_epoch_info = builder
1438-
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn)
1438+
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn, true)
14391439
.unwrap();
14401440
let mut epoch = builder
14411441
.epoch_begin(&sort_iconn, &mut miner_epoch_info)
@@ -1480,7 +1480,7 @@ where
14801480

14811481
let sort_iconn = sortdb.index_conn();
14821482
let mut miner_epoch_info = builder
1483-
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn)
1483+
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn, true)
14841484
.unwrap();
14851485
let mut epoch = builder
14861486
.epoch_begin(&sort_iconn, &mut miner_epoch_info)
@@ -1682,7 +1682,7 @@ where
16821682

16831683
let sort_iconn = sortdb.index_conn();
16841684
let mut miner_epoch_info = builder
1685-
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn)
1685+
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn, true)
16861686
.unwrap();
16871687
let mut epoch = builder
16881688
.epoch_begin(&sort_iconn, &mut miner_epoch_info)
@@ -1730,7 +1730,7 @@ where
17301730

17311731
let sort_iconn = sortdb.index_conn();
17321732
let mut miner_epoch_info = builder
1733-
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn)
1733+
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn, true)
17341734
.unwrap();
17351735
let mut epoch = builder
17361736
.epoch_begin(&sort_iconn, &mut miner_epoch_info)
@@ -1990,7 +1990,7 @@ where
19901990

19911991
let sort_iconn = sortdb.index_conn();
19921992
let mut miner_epoch_info = builder
1993-
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn)
1993+
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn, true)
19941994
.unwrap();
19951995
let mut epoch = builder
19961996
.epoch_begin(&sort_iconn, &mut miner_epoch_info)
@@ -2035,7 +2035,7 @@ where
20352035

20362036
let sort_iconn = sortdb.index_conn();
20372037
let mut miner_epoch_info = builder
2038-
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn)
2038+
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn, true)
20392039
.unwrap();
20402040
let mut epoch = builder
20412041
.epoch_begin(&sort_iconn, &mut miner_epoch_info)
@@ -2237,7 +2237,7 @@ where
22372237

22382238
let sort_iconn = sortdb.index_conn();
22392239
let mut miner_epoch_info = builder
2240-
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn)
2240+
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn, true)
22412241
.unwrap();
22422242
let mut epoch = builder
22432243
.epoch_begin(&sort_iconn, &mut miner_epoch_info)
@@ -2285,7 +2285,7 @@ where
22852285

22862286
let sort_iconn = sortdb.index_conn();
22872287
let mut miner_epoch_info = builder
2288-
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn)
2288+
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn, true)
22892289
.unwrap();
22902290
let mut epoch = builder
22912291
.epoch_begin(&sort_iconn, &mut miner_epoch_info)

stackslib/src/net/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3494,7 +3494,7 @@ pub mod test {
34943494
let sort_iconn = sortdb.index_conn();
34953495

34963496
let mut miner_epoch_info = builder
3497-
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn)
3497+
.pre_epoch_begin(&mut miner_chainstate, &sort_iconn, true)
34983498
.unwrap();
34993499
let mut epoch = builder
35003500
.epoch_begin(&sort_iconn, &mut miner_epoch_info)

testnet/stacks-node/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,7 @@ impl Config {
11121112
filter_origins: miner_config.filter_origins,
11131113
},
11141114
miner_status,
1115+
confirm_microblocks: true,
11151116
}
11161117
}
11171118

0 commit comments

Comments
 (0)