Skip to content

Commit

Permalink
Disable hooks during sync (#2695)
Browse files Browse the repository at this point in the history
* disable hooks during sync
* remove trigger in headers_sync
  • Loading branch information
mcdallas authored and ignopeverell committed Mar 23, 2019
1 parent 2e72ed9 commit c263884
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions servers/src/common/adapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ impl p2p::ChainAdapter for NetToChainAdapter {
}

fn block_received(&self, b: core::Block, addr: PeerAddr, was_requested: bool) -> bool {
for hook in &self.hooks {
hook.on_block_received(&b, &addr);
if !self.sync_state.is_syncing() {
for hook in &self.hooks {
hook.on_block_received(&b, &addr);
}
}

self.process_block(b, addr, was_requested)
}

Expand All @@ -123,8 +124,10 @@ impl p2p::ChainAdapter for NetToChainAdapter {
// push the freshly hydrated block through the chain pipeline
match core::Block::hydrate_from(cb, vec![]) {
Ok(block) => {
for hook in &self.hooks {
hook.on_block_received(&block, &addr);
if !self.sync_state.is_syncing() {
for hook in &self.hooks {
hook.on_block_received(&block, &addr);
}
}
self.process_block(block, addr, false)
}
Expand Down Expand Up @@ -162,8 +165,10 @@ impl p2p::ChainAdapter for NetToChainAdapter {

let block = match core::Block::hydrate_from(cb.clone(), txs) {
Ok(block) => {
for hook in &self.hooks {
hook.on_block_received(&block, &addr);
if !self.sync_state.is_syncing() {
for hook in &self.hooks {
hook.on_block_received(&block, &addr);
}
}
block
}
Expand Down Expand Up @@ -198,8 +203,10 @@ impl p2p::ChainAdapter for NetToChainAdapter {
}

fn header_received(&self, bh: core::BlockHeader, addr: PeerAddr) -> bool {
for hook in &self.hooks {
hook.on_header_received(&bh, &addr);
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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -619,12 +620,11 @@ pub struct ChainToPoolAndNetAdapter {

impl ChainAdapter for ChainToPoolAndNetAdapter {
fn block_accepted(&self, b: &core::Block, status: BlockStatus, opts: Options) {
for hook in &self.hooks {
hook.on_block_accepted(b, &status);
}

// not broadcasting blocks received through sync
if !opts.contains(chain::Options::SYNC) {
for hook in &self.hooks {
hook.on_block_accepted(b, &status);
}
// 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.
Expand Down

0 comments on commit c263884

Please sign in to comment.