Skip to content

Commit 1767ee0

Browse files
committed
chore: Remove double lookup of chain tip in try-mine
1 parent 55961e3 commit 1767ee0

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

stackslib/src/cli.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -439,16 +439,9 @@ pub fn command_try_mine(argv: &[String], conf: Option<&Config>) {
439439
)
440440
.unwrap_or_else(|e| panic!("Failed to open mempool db: {e}"));
441441

442-
let header_tip = NakamotoChainState::get_canonical_block_header(chain_state.db(), &sort_db)
443-
.unwrap()
444-
.unwrap();
445-
let parent_header = StacksChainState::get_anchored_block_header_info(
446-
chain_state.db(),
447-
&header_tip.consensus_hash,
448-
&header_tip.anchored_header.block_hash(),
449-
)
450-
.unwrap_or_else(|e| panic!("Failed to load chain tip header info: {e}"))
451-
.expect("Failed to load chain tip header info");
442+
let tip_header = NakamotoChainState::get_canonical_block_header(chain_state.db(), &sort_db)
443+
.unwrap_or_else(|e| panic!("Error looking up chain tip: {e}"))
444+
.expect("No chain tip found");
452445

453446
let sk = StacksPrivateKey::new();
454447
let mut tx_auth = TransactionAuth::from_p2pkh(&sk).unwrap();
@@ -473,7 +466,7 @@ pub fn command_try_mine(argv: &[String], conf: Option<&Config>) {
473466
&chain_state,
474467
&sort_db.index_handle(&chain_tip.sortition_id),
475468
&mut mempool_db,
476-
&parent_header,
469+
&tip_header,
477470
chain_tip.total_burn,
478471
VRFProof::empty(),
479472
Hash160([0; 20]),
@@ -497,13 +490,13 @@ pub fn command_try_mine(argv: &[String], conf: Option<&Config>) {
497490
} else {
498491
"Failed to"
499492
},
500-
parent_header.stacks_block_height + 1,
493+
tip_header.stacks_block_height + 1,
501494
StacksBlockHeader::make_index_block_hash(
502-
&parent_header.consensus_hash,
503-
&parent_header.anchored_header.block_hash()
495+
&tip_header.consensus_hash,
496+
&tip_header.anchored_header.block_hash()
504497
),
505-
&parent_header.consensus_hash,
506-
&parent_header.anchored_header.block_hash(),
498+
&tip_header.consensus_hash,
499+
&tip_header.anchored_header.block_hash(),
507500
stop.saturating_sub(start),
508501
min_fee,
509502
max_time

0 commit comments

Comments
 (0)