From 1d4d95244ae888c8fd4f27372a077547d5540488 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Mon, 18 Sep 2023 17:42:42 +0800 Subject: [PATCH] wip Signed-off-by: Eval EXEC --- chain/src/chain.rs | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/chain/src/chain.rs b/chain/src/chain.rs index 2bc20fb419..d1d7bc57ca 100644 --- a/chain/src/chain.rs +++ b/chain/src/chain.rs @@ -6,7 +6,7 @@ use crate::orphan_block_pool::OrphanBlockPool; use ckb_chain_spec::versionbits::VersionbitsIndexer; use ckb_channel::{self as channel, select, Receiver, SendError, Sender}; use ckb_constant::sync::BLOCK_DOWNLOAD_WINDOW; -use ckb_error::{Error, InternalErrorKind}; +use ckb_error::{Error, ErrorKind, InternalError, InternalErrorKind}; use ckb_logger::Level::Trace; use ckb_logger::{ self, debug, error, info, log_enabled, log_enabled_target, trace, trace_target, warn, @@ -54,7 +54,16 @@ const ORPHAN_BLOCK_SIZE: usize = (BLOCK_DOWNLOAD_WINDOW * 2) as usize; type ProcessBlockRequest = Request; type TruncateRequest = Request>; -pub type VerifyCallback = dyn FnOnce(Result<(), ckb_error::Error>) + Send + Sync; +pub type VerifyCallback = dyn FnOnce(Result) + Send + Sync; + +/// VerifiedBlockStatus is +pub enum VerifiedBlockStatus { + // The block is being seen for the first time. + FirstSeen, + + // The block has been verified before. + PreviouslyVerified, +} /// Controller to the chain service. /// @@ -377,7 +386,10 @@ impl ChainService { } } - fn consume_unverified_blocks(&self, unverified_block: &UnverifiedBlock) -> Result<(), Error> { + fn consume_unverified_blocks( + &self, + unverified_block: &UnverifiedBlock, + ) -> Result { // process this unverified block let verify_result = self.verify_block(unverified_block); match &verify_result { @@ -682,8 +694,15 @@ impl ChainService { match lonely_block_tx.send(lonely_block) { Ok(_) => {} - Err(err) => { - error!("notify new block to orphan pool err: {}", err) + Err(SendError(lonely_block)) => { + error!("notify new block to orphan pool err: {}", err); + if let Some(verify_callback) = lonely_block.verify_callback { + verify_callback( + InternalErrorKind::System + .other("OrphanBlock broker disconnected") + .into(), + ); + } } } debug!(