mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-05-25 18:21:36 +08:00
feat: when the chains coordinator is about to start processing a burnchain or stacks block, signal to any running miner thread that it should cease what it's doing. This prevents the miner from holding open the write lock on the underlying DB, and in doing so, blocking the coordinator (whose operation takes precedence since the miner builds off of a chain tip produced by the coordinator)
This commit is contained in:
@@ -19,6 +19,8 @@ use std::convert::{TryFrom, TryInto};
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::mpsc::SyncSender;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::burnchains::{
|
||||
@@ -39,6 +41,7 @@ use crate::chainstate::stacks::{
|
||||
StacksHeaderInfo,
|
||||
},
|
||||
events::{StacksTransactionEvent, StacksTransactionReceipt, TransactionOrigin},
|
||||
miner::{signal_mining_blocked, signal_mining_ready, MinerStatus},
|
||||
Error as ChainstateError, StacksBlock, TransactionPayload,
|
||||
};
|
||||
use crate::core::StacksEpoch;
|
||||
@@ -272,6 +275,7 @@ impl<'a, T: BlockEventDispatcher, CE: CostEstimator + ?Sized, FE: FeeEstimator +
|
||||
atlas_config: AtlasConfig,
|
||||
cost_estimator: Option<&mut CE>,
|
||||
fee_estimator: Option<&mut FE>,
|
||||
miner_status: Arc<Mutex<MinerStatus>>,
|
||||
) where
|
||||
T: BlockEventDispatcher,
|
||||
{
|
||||
@@ -311,18 +315,23 @@ impl<'a, T: BlockEventDispatcher, CE: CostEstimator + ?Sized, FE: FeeEstimator +
|
||||
// timeout so that we handle Ctrl-C a little gracefully
|
||||
match comms.wait_on() {
|
||||
CoordinatorEvents::NEW_STACKS_BLOCK => {
|
||||
signal_mining_blocked(miner_status.clone());
|
||||
debug!("Received new stacks block notice");
|
||||
if let Err(e) = inst.handle_new_stacks_block() {
|
||||
warn!("Error processing new stacks block: {:?}", e);
|
||||
}
|
||||
signal_mining_ready(miner_status.clone());
|
||||
}
|
||||
CoordinatorEvents::NEW_BURN_BLOCK => {
|
||||
signal_mining_blocked(miner_status.clone());
|
||||
debug!("Received new burn block notice");
|
||||
if let Err(e) = inst.handle_new_burnchain_block() {
|
||||
warn!("Error processing new burn block: {:?}", e);
|
||||
}
|
||||
signal_mining_ready(miner_status.clone());
|
||||
}
|
||||
CoordinatorEvents::STOP => {
|
||||
signal_mining_blocked(miner_status.clone());
|
||||
debug!("Received stop notice");
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user