Skip to content

Commit

Permalink
feat: slown down burn blocks when getting close to epoch 3.0 transiti…
Browse files Browse the repository at this point in the history
…on (#1569)
  • Loading branch information
hugocaillard authored Sep 27, 2024
1 parent be42dd9 commit 8fc863d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion components/stacks-network/src/chains_coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ pub async fn start_chains_coordinator(
) -> Result<(), String> {
let mut should_deploy_protocol = true; // Will change when `stacks-network` components becomes compatible with Testnet / Mainnet setups
let boot_completed = Arc::new(AtomicBool::new(false));
let mut current_burn_height = 0;

let (deployment_commands_tx, deployments_command_rx) = channel();
let (deployment_events_tx, deployment_events_rx) = channel();
Expand Down Expand Up @@ -308,6 +309,7 @@ pub async fn start_chains_coordinator(
BitcoinChainEvent::ChainUpdatedWithBlocks(event) => {
let tip = event.new_blocks.last().unwrap();
let bitcoin_block_height = tip.block_identifier.index;
current_burn_height = bitcoin_block_height;
let log = format!("Bitcoin block #{} received", bitcoin_block_height);
let comment =
format!("mining blocks (chain_tip = #{})", bitcoin_block_height);
Expand Down Expand Up @@ -337,6 +339,8 @@ pub async fn start_chains_coordinator(
}
BitcoinChainEvent::ChainUpdatedWithReorg(events) => {
let tip = events.blocks_to_apply.last().unwrap();
let bitcoin_block_height = tip.block_identifier.index;
current_burn_height = bitcoin_block_height;
let log = format!(
"Bitcoin reorg received (new height: {})",
tip.block_identifier.index
Expand Down Expand Up @@ -450,7 +454,17 @@ pub async fn start_chains_coordinator(
}
ObserverEvent::NotifyBitcoinTransactionProxied => {
if !boot_completed.load(Ordering::SeqCst) {
std::thread::sleep(std::time::Duration::from_secs(1));
if config
.devnet_config
.epoch_3_0
.saturating_sub(current_burn_height)
> 20
{
std::thread::sleep(std::time::Duration::from_secs(2));
} else {
// as epoch 3.0 gets closer, bitcoin blocks need to slow down
std::thread::sleep(std::time::Duration::from_secs(5));
}
let res = mine_bitcoin_block(
&config.services_map_hosts.bitcoin_node_host,
config.devnet_config.bitcoin_node_username.as_str(),
Expand Down

0 comments on commit 8fc863d

Please sign in to comment.