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

chore(dot/sync): add Fragment struct for chain of blocks #4274

Open
wants to merge 6 commits into
base: development
Choose a base branch
from

Conversation

EclesioMeloJunior
Copy link
Member

@EclesioMeloJunior EclesioMeloJunior commented Oct 22, 2024

Changes

  • Adds a specialized struct to accommodate fragment of blocks acquired through sync process instead of using the raw [][]*types.BlockData
  • The changes don't change the current full sync behavior

Tests

  • N/A

Issues

@EclesioMeloJunior EclesioMeloJunior changed the title Eclesio/fragments chore(dot/sync): add Fragment struct for chain of blocks Oct 22, 2024
go.mod Outdated Show resolved Hide resolved
Copy link
Contributor

@haikoschol haikoschol left a comment

Choose a reason for hiding this comment

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

just a few nits, can be merged as is imho

// disjoint set and return the fragment concatenated with the chain argument
func (u *unreadyBlocks) updateDisjointFragments(chain []*types.BlockData) ([]*types.BlockData, bool) {
// connects to a disjoint fragment, and returns a ne fragment
func (u *unreadyBlocks) updateDisjointFragment(chain *Fragment) (*Fragment, bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func (u *unreadyBlocks) updateDisjointFragment(chain *Fragment) (*Fragment, bool) {
func (u *unreadyBlocks) updateDisjointFragments(chain *Fragment) (*Fragment, bool) {

I would keep the plural here. Alternatively, update the doc comment as well.

Comment on lines +203 to +205
// LowerThanOrEqHighestFinalized returns true if the fragment contains
// a block that has a number lower than highest finalized number
func LowerThanOrEqHighestFinalized(highestFinalizedNumber uint) func(*Fragment) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
// LowerThanOrEqHighestFinalized returns true if the fragment contains
// a block that has a number lower than highest finalized number
func LowerThanOrEqHighestFinalized(highestFinalizedNumber uint) func(*Fragment) bool {
// LowerThanOrEq returns a function that returns true if the fragment contains
// a block that has a number lower than or equal to the passed in number
func LowerThanOrEq(blockNumber uint) func(*Fragment) bool {

The function is more general than the name and doc comment suggests. It could be called with something other than the highest finalized number.

// connects to a disjoint fragment, if so we remove the fragment from the
// disjoint set and return the fragment concatenated with the chain argument
func (u *unreadyBlocks) updateDisjointFragments(chain []*types.BlockData) ([]*types.BlockData, bool) {
// connects to a disjoint fragment, and returns a ne fragment
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// connects to a disjoint fragment, and returns a ne fragment
// connects to a disjoint fragment, and returns a new fragment

func (f *Fragment) Iter() iter.Seq[*types.BlockData] {
return func(yield func(*types.BlockData) bool) {
for _, bd := range f.chain {
yield(bd)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should check the yield function result

Suggested change
yield(bd)
if !yield(bd){
return
}

@@ -43,6 +44,16 @@ func (f *Fragment) Find(p func(*types.BlockData) bool) *types.BlockData {
return nil
}

// Last returns the first block in the fragment or nil otherwise
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Last returns the first block in the fragment or nil otherwise
// First returns the first block in the fragment or nil otherwise

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.

chore(dot/sync): Introduce Fragment type to FullSync strategy
3 participants