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: support in memory lookups in BlockchainProvider2 #9999

Merged
merged 7 commits into from
Aug 2, 2024

Conversation

fgimenez
Copy link
Member

@fgimenez fgimenez commented Aug 1, 2024

Closes #9924

I've left all the methods involving TxNumber untouched, not sure how to manage them.

let block = executed_block.block();
let receipts = block_state.executed_block_receipts();

// assuming 1:1 correspondence between transactions and receipts
Copy link
Member Author

Choose a reason for hiding this comment

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

is this always true, do we have one receipt per tx?

Copy link
Member

Choose a reason for hiding this comment

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

yeah if you look at the tables they're both keyed by number and the only junction table is the one that maps txhash to number

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.

awesome, only a few stylistic suggestions

let pending = self.inner.in_memory_state.pending.read().clone();
let head = self.inner.in_memory_state.head_state();

let blocks = self.inner.in_memory_state.blocks.read().clone();
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should be okay because we only expect a few blocks and all of them are just arcs

Copy link
Member Author

Choose a reason for hiding this comment

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

yep, added a comment to make it more clear

Comment on lines +143 to +144
if let Some(block_state) = self.canonical_in_memory_state.state_by_hash(*block_hash) {
return Ok(Some(block_state.block().block().header.header().clone()));
Copy link
Collaborator

Choose a reason for hiding this comment

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

doing mem lookups first is the right order because we only remove from mem after we flushed

Comment on lines 179 to 181
for num in start..=end {
if let Some(block_state) = self.canonical_in_memory_state.state_by_number(num) {
headers.push(block_state.block().block().header.header().clone());
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is fine for now, but I suppose there's a low chance of a race condition because there can be an update in between these calls, we can track this in new issues though.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, added TODO to keep it in mind

Comment on lines 205 to 214
let start = match range.start_bound() {
Bound::Included(&n) => n,
Bound::Excluded(&n) => n + 1,
Bound::Unbounded => 0,
};
let end = match range.end_bound() {
Bound::Included(&n) => n,
Bound::Excluded(&n) => n - 1,
Bound::Unbounded => self.canonical_in_memory_state.get_canonical_block_number(),
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

this pattern repeats a few times, should we extract this into a function instead?

something that accepts a closure for the end unbounded case? or just fetches the canonical block number

Copy link
Member Author

Choose a reason for hiding this comment

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

sure done here 77bbd85

Comment on lines 541 to 543
for (block_number, block_state) in
self.canonical_in_memory_state.canonical_chain().enumerate()
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd actually like to move these helper functions into the canonical memory type directly

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, I've moved the tx-related functions to CanonicalInMemoryState, should we move anything else?

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.

lgtm!

crates/chain-state/src/in_memory.rs Outdated Show resolved Hide resolved
Comment on lines +198 to +199
// TODO: there might be an update between loop iterations, we
// need to handle that situation.
Copy link
Collaborator

Choose a reason for hiding this comment

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

it might be that we need to move this feature into the canonicalmemory type directly.

will track in a new issue

@fgimenez fgimenez added this pull request to the merge queue Aug 2, 2024
Merged via the queue into main with commit e9870e0 Aug 2, 2024
32 checks passed
@fgimenez fgimenez deleted the fgimenez/support-in-memory-lookups branch August 2, 2024 16:30
martinezjorge pushed a commit to martinezjorge/reth that referenced this pull request Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support in memory lookups in BlockchainProvider2
3 participants