Skip to content

Commit

Permalink
add source path to avoid go back of the dag node
Browse files Browse the repository at this point in the history
  • Loading branch information
jackzhhuang committed Mar 25, 2024
1 parent dceca50 commit b295426
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions sync/src/tasks/block_sync_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ where
}
}

pub fn ensure_dag_parent_blocks_exist(&mut self, block_header: BlockHeader) -> Result<()> {
pub fn ensure_dag_parent_blocks_exist(&mut self, block_header: BlockHeader, source_path: &mut HashSet<HashValue>) -> Result<()> {
if !block_header.is_dag() {
info!(
"the block is not a dag block, skipping, its id: {:?}, its number {:?}",
Expand Down Expand Up @@ -489,7 +489,7 @@ where

// remove the key in the source path to avoid indefinite recursive!
info!("jacktest: before removing the source path from the dag ancestors: dag ancetsor: {:?}", dag_ancestors);
// dag_ancestors.retain(|key| !source_path.contains(key));
dag_ancestors.retain(|key| !source_path.contains(key));
dag_ancestors.reverse();
info!("jacktest: after removing the source path from the dag ancestors: dag ancetsor: {:?}", dag_ancestors);

Expand Down Expand Up @@ -575,10 +575,10 @@ where
}
dag_ancestors = std::mem::take(&mut process_dag_ancestors);
// process_dag_ancestors = vec![];
// source_path.extend(&dag_ancestors);

// info!("jacktest: find {:?} 's children", dag_ancestors);
dag_ancestors = Self::remove_repeated(&self.fetch_dag_block_absent_children(dag_ancestors).await?);
source_path.extend(&dag_ancestors);
// info!("jacktest: its next children is {:?}", next_children);

// info!("jacktest: now find the absent children");
Expand All @@ -593,7 +593,7 @@ where
if !dag_ancestors.is_empty() {
for (id, op_header) in self.fetcher.fetch_block_headers(dag_ancestors.clone()).await? {
if let Some(header) = op_header {
self.ensure_dag_parent_blocks_exist(header)?;
self.ensure_dag_parent_blocks_exist(header, source_path)?;
} else {
bail!("when finding the ancestor's children's parents, fetching block header failed, block id: {:?}", id);
}
Expand Down Expand Up @@ -748,7 +748,7 @@ where
// if it is a dag block, we must ensure that its dag parent blocks exist.
// if it is not, we must pull the dag parent blocks from the peer.
info!("now sync dag block -- ensure_dag_parent_blocks_exist");
self.ensure_dag_parent_blocks_exist(block.header().clone())?;
self.ensure_dag_parent_blocks_exist(block.header().clone(), &mut [].into_iter().collect())?;
let state = self.check_enough();
if let anyhow::Result::Ok(CollectorState::Enough) = &state {
let current_header = self.chain.current_header();
Expand Down

0 comments on commit b295426

Please sign in to comment.