Skip to content

Commit

Permalink
Do not re-store_unverified_block if it is still verifying by ConsumeU…
Browse files Browse the repository at this point in the history
…nverified
  • Loading branch information
eval-exec committed Mar 21, 2024
1 parent 56b7b42 commit 5245acb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ crossbeam = "0.8.2"
ckb-network = { path = "../network", version = "= 0.115.0-pre" }
ckb-tx-pool = { path = "../tx-pool", version = "= 0.115.0-pre" }
minstant = "0.1.4"
dashmap = "4.0"

[dev-dependencies]
ckb-test-chain-utils = { path = "../util/test-chain-utils", version = "= 0.115.0-pre" }
Expand Down
19 changes: 18 additions & 1 deletion chain/src/consume_orphan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::utils::orphan_block_pool::OrphanBlockPool;
use crate::{LonelyBlock, LonelyBlockHash};
use ckb_channel::{select, Receiver, Sender};
use ckb_error::Error;
use ckb_error::{Error, InternalErrorKind};
use ckb_logger::internal::trace;
use ckb_logger::{debug, error, info};
use ckb_shared::block_status::BlockStatus;
Expand All @@ -14,6 +14,7 @@ use ckb_types::core::{BlockExt, BlockView, EpochNumber, EpochNumberWithFraction,
use ckb_types::U256;
use ckb_verification::InvalidParentError;
use std::sync::Arc;
use dashmap::mapref::entry::Entry;

pub(crate) struct ConsumeDescendantProcessor {
pub shared: Shared,
Expand Down Expand Up @@ -328,6 +329,22 @@ impl ConsumeOrphan {
let parent_hash = lonely_block.block().parent_hash();
let block_hash = lonely_block.block().hash();
let block_number = lonely_block.block().number();

{
// Is this block still verifying by ConsumeUnverified?
// If yes, skip it.
if let Entry::Occupied(entry) = self.shared.block_status_map().entry(block_hash.clone())
{
if entry.get().eq(&BlockStatus::BLOCK_STORED) {
debug!(
"in process_lonely_block, {} is BLOCK_STORED in block_status_map, it is still verifying by ConsumeUnverified thread",
block_hash,
);
return;
}
}
}

let parent_status = self
.shared
.get_block_status(self.shared.store(), &parent_hash);
Expand Down
5 changes: 5 additions & 0 deletions sync/src/tests/sync_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ fn test_insert_child_block_with_stored_but_unverified_parent() {
.build()
.unwrap();
let chain_controller = start_chain_services(pack.take_chain_services_builder());

while chain_controller.is_verifying_unverified_blocks_on_startup() {
std::thread::sleep(std::time::Duration::from_millis(10));
}

(
SyncShared::new(shared, Default::default(), pack.take_relay_tx_receiver()),
chain_controller,
Expand Down

0 comments on commit 5245acb

Please sign in to comment.