-
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
refactor(storage): unify blocks insertion logic #12694
Conversation
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.
need @joshieDo input here
all of this makes sense
his required a drive-by change of making SealedBlockWithSenders generic over header and body like SealedBlock
this is fine for me in this pr, but would have preferred a separate one for this.
one question about elapsed insert tracking
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.
why do we no longer need these metrics?
EDIT: ah because we now operate on block bodies
makes sense
// write transactions | ||
for transaction in body.transactions() { | ||
let hash = transaction.tx_hash(); | ||
let start = Instant::now(); |
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 way too expensive to do per tx
was this the case before?
I'd rather not do this at all
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 was the case for live sync but not for the pipeline, should I remove it or just make optional?
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'd prefer removing this entirely, doesn't seem very useful, just needlessly expensive
wdyt @joshieDo
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.
don't want to block this pr for this,
but would like to get rid of this detailed time tracking entirely because these additional syscall per tx are likely expensive (400 timesyscalls for a 200txs block)
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.
removed the per-tx metrics
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 makes sense
/// Write to both the database and static files. | ||
Both, |
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.
does this mean data is duplicated?
not obvious where we need this
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.
right now we are using insert_block
which does this by default and on reorgs we use take_block_transactions_range
which relies on all transactions being present in database
let transactions = self |
to get rid of this we'd need a separate fn for reorgs in new engine which I am planning to do in a follow-up
b8980e5
to
f1725c3
Compare
// write transactions | ||
for transaction in body.transactions() { | ||
let hash = transaction.tx_hash(); | ||
let start = Instant::now(); |
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.
don't want to block this pr for this,
but would like to get rid of this detailed time tracking entirely because these additional syscall per tx are likely expensive (400 timesyscalls for a 200txs block)
pending @joshieDo |
@@ -225,6 +227,7 @@ impl_compression_for_compact!( | |||
Bytecode, | |||
AccountBeforeTx, | |||
TransactionSignedNoHash, | |||
TransactionSigned, |
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.
why ? this should not be written to storage
.database() | ||
.then(|| { | ||
self.tx.cursor_write::<tables::Transactions< | ||
<Self::Body as reth_primitives_traits::BlockBody>::Transaction, |
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.
are we sure we are writing TransactionSignedNoHash
and not TransactionSigned
here?
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.
TransactionSigned
Compact impl delegates to TransactionSignedNoHash
reth/crates/primitives/src/transaction/mod.rs
Lines 1053 to 1067 in e3702cf
#[cfg(any(test, feature = "reth-codec"))] | |
impl reth_codecs::Compact for TransactionSigned { | |
fn to_compact<B>(&self, buf: &mut B) -> usize | |
where | |
B: bytes::BufMut + AsMut<[u8]>, | |
{ | |
let tx: TransactionSignedNoHash = self.clone().into(); | |
tx.to_compact(buf) | |
} | |
fn from_compact(buf: &[u8], len: usize) -> (Self, &[u8]) { | |
let (tx, buf) = TransactionSignedNoHash::from_compact(buf, len); | |
(tx.into(), buf) | |
} | |
} |
those should be unified soon with #12596
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.
need to make sure this happens before we get to readers abstraction though so that we don't do hashing on every storage read
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.
oh i see we introduced it here: #12539
Updates
UnifiedStorageWriter
to reuse code paths fromBodyStage
for blocks writing. This is done by extendingBlockWriter
methods with an additionalwrite_transactions_to
parameter:reth/crates/storage/provider/src/traits/block.rs
Lines 67 to 71 in b8980e5
reth/crates/storage/provider/src/traits/block.rs
Lines 10 to 19 in b8980e5
StorageLocation::Database
is a default forinsert_block
and only writes transactions to database, used by legacy engine and components which need to operate on database without ever commiting anything (like debugging CLI commands)StorageLocation::Both
writes to both database and staticfiles, used by new engine right now.StorageLocation::StaticFiles
only writes transactions to staticfiles, used byBodyStage
. Should be used by new engine as well eventually.Same can be done with headers and receipts as well
This required a drive-by change of making
SealedBlockWithSenders
generic over header and body likeSealedBlock