Skip to content

Commit 697fe43

Browse files
Merge pull request #6684 from jacinta-stacks/fix/make-pre-naka-blocks-failable
Update ConsensusTest to enable invalid pre-naka blocks
2 parents 46d7bd1 + 594a7be commit 697fe43

File tree

51 files changed

+1320
-404
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1320
-404
lines changed

stackslib/src/chainstate/nakamoto/tests/node.rs

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,6 @@ impl TestStacksNode {
10721072
stacks_node: &mut TestStacksNode,
10731073
sortdb: &mut SortitionDB,
10741074
miner: &mut TestMiner,
1075-
tenure_id_consensus_hash: &ConsensusHash,
10761075
coord: &mut ChainsCoordinator<
10771076
'a,
10781077
TestEventObserver,
@@ -1089,10 +1088,56 @@ impl TestStacksNode {
10891088
{
10901089
let ic = sortdb.index_conn();
10911090
let tip = SortitionDB::get_canonical_burn_chain_tip(&ic).unwrap();
1092-
stacks_node
1093-
.chainstate
1094-
.preprocess_stacks_epoch(&ic, &tip, block, microblocks)
1091+
1092+
let blocks_path = stacks_node.chainstate.blocks_path.clone();
1093+
1094+
let mut block_tx = stacks_node.chainstate.db_tx_begin()?;
1095+
1096+
let block_hash = block.block_hash();
1097+
let sort_handle = SortitionHandleConn::open_reader_consensus(&ic, &tip.consensus_hash)?;
1098+
let block_commit = SortitionDB::get_block_commit_for_stacks_block(
1099+
sort_handle.conn(),
1100+
&tip.consensus_hash,
1101+
&block_hash,
1102+
)
1103+
.unwrap()
1104+
.unwrap();
1105+
1106+
let parent_snapshot = SortitionDB::get_block_snapshot_for_winning_stacks_block(
1107+
&ic,
1108+
&tip.parent_sortition_id,
1109+
&block.header.parent_block,
1110+
)
1111+
.unwrap()
1112+
.unwrap();
1113+
// burn chain tip that selected this commit's block
1114+
let burn_chain_tip = sort_handle
1115+
.get_block_snapshot(&block_commit.burn_header_hash)
1116+
.unwrap()
10951117
.unwrap();
1118+
1119+
let sortition_burns = SortitionDB::get_block_burn_amount(&sort_handle, &burn_chain_tip)
1120+
.expect("FATAL: have block commit but no total burns in its sortition");
1121+
1122+
// queue block up for processing
1123+
StacksChainState::store_staging_block_test(
1124+
&mut block_tx,
1125+
&blocks_path,
1126+
&tip.consensus_hash,
1127+
block,
1128+
&parent_snapshot.consensus_hash,
1129+
block_commit.burn_fee,
1130+
sortition_burns,
1131+
5,
1132+
)?;
1133+
1134+
block_tx.commit()?;
1135+
1136+
debug!(
1137+
"Stored {}/{} to staging",
1138+
&tip.consensus_hash,
1139+
&block.block_hash()
1140+
);
10961141
}
10971142

10981143
let canonical_sortition_tip = coord.canonical_sortition_tip.clone().expect(

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,31 @@ impl StacksChainState {
15161516
return Ok(None);
15171517
}
15181518

1519+
#[cfg(test)]
1520+
#[allow(clippy::too_many_arguments)]
1521+
/// A helper function for exposing store_staging_block
1522+
pub fn store_staging_block_test(
1523+
tx: &mut DBTx<'_>,
1524+
blocks_path: &str,
1525+
consensus_hash: &ConsensusHash,
1526+
block: &StacksBlock,
1527+
parent_consensus_hash: &ConsensusHash,
1528+
commit_burn: u64,
1529+
sortition_burn: u64,
1530+
download_time: u64,
1531+
) -> Result<(), Error> {
1532+
Self::store_staging_block(
1533+
tx,
1534+
blocks_path,
1535+
consensus_hash,
1536+
block,
1537+
parent_consensus_hash,
1538+
commit_burn,
1539+
sortition_burn,
1540+
download_time,
1541+
)
1542+
}
1543+
15191544
/// Store a preprocessed block, queuing it up for subsequent processing.
15201545
/// The caller should at least verify that the block is attached to some fork in the burn
15211546
/// chain.
@@ -3102,7 +3127,6 @@ impl StacksChainState {
31023127
return Err(e.into());
31033128
}
31043129
};
3105-
31063130
// burn chain tip that selected this commit's block
31073131
let burn_chain_tip = db_handle
31083132
.get_block_snapshot(&block_commit.burn_header_hash)?

0 commit comments

Comments
 (0)