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

feat: add get_in_memory_or_storage_by_block to BlockchainProvider2 #11384

Merged
merged 13 commits into from
Oct 2, 2024

Conversation

joshieDo
Copy link
Collaborator

@joshieDo joshieDo commented Oct 1, 2024

  • Refactor logic into a single method, similar to others get_in_memory_or_storage methods
  • fixes race condition on BlockchainProvider2::history_by_block_hash

@joshieDo joshieDo added C-enhancement New feature or request A-blockchain-tree Related to sidechains, reorgs and pending blocks labels Oct 1, 2024
Copy link
Member

@Rjected Rjected left a 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.

Comment on lines +309 to +322
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()?)
}
Copy link
Member

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

Copy link
Collaborator Author

@joshieDo joshieDo Oct 1, 2024

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

Copy link
Collaborator

@mattsse mattsse Oct 1, 2024

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

Copy link
Member

Choose a reason for hiding this comment

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

makes sense

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

lgtm

Comment on lines +309 to +322
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()?)
}
Copy link
Collaborator

@mattsse mattsse Oct 1, 2024

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

@joshieDo joshieDo added this pull request to the merge queue Oct 2, 2024
Merged via the queue into main with commit 7c15326 Oct 2, 2024
36 checks passed
@joshieDo joshieDo deleted the joshie/bblock branch October 2, 2024 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-blockchain-tree Related to sidechains, reorgs and pending blocks C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants