Disable hooks during sync (#2695)

* disable hooks during sync
* remove trigger in headers_sync
This commit is contained in:
Mike Dallas 2019-03-23 20:38:28 +00:00 committed by Ignotus Peverell
parent 2e72ed91f3
commit c2638844b2

View file

@ -110,10 +110,11 @@ impl p2p::ChainAdapter for NetToChainAdapter {
}
fn block_received(&self, b: core::Block, addr: PeerAddr, was_requested: bool) -> bool {
if !self.sync_state.is_syncing() {
for hook in &self.hooks {
hook.on_block_received(&b, &addr);
}
}
self.process_block(b, addr, was_requested)
}
@ -123,9 +124,11 @@ impl p2p::ChainAdapter for NetToChainAdapter {
// push the freshly hydrated block through the chain pipeline
match core::Block::hydrate_from(cb, vec![]) {
Ok(block) => {
if !self.sync_state.is_syncing() {
for hook in &self.hooks {
hook.on_block_received(&block, &addr);
}
}
self.process_block(block, addr, false)
}
Err(e) => {
@ -162,9 +165,11 @@ impl p2p::ChainAdapter for NetToChainAdapter {
let block = match core::Block::hydrate_from(cb.clone(), txs) {
Ok(block) => {
if !self.sync_state.is_syncing() {
for hook in &self.hooks {
hook.on_block_received(&block, &addr);
}
}
block
}
Err(e) => {
@ -198,9 +203,11 @@ impl p2p::ChainAdapter for NetToChainAdapter {
}
fn header_received(&self, bh: core::BlockHeader, addr: PeerAddr) -> bool {
if !self.sync_state.is_syncing() {
for hook in &self.hooks {
hook.on_header_received(&bh, &addr);
}
}
// pushing the new block header through the header chain pipeline
// we will go ask for the block if this is a new header
@ -238,12 +245,6 @@ impl p2p::ChainAdapter for NetToChainAdapter {
return false;
}
for header in bhs.iter() {
for hook in &self.hooks {
hook.on_header_received(&header, &addr);
}
}
// try to add headers to our header chain
let res = self.chain().sync_block_headers(bhs, self.chain_opts(true));
if let &Err(ref e) = &res {
@ -619,12 +620,11 @@ pub struct ChainToPoolAndNetAdapter {
impl ChainAdapter for ChainToPoolAndNetAdapter {
fn block_accepted(&self, b: &core::Block, status: BlockStatus, opts: Options) {
// not broadcasting blocks received through sync
if !opts.contains(chain::Options::SYNC) {
for hook in &self.hooks {
hook.on_block_accepted(b, &status);
}
// not broadcasting blocks received through sync
if !opts.contains(chain::Options::SYNC) {
// If we mined the block then we want to broadcast the compact block.
// If we received the block from another node then broadcast "header first"
// to minimize network traffic.