From a12cd964ba5d5bf5416760f043383e53dc2e7983 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 13 Dec 2024 15:11:45 +0800 Subject: [PATCH] Put non-continous headers to header_cache, and re-check it after header_process success --- sync/src/synchronizer/headers_process.rs | 9 +++++++++ sync/src/synchronizer/mod.rs | 3 +++ 2 files changed, 12 insertions(+) diff --git a/sync/src/synchronizer/headers_process.rs b/sync/src/synchronizer/headers_process.rs index 5c3d1bc1da..309244da8f 100644 --- a/sync/src/synchronizer/headers_process.rs +++ b/sync/src/synchronizer/headers_process.rs @@ -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(); } @@ -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() } } diff --git a/sync/src/synchronizer/mod.rs b/sync/src/synchronizer/mod.rs index 83aa1213c3..c716b9f1d0 100644 --- a/sync/src/synchronizer/mod.rs +++ b/sync/src/synchronizer/mod.rs @@ -301,6 +301,9 @@ pub struct Synchronizer { pub(crate) chain: ChainController, /// Sync shared state pub shared: Arc, + + // First Headers's parent_hash -> Headers + pub(crate) header_cache: HashMap>, fetch_channel: Option>, }