fix: correctly detect first sync on headers stage (#12085)

This commit is contained in:
Arsenii Kulikov
2024-10-26 03:18:34 +04:00
committed by GitHub
parent a349919b5c
commit fa59bd512e

View File

@ -2,7 +2,7 @@ use alloy_primitives::{BlockHash, BlockNumber, Bytes, B256};
use futures_util::StreamExt; use futures_util::StreamExt;
use reth_config::config::EtlConfig; use reth_config::config::EtlConfig;
use reth_consensus::Consensus; use reth_consensus::Consensus;
use reth_db::{tables, RawKey, RawTable, RawValue}; use reth_db::{tables, transaction::DbTx, RawKey, RawTable, RawValue};
use reth_db_api::{ use reth_db_api::{
cursor::{DbCursorRO, DbCursorRW}, cursor::{DbCursorRO, DbCursorRW},
transaction::DbTxMut, transaction::DbTxMut,
@ -155,11 +155,13 @@ where
// If we only have the genesis block hash, then we are at first sync, and we can remove it, // If we only have the genesis block hash, then we are at first sync, and we can remove it,
// add it to the collector and use tx.append on all hashes. // add it to the collector and use tx.append on all hashes.
if let Some((hash, block_number)) = cursor_header_numbers.last()? { if provider.tx_ref().entries::<RawTable<tables::HeaderNumbers>>()? == 1 {
if block_number.value()? == 0 { if let Some((hash, block_number)) = cursor_header_numbers.last()? {
self.hash_collector.insert(hash.key()?, 0)?; if block_number.value()? == 0 {
cursor_header_numbers.delete_current()?; self.hash_collector.insert(hash.key()?, 0)?;
first_sync = true; cursor_header_numbers.delete_current()?;
first_sync = true;
}
} }
} }