-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
refactor: remove Option<BlockHeight>
and use new enum where applicable
#2033
base: master
Are you sure you want to change the base?
Conversation
@@ -508,7 +508,7 @@ where | |||
off_chain_height.map(|height| BlockHeight::new(height.saturating_add(1))); | |||
|
|||
let import_result = | |||
import_result_provider.block_event_at_height(next_block_height)?; | |||
import_result_provider.block_event_at_height(next_block_height.into())?; |
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 it possible to make on_chain_database.latest_height()
return BlockHeightQuery
?
This makes me think that the name should be something different.
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.
We could change latest_height()
to return BlockHeightQuery
. I didn't do this because, IIUC, a database should be able to return None if it can't find the requested key. Is the genesis block stored in the DB? I agree the name BlockHeightQuery
isn't quite right. The only other name I can think of is SpecificBlockOrGenesis
@matt-user / @MitchTurner can I just regen the state transition bytecode, run tests again and then merge? |
Ah dang. Sorry @matt-user I thought this got merged :o |
Hello @matt-user , Sorry for letting your PR became stale like this. Are you ok to resolve the conflicts so that we can gett this merge soonish ? If you prefer we can take care of the conflicts for you, let me know :) |
Yeah sorry, I completely forgot about this. I will resolve the conflicts |
|
||
/// Represents either the Genesis Block or a block at a specific height | ||
#[derive(Copy, Clone, Debug, Display, PartialEq, Eq, Hash, Ord, PartialOrd)] | ||
pub enum BlockHeightQuery { |
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.
Hm, the "Query" part is a bit confusing, but I can't think of better name :)
Maybe I'm lacking a bit of context, but if Genesis
has no BlockHeight
, the better name would be just BlockQuery
? But Query
implies that this is intended to be used as an input to some function. I can imagine that there could be places where we want to get block height and we will be given the "query" back.
Or, maybe something like:
pub enum BlockAt {
Genesis,
Height(BlockHeight)
}
Anyways, it's pretty much a minor thing.
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 like BlockAt
better. Thanks for the suggestion
) -> anyhow::Result<SharedImportResult> { | ||
if let Some(height) = height { | ||
if let BlockHeightQuery::Specific(height) = height { |
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.
Now that we use an enum which, on the contrary to Option
, can have more variants, I'd vote for using an explicit match
.
Currently, if we add a third variant to BlockHeightQuery
it'll be treated as Genesis
, which may be not what we want. Compiler will not warn us.
closes #2005
I replaced
Option<BlockHeight>
withBlockHeightQuery
where applicable. IIUC there areOption<BlockHeight>
which should remain.Checklist
Before requesting review
After merging, notify other teams
[Add or remove entries as needed]