Skip to content

Commit

Permalink
Shared::get_block_status always read BlockExt from snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
eval-exec committed Mar 27, 2024
1 parent 441bb8a commit da0db29
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
1 change: 0 additions & 1 deletion chain/src/init_load_unverified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use ckb_constant::sync::BLOCK_DOWNLOAD_WINDOW;
use ckb_db::{Direction, IteratorMode};
use ckb_db_schema::COLUMN_NUMBER_HASH;
use ckb_logger::info;
use ckb_shared::block_status::BlockStatus;
use ckb_shared::Shared;
use ckb_stop_handler::has_received_stop_signal;
use ckb_store::ChainStore;
Expand Down
8 changes: 2 additions & 6 deletions chain/src/orphan_broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ impl OrphanBroker {
}

fn search_orphan_leader(&self, leader_hash: ParentHash) {
let leader_status = self
.shared
.get_block_status(self.shared.store(), &leader_hash);
let leader_status = self.shared.get_block_status(&leader_hash);

if leader_status.eq(&BlockStatus::BLOCK_INVALID) {
let descendants: Vec<LonelyBlockHash> = self
Expand Down Expand Up @@ -148,9 +146,7 @@ impl OrphanBroker {
let block_number = lonely_block.block_number_and_hash.number();
let parent_hash = lonely_block.parent_hash();
let parent_is_pending_verify = self.is_pending_verify.contains(&parent_hash);
let parent_status = self
.shared
.get_block_status(self.shared.store(), &parent_hash);
let parent_status = self.shared.get_block_status(&parent_hash);
if parent_is_pending_verify || parent_status.contains(BlockStatus::BLOCK_STORED) {
debug!(
"parent {} has stored: {:?} or is_pending_verify: {}, processing descendant directly {}-{}",
Expand Down
8 changes: 4 additions & 4 deletions shared/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,15 @@ impl Shared {
&self.block_status_map
}

pub fn get_block_status<T: ChainStore>(&self, store: &T, block_hash: &Byte32) -> BlockStatus {
pub fn get_block_status(&self, block_hash: &Byte32) -> BlockStatus {
match self.block_status_map().get(block_hash) {
Some(status_ref) => *status_ref.value(),
None => {
if self.header_map().contains_key(block_hash) {
BlockStatus::HEADER_VALID
} else {
let verified = store
let verified = self
.snapshot()
.get_block_ext(block_hash)
.map(|block_ext| block_ext.verified);
match verified {
Expand All @@ -442,11 +443,10 @@ impl Shared {

pub fn contains_block_status<T: ChainStore>(
&self,
store: &T,
block_hash: &Byte32,
status: BlockStatus,
) -> bool {
self.get_block_status(store, block_hash).contains(status)
self.get_block_status(block_hash).contains(status)
}

pub fn insert_block_status(&self, block_hash: Byte32, status: BlockStatus) {
Expand Down
2 changes: 1 addition & 1 deletion sync/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1953,7 +1953,7 @@ impl ActiveChain {
}

pub fn get_block_status(&self, block_hash: &Byte32) -> BlockStatus {
self.shared().get_block_status(self.snapshot(), block_hash)
self.shared().get_block_status(block_hash)
}

pub fn contains_block_status(&self, block_hash: &Byte32, status: BlockStatus) -> bool {
Expand Down

0 comments on commit da0db29

Please sign in to comment.