|
@@ -49,7 +49,7 @@ use rpc::{management::ManagementRpcHandler, DefaultRpcHandler};
|
|
|
|
|
|
|
|
/// Validator async tasks
|
|
/// Validator async tasks
|
|
|
pub mod task;
|
|
pub mod task;
|
|
|
-use task::{consensus::ConsensusInitTaskConfig, consensus_init_task};
|
|
|
|
|
|
|
+use task::{consensus::ConsensusInitTaskConfig, consensus_init_task, garbage_collect_task};
|
|
|
|
|
|
|
|
/// P2P net protocols
|
|
/// P2P net protocols
|
|
|
mod proto;
|
|
mod proto;
|
|
@@ -70,8 +70,6 @@ pub struct DarkfiNode {
|
|
|
p2p_handler: DarkfidP2pHandlerPtr,
|
|
p2p_handler: DarkfidP2pHandlerPtr,
|
|
|
/// Node miners registry pointer
|
|
/// Node miners registry pointer
|
|
|
registry: DarkfiMinersRegistryPtr,
|
|
registry: DarkfiMinersRegistryPtr,
|
|
|
- /// Garbage collection task transactions batch size
|
|
|
|
|
- txs_batch_size: usize,
|
|
|
|
|
/// A map of various subscribers exporting live info from the blockchain
|
|
/// A map of various subscribers exporting live info from the blockchain
|
|
|
subscribers: HashMap<&'static str, JsonSubscriber>,
|
|
subscribers: HashMap<&'static str, JsonSubscriber>,
|
|
|
/// Main JSON-RPC connection tracker
|
|
/// Main JSON-RPC connection tracker
|
|
@@ -85,14 +83,12 @@ impl DarkfiNode {
|
|
|
validator: ValidatorPtr,
|
|
validator: ValidatorPtr,
|
|
|
p2p_handler: DarkfidP2pHandlerPtr,
|
|
p2p_handler: DarkfidP2pHandlerPtr,
|
|
|
registry: DarkfiMinersRegistryPtr,
|
|
registry: DarkfiMinersRegistryPtr,
|
|
|
- txs_batch_size: usize,
|
|
|
|
|
subscribers: HashMap<&'static str, JsonSubscriber>,
|
|
subscribers: HashMap<&'static str, JsonSubscriber>,
|
|
|
) -> Result<DarkfiNodePtr> {
|
|
) -> Result<DarkfiNodePtr> {
|
|
|
Ok(Arc::new(Self {
|
|
Ok(Arc::new(Self {
|
|
|
validator,
|
|
validator,
|
|
|
p2p_handler,
|
|
p2p_handler,
|
|
|
registry,
|
|
registry,
|
|
|
- txs_batch_size,
|
|
|
|
|
subscribers,
|
|
subscribers,
|
|
|
rpc_connections: Mutex::new(HashSet::new()),
|
|
rpc_connections: Mutex::new(HashSet::new()),
|
|
|
management_rpc_connections: Mutex::new(HashSet::new()),
|
|
management_rpc_connections: Mutex::new(HashSet::new()),
|
|
@@ -115,6 +111,8 @@ pub struct Darkfid {
|
|
|
management_rpc_task: StoppableTaskPtr,
|
|
management_rpc_task: StoppableTaskPtr,
|
|
|
/// Consensus protocol background task
|
|
/// Consensus protocol background task
|
|
|
consensus_task: StoppableTaskPtr,
|
|
consensus_task: StoppableTaskPtr,
|
|
|
|
|
+ /// Node garbage collection background task
|
|
|
|
|
+ gc_task: StoppableTaskPtr,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
impl Darkfid {
|
|
impl Darkfid {
|
|
@@ -127,7 +125,6 @@ impl Darkfid {
|
|
|
sled_db: &sled_overlay::sled::Db,
|
|
sled_db: &sled_overlay::sled::Db,
|
|
|
config: &ValidatorConfig,
|
|
config: &ValidatorConfig,
|
|
|
net_settings: &Settings,
|
|
net_settings: &Settings,
|
|
|
- txs_batch_size: &Option<usize>,
|
|
|
|
|
ex: &ExecutorPtr,
|
|
ex: &ExecutorPtr,
|
|
|
) -> Result<DarkfidPtr> {
|
|
) -> Result<DarkfidPtr> {
|
|
|
info!(target: "darkfid::Darkfid::init", "Initializing a Darkfi daemon...");
|
|
info!(target: "darkfid::Darkfid::init", "Initializing a Darkfi daemon...");
|
|
@@ -140,12 +137,6 @@ impl Darkfid {
|
|
|
// Initialize the miners registry
|
|
// Initialize the miners registry
|
|
|
let registry = DarkfiMinersRegistry::init(network, &validator).await?;
|
|
let registry = DarkfiMinersRegistry::init(network, &validator).await?;
|
|
|
|
|
|
|
|
- // Grab blockchain network configured transactions batch size for garbage collection
|
|
|
|
|
- let txs_batch_size = match txs_batch_size {
|
|
|
|
|
- Some(b) if *b > 0 => *b,
|
|
|
|
|
- _ => 50,
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
// Here we initialize various subscribers that can export live blockchain/consensus data.
|
|
// Here we initialize various subscribers that can export live blockchain/consensus data.
|
|
|
let mut subscribers = HashMap::new();
|
|
let mut subscribers = HashMap::new();
|
|
|
subscribers.insert("blocks", JsonSubscriber::new("blockchain.subscribe_blocks"));
|
|
subscribers.insert("blocks", JsonSubscriber::new("blockchain.subscribe_blocks"));
|
|
@@ -154,18 +145,25 @@ impl Darkfid {
|
|
|
subscribers.insert("dnet", JsonSubscriber::new("dnet.subscribe_events"));
|
|
subscribers.insert("dnet", JsonSubscriber::new("dnet.subscribe_events"));
|
|
|
|
|
|
|
|
// Initialize node
|
|
// Initialize node
|
|
|
- let node =
|
|
|
|
|
- DarkfiNode::new(validator, p2p_handler, registry, txs_batch_size, subscribers).await?;
|
|
|
|
|
|
|
+ let node = DarkfiNode::new(validator, p2p_handler, registry, subscribers).await?;
|
|
|
|
|
|
|
|
// Generate the background tasks
|
|
// Generate the background tasks
|
|
|
let dnet_task = StoppableTask::new();
|
|
let dnet_task = StoppableTask::new();
|
|
|
let rpc_task = StoppableTask::new();
|
|
let rpc_task = StoppableTask::new();
|
|
|
let management_rpc_task = StoppableTask::new();
|
|
let management_rpc_task = StoppableTask::new();
|
|
|
let consensus_task = StoppableTask::new();
|
|
let consensus_task = StoppableTask::new();
|
|
|
|
|
+ let gc_task = StoppableTask::new();
|
|
|
|
|
|
|
|
info!(target: "darkfid::Darkfid::init", "Darkfi daemon initialized successfully!");
|
|
info!(target: "darkfid::Darkfid::init", "Darkfi daemon initialized successfully!");
|
|
|
|
|
|
|
|
- Ok(Arc::new(Self { node, dnet_task, rpc_task, management_rpc_task, consensus_task }))
|
|
|
|
|
|
|
+ Ok(Arc::new(Self {
|
|
|
|
|
+ node,
|
|
|
|
|
+ dnet_task,
|
|
|
|
|
+ rpc_task,
|
|
|
|
|
+ management_rpc_task,
|
|
|
|
|
+ consensus_task,
|
|
|
|
|
+ gc_task,
|
|
|
|
|
+ }))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// Start the DarkFi daemon in the given executor, using the
|
|
/// Start the DarkFi daemon in the given executor, using the
|
|
@@ -243,13 +241,16 @@ impl Darkfid {
|
|
|
info!(target: "darkfid::Darkfid::start", "Starting P2P network");
|
|
info!(target: "darkfid::Darkfid::start", "Starting P2P network");
|
|
|
self.node.p2p_handler.start(executor, &self.node).await?;
|
|
self.node.p2p_handler.start(executor, &self.node).await?;
|
|
|
|
|
|
|
|
|
|
+ // Generate the signal queue smol channel
|
|
|
|
|
+ let (sender, receiver) = smol::channel::unbounded::<()>();
|
|
|
|
|
+
|
|
|
// Start the consensus protocol
|
|
// Start the consensus protocol
|
|
|
info!(target: "darkfid::Darkfid::start", "Starting consensus protocol task");
|
|
info!(target: "darkfid::Darkfid::start", "Starting consensus protocol task");
|
|
|
self.consensus_task.clone().start(
|
|
self.consensus_task.clone().start(
|
|
|
consensus_init_task(
|
|
consensus_init_task(
|
|
|
self.node.clone(),
|
|
self.node.clone(),
|
|
|
config.clone(),
|
|
config.clone(),
|
|
|
- executor.clone(),
|
|
|
|
|
|
|
+ sender,
|
|
|
),
|
|
),
|
|
|
|res| async move {
|
|
|res| async move {
|
|
|
match res {
|
|
match res {
|
|
@@ -261,6 +262,22 @@ impl Darkfid {
|
|
|
executor.clone(),
|
|
executor.clone(),
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
|
|
+ // Start the garbage collection task
|
|
|
|
|
+ info!(target: "darkfid::Darkfid::start", "Starting garbage collection task");
|
|
|
|
|
+ self.gc_task.clone().start(
|
|
|
|
|
+ garbage_collect_task(receiver, self.node.clone()),
|
|
|
|
|
+ |res| async {
|
|
|
|
|
+ match res {
|
|
|
|
|
+ Ok(()) | Err(Error::GarbageCollectionTaskStopped) => { /* Do nothing */ }
|
|
|
|
|
+ Err(e) => {
|
|
|
|
|
+ error!(target: "darkfid", "Failed starting garbage collection task: {e}")
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ Error::GarbageCollectionTaskStopped,
|
|
|
|
|
+ executor.clone(),
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
info!(target: "darkfid::Darkfid::start", "Darkfi daemon started successfully!");
|
|
info!(target: "darkfid::Darkfid::start", "Darkfi daemon started successfully!");
|
|
|
Ok(())
|
|
Ok(())
|
|
|
}
|
|
}
|
|
@@ -289,6 +306,10 @@ impl Darkfid {
|
|
|
info!(target: "darkfid::Darkfid::stop", "Stopping P2P network protocols handler...");
|
|
info!(target: "darkfid::Darkfid::stop", "Stopping P2P network protocols handler...");
|
|
|
self.node.p2p_handler.stop().await;
|
|
self.node.p2p_handler.stop().await;
|
|
|
|
|
|
|
|
|
|
+ // Stop the garbage collection task
|
|
|
|
|
+ info!(target: "darkfid::Darkfid::stop", "Stopping garbage collection task...");
|
|
|
|
|
+ self.gc_task.stop().await;
|
|
|
|
|
+
|
|
|
// Stop the consensus task
|
|
// Stop the consensus task
|
|
|
info!(target: "darkfid::Darkfid::stop", "Stopping consensus task...");
|
|
info!(target: "darkfid::Darkfid::stop", "Stopping consensus task...");
|
|
|
self.consensus_task.stop().await;
|
|
self.consensus_task.stop().await;
|