Skip to content

Commit

Permalink
Merge pull request #2931 from blockstack/fix/race-to-connect
Browse files Browse the repository at this point in the history
next-costs fix: invoke connect early to avoid race-to-connect
  • Loading branch information
kantai authored Nov 17, 2021
2 parents c694612 + 97285d4 commit 7400c34
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/stacks-blockchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ jobs:
tag_name: ${{ github.event.inputs.tag || github.ref }}
release_name: Release ${{ github.event.inputs.tag || github.ref }}
draft: false
prerelease: false
prerelease: true

# Upload distributables to a new release if we're building a tag or a tag was passed in
upload-dist:
Expand Down
11 changes: 11 additions & 0 deletions testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,17 @@ impl BurnchainController for BitcoinRegtestController {
}
}

fn connect_dbs(&mut self) -> Result<(), BurnchainControllerError> {
let (burnchain, burnchain_indexer) = self.setup_indexer_runtime();
burnchain.connect_db(
&burnchain_indexer,
true,
burnchain_indexer.get_first_block_header_hash()?,
burnchain_indexer.get_first_block_header_timestamp()?,
)?;
Ok(())
}

fn start(
&mut self,
target_block_height_opt: Option<u64>,
Expand Down
4 changes: 4 additions & 0 deletions testnet/stacks-node/src/burnchains/mocknet_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,8 @@ impl BurnchainController for MocknetController {

#[cfg(test)]
fn bootstrap_chain(&mut self, _num_blocks: u64) {}

fn connect_dbs(&mut self) -> Result<(), BurnchainControllerError> {
Ok(())
}
}
10 changes: 9 additions & 1 deletion testnet/stacks-node/src/burnchains/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ impl fmt::Display for Error {
}
}

impl From<burnchains::Error> for Error {
fn from(e: burnchains::Error) -> Self {
Error::IndexerError(e)
}
}

pub trait BurnchainController {
fn start(&mut self, target_block_height_opt: Option<u64>)
-> Result<(BurnchainTip, u64), Error>;
Expand All @@ -43,7 +49,9 @@ pub trait BurnchainController {
fn sortdb_ref(&self) -> &SortitionDB;
fn sortdb_mut(&mut self) -> &mut SortitionDB;
fn get_chain_tip(&self) -> BurnchainTip;

/// Invoke connect() on underlying burnchain and sortition databases, to perform any migration
/// or instantiation before other callers may use open()
fn connect_dbs(&mut self) -> Result<(), Error>;
#[cfg(test)]
fn bootstrap_chain(&mut self, blocks_count: u64);
}
Expand Down
7 changes: 7 additions & 0 deletions testnet/stacks-node/src/run_loop/neon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ impl RunLoop {
burnchain_opt,
Some(should_keep_running.clone()),
);

let pox_constants = burnchain.get_pox_constants();

let is_miner = if self.config.node.miner {
Expand Down Expand Up @@ -217,6 +218,12 @@ impl RunLoop {
}
};

// Invoke connect() to perform any db instantiation early
if let Err(e) = burnchain.connect_dbs() {
error!("Failed to connect to burnchain databases: {}", e);
return;
};

let mainnet = self.config.is_mainnet();
let chainid = self.config.burnchain.chain_id;
let initial_balances = self
Expand Down

0 comments on commit 7400c34

Please sign in to comment.