Skip to content
53 changes: 49 additions & 4 deletions stackslib/src/chainstate/nakamoto/tests/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,6 @@ impl TestStacksNode {
stacks_node: &mut TestStacksNode,
sortdb: &mut SortitionDB,
miner: &mut TestMiner,
tenure_id_consensus_hash: &ConsensusHash,
coord: &mut ChainsCoordinator<
'a,
TestEventObserver,
Expand All @@ -1089,10 +1088,56 @@ impl TestStacksNode {
{
let ic = sortdb.index_conn();
let tip = SortitionDB::get_canonical_burn_chain_tip(&ic).unwrap();
stacks_node
.chainstate
.preprocess_stacks_epoch(&ic, &tip, block, microblocks)

let blocks_path = stacks_node.chainstate.blocks_path.clone();

let mut block_tx = stacks_node.chainstate.db_tx_begin()?;

let block_hash = block.block_hash();
let sort_handle = SortitionHandleConn::open_reader_consensus(&ic, &tip.consensus_hash)?;
let block_commit = SortitionDB::get_block_commit_for_stacks_block(
sort_handle.conn(),
&tip.consensus_hash,
&block_hash,
)
.unwrap()
.unwrap();

let parent_snapshot = SortitionDB::get_block_snapshot_for_winning_stacks_block(
&ic,
&tip.parent_sortition_id,
&block.header.parent_block,
)
.unwrap()
.unwrap();
// burn chain tip that selected this commit's block
let burn_chain_tip = sort_handle
.get_block_snapshot(&block_commit.burn_header_hash)
.unwrap()
.unwrap();

let sortition_burns = SortitionDB::get_block_burn_amount(&sort_handle, &burn_chain_tip)
.expect("FATAL: have block commit but no total burns in its sortition");

// queue block up for processing
StacksChainState::store_staging_block_test(
&mut block_tx,
&blocks_path,
&tip.consensus_hash,
block,
&parent_snapshot.consensus_hash,
block_commit.burn_fee,
sortition_burns,
5,
)?;

block_tx.commit()?;

debug!(
"Stored {}/{} to staging",
&tip.consensus_hash,
&block.block_hash()
);
}

let canonical_sortition_tip = coord.canonical_sortition_tip.clone().expect(
Expand Down
26 changes: 25 additions & 1 deletion stackslib/src/chainstate/stacks/db/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,31 @@ impl StacksChainState {
return Ok(None);
}

#[cfg(test)]
#[allow(clippy::too_many_arguments)]
/// A helper function for exposing store_staging_block
pub fn store_staging_block_test(
tx: &mut DBTx<'_>,
blocks_path: &str,
consensus_hash: &ConsensusHash,
block: &StacksBlock,
parent_consensus_hash: &ConsensusHash,
commit_burn: u64,
sortition_burn: u64,
download_time: u64,
) -> Result<(), Error> {
Self::store_staging_block(
tx,
blocks_path,
consensus_hash,
block,
parent_consensus_hash,
commit_burn,
sortition_burn,
download_time,
)
}

/// Store a preprocessed block, queuing it up for subsequent processing.
/// The caller should at least verify that the block is attached to some fork in the burn
/// chain.
Expand Down Expand Up @@ -3102,7 +3127,6 @@ impl StacksChainState {
return Err(e.into());
}
};

// burn chain tip that selected this commit's block
let burn_chain_tip = db_handle
.get_block_snapshot(&block_commit.burn_header_hash)?
Expand Down
Loading