Merge branch 'develop' into fix/utxo-lookup

This commit is contained in:
wileyj
2023-06-29 13:06:19 -07:00
committed by GitHub
7 changed files with 76 additions and 79 deletions

View File

@@ -132,7 +132,10 @@ pub fn addr2str(btc_addr: &BitcoinAddress) -> String {
}
/// Helper method to create a BitcoinIndexer
pub fn make_bitcoin_indexer(config: &Config) -> BitcoinIndexer {
pub fn make_bitcoin_indexer(
config: &Config,
should_keep_running: Option<Arc<AtomicBool>>,
) -> BitcoinIndexer {
let (network, _) = config.burnchain.get_bitcoin_network();
let burnchain_params = BurnchainParameters::from_params(&config.burnchain.chain, &network)
.expect("Bitcoin network unsupported");
@@ -158,6 +161,7 @@ pub fn make_bitcoin_indexer(config: &Config) -> BitcoinIndexer {
let burnchain_indexer = BitcoinIndexer {
config: indexer_config.clone(),
runtime: indexer_runtime,
should_keep_running: should_keep_running,
};
burnchain_indexer
}
@@ -307,6 +311,7 @@ impl BitcoinRegtestController {
let burnchain_indexer = BitcoinIndexer {
config: indexer_config.clone(),
runtime: indexer_runtime,
should_keep_running: should_keep_running.clone(),
};
Self {
@@ -352,6 +357,7 @@ impl BitcoinRegtestController {
let burnchain_indexer = BitcoinIndexer {
config: indexer_config.clone(),
runtime: indexer_runtime,
should_keep_running: None,
};
Self {

View File

@@ -4060,7 +4060,11 @@ impl StacksNode {
/// Main loop of the p2p thread.
/// Runs in a separate thread.
/// Continuously receives, until told otherwise.
pub fn p2p_main(mut p2p_thread: PeerThread, event_dispatcher: EventDispatcher) {
pub fn p2p_main(
mut p2p_thread: PeerThread,
event_dispatcher: EventDispatcher,
should_keep_running: Arc<AtomicBool>,
) {
let (mut dns_resolver, mut dns_client) = DNSResolver::new(10);
// spawn a daemon thread that runs the DNS resolver.
@@ -4087,7 +4091,7 @@ impl StacksNode {
.make_cost_metric()
.unwrap_or_else(|| Box::new(UnitMetric));
let indexer = make_bitcoin_indexer(&p2p_thread.config);
let indexer = make_bitcoin_indexer(&p2p_thread.config, Some(should_keep_running));
// receive until we can't reach the receiver thread
loop {
@@ -4187,6 +4191,7 @@ impl StacksNode {
})
.expect("FATAL: failed to start relayer thread");
let should_keep_running_clone = globals.should_keep_running.clone();
let p2p_event_dispatcher = runloop.get_event_dispatcher();
let p2p_thread = PeerThread::new(runloop, p2p_net);
let p2p_thread_handle = thread::Builder::new()
@@ -4197,7 +4202,7 @@ impl StacksNode {
))
.spawn(move || {
debug!("p2p thread ID is {:?}", thread::current().id());
Self::p2p_main(p2p_thread, p2p_event_dispatcher);
Self::p2p_main(p2p_thread, p2p_event_dispatcher, should_keep_running_clone);
})
.expect("FATAL: failed to start p2p thread");

View File

@@ -163,6 +163,7 @@ pub fn get_names(use_test_chainstate_data: bool) -> Box<dyn Iterator<Item = Chai
)
}
// This function is called for helium and mocknet.
fn spawn_peer(
is_mainnet: bool,
chain_id: u32,
@@ -239,7 +240,7 @@ fn spawn_peer(
}
};
let indexer = make_bitcoin_indexer(&config);
let indexer = make_bitcoin_indexer(&config, None);
let net_result = this
.run(
@@ -379,72 +380,6 @@ impl Node {
}
}
pub fn init_and_sync(
config: Config,
burnchain_controller: &mut Box<dyn BurnchainController>,
) -> Node {
let burnchain_tip = burnchain_controller.get_chain_tip();
let keychain = Keychain::default(config.node.seed.clone());
let mut event_dispatcher = EventDispatcher::new();
for observer in &config.events_observers {
event_dispatcher.register_observer(observer);
}
let chainstate_path = config.get_chainstate_path_str();
let sortdb_path = config.get_burn_db_file_path();
let (chain_state, _) = match StacksChainState::open(
config.is_mainnet(),
config.burnchain.chain_id,
&chainstate_path,
Some(config.node.get_marf_opts()),
) {
Ok(x) => x,
Err(_e) => panic!(),
};
let mut node = Node {
active_registered_key: None,
bootstraping_chain: false,
chain_state,
chain_tip: None,
keychain,
last_sortitioned_block: None,
config,
burnchain_tip: None,
nonce: 0,
event_dispatcher,
leader_key_registers: HashSet::new(),
block_commits: HashSet::new(),
};
node.spawn_peer_server();
let pox_constants = burnchain_controller.sortdb_ref().pox_constants.clone();
loop {
let sortdb = SortitionDB::open(&sortdb_path, false, pox_constants.clone())
.expect("BUG: failed to open burn database");
if let Ok(Some(ref chain_tip)) = node.chain_state.get_stacks_chain_tip(&sortdb) {
if chain_tip.consensus_hash == burnchain_tip.block_snapshot.consensus_hash {
info!("Syncing Stacks blocks - completed");
break;
} else {
info!(
"Syncing Stacks blocks - received block #{}",
chain_tip.height
);
}
} else {
info!("Syncing Stacks blocks - unable to progress");
}
thread::sleep(time::Duration::from_secs(5));
}
node
}
fn make_atlas_config() -> AtlasConfig {
AtlasConfig::new(false)
}
@@ -458,6 +393,7 @@ impl Node {
.unwrap()
}
// This function is used for helium and mocknet.
pub fn spawn_peer_server(&mut self) {
// we can call _open_ here rather than _connect_, since connect is first called in
// make_genesis_block

View File

@@ -525,7 +525,8 @@ impl RunLoop {
true,
)
.expect("Failed to connect Atlas DB during startup");
let coordinator_indexer = make_bitcoin_indexer(&self.config);
let coordinator_indexer =
make_bitcoin_indexer(&self.config, Some(self.should_keep_running.clone()));
let coordinator_thread_handle = thread::Builder::new()
.name(format!(
@@ -652,7 +653,7 @@ impl RunLoop {
let sn = SortitionDB::get_canonical_burn_chain_tip(sortdb.conn())
.expect("FATAL: could not read sortition DB");
let indexer = make_bitcoin_indexer(config);
let indexer = make_bitcoin_indexer(config, Some(globals.should_keep_running.clone()));
let heaviest_affirmation_map = match static_get_heaviest_affirmation_map(
&burnchain,
@@ -799,7 +800,7 @@ impl RunLoop {
}
};
let indexer = make_bitcoin_indexer(config);
let indexer = make_bitcoin_indexer(config, Some(globals.should_keep_running.clone()));
let heaviest_affirmation_map = match static_get_heaviest_affirmation_map(
&burnchain,