Skip to content

Commit f4b89f8

Browse files
committed
refactor: Move AssembledAnchorBlock into stackslib
1 parent a6fd22b commit f4b89f8

File tree

3 files changed

+28
-29
lines changed

3 files changed

+28
-29
lines changed

stackslib/src/chainstate/stacks/miner.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,28 @@ use crate::monitoring::{
6666
use crate::net::relay::Relayer;
6767
use crate::net::Error as net_error;
6868

69+
/// Fully-assembled Stacks anchored, block as well as some extra metadata pertaining to how it was
70+
/// linked to the burnchain and what view(s) the miner had of the burnchain before and after
71+
/// completing the block.
72+
#[derive(Debug, Clone, Serialize, Deserialize)]
73+
pub struct AssembledAnchorBlock {
74+
/// Consensus hash of the parent Stacks block
75+
pub parent_consensus_hash: ConsensusHash,
76+
/// Burnchain tip's block hash when we finished mining
77+
pub my_burn_hash: BurnchainHeaderHash,
78+
/// Burnchain tip's block height when we finished mining
79+
pub my_block_height: u64,
80+
/// Burnchain tip's block hash when we started mining (could be different)
81+
pub orig_burn_hash: BurnchainHeaderHash,
82+
/// The block we produced
83+
pub anchored_block: StacksBlock,
84+
/// The attempt count of this block (multiple blocks will be attempted per burnchain block)
85+
pub attempt: u64,
86+
/// Epoch timestamp in milliseconds when we started producing the block.
87+
pub tenure_begin: u128,
88+
}
89+
impl_file_io_serde_json!(AssembledAnchorBlock);
90+
6991
/// System status for mining.
7092
/// The miner can be Ready, in which case a miner is allowed to run
7193
/// The miner can be Blocked, in which case the miner *should not start* and/or *should terminate*

stackslib/src/main.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,14 +1988,12 @@ fn replay_mock_mining(argv: Vec<String>) {
19881988
let print_help_and_exit = || -> ! {
19891989
let n = &argv[0];
19901990
eprintln!("Usage:");
1991-
eprintln!(" {n} <mock-miner-output-dir>");
1991+
eprintln!(" {n} <chainstate-path> <mock-miner-output-path>");
19921992
process::exit(1);
19931993
};
19941994

19951995
// Process CLI args
1996-
let chainstate_path = argv
1997-
.get(2)
1998-
.unwrap_or_else(|| print_help_and_exit());
1996+
let chainstate_path = argv.get(2).unwrap_or_else(|| print_help_and_exit());
19991997

20001998
let blocks_path = argv
20011999
.get(3)
@@ -2058,8 +2056,8 @@ fn replay_mock_mining(argv: Vec<String>) {
20582056

20592057
for (bh, filename) in indexed_files {
20602058
let filepath = blocks_path.join(filename);
2061-
// let block = AssembledAnchorBlock::deserialize_from_file(&filepath)
2062-
// .unwrap_or_else(|e| panic!("Error reading block {bh} from file: {e}"));
2059+
let block = AssembledAnchorBlock::deserialize_from_file(&filepath)
2060+
.unwrap_or_else(|e| panic!("Error reading block {bh} from file: {e}"));
20632061
debug!("Replaying block from {filepath:?}";
20642062
"block_height" => bh,
20652063
"block" => ?block

testnet/stacks-node/src/neon_node.rs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ use stacks::chainstate::stacks::address::PoxAddress;
167167
use stacks::chainstate::stacks::db::blocks::StagingBlock;
168168
use stacks::chainstate::stacks::db::{StacksChainState, StacksHeaderInfo, MINER_REWARD_MATURITY};
169169
use stacks::chainstate::stacks::miner::{
170-
signal_mining_blocked, signal_mining_ready, BlockBuilderSettings, StacksMicroblockBuilder,
170+
signal_mining_blocked, signal_mining_ready, AssembledAnchorBlock, BlockBuilderSettings,
171+
StacksMicroblockBuilder,
171172
};
172173
use stacks::chainstate::stacks::{
173174
CoinbasePayload, Error as ChainstateError, StacksBlock, StacksBlockBuilder, StacksBlockHeader,
@@ -234,28 +235,6 @@ pub(crate) enum MinerThreadResult {
234235
),
235236
}
236237

237-
/// Fully-assembled Stacks anchored, block as well as some extra metadata pertaining to how it was
238-
/// linked to the burnchain and what view(s) the miner had of the burnchain before and after
239-
/// completing the block.
240-
#[derive(Debug, Clone, Serialize, Deserialize)]
241-
pub struct AssembledAnchorBlock {
242-
/// Consensus hash of the parent Stacks block
243-
parent_consensus_hash: ConsensusHash,
244-
/// Burnchain tip's block hash when we finished mining
245-
my_burn_hash: BurnchainHeaderHash,
246-
/// Burnchain tip's block height when we finished mining
247-
my_block_height: u64,
248-
/// Burnchain tip's block hash when we started mining (could be different)
249-
orig_burn_hash: BurnchainHeaderHash,
250-
/// The block we produced
251-
anchored_block: StacksBlock,
252-
/// The attempt count of this block (multiple blocks will be attempted per burnchain block)
253-
attempt: u64,
254-
/// Epoch timestamp in milliseconds when we started producing the block.
255-
tenure_begin: u128,
256-
}
257-
impl_file_io_serde_json!(AssembledAnchorBlock);
258-
259238
/// Miner chain tip, on top of which to build microblocks
260239
#[derive(Debug, Clone, PartialEq)]
261240
pub struct MinerTip {

0 commit comments

Comments
 (0)