-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [miner] Merge headblock pacemaker with ondemand pacemaker. * [sync] Refactor SyncStatus, remove judgement about is_nearly_synced. * [sync] Add a way to reuse blocks that have already been fetched in a previous sync task.
- Loading branch information
Showing
16 changed files
with
620 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright (c) The Starcoin Core Contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::GenerateBlockEvent; | ||
use anyhow::Result; | ||
use logger::prelude::*; | ||
use starcoin_service_registry::{ActorService, EventHandler, ServiceContext}; | ||
use tx_relay::PropagateNewTransactions; | ||
use types::{ | ||
sync_status::SyncStatus, | ||
system_events::{NewHeadBlock, SyncStatusChangeEvent}, | ||
}; | ||
|
||
#[derive(Default)] | ||
pub struct GenerateBlockEventPacemaker { | ||
sync_status: Option<SyncStatus>, | ||
} | ||
|
||
impl GenerateBlockEventPacemaker { | ||
pub fn send_event(&mut self, force: bool, ctx: &mut ServiceContext<Self>) { | ||
ctx.broadcast(GenerateBlockEvent::new(force)); | ||
} | ||
|
||
pub fn is_synced(&self) -> bool { | ||
match self.sync_status.as_ref() { | ||
Some(sync_status) => sync_status.is_synced(), | ||
None => false, | ||
} | ||
} | ||
} | ||
|
||
impl ActorService for GenerateBlockEventPacemaker { | ||
fn started(&mut self, ctx: &mut ServiceContext<Self>) -> Result<()> { | ||
ctx.subscribe::<SyncStatusChangeEvent>(); | ||
ctx.subscribe::<NewHeadBlock>(); | ||
ctx.subscribe::<PropagateNewTransactions>(); | ||
Ok(()) | ||
} | ||
|
||
fn stopped(&mut self, ctx: &mut ServiceContext<Self>) -> Result<()> { | ||
ctx.unsubscribe::<SyncStatusChangeEvent>(); | ||
ctx.unsubscribe::<NewHeadBlock>(); | ||
ctx.unsubscribe::<PropagateNewTransactions>(); | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl EventHandler<Self, NewHeadBlock> for GenerateBlockEventPacemaker { | ||
fn handle_event( | ||
&mut self, | ||
_msg: NewHeadBlock, | ||
ctx: &mut ServiceContext<GenerateBlockEventPacemaker>, | ||
) { | ||
if self.is_synced() { | ||
self.send_event(true, ctx) | ||
} else { | ||
debug!("[pacemaker] Ignore NewHeadBlock event because the node has not been synchronized yet.") | ||
} | ||
} | ||
} | ||
|
||
impl EventHandler<Self, PropagateNewTransactions> for GenerateBlockEventPacemaker { | ||
fn handle_event(&mut self, _msg: PropagateNewTransactions, ctx: &mut ServiceContext<Self>) { | ||
if self.is_synced() { | ||
self.send_event(false, ctx) | ||
} else { | ||
debug!("[pacemaker] Ignore PropagateNewTransactions event because the node has not been synchronized yet.") | ||
} | ||
} | ||
} | ||
|
||
impl EventHandler<Self, SyncStatusChangeEvent> for GenerateBlockEventPacemaker { | ||
fn handle_event(&mut self, msg: SyncStatusChangeEvent, ctx: &mut ServiceContext<Self>) { | ||
let is_synced = msg.0.is_synced(); | ||
self.sync_status = Some(msg.0); | ||
if is_synced { | ||
self.send_event(false, ctx); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.