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 reth_config::config::EtlConfig;
use reth_consensus::Consensus;
use reth_db::{tables, RawKey, RawTable, RawValue};
use reth_db::{tables, transaction::DbTx, RawKey, RawTable, RawValue};
use reth_db_api::{
cursor::{DbCursorRO, DbCursorRW},
transaction::DbTxMut,
@ -155,6 +155,7 @@ where
// 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.
if provider.tx_ref().entries::<RawTable<tables::HeaderNumbers>>()? == 1 {
if let Some((hash, block_number)) = cursor_header_numbers.last()? {
if block_number.value()? == 0 {
self.hash_collector.insert(hash.key()?, 0)?;
@ -162,6 +163,7 @@ where
first_sync = true;
}
}
}
// Since ETL sorts all entries by hashes, we are either appending (first sync) or inserting
// in order (further syncs).