From 0838474a1c62e9059227f73d81a6e133098a2807 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 1 Sep 2023 13:39:32 +0800 Subject: [PATCH] Insert orphan blocks and search orphan blocks in same thread --- chain/src/chain.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/chain/src/chain.rs b/chain/src/chain.rs index ac09c40739..d3a2a524c4 100644 --- a/chain/src/chain.rs +++ b/chain/src/chain.rs @@ -243,8 +243,8 @@ pub struct ChainService { orphan_blocks_broker: Arc, - new_block_tx: Sender, - new_block_rx: Receiver, + new_block_tx: Sender<(Arc, Switch)>, + new_block_rx: Receiver<(Arc, Switch)>, unverified_tx: Sender, unverified_rx: Receiver, @@ -264,7 +264,7 @@ impl ChainService { channel::bounded::(BLOCK_DOWNLOAD_WINDOW as usize * 3); let (new_block_tx, new_block_rx) = - channel::bounded::(BLOCK_DOWNLOAD_WINDOW as usize); + channel::bounded::<(Arc, Switch)>(BLOCK_DOWNLOAD_WINDOW as usize); ChainService { shared, @@ -450,7 +450,8 @@ impl ChainService { return; }, recv(self.new_block_rx) -> msg => match msg { - Ok(switch) => { + Ok((block, switch)) => { + self.orphan_blocks_broker.insert(block); self.search_orphan_pool(switch) }, Err(err) => { @@ -660,9 +661,7 @@ impl ChainService { self.non_contextual_verify(&block)?; } - self.orphan_blocks_broker.insert(block); - - match self.new_block_tx.send(switch) { + match self.new_block_tx.send((block, switch)) { Ok(_) => {} Err(err) => { error!("notify new block to orphan pool err: {}", err)