-
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(storage): better sender recovery if not found in database #4471
Conversation
Codecov Report
... and 18 files with indirect coverage changes
Flags with carried forward coverage won't be shown. Click here to find out more.
|
32bb376
to
06d48ff
Compare
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.
lgtm
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)); | ||
} |
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.
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)); | |
} |
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 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)); |
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.
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()); |
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.
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() { |
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.
nit: we can senders.reserve the remaining len
#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 isPruneMode::All
.