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 19 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
@@ -132,7 +132,7 @@ impl TxQuery {
|start: &Option<SortedTxCursor>, direction| {
let start = *start;
let block_id = start.map(|sorted| sorted.block_height);
let all_block_ids = query.compressed_blocks(block_id, direction);
let all_block_ids = query.compressed_blocks(block_id.into(), direction);
Copy link
Member

Choose a reason for hiding this comment

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

Why is this block_id? Obviously this pre-existed your PR :)

Copy link
Member

Choose a reason for hiding this comment

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

it's the cursor to a paginated query

}
(true, IterDirection::Forward) => self
.on_chain
.blocks(BlockHeightQuery::Specific(height), direction),
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a smell. We are matching on the BlockHeightQuery then we reconstruct the BlockHeightQuery. I think blocks and old_blocks can probably just take Option<BlockHeight> and we can get rid of the From impl into Option./F

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only issue with this is that blocks is a port so it can either take Option<BlockHeight> or BlockHeightQuery so then this blocks function in database.rs would have to take a Option<BlockHeight>. What's the difference between reconstructing BlockHeightQuery and reconstructing the Option like the previous implementation?

Copy link
Member

Choose a reason for hiding this comment

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

What's the difference between reconstructing BlockHeightQuery and reconstructing the Option like the previous implementation?

There's no difference. I think it was a smell in the old code too.

How about

        if let BlockHeightQuery::Specific(inner) = height {
            match (inner >= self.genesis_height, direction) {
                (true, IterDirection::Forward) => self
                    .on_chain
                    .blocks(height, direction),

It would be nice if we had some type guarantee since the inner >= self.genesis_height is kinda redundant.

@@ -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

@@ -292,7 +295,7 @@ impl BlockQuery {
crate::schema::query_pagination(after, before, first, last, |start, direction| {
Ok(blocks_query(
query.as_ref(),
start.map(Into::into),
start.map(Into::<BlockHeight>::into).into(),
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't look like we can avoid the Option here, so this is where we are giving the business-level context to a None I guess.

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
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
5 participants