Skip to content

Commit 58f0ab8

Browse files
committed
fix: stacks-inspect commands work with default mainnet config again
1 parent 66a100f commit 58f0ab8

File tree

4 files changed

+29
-26
lines changed

4 files changed

+29
-26
lines changed

stackslib/src/chainstate/nakamoto/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,10 +2701,12 @@ impl NakamotoChainState {
27012701
index_block_hash: &StacksBlockId,
27022702
) -> Result<Option<StacksHeaderInfo>, ChainstateError> {
27032703
let sql = "SELECT * FROM block_headers WHERE index_block_hash = ?1";
2704+
println!("get_block_header_epoch2(): Looking for block {index_block_hash}");
27042705
let result = query_row_panic(chainstate_conn, sql, &[&index_block_hash], || {
27052706
"FATAL: multiple rows for the same block hash".to_string()
27062707
})?;
27072708

2709+
println!("get_block_header_epoch2(): Found {result:?}");
27082710
Ok(result)
27092711
}
27102712

@@ -2713,6 +2715,7 @@ impl NakamotoChainState {
27132715
chainstate_conn: &Connection,
27142716
index_block_hash: &StacksBlockId,
27152717
) -> Result<Option<StacksHeaderInfo>, ChainstateError> {
2718+
println!("get_block_header(): Looking for block {index_block_hash}");
27162719
if let Some(header) = Self::get_block_header_nakamoto(chainstate_conn, index_block_hash)? {
27172720
return Ok(Some(header));
27182721
}

stackslib/src/cli.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,8 @@ pub fn command_try_mine(argv: &[String], conf: Option<&Config>) {
390390
eprintln!("");
391391
eprintln!("Given a <working-dir>, try to ''mine'' an anchored block. This invokes the miner block");
392392
eprintln!("assembly, but does not attempt to broadcast a block commit. This is useful for determining");
393-
eprintln!(
394-
"what transactions a given chain state would include in an anchor block, or otherwise"
395-
);
396-
eprintln!("simulating a miner.");
393+
eprintln!("what transactions a given chain state would include in an anchor block,");
394+
eprintln!("or otherwise simulating a miner.");
397395
process::exit(1);
398396
};
399397

@@ -418,16 +416,16 @@ pub fn command_try_mine(argv: &[String], conf: Option<&Config>) {
418416

419417
let burnchain = conf.get_burnchain();
420418
let sort_db = SortitionDB::open(&sort_db_path, false, burnchain.pox_constants.clone())
421-
.unwrap_or_else(|_| panic!("Failed to open {sort_db_path}"));
419+
.unwrap_or_else(|e| panic!("Failed to open {sort_db_path}: {e}"));
422420
let (chain_state, _) = StacksChainState::open(
423421
conf.is_mainnet(),
424422
conf.burnchain.chain_id,
425423
&chain_state_path,
426424
None,
427425
)
428-
.expect("Failed to open stacks chain state");
426+
.unwrap_or_else(|e| panic!("Failed to open stacks chain state: {e}"));
429427
let chain_tip = SortitionDB::get_canonical_burn_chain_tip(sort_db.conn())
430-
.expect("Failed to get sortition chain tip");
428+
.unwrap_or_else(|e| panic!("Failed to get sortition chain tip: {e}"));
431429

432430
let estimator = Box::new(UnitEstimator);
433431
let metric = Box::new(UnitMetric);
@@ -439,7 +437,7 @@ pub fn command_try_mine(argv: &[String], conf: Option<&Config>) {
439437
estimator,
440438
metric,
441439
)
442-
.expect("Failed to open mempool db");
440+
.unwrap_or_else(|e| panic!("Failed to open mempool db: {e}"));
443441

444442
let header_tip = NakamotoChainState::get_canonical_block_header(chain_state.db(), &sort_db)
445443
.unwrap()
@@ -449,7 +447,7 @@ pub fn command_try_mine(argv: &[String], conf: Option<&Config>) {
449447
&header_tip.consensus_hash,
450448
&header_tip.anchored_header.block_hash(),
451449
)
452-
.expect("Failed to load chain tip header info")
450+
.unwrap_or_else(|e| panic!("Failed to load chain tip header info: {e}"))
453451
.expect("Failed to load chain tip header info");
454452

455453
let sk = StacksPrivateKey::new();
@@ -482,7 +480,12 @@ pub fn command_try_mine(argv: &[String], conf: Option<&Config>) {
482480
&coinbase_tx,
483481
settings,
484482
None,
485-
&Burnchain::new(&burnchain_path, "bitcoin", "main").unwrap(),
483+
&Burnchain::new(
484+
&burnchain_path,
485+
&burnchain.chain_name,
486+
&burnchain.network_name,
487+
)
488+
.unwrap(),
486489
);
487490

488491
let stop = get_epoch_time_ms();
@@ -542,13 +545,13 @@ fn replay_staging_block(db_path: &str, index_block_hash_hex: &str, conf: Option<
542545
.unwrap();
543546

544547
let burnchain = conf.get_burnchain();
545-
let epochs = conf.burnchain.epochs.as_ref().expect("No Epochs found");
548+
let epochs = conf.burnchain.get_epoch_list();
546549
let mut sortdb = SortitionDB::connect(
547550
&sort_db_path,
548551
burnchain.first_block_height,
549552
&burnchain.first_block_hash,
550553
u64::from(burnchain.first_block_timestamp),
551-
epochs,
554+
&epochs,
552555
burnchain.pox_constants.clone(),
553556
None,
554557
true,
@@ -620,13 +623,13 @@ fn replay_mock_mined_block(db_path: &str, block: AssembledAnchorBlock, conf: Opt
620623
.unwrap();
621624

622625
let burnchain = conf.get_burnchain();
623-
let epochs = conf.burnchain.epochs.as_ref().expect("No Epochs found");
626+
let epochs = conf.burnchain.get_epoch_list();
624627
let mut sortdb = SortitionDB::connect(
625628
&sort_db_path,
626629
burnchain.first_block_height,
627630
&burnchain.first_block_hash,
628631
u64::from(burnchain.first_block_timestamp),
629-
epochs,
632+
&epochs,
630633
burnchain.pox_constants.clone(),
631634
None,
632635
true,
@@ -820,13 +823,13 @@ fn replay_naka_staging_block(db_path: &str, index_block_hash_hex: &str, conf: &C
820823
.unwrap();
821824

822825
let burnchain = conf.get_burnchain();
823-
let epochs = conf.burnchain.epochs.as_ref().expect("No Epochs found");
826+
let epochs = conf.burnchain.get_epoch_list();
824827
let mut sortdb = SortitionDB::connect(
825828
&sort_db_path,
826829
burnchain.first_block_height,
827830
&burnchain.first_block_hash,
828831
u64::from(burnchain.first_block_timestamp),
829-
epochs,
832+
&epochs,
830833
burnchain.pox_constants.clone(),
831834
None,
832835
true,

stackslib/src/config/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,10 +521,7 @@ impl Config {
521521
}
522522

523523
fn check_nakamoto_config(&self, burnchain: &Burnchain) {
524-
let epochs = StacksEpoch::get_epochs(
525-
self.burnchain.get_bitcoin_network().1,
526-
self.burnchain.epochs.as_ref(),
527-
);
524+
let epochs = self.burnchain.get_epoch_list();
528525
let Some(epoch_30) = epochs.get(StacksEpochId::Epoch30) else {
529526
// no Epoch 3.0, so just return
530527
return;
@@ -1288,6 +1285,10 @@ impl BurnchainConfig {
12881285
other => panic!("Invalid stacks-node mode: {other}"),
12891286
}
12901287
}
1288+
1289+
pub fn get_epoch_list(&self) -> EpochList<ExecutionCost> {
1290+
StacksEpoch::get_epochs(self.get_bitcoin_network().1, self.epochs.as_ref())
1291+
}
12911292
}
12921293

12931294
#[derive(Clone, Deserialize, Default, Debug)]

testnet/stacks-node/src/run_loop/boot_nakamoto.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ use std::{fs, thread};
2222
use stacks::burnchains::Burnchain;
2323
use stacks::chainstate::burn::db::sortdb::SortitionDB;
2424
use stacks::chainstate::coordinator::comm::CoordinatorChannels;
25-
use stacks::core::StacksEpochExtension;
2625
use stacks::net::p2p::PeerNetwork;
27-
use stacks_common::types::{StacksEpoch, StacksEpochId};
26+
use stacks_common::types::StacksEpochId;
2827

2928
use crate::event_dispatcher::EventDispatcher;
3029
use crate::globals::NeonGlobals;
@@ -233,10 +232,7 @@ impl BootRunLoop {
233232

234233
fn reached_epoch_30_transition(config: &Config) -> Result<bool, String> {
235234
let burn_height = Self::get_burn_height(config)?;
236-
let epochs = StacksEpoch::get_epochs(
237-
config.burnchain.get_bitcoin_network().1,
238-
config.burnchain.epochs.as_ref(),
239-
);
235+
let epochs = config.burnchain.get_epoch_list();
240236
let epoch_3 = epochs
241237
.get(StacksEpochId::Epoch30)
242238
.ok_or("No Epoch-3.0 defined")?;

0 commit comments

Comments
 (0)