-
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: add get_in_memory_or_storage_by_block
to BlockchainProvider2
#11384
Conversation
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 nice, I have one comment nit and one question about if we should add to the API.
let block_state = match id { | ||
BlockHashOrNumber::Hash(block_hash) => { | ||
self.canonical_in_memory_state.state_by_hash(block_hash) | ||
} | ||
BlockHashOrNumber::Number(block_number) => { | ||
self.canonical_in_memory_state.state_by_number(block_number) | ||
} | ||
}; | ||
|
||
if let Some(block_state) = block_state { | ||
return fetch_from_block_state(block_state) | ||
} | ||
fetch_from_db(self.database_provider_ro()?) | ||
} |
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 makes me wonder if we should just have a method that does the:
if let Some(block_state) = block_state {
return fetch_from_block_state(block_state)
}
fetch_from_db(self.database_provider_ro()?)
part, and provide by_block_hash
or by_block_num
methods so we don't have to go from number -> id -> match to number. same for hash -> id -> hash
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 think those conversions should be perf-wise negligible, and it's worth imo having all logic in one single method
not that strongly opinated, if someone else would rather have by_block_hash
and by_block_num
additions i'll add those cc @mattsse
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 I think using the enum type here is fine, because some functions that need this feature accept NumHash themselves
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.
makes sense
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
let block_state = match id { | ||
BlockHashOrNumber::Hash(block_hash) => { | ||
self.canonical_in_memory_state.state_by_hash(block_hash) | ||
} | ||
BlockHashOrNumber::Number(block_number) => { | ||
self.canonical_in_memory_state.state_by_number(block_number) | ||
} | ||
}; | ||
|
||
if let Some(block_state) = block_state { | ||
return fetch_from_block_state(block_state) | ||
} | ||
fetch_from_db(self.database_provider_ro()?) | ||
} |
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 I think using the enum type here is fine, because some functions that need this feature accept NumHash themselves
BlockchainProvider2::history_by_block_hash