Skip to content

Commit

Permalink
remove the used codes
Browse files Browse the repository at this point in the history
  • Loading branch information
jackzhhuang committed Oct 9, 2024
1 parent ea56f4a commit 0addbf7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
4 changes: 4 additions & 0 deletions flexidag/src/blockdag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,10 @@ impl BlockDAG {
self.storage.reachability_store.clone()
}

pub fn reachability_service(&self) -> MTReachabilityService<DbReachabilityStore> {
self.pruning_point_manager().reachability_service()
}

pub fn verify_and_ghostdata(
&self,
blue_blocks: &[BlockHeader],
Expand Down
2 changes: 1 addition & 1 deletion flexidag/src/ghostdag/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct GhostdagManager<
pub(super) ghostdag_store: T,
pub(super) relations_store: Arc<RwLock<S>>,
pub(super) headers_store: V,
pub(super) reachability_service: U,
pub reachability_service: U,
}

impl<
Expand Down
38 changes: 28 additions & 10 deletions sync/src/block_connector/write_block_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,18 +377,36 @@ where
self.dag.clone(),
)?;

// delete block since from block.number + 1 to latest.
let start = new_head_block.header().number().saturating_add(1);
let latest = self.main.status().head.number();
for block_number in start..latest {
if let Some(block) = self.main.get_block_by_number(block_number)? {
info!("Delete block({:?})", block.header);
self.storage.delete_block(block.id())?;
self.storage.delete_block_info(block.id())?;
} else {
warn!("Can not find block by number:{}", block_number);
let start = new_head_block.header().id();
let lastest = self.main.status().head.id();
let reachability_service = self.main.dag().reachability_service();
for child in reachability_service.forward_chain_iterator(start, lastest, true) {
if child == start {
continue;
}

let child_block = self
.main
.get_storage()
.get_block_header_by_hash(child)?
.ok_or_else(|| format_err!("Cannot find block header by hash: {:?}", child))?;

self.storage.delete_block(child)?;
self.storage.delete_block_info(child)?;

for parent in child_block.parents_hash().into_iter() {
if parent == start {
continue;
}
if self.main.dag().check_ancestor_of(parent, vec![start])? {
continue;
}

self.storage.delete_block(parent)?;
self.storage.delete_block_info(parent)?;
}
}

let executed_block = new_branch.head_block();

self.main = new_branch;
Expand Down

0 comments on commit 0addbf7

Please sign in to comment.