Skip to content
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(storage): better sender recovery if not found in database #4471

Merged
merged 9 commits into from
Sep 5, 2023

Conversation

shekhirin
Copy link
Collaborator

@shekhirin shekhirin commented Sep 4, 2023

#4280 had as assumption that senders can be only missing the beginning of the tx range requested from the database, because pruning is done in the chain growth direction.

The problem is that with #4431 we will have senders missing from the database in both beginning and end of the tx range, because pruner removes the senders from the beginning, and senders from the end are not written at all if SenderRecovery prune part is PruneMode::All.

@rkrasiuk rkrasiuk added A-db Related to the database A-pruning Related to pruning or full node labels Sep 4, 2023
@codecov
Copy link

codecov bot commented Sep 4, 2023

Codecov Report

Merging #4471 (d317e84) into main (b32562f) will decrease coverage by 0.02%.
Report is 5 commits behind head on main.
The diff coverage is 98.00%.

Impacted file tree graph

Files Changed Coverage Δ
crates/transaction-pool/src/pool/best.rs 71.42% <ø> (-4.54%) ⬇️
...torage/provider/src/providers/database/provider.rs 80.25% <97.14%> (+0.16%) ⬆️
...tes/storage/provider/src/providers/database/mod.rs 46.13% <100.00%> (+1.75%) ⬆️

... and 18 files with indirect coverage changes

Flag Coverage Δ
integration-tests 16.61% <0.00%> (-0.02%) ⬇️
unit-tests 63.81% <98.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
reth binary 29.71% <ø> (ø)
blockchain tree 83.58% <ø> (ø)
pipeline 90.56% <ø> (ø)
storage (db) 75.04% <98.00%> (+0.05%) ⬆️
trie 94.88% <ø> (ø)
txpool 47.42% <ø> (-0.06%) ⬇️
networking 77.46% <ø> (-0.07%) ⬇️
rpc 57.41% <ø> (+0.04%) ⬆️
consensus 63.40% <ø> (ø)
revm 31.74% <ø> (ø)
payload builder 6.34% <ø> (-0.03%) ⬇️
primitives 86.11% <ø> (-0.04%) ⬇️

Base automatically changed from alexey/provider-sender-recover-test to main September 4, 2023 12:32
@shekhirin shekhirin marked this pull request as ready for review September 4, 2023 13:17
@shekhirin shekhirin marked this pull request as draft September 4, 2023 13:17
@shekhirin shekhirin force-pushed the alexey/provider-sender-recover branch 6 times, most recently from 32bb376 to 06d48ff Compare September 4, 2023 13:23
@shekhirin shekhirin marked this pull request as ready for review September 4, 2023 15:56
Copy link
Member

@rkrasiuk rkrasiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Comment on lines +452 to +466
if let Some((sender_tx_number, _)) = senders.peek() {
if sender_tx_number == tx_number {
// If current sender's `TxNumber` matches current transaction's
// `TxNumber`, advance the senders iterator.
senders.next();
} else {
// If current sender's `TxNumber` doesn't match current transaction's
// `TxNumber`, add it to missing senders.
missing_senders.push((i, tx_number, transaction));
}
} else {
// If there's no more senders left, but we're still iterating over
// transactions, add them to missing senders
missing_senders.push((i, tx_number, transaction));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if let Some((sender_tx_number, _)) = senders.peek() {
if sender_tx_number == tx_number {
// If current sender's `TxNumber` matches current transaction's
// `TxNumber`, advance the senders iterator.
senders.next();
} else {
// If current sender's `TxNumber` doesn't match current transaction's
// `TxNumber`, add it to missing senders.
missing_senders.push((i, tx_number, transaction));
}
} else {
// If there's no more senders left, but we're still iterating over
// transactions, add them to missing senders
missing_senders.push((i, tx_number, transaction));
}
if lsenders.peek().map_or(false, |(sender_tx_number, _)| sender_tx_number == tx_number) {
// If current sender's `TxNumber` matches current transaction's
// `TxNumber`, advance the senders iterator.
senders.next();
} else {
// If current sender's `TxNumber` doesn't match current transaction's or
// there're no more senders left, but we're still iterating over transactions,
// add them to missing senders
missing_senders.push((i, tx_number, transaction));
}

Copy link
Collaborator Author

@shekhirin shekhirin Sep 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it even more verbose, because I personally often get confused by map_or(false, ... or map_or(true, ...

// Insert recovered senders along with tx numbers at the corresponding indexes to the
// original `senders` vector
for ((i, tx_number, _), sender) in missing_senders.into_iter().zip(recovered_senders) {
senders.insert(i, (*tx_number, sender));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
senders.insert(i, (*tx_number, sender));
// Insert will put recovered senders at necessary positions and shift the rest
senders.insert(i, (*tx_number, sender));

if senders.len() != transactions.len() {
// Find all missing senders, their corresponding tx numbers and indexes to the original
// `senders` vector at which the recovered senders will be inserted
let mut missing_senders = Vec::with_capacity(transactions.len() - senders.len());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let mut missing_senders = Vec::with_capacity(transactions.len() - senders.len());
// SAFETY: Transactions are always guaranteed to be in the database whereas
// senders might be pruned
let mut missing_senders = Vec::with_capacity(transactions.len() - senders.len());

))?,
// SAFETY: Transactions are always guaranteed to be in the database whereas
// senders might be pruned.
if senders.len() != transactions.len() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we can senders.reserve the remaining len

@shekhirin shekhirin added this pull request to the merge queue Sep 5, 2023
Merged via the queue into main with commit 843d504 Sep 5, 2023
24 checks passed
@shekhirin shekhirin deleted the alexey/provider-sender-recover branch September 5, 2023 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-db Related to the database A-pruning Related to pruning or full node
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants