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

refactor: remove Option<BlockHeight> and use new enum where applicable #2033

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

matt-user
Copy link
Contributor

@matt-user matt-user commented Jul 16, 2024

closes #2005

I replaced Option<BlockHeight> with BlockHeightQuery where applicable. IIUC there are Option<BlockHeight> which should remain.

Checklist

  • Breaking changes are clearly marked as such in the PR description and changelog
  • New behavior is reflected in tests
  • The specification matches the implemented behavior (link update PR if changes are needed)

Before requesting review

  • I have reviewed the code myself
  • I have created follow-up issues caused by this PR and linked them here

After merging, notify other teams

[Add or remove entries as needed]

@matt-user matt-user added the enhancement New feature or request label Jul 16, 2024
@matt-user matt-user self-assigned this Jul 16, 2024
@matt-user matt-user marked this pull request as ready for review July 16, 2024 01:21
@matt-user matt-user requested a review from a team July 16, 2024 01:21
crates/fuel-core/src/schema/tx.rs Outdated Show resolved Hide resolved
crates/fuel-core/src/graphql_api/database.rs Outdated Show resolved Hide resolved
@@ -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())?;
Copy link
Member

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.

Copy link
Contributor Author

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

crates/fuel-core/src/schema/block.rs Show resolved Hide resolved
MitchTurner
MitchTurner previously approved these changes Aug 14, 2024
@rymnc
Copy link
Member

rymnc commented Aug 17, 2024

@matt-user / @MitchTurner can I just regen the state transition bytecode, run tests again and then merge?

@MitchTurner
Copy link
Member

Ah dang. Sorry @matt-user I thought this got merged :o

@AurelienFT
Copy link
Contributor

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 :)
Sorry again.

@matt-user
Copy link
Contributor Author

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 :) Sorry again.

Yeah sorry, I completely forgot about this. I will resolve the conflicts

@matt-user matt-user enabled auto-merge (squash) November 7, 2024 08:53
@matt-user matt-user requested review from MitchTurner, Voxelot and a team November 10, 2024 05:02

/// 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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove use of Option<BlockHeight> as a query for blocks
6 participants