Skip to content

Commit 8e487b3

Browse files
feat: change SortitionDB::open_index(..) to accept MARFOpenOpts, #6593
1 parent 0f2c048 commit 8e487b3

File tree

29 files changed

+235
-78
lines changed

29 files changed

+235
-78
lines changed

contrib/stacks-inspect/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ pub fn command_try_mine(argv: &[String], conf: Option<&Config>) {
425425
let chain_state_path = format!("{db_path}/chainstate/");
426426

427427
let burnchain = conf.get_burnchain();
428-
let sort_db = SortitionDB::open(&sort_db_path, false, burnchain.pox_constants.clone())
428+
let sort_db = SortitionDB::open(&sort_db_path, false, burnchain.pox_constants.clone(), None)
429429
.unwrap_or_else(|e| panic!("Failed to open {sort_db_path}: {e}"));
430430
let (chainstate, _) = StacksChainState::open(
431431
conf.is_mainnet(),
@@ -493,6 +493,7 @@ pub fn command_try_mine(argv: &[String], conf: Option<&Config>) {
493493
&burnchain_path,
494494
&burnchain.chain_name,
495495
&burnchain.network_name,
496+
None,
496497
)
497498
.unwrap_or_else(|e| panic!("Failed to instantiate burnchain: {e}")),
498499
)
@@ -609,6 +610,7 @@ fn replay_staging_block(db_path: &str, index_block_hash_hex: &str, conf: Option<
609610
burnchain.pox_constants.clone(),
610611
None,
611612
true,
613+
None,
612614
)
613615
.unwrap();
614616
let sort_tx = sortdb.tx_begin_at_tip();
@@ -684,6 +686,7 @@ fn replay_mock_mined_block(db_path: &str, block: AssembledAnchorBlock, conf: Opt
684686
burnchain.pox_constants.clone(),
685687
None,
686688
true,
689+
None,
687690
)
688691
.unwrap();
689692
let sort_tx = sortdb.tx_begin_at_tip();
@@ -891,6 +894,7 @@ fn replay_naka_staging_block(db_path: &str, index_block_hash_hex: &str, conf: &C
891894
burnchain.pox_constants.clone(),
892895
None,
893896
true,
897+
None,
894898
)
895899
.unwrap();
896900

contrib/stacks-inspect/src/main.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ fn open_nakamoto_chainstate_dbs(
280280
let chain_state_path = format!("{chainstate_dir}/{dirname}/chainstate/");
281281
let sort_db_path = format!("{chainstate_dir}/{dirname}/burnchain/sortition/");
282282

283-
let sort_db = SortitionDB::open(&sort_db_path, true, pox_constants)
283+
let sort_db = SortitionDB::open(&sort_db_path, true, pox_constants, None)
284284
.unwrap_or_else(|_| panic!("Failed to open {sort_db_path}"));
285285

286286
let (chain_state, _) = StacksChainState::open(mainnet, chain_id, &chain_state_path, None)
@@ -594,8 +594,9 @@ Given a <working-dir>, obtain a 2100 header hash block inventory (with an empty
594594
let sort_db_path = format!("{}/mainnet/burnchain/sortition", &argv[2]);
595595
let chain_state_path = format!("{}/mainnet/chainstate/", &argv[2]);
596596

597-
let sort_db = SortitionDB::open(&sort_db_path, false, PoxConstants::mainnet_default())
598-
.unwrap_or_else(|_| panic!("Failed to open {sort_db_path}"));
597+
let sort_db =
598+
SortitionDB::open(&sort_db_path, false, PoxConstants::mainnet_default(), None)
599+
.unwrap_or_else(|_| panic!("Failed to open {sort_db_path}"));
599600
let chain_id = CHAIN_ID_MAINNET;
600601
let (chain_state, _) = StacksChainState::open(true, chain_id, &chain_state_path, None)
601602
.expect("Failed to open stacks chain state");
@@ -638,8 +639,9 @@ check if the associated microblocks can be downloaded
638639
let sort_db_path = format!("{}/mainnet/burnchain/sortition", &argv[2]);
639640
let chain_state_path = format!("{}/mainnet/chainstate/", &argv[2]);
640641

641-
let sort_db = SortitionDB::open(&sort_db_path, false, PoxConstants::mainnet_default())
642-
.unwrap_or_else(|_| panic!("Failed to open {sort_db_path}"));
642+
let sort_db =
643+
SortitionDB::open(&sort_db_path, false, PoxConstants::mainnet_default(), None)
644+
.unwrap_or_else(|_| panic!("Failed to open {sort_db_path}"));
643645
let chain_id = CHAIN_ID_MAINNET;
644646
let (chain_state, _) = StacksChainState::open(true, chain_id, &chain_state_path, None)
645647
.expect("Failed to open stacks chain state");
@@ -750,7 +752,7 @@ check if the associated microblocks can be downloaded
750752
.map(|x| x.parse().expect("Failed to parse <end-height> argument"))
751753
.unwrap_or(start_height);
752754

753-
let sort_db = SortitionDB::open(&argv[2], false, PoxConstants::mainnet_default())
755+
let sort_db = SortitionDB::open(&argv[2], false, PoxConstants::mainnet_default(), None)
754756
.unwrap_or_else(|_| panic!("Failed to open {}", argv[2]));
755757
let chain_tip = SortitionDB::get_canonical_sortition_tip(sort_db.conn())
756758
.expect("Failed to get sortition chain tip");
@@ -1304,7 +1306,7 @@ check if the associated microblocks can be downloaded
13041306
let (old_chainstate, _) =
13051307
StacksChainState::open(false, 0x80000000, old_chainstate_path, None).unwrap();
13061308
let old_sortition_db =
1307-
SortitionDB::open(old_sort_path, true, PoxConstants::mainnet_default()).unwrap();
1309+
SortitionDB::open(old_sort_path, true, PoxConstants::mainnet_default(), None).unwrap();
13081310

13091311
// initial argon balances -- see sample/conf/testnet-follower-conf.toml
13101312
let initial_balances = vec![
@@ -1655,7 +1657,7 @@ simulating a miner.
16551657
let mine_tip_height: u64 = argv[4].parse().expect("Could not parse mine_tip_height");
16561658
let mine_max_txns: u64 = argv[5].parse().expect("Could not parse mine-num-txns");
16571659

1658-
let sort_db = SortitionDB::open(&sort_db_path, false, PoxConstants::mainnet_default())
1660+
let sort_db = SortitionDB::open(&sort_db_path, false, PoxConstants::mainnet_default(), None)
16591661
.unwrap_or_else(|_| panic!("Failed to open {sort_db_path}"));
16601662
let chain_id = CHAIN_ID_MAINNET;
16611663
let mut chain_state = StacksChainState::open(true, chain_id, &chain_state_path, None)
@@ -1821,7 +1823,7 @@ simulating a miner.
18211823
&coinbase_tx,
18221824
settings,
18231825
None,
1824-
&Burnchain::new(&burnchain_path, "bitcoin", "main").unwrap(),
1826+
&Burnchain::new(&burnchain_path, "bitcoin", "main", None).unwrap(),
18251827
);
18261828

18271829
let stop = get_epoch_time_ms();
@@ -1888,9 +1890,9 @@ fn analyze_sortition_mev(argv: Vec<String>) {
18881890
}
18891891

18901892
let mut sortdb =
1891-
SortitionDB::open(&sortdb_path, true, PoxConstants::mainnet_default()).unwrap();
1893+
SortitionDB::open(&sortdb_path, true, PoxConstants::mainnet_default(), None).unwrap();
18921894
sortdb.dryrun = true;
1893-
let burnchain = Burnchain::new(&burnchaindb_path, "bitcoin", "mainnet").unwrap();
1895+
let burnchain = Burnchain::new(&burnchaindb_path, "bitcoin", "mainnet", None).unwrap();
18941896
let burnchaindb = BurnchainDB::connect(&burnchaindb_path, &burnchain, true).unwrap();
18951897
let (mut chainstate, _) =
18961898
StacksChainState::open(true, 0x00000001, &chainstate_path, None).unwrap();

stacks-node/src/burnchains/mocknet_controller.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ impl BurnchainController for MocknetController {
143143
self.burnchain.pox_constants.clone(),
144144
None,
145145
true,
146+
None,
146147
) {
147148
Ok(db) => db,
148149
Err(_) => panic!("Error while connecting to burnchain db"),

stacks-node/src/main.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,13 @@ fn cli_pick_best_tip(config_path: &str, at_stacks_height: Option<u64>) -> TipCan
7979
Some(config.node.get_marf_opts()),
8080
)
8181
.unwrap();
82-
let mut sortdb = SortitionDB::open(&burn_db_path, false, burnchain.pox_constants).unwrap();
82+
let mut sortdb = SortitionDB::open(
83+
&burn_db_path,
84+
false,
85+
burnchain.pox_constants,
86+
Some(config.node.get_marf_opts()),
87+
)
88+
.unwrap();
8389

8490
let max_depth = config.miner.max_reorg_depth;
8591

@@ -120,8 +126,13 @@ fn cli_get_miner_spend(
120126
Some(config.node.get_marf_opts()),
121127
)
122128
.unwrap();
123-
let mut sortdb =
124-
SortitionDB::open(&burn_db_path, true, burnchain.pox_constants.clone()).unwrap();
129+
let mut sortdb = SortitionDB::open(
130+
&burn_db_path,
131+
true,
132+
burnchain.pox_constants.clone(),
133+
Some(config.node.get_marf_opts()),
134+
)
135+
.unwrap();
125136
let tip = if let Some(at_burnchain_height) = at_burnchain_height {
126137
let tip = SortitionDB::get_canonical_burn_chain_tip(sortdb.conn()).unwrap();
127138
let ih = sortdb.index_handle(&tip.sortition_id);
@@ -157,8 +168,13 @@ fn cli_get_miner_spend(
157168
mine_start.unwrap_or(tip.block_height),
158169
at_burnchain_height,
159170
|burn_block_height| {
160-
let sortdb =
161-
SortitionDB::open(&burn_db_path, true, burnchain.pox_constants.clone()).unwrap();
171+
let sortdb = SortitionDB::open(
172+
&burn_db_path,
173+
true,
174+
burnchain.pox_constants.clone(),
175+
Some(config.node.get_marf_opts()),
176+
)
177+
.unwrap();
162178
let Some(miner_stats) = config.get_miner_stats() else {
163179
return 0.0;
164180
};

stacks-node/src/nakamoto_node/miner.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ impl BlockMinerThread {
511511
&self.config.get_burn_db_file_path(),
512512
true,
513513
self.burnchain.pox_constants.clone(),
514+
Some(self.config.node.get_marf_opts()),
514515
)
515516
.expect("FATAL: could not open sortition DB");
516517

@@ -664,9 +665,13 @@ impl BlockMinerThread {
664665
chain_state: &mut StacksChainState,
665666
) -> Result<bool, NakamotoNodeError> {
666667
let burn_db_path = self.config.get_burn_db_file_path();
667-
let mut burn_db =
668-
SortitionDB::open(&burn_db_path, true, self.burnchain.pox_constants.clone())
669-
.expect("FATAL: could not open sortition DB");
668+
let mut burn_db = SortitionDB::open(
669+
&burn_db_path,
670+
true,
671+
self.burnchain.pox_constants.clone(),
672+
Some(self.config.node.get_marf_opts()),
673+
)
674+
.expect("FATAL: could not open sortition DB");
670675
self.check_burn_tip_changed(&burn_db)?;
671676
match self.load_block_parent_info(&mut burn_db, chain_state) {
672677
Ok(..) => Ok(true),
@@ -734,6 +739,7 @@ impl BlockMinerThread {
734739
&self.config.get_burn_db_file_path(),
735740
false,
736741
self.burnchain.pox_constants.clone(),
742+
Some(self.config.node.get_marf_opts()),
737743
) else {
738744
error!("Failed to open sortition DB. Will try mining again.");
739745
return Ok(None);
@@ -910,6 +916,7 @@ impl BlockMinerThread {
910916
&self.config.get_burn_db_file_path(),
911917
false,
912918
self.burnchain.pox_constants.clone(),
919+
Some(self.config.node.get_marf_opts()),
913920
) else {
914921
error!("Failed to open sortition DB. Will try mining again.");
915922
return Ok(());
@@ -962,6 +969,7 @@ impl BlockMinerThread {
962969
&self.config.get_burn_db_file_path(),
963970
true,
964971
self.burnchain.pox_constants.clone(),
972+
Some(self.config.node.get_marf_opts()),
965973
)
966974
.map_err(|e| {
967975
NakamotoNodeError::SigningCoordinatorFailure(format!(
@@ -1117,6 +1125,7 @@ impl BlockMinerThread {
11171125
&self.config.get_burn_db_file_path(),
11181126
true,
11191127
self.burnchain.pox_constants.clone(),
1128+
Some(self.config.node.get_marf_opts()),
11201129
)
11211130
.expect("FATAL: could not open sortition DB");
11221131

@@ -1462,9 +1471,13 @@ impl BlockMinerThread {
14621471

14631472
// NOTE: read-write access is needed in order to be able to query the recipient set.
14641473
// This is an artifact of the way the MARF is built (see #1449)
1465-
let mut burn_db =
1466-
SortitionDB::open(&burn_db_path, true, self.burnchain.pox_constants.clone())
1467-
.expect("FATAL: could not open sortition DB");
1474+
let mut burn_db = SortitionDB::open(
1475+
&burn_db_path,
1476+
true,
1477+
self.burnchain.pox_constants.clone(),
1478+
Some(self.config.node.get_marf_opts()),
1479+
)
1480+
.expect("FATAL: could not open sortition DB");
14681481

14691482
let mut chain_state = neon_node::open_chainstate_with_faults(&self.config)
14701483
.expect("FATAL: could not open chainstate DB");

stacks-node/src/nakamoto_node/peer.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,13 @@ impl PeerThread {
162162
.expect("FATAL: database failure opening mempool");
163163
let burn_db_path = config.get_burn_db_file_path();
164164

165-
let sortdb = SortitionDB::open(&burn_db_path, false, pox_constants)
166-
.expect("FATAL: could not open sortition DB");
165+
let sortdb = SortitionDB::open(
166+
&burn_db_path,
167+
false,
168+
pox_constants,
169+
Some(config.node.get_marf_opts()),
170+
)
171+
.expect("FATAL: could not open sortition DB");
167172

168173
let chainstate =
169174
open_chainstate_with_faults(&config).expect("FATAL: could not open chainstate DB");

stacks-node/src/nakamoto_node/relayer.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,13 @@ impl RelayerThread {
487487
let burn_db_path = config.get_burn_db_file_path();
488488
let is_miner = runloop.is_miner();
489489

490-
let sortdb = SortitionDB::open(&burn_db_path, true, runloop.get_burnchain().pox_constants)
491-
.expect("FATAL: failed to open burnchain DB");
490+
let sortdb = SortitionDB::open(
491+
&burn_db_path,
492+
true,
493+
runloop.get_burnchain().pox_constants,
494+
Some(config.node.get_marf_opts()),
495+
)
496+
.expect("FATAL: failed to open burnchain DB");
492497

493498
let chainstate =
494499
open_chainstate_with_faults(&config).expect("FATAL: failed to open chainstate DB");

stacks-node/src/neon_node.rs

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -575,12 +575,17 @@ impl MicroblockMinerThread {
575575

576576
// NOTE: read-write access is needed in order to be able to query the recipient set.
577577
// This is an artifact of the way the MARF is built (see #1449)
578-
let sortdb = SortitionDB::open(&burn_db_path, true, burnchain.pox_constants)
579-
.map_err(|e| {
580-
error!("Relayer: Could not open sortdb '{burn_db_path}' ({e:?}); skipping tenure");
581-
e
582-
})
583-
.ok()?;
578+
let sortdb = SortitionDB::open(
579+
&burn_db_path,
580+
true,
581+
burnchain.pox_constants,
582+
Some(config.node.get_marf_opts()),
583+
)
584+
.map_err(|e| {
585+
error!("Relayer: Could not open sortdb '{burn_db_path}' ({e:?}); skipping tenure");
586+
e
587+
})
588+
.ok()?;
584589

585590
let mut chainstate = open_chainstate_with_faults(&config)
586591
.map_err(|e| {
@@ -2309,8 +2314,13 @@ impl BlockMinerThread {
23092314
/// Read any mock signatures from stackerdb and respond to them
23102315
pub fn send_mock_miner_messages(&mut self) -> Result<(), String> {
23112316
let burn_db_path = self.config.get_burn_db_file_path();
2312-
let burn_db = SortitionDB::open(&burn_db_path, false, self.burnchain.pox_constants.clone())
2313-
.expect("FATAL: could not open sortition DB");
2317+
let burn_db = SortitionDB::open(
2318+
&burn_db_path,
2319+
false,
2320+
self.burnchain.pox_constants.clone(),
2321+
Some(self.config.node.get_marf_opts()),
2322+
)
2323+
.expect("FATAL: could not open sortition DB");
23142324
let epoch_id = SortitionDB::get_stacks_epoch(burn_db.conn(), self.burn_block.block_height)
23152325
.map_err(|e| e.to_string())?
23162326
.expect("FATAL: no epoch defined")
@@ -2459,9 +2469,13 @@ impl BlockMinerThread {
24592469

24602470
// NOTE: read-write access is needed in order to be able to query the recipient set.
24612471
// This is an artifact of the way the MARF is built (see #1449)
2462-
let mut burn_db =
2463-
SortitionDB::open(&burn_db_path, true, self.burnchain.pox_constants.clone())
2464-
.expect("FATAL: could not open sortition DB");
2472+
let mut burn_db = SortitionDB::open(
2473+
&burn_db_path,
2474+
true,
2475+
self.burnchain.pox_constants.clone(),
2476+
Some(self.config.node.get_marf_opts()),
2477+
)
2478+
.expect("FATAL: could not open sortition DB");
24652479

24662480
let mut chain_state =
24672481
open_chainstate_with_faults(&self.config).expect("FATAL: could not open chainstate DB");
@@ -2806,8 +2820,13 @@ impl RelayerThread {
28062820
let is_mainnet = config.is_mainnet();
28072821
let chain_id = config.burnchain.chain_id;
28082822

2809-
let sortdb = SortitionDB::open(&burn_db_path, true, runloop.get_burnchain().pox_constants)
2810-
.expect("FATAL: failed to open burnchain DB");
2823+
let sortdb = SortitionDB::open(
2824+
&burn_db_path,
2825+
true,
2826+
runloop.get_burnchain().pox_constants,
2827+
Some(config.node.get_marf_opts()),
2828+
)
2829+
.expect("FATAL: failed to open burnchain DB");
28112830

28122831
let chainstate =
28132832
open_chainstate_with_faults(&config).expect("FATAL: failed to open chainstate DB");
@@ -4376,8 +4395,13 @@ impl PeerThread {
43764395
let mempool = Self::connect_mempool_db(&config);
43774396
let burn_db_path = config.get_burn_db_file_path();
43784397

4379-
let sortdb = SortitionDB::open(&burn_db_path, false, pox_constants)
4380-
.expect("FATAL: could not open sortition DB");
4398+
let sortdb = SortitionDB::open(
4399+
&burn_db_path,
4400+
false,
4401+
pox_constants,
4402+
Some(config.node.get_marf_opts()),
4403+
)
4404+
.expect("FATAL: could not open sortition DB");
43814405

43824406
let chainstate =
43834407
open_chainstate_with_faults(&config).expect("FATAL: could not open chainstate DB");
@@ -4762,6 +4786,7 @@ impl StacksNode {
47624786
&config.get_burn_db_file_path(),
47634787
true,
47644788
burnchain.pox_constants.clone(),
4789+
Some(config.node.get_marf_opts()),
47654790
)
47664791
.expect("Error while instantiating sor/tition db");
47674792

0 commit comments

Comments
 (0)