mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 11:31:08 +03:00
Disable hooks during sync (#2695)
* disable hooks during sync * remove trigger in headers_sync
This commit is contained in:
parent
2e72ed91f3
commit
c2638844b2
1 changed files with 19 additions and 19 deletions
|
@ -110,10 +110,11 @@ impl p2p::ChainAdapter for NetToChainAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_received(&self, b: core::Block, addr: PeerAddr, was_requested: bool) -> bool {
|
fn block_received(&self, b: core::Block, addr: PeerAddr, was_requested: bool) -> bool {
|
||||||
|
if !self.sync_state.is_syncing() {
|
||||||
for hook in &self.hooks {
|
for hook in &self.hooks {
|
||||||
hook.on_block_received(&b, &addr);
|
hook.on_block_received(&b, &addr);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
self.process_block(b, addr, was_requested)
|
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
|
// push the freshly hydrated block through the chain pipeline
|
||||||
match core::Block::hydrate_from(cb, vec![]) {
|
match core::Block::hydrate_from(cb, vec![]) {
|
||||||
Ok(block) => {
|
Ok(block) => {
|
||||||
|
if !self.sync_state.is_syncing() {
|
||||||
for hook in &self.hooks {
|
for hook in &self.hooks {
|
||||||
hook.on_block_received(&block, &addr);
|
hook.on_block_received(&block, &addr);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
self.process_block(block, addr, false)
|
self.process_block(block, addr, false)
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -162,9 +165,11 @@ impl p2p::ChainAdapter for NetToChainAdapter {
|
||||||
|
|
||||||
let block = match core::Block::hydrate_from(cb.clone(), txs) {
|
let block = match core::Block::hydrate_from(cb.clone(), txs) {
|
||||||
Ok(block) => {
|
Ok(block) => {
|
||||||
|
if !self.sync_state.is_syncing() {
|
||||||
for hook in &self.hooks {
|
for hook in &self.hooks {
|
||||||
hook.on_block_received(&block, &addr);
|
hook.on_block_received(&block, &addr);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
block
|
block
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -198,9 +203,11 @@ impl p2p::ChainAdapter for NetToChainAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn header_received(&self, bh: core::BlockHeader, addr: PeerAddr) -> bool {
|
fn header_received(&self, bh: core::BlockHeader, addr: PeerAddr) -> bool {
|
||||||
|
if !self.sync_state.is_syncing() {
|
||||||
for hook in &self.hooks {
|
for hook in &self.hooks {
|
||||||
hook.on_header_received(&bh, &addr);
|
hook.on_header_received(&bh, &addr);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// pushing the new block header through the header chain pipeline
|
// pushing the new block header through the header chain pipeline
|
||||||
// we will go ask for the block if this is a new header
|
// we will go ask for the block if this is a new header
|
||||||
|
@ -238,12 +245,6 @@ impl p2p::ChainAdapter for NetToChainAdapter {
|
||||||
return false;
|
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
|
// try to add headers to our header chain
|
||||||
let res = self.chain().sync_block_headers(bhs, self.chain_opts(true));
|
let res = self.chain().sync_block_headers(bhs, self.chain_opts(true));
|
||||||
if let &Err(ref e) = &res {
|
if let &Err(ref e) = &res {
|
||||||
|
@ -619,12 +620,11 @@ pub struct ChainToPoolAndNetAdapter {
|
||||||
|
|
||||||
impl ChainAdapter for ChainToPoolAndNetAdapter {
|
impl ChainAdapter for ChainToPoolAndNetAdapter {
|
||||||
fn block_accepted(&self, b: &core::Block, status: BlockStatus, opts: Options) {
|
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 {
|
for hook in &self.hooks {
|
||||||
hook.on_block_accepted(b, &status);
|
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 mined the block then we want to broadcast the compact block.
|
||||||
// If we received the block from another node then broadcast "header first"
|
// If we received the block from another node then broadcast "header first"
|
||||||
// to minimize network traffic.
|
// to minimize network traffic.
|
||||||
|
|
Loading…
Reference in a new issue