-
Notifications
You must be signed in to change notification settings - Fork 129
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(dot/state): only store finalised blocks in database #1833
Conversation
…s upon SetFinalisedHash
…into noot/store-finalised
lib/blocktree/blocktree_test.go
Outdated
bn := bt.nodeCache[best] | ||
|
||
fmt.Println(bt) | ||
fmt.Println(best) |
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.
remove?
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.
LGTM!! 🎉
return fmt.Errorf("failed to get header in subchain: %w", err) | ||
|
||
// root of subchain is previously finalised block, which has already been stored in the db | ||
for _, hash := range subchain[1:] { |
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.
why subchain[1:]
? Could this ever panic?
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.
the comment explains it: root of subchain is previously finalised block, which has already been stored in the db
also, the previously finalised block is no longer in the unfinalised blocks map, so the code after will error. I don't think it will ever panic as the result of subchain is either a slice with at least 1 hash in it, or it'll return an error
|
||
// create block state | ||
s.Block, err = NewBlockState(db, bt) | ||
s.Block, err = NewBlockState(db) |
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.
should we assign this to s.Block
if there is an error?
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.
the error gets returned right after, if there is one, so I think it's ok... what do you think?
…into noot/store-finalised
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.
Great work, lgtm.
🎉 This PR is included in version 0.6.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Changes
*types.Block
are stored in a map in the*state.Block
*state.Block
getter functions to getunfinalisedBlocks
map*state.Block.SetFinalisedHash
(which is called when a block is marked finalised) to store blocks that are an ancestor of the finalised block (or are the finalised block) inunfinalisedBlocks
map into the database*state.BlockState
NewBlockState
to create a blocktree on startup from the latest finalised blockTests
Issues
Primary Reviewer