From 7accf535594b84d28184f3864bbdc50ba3c0d89e Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 13 Dec 2024 15:01:17 +0800 Subject: [PATCH] Add is_parent_exists for HeaderProcess --- sync/src/synchronizer/headers_process.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sync/src/synchronizer/headers_process.rs b/sync/src/synchronizer/headers_process.rs index 9fdeeb94bc..5c3d1bc1da 100644 --- a/sync/src/synchronizer/headers_process.rs +++ b/sync/src/synchronizer/headers_process.rs @@ -52,6 +52,12 @@ impl<'a> HeadersProcess<'a> { true } + fn is_parent_exists(&self, first_header: &core:HeaderView) -> bool { + let shared: &SyncShared = self.synchronizer.shared(); + shared.get_header_fields(first_header.parent_hash).is_some() + } + + pub fn accept_first(&self, first: &core::HeaderView) -> ValidationResult { let shared: &SyncShared = self.synchronizer.shared(); let verifier = HeaderVerifier::new(shared, shared.consensus()); @@ -128,6 +134,12 @@ impl<'a> HeadersProcess<'a> { return StatusCode::HeadersIsInvalid.with_context("not continuous"); } + if !self.is_parent_exists(&headers[0]) { + // put the headers into a memory cache + // verify them later + return Status::ok(); + } + let result = self.accept_first(&headers[0]); match result.state { ValidationState::Invalid => {