-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat(snapshots): write Headers to snapshots during HeaderStage
#6273
Changes from all commits
24b9a1e
a7132ea
fd32124
5f0d4c6
3ed71ee
290f5da
eee811f
6c50aff
ad6bb26
debaca4
489b582
c1f5704
f8cdc93
3d2514e
8673d82
155ce6e
b442fee
c04e3dc
c988685
8873287
5b20c26
cc2adfa
c186a5e
7ddad97
78e0ab2
8890dc9
4778948
3fda062
9dcf073
e1647ac
b74b726
d0a14f1
4b6eb0a
a201af2
874ae1c
4a36762
ced4432
9b0ff57
0088ff1
e0668ef
13382ce
94c6d16
132bd00
483ae7f
c29c100
ed4d768
0210eb9
f6a8b5e
05ad35e
b2dfb31
6c515f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
//! Blockchain tree externals. | ||
|
||
use reth_db::{cursor::DbCursorRO, database::Database, tables, transaction::DbTx}; | ||
use reth_db::{ | ||
cursor::DbCursorRO, database::Database, snapshot::HeaderMask, tables, transaction::DbTx, | ||
}; | ||
use reth_interfaces::{consensus::Consensus, RethResult}; | ||
use reth_primitives::{BlockHash, BlockNumber}; | ||
use reth_provider::ProviderFactory; | ||
use reth_primitives::{BlockHash, BlockNumber, SnapshotSegment}; | ||
use reth_provider::{ProviderFactory, StatsReader}; | ||
use std::{collections::BTreeMap, sync::Arc}; | ||
|
||
/// A container for external components. | ||
|
@@ -44,13 +46,33 @@ impl<DB: Database, EF> TreeExternals<DB, EF> { | |
&self, | ||
num_hashes: usize, | ||
) -> RethResult<BTreeMap<BlockNumber, BlockHash>> { | ||
Ok(self | ||
let mut hashes = self | ||
.provider_factory | ||
.provider()? | ||
.tx_ref() | ||
.cursor_read::<tables::CanonicalHeaders>()? | ||
.walk_back(None)? | ||
.take(num_hashes) | ||
.collect::<Result<BTreeMap<BlockNumber, BlockHash>, _>>()?) | ||
.collect::<Result<BTreeMap<BlockNumber, BlockHash>, _>>()?; | ||
|
||
if hashes.len() < num_hashes { | ||
let snapshot_provider = self.provider_factory.snapshot_provider(); | ||
let total_headers = snapshot_provider.count_entries::<tables::Headers>()? as u64; | ||
if total_headers > 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm this is ok for now, i'd add a comment on what this is doing, but ideally the switch between fetching from db vs snapshots would be a bit more transparent 😬 |
||
let range = total_headers | ||
.saturating_sub(1) | ||
.saturating_sub((num_hashes - hashes.len()) as u64).. | ||
total_headers; | ||
|
||
hashes.extend(range.clone().zip(snapshot_provider.fetch_range_with_predicate( | ||
SnapshotSegment::Headers, | ||
range, | ||
|cursor, number| cursor.get_one::<HeaderMask<BlockHash>>(number.into()), | ||
|_| true, | ||
)?)); | ||
} | ||
} | ||
|
||
Ok(hashes) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -288,7 +288,7 @@ impl TransactionFetcher { | |
); | ||
|
||
max_retried_hashes.push(hash); | ||
continue; | ||
continue | ||
} | ||
*retries += 1; | ||
} | ||
|
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.
this is better!!