-
Notifications
You must be signed in to change notification settings - Fork 2.2k
chore: remove total difficulty from HeaderProvider
#19151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
5e4f1ad
dd12287
2b5ccc3
56633ef
6543a3a
4bdb89e
5e95536
296f508
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| use alloy_consensus::BlockHeader; | ||
| use alloy_primitives::{BlockHash, BlockNumber, Bytes, B256}; | ||
| use alloy_primitives::{BlockHash, BlockNumber, Bytes, B256, U256}; | ||
| use futures_util::StreamExt; | ||
| use reth_config::config::EtlConfig; | ||
| use reth_db_api::{ | ||
|
|
@@ -16,15 +16,14 @@ use reth_network_p2p::headers::{ | |
| }; | ||
| use reth_primitives_traits::{serde_bincode_compat, FullBlockHeader, NodePrimitives, SealedHeader}; | ||
| use reth_provider::{ | ||
| providers::StaticFileWriter, BlockHashReader, DBProvider, HeaderProvider, | ||
| HeaderSyncGapProvider, StaticFileProviderFactory, | ||
| providers::StaticFileWriter, BlockHashReader, DBProvider, HeaderSyncGapProvider, | ||
| StaticFileProviderFactory, | ||
| }; | ||
| use reth_stages_api::{ | ||
| CheckpointBlockRange, EntitiesCheckpoint, ExecInput, ExecOutput, HeadersCheckpoint, Stage, | ||
| StageCheckpoint, StageError, StageId, UnwindInput, UnwindOutput, | ||
| }; | ||
| use reth_static_file_types::StaticFileSegment; | ||
| use reth_storage_errors::provider::ProviderError; | ||
| use std::task::{ready, Context, Poll}; | ||
|
|
||
| use tokio::sync::watch; | ||
|
|
@@ -107,11 +106,6 @@ where | |
| .get_highest_static_file_block(StaticFileSegment::Headers) | ||
| .unwrap_or_default(); | ||
|
|
||
| // Find the latest total difficulty | ||
| let mut td = static_file_provider | ||
| .header_td_by_number(last_header_number)? | ||
| .ok_or(ProviderError::TotalDifficultyNotFound(last_header_number))?; | ||
|
|
||
| // Although headers were downloaded in reverse order, the collector iterates it in ascending | ||
| // order | ||
| let mut writer = static_file_provider.latest_writer(StaticFileSegment::Headers)?; | ||
|
|
@@ -134,11 +128,8 @@ where | |
| } | ||
| last_header_number = header.number(); | ||
|
|
||
| // Increase total difficulty | ||
| td += header.difficulty(); | ||
|
|
||
| // Append to Headers segment | ||
| writer.append_header(header, td, header_hash)?; | ||
| writer.append_header(header, U256::ZERO, header_hash)?; | ||
|
||
| } | ||
|
|
||
| info!(target: "sync::stages::headers", total = total_headers, "Writing headers hash index"); | ||
|
|
@@ -399,7 +390,7 @@ mod tests { | |
| use crate::test_utils::{ | ||
| stage_test_suite, ExecuteStageTestRunner, StageTestRunner, UnwindStageTestRunner, | ||
| }; | ||
| use alloy_primitives::B256; | ||
| use alloy_primitives::{B256, U256}; | ||
| use assert_matches::assert_matches; | ||
| use reth_provider::{DatabaseProviderFactory, ProviderFactory, StaticFileProviderFactory}; | ||
| use reth_stages_api::StageUnitCheckpoint; | ||
|
|
@@ -415,7 +406,7 @@ mod tests { | |
| ReverseHeadersDownloader, ReverseHeadersDownloaderBuilder, | ||
| }; | ||
| use reth_network_p2p::test_utils::{TestHeaderDownloader, TestHeadersClient}; | ||
| use reth_provider::{test_utils::MockNodeTypesWithDB, BlockNumReader}; | ||
| use reth_provider::{test_utils::MockNodeTypesWithDB, BlockNumReader, HeaderProvider}; | ||
| use tokio::sync::watch; | ||
|
|
||
| pub(crate) struct HeadersTestRunner<D: HeaderDownloader> { | ||
|
|
@@ -493,9 +484,6 @@ mod tests { | |
| match output { | ||
| Some(output) if output.checkpoint.block_number > initial_checkpoint => { | ||
| let provider = self.db.factory.provider()?; | ||
| let mut td = provider | ||
| .header_td_by_number(initial_checkpoint.saturating_sub(1))? | ||
| .unwrap_or_default(); | ||
|
|
||
| for block_num in initial_checkpoint..output.checkpoint.block_number { | ||
| // look up the header hash | ||
|
|
@@ -509,10 +497,6 @@ mod tests { | |
| assert!(header.is_some()); | ||
| let header = SealedHeader::seal_slow(header.unwrap()); | ||
| assert_eq!(header.hash(), hash); | ||
|
|
||
| // validate the header total difficulty | ||
| td += header.difficulty; | ||
| assert_eq!(provider.header_td_by_number(block_num)?, Some(td)); | ||
| } | ||
| } | ||
| _ => self.check_no_header_entry_above(initial_checkpoint)?, | ||
|
|
@@ -635,16 +619,7 @@ mod tests { | |
| let static_file_provider = provider.static_file_provider(); | ||
| let mut writer = static_file_provider.latest_writer(StaticFileSegment::Headers).unwrap(); | ||
| for header in sealed_headers { | ||
| let ttd = if header.number() == 0 { | ||
| header.difficulty() | ||
| } else { | ||
| let parent_block_number = header.number() - 1; | ||
| let parent_ttd = | ||
| provider.header_td_by_number(parent_block_number).unwrap().unwrap_or_default(); | ||
| parent_ttd + header.difficulty() | ||
| }; | ||
|
|
||
| writer.append_header(header.header(), ttd, &header.hash()).unwrap(); | ||
| writer.append_header(header.header(), U256::ZERO, &header.hash()).unwrap(); | ||
| } | ||
| drop(writer); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im guessing so, but is this okay?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be fine, in p2p this is deprecated as of
eth/69and the node builder only uses theHeadto get the timestamp