-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
let block = executed_block.block(); | ||
let receipts = block_state.executed_block_receipts(); | ||
|
||
// assuming 1:1 correspondence between transactions and receipts |
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.
is this always true, do we have one receipt per tx?
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.
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
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.
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(); |
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 should be okay because we only expect a few blocks and all of them are just arcs
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.
yep, added a comment to make it more clear
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())); |
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.
doing mem lookups first is the right order because we only remove from mem after we flushed
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()); |
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 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.
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.
ok, added TODO to keep it in mind
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(), | ||
}; |
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 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
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.
sure done here 77bbd85
for (block_number, block_state) in | ||
self.canonical_in_memory_state.canonical_chain().enumerate() | ||
{ |
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 actually like to move these helper functions into the canonical memory type directly
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.
ok, I've moved the tx-related functions to CanonicalInMemoryState
, should we move anything else?
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!
// TODO: there might be an update between loop iterations, we | ||
// need to handle that situation. |
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.
it might be that we need to move this feature into the canonicalmemory type directly.
will track in a new issue
Closes #9924
I've left all the methods involving
TxNumber
untouched, not sure how to manage them.