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(dot/state): only store finalised blocks in database #1833

Merged
merged 43 commits into from
Oct 21, 2021

Conversation

noot
Copy link
Contributor

@noot noot commented Oct 5, 2021

Changes

  • refactor gossamer to only store finalised blocks in the database, unfinalised forks are stored in the blocktree and unfinalised *types.Block are stored in a map in the *state.Block
  • update *state.Blockgetter functions to get unfinalisedBlocks map
  • update *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) in unfinalisedBlocks map into the database
  • remove need for database within blocktree package, as the blocktree is no longer written to the db at all
  • update *state.BlockState NewBlockState to create a blocktree on startup from the latest finalised block

Tests

go test ./dot/state
go test ./lib/blocktree

Issues

Primary Reviewer

dot/types/body.go Outdated Show resolved Hide resolved
dot/types/body.go Outdated Show resolved Hide resolved
@noot noot requested a review from EclesioMeloJunior October 5, 2021 12:41
dot/state/block_finalisation.go Show resolved Hide resolved
dot/state/service.go Outdated Show resolved Hide resolved
lib/babe/build_test.go Outdated Show resolved Hide resolved
bn := bt.nodeCache[best]

fmt.Println(bt)
fmt.Println(best)
Copy link
Member

Choose a reason for hiding this comment

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

remove?

lib/blocktree/node.go Outdated Show resolved Hide resolved
Copy link
Member

@EclesioMeloJunior EclesioMeloJunior left a 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:] {
Copy link
Contributor

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?

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

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?

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 error gets returned right after, if there is one, so I think it's ok... what do you think?

Copy link
Contributor

@edwardmack edwardmack left a comment

Choose a reason for hiding this comment

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

Great work, lgtm.

@noot noot requested a review from timwu20 October 21, 2021 09:15
@noot noot merged commit 5e42215 into development Oct 21, 2021
@noot noot deleted the noot/store-finalised branch October 21, 2021 09:15
@github-actions
Copy link

github-actions bot commented Dec 3, 2021

🎉 This PR is included in version 0.6.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

timwu20 pushed a commit to timwu20/gossamer that referenced this pull request Dec 6, 2021
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.

gossamer should only store finalized blocks in the database
4 participants