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

add block id to protocol state #5328

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zhangchiqing
Copy link
Member

No description provided.

@@ -698,8 +698,7 @@ func (state *State) Final() protocol.Snapshot {
// - exception for critical unexpected storage errors
func (state *State) AtHeight(height uint64) protocol.Snapshot {
// retrieve the block ID for the finalized height
var blockID flow.Identifier
err := state.db.View(operation.LookupBlockHeight(height, &blockID))
blockID, err := state.headers.BlockIDByHeight(height)
Copy link
Member Author

Choose a reason for hiding this comment

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

Same DB operation, except it reuses the cache from the headers module

@@ -210,7 +210,7 @@ func (e *Engine) BlockProcessable(b *flow.Header, _ *flow.QuorumCertificate) {
return
}

blockID := b.ID()
blockID := qc.BlockID
Copy link
Member Author

Choose a reason for hiding this comment

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

The caller guarantees the qc is for the block ID, this allows us to save a ID() call

@@ -72,6 +72,10 @@ func (s *Snapshot) Head() (*flow.Header, error) {
return head, err
}

func (s *Snapshot) BlockID() (flow.Identifier, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Some modules already depend on protocol state, however, they still import storage.Headers, because they need to find blockID by height using the headers.BlockIDByHeight method.

With the BlockID method added to snapshot along with the changes in the AtHeight method as below, we could use state.AtHeight(height).BlockID() to replace headers.BlockIDByHeight, which has been used a lot, and remove the dependency on storage.Headers.

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

Successfully merging this pull request may close these issues.

None yet

1 participant