Skip to content

Commit

Permalink
Put non-continous headers to header_cache, and re-check it after head…
Browse files Browse the repository at this point in the history
…er_process success
  • Loading branch information
eval-exec committed Dec 13, 2024
1 parent 7accf53 commit a12cd96
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sync/src/synchronizer/headers_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ impl<'a> HeadersProcess<'a> {

if !self.is_parent_exists(&headers[0]) {
// put the headers into a memory cache
self.synchronizer.header_cache.insert(headers[0].parent_hash, headers);
// verify them later
return Status::ok();
}
Expand Down Expand Up @@ -222,6 +223,14 @@ impl<'a> HeadersProcess<'a> {
}
}

{
// these headers verify success
// may the headers's tail header_hash exist in headers_cahce?
if let Some(headers) = self.synchronizer.headers_cache.get(headers.last().expect("last header must exist").hash){
HeadersProcess::new().execute();
}
}

Status::ok()
}
}
Expand Down
3 changes: 3 additions & 0 deletions sync/src/synchronizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ pub struct Synchronizer {
pub(crate) chain: ChainController,
/// Sync shared state
pub shared: Arc<SyncShared>,

// First Headers's parent_hash -> Headers
pub(crate) header_cache: HashMap<Byte32, Vec<Header>>,
fetch_channel: Option<channel::Sender<FetchCMD>>,
}

Expand Down

0 comments on commit a12cd96

Please sign in to comment.