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: Implement BlockReader::block_with_senders_range #7402

Merged
merged 12 commits into from Apr 12, 2024

Conversation

AbnerZheng
Copy link
Contributor

close #7395

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

ptal @joshieDo

Copy link
Collaborator

Choose a reason for hiding this comment

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

please keep this pr limited to adding the new function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@mattsse mattsse added C-enhancement New feature or request A-db Related to the database labels Apr 1, 2024
let len = range.end().saturating_sub(*range.start()) as usize;
let mut blocks = Vec::with_capacity(len);

let mut headers_cursor = self.tx.cursor_read::<tables::Headers>()?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

there was recently a PR that fixed an issue in this snippet of code

#7429

would need the same fix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 1452 to 1455
let senders = senders_cursor
.walk_range(tx_range)?
.map(|entry| entry.map(|(_, sender)| sender))
.collect::<Result<Vec<_>, _>>()?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

senders might be missing from the table if they are pruned, there other provider functions that can be used to get them, so you might need to do a mix of fetching what you can, and recover the rest (take a look at senders_by_tx_range)

Copy link
Collaborator

@joshieDo joshieDo Apr 4, 2024

Choose a reason for hiding this comment

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

otherwise, if they are pruned try_with_senders_unchecked will be recalculating every sender from the body, since txes.len != senders.len

If the above comment suggestion seems too complex, you could just let try_with_senders_unchecked calculate the senders by passing an empty vec. It can be improved on another PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Never mind, will give it a try later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@AbnerZheng AbnerZheng requested a review from joshieDo April 4, 2024 17:35
@mattsse
Copy link
Collaborator

mattsse commented Apr 9, 2024

ping @joshieDo

Comment on lines +1510 to +1519
for (tx_num, tx) in tx_range.zip(body.iter()) {
match known_senders.get(&tx_num) {
None => {
// recover the sender from the transaction if not found
let sender = tx
.recover_signer_unchecked()
.ok_or_else(|| ProviderError::SenderRecoveryError)?;
senders.push(sender);
}
Some(sender) => senders.push(*sender),
Copy link
Collaborator

Choose a reason for hiding this comment

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

There might be an improved performance route here by collecting all txes ref in a list and recover all signers in parallel, but can be done in a follow-up imo

.map(|(_, o)| o.ommers)
.unwrap_or_default()
};
if let Ok(b) = process_tx(tx_range, header, ommers, withdrawals) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

process_tx is a weird name here tho

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@AbnerZheng
Copy link
Contributor Author

@mattsse PTAL

@mattsse mattsse added this pull request to the merge queue Apr 12, 2024
Merged via the queue into paradigmxyz:main with commit 7918759 Apr 12, 2024
27 checks passed
@AbnerZheng AbnerZheng deleted the issue-7395 branch April 12, 2024 16:18
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 C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add BlockReader::block_with_senders_range
3 participants