Skip to content

Commit

Permalink
Create VerifyCallback type alias
Browse files Browse the repository at this point in the history
  • Loading branch information
eval-exec committed Sep 20, 2023
1 parent ea9f7ea commit c8cb225
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const ORPHAN_BLOCK_SIZE: usize = (BLOCK_DOWNLOAD_WINDOW * 2) as usize;
type ProcessBlockRequest = Request<LonelyBlock, ()>;
type TruncateRequest = Request<Byte32, Result<(), Error>>;

pub type VerifyCallback = dyn FnOnce(Result<(), ckb_error::Error>) + Send + Sync;

/// Controller to the chain service.
///
/// The controller is internally reference-counted and can be freely cloned.
Expand Down Expand Up @@ -94,7 +96,7 @@ impl ChainController {
pub fn process_block_with_callback(
&self,
block: Arc<BlockView>,
verify_callback: Box<dyn FnOnce(Result<(), ckb_error::Error>) + Send + Sync>,
verify_callback: Box<VerifyCallback>,
) {
self.internal_process_lonely_block(LonelyBlock {
block,
Expand Down Expand Up @@ -194,14 +196,12 @@ pub struct ChainService {
orphan_blocks_broker: Arc<OrphanBlockPool>,
}

pub type VerifyCallbackArgs<'a> = (&'a Shared, PeerIndex, Arc<BlockView>);

pub struct LonelyBlock {
pub block: Arc<BlockView>,
pub peer_id: Option<PeerIndex>,
pub switch: Option<Switch>,

pub verify_callback: Option<Box<dyn FnOnce(Result<(), ckb_error::Error>) + Send + Sync>>,
pub verify_callback: Option<Box<VerifyCallback>>,
}

impl LonelyBlock {
Expand All @@ -220,7 +220,7 @@ struct UnverifiedBlock {
pub block: Arc<BlockView>,
pub peer_id: Option<PeerIndex>,
pub switch: Switch,
pub verify_callback: Option<Box<dyn FnOnce(Result<(), ckb_error::Error>) + Send + Sync>>,
pub verify_callback: Option<Box<VerifyCallback>>,
pub parent_header: HeaderView,
}

Expand Down
2 changes: 1 addition & 1 deletion sync/src/relayer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl Relayer {

let block = Arc::new(block);

let verify_success_callback: fn(Result<(), ckb_error::Error>) = {
let verify_success_callback = {
let broadcast_compact_block_tx = self.broadcast_compact_block_tx.clone();
let block = Arc::clone(&block);
let peer = peer.clone();
Expand Down
6 changes: 3 additions & 3 deletions sync/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::orphan_block_pool::OrphanBlockPool;
use crate::utils::is_internal_db_error;
use crate::{Status, StatusCode, FAST_INDEX, LOW_INDEX, NORMAL_INDEX, TIME_TRACE_SIZE};
use ckb_app_config::SyncConfig;
use ckb_chain::chain::{ChainController, LonelyBlock};
use ckb_chain::chain::{ChainController, LonelyBlock, VerifyCallback};
use ckb_chain_spec::consensus::Consensus;
use ckb_channel::Receiver;
use ckb_constant::sync::{
Expand Down Expand Up @@ -1121,7 +1121,7 @@ impl SyncShared {
chain,
Arc::clone(&block),
peer_id,
None::<Box<dyn FnOnce(Result<(), ckb_error::Error>) + Send + Sync>>,
None::<Box<VerifyCallback>>,
);
// if ret.is_err() {
// debug!("accept block {:?} {:?}", block, ret);
Expand Down Expand Up @@ -1191,7 +1191,7 @@ impl SyncShared {
chain: &ChainController,
block: Arc<core::BlockView>,
peer_id: PeerIndex,
verify_callback: Option<Box<dyn FnOnce(Result<(), ckb_error::Error>) + Sync + Send>>,
verify_callback: Option<Box<VerifyCallback>>,
) {
// let ret = {
// let mut assume_valid_target = self.state.assume_valid_target();
Expand Down

0 comments on commit c8cb225

Please sign in to comment.