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 feature flag to start from any beacon block in db #15000

Merged
merged 8 commits into from
Mar 10, 2025
Merged

Conversation

potuz
Copy link
Contributor

@potuz potuz commented Feb 28, 2025

The new feature flag called --sync-from takes a string that can take
values:

  • head or
  • a 0x-prefixed hex encoded beacon block root.

The beacon block root or the head block root has to be known in db and
has to be a descendant of the current justified checkpoint.

@potuz potuz force-pushed the sync_from_head branch 2 times, most recently from b3af6be to 602cb24 Compare February 28, 2025 13:45
The new feature flag called --sync-from takes a string that can take
values:

- `head` or
- a 0x-prefixed hex encoded beacon block root.

The beacon block root or the head block root has to be known in db and
has to be a descendant of the current justified checkpoint.
@nisdas nisdas mentioned this pull request Mar 1, 2025
4 tasks
@potuz potuz marked this pull request as ready for review March 7, 2025 20:31
@potuz potuz requested a review from a team as a code owner March 7, 2025 20:31
err := s.db.View(func(tx *bolt.Tx) error {
bkt := tx.Bucket(blocksBucket)
headRoot := bkt.Get(headBlockRootKey)
if headRoot == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: I looked at the Get code to make sure there's no way for a "not found" value to be an empty slice, so I'm confident what you have here works, but as a general rule, I think we should prefer len(headRoot) == 0 over headRoot == nil when checking byte slices.

return nil, err
}
// This chain sets the justified checkpoint for every block, including some that are older than jp.
// This should be however safe for forkchoice at startup.
Copy link
Contributor

Choose a reason for hiding this comment

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

A comment explaining /why/ we are setting a future justified checkpoint on blocks that precede the jp would be helpful.

log.Infof("Using Head root of %#x", root)
return root
}
root, err := bytesutil.DecodeHexWithLength(headStr, 32)
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 make a note to move this into cmd/beacon-chain/blockchain/options.go so we can fail faster if there is a user input validation error.

st,
blk.Block().Slot(),
false,
}), "could not set head")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: IMO this style is distracting compared to the typical:

if err := s.setHead(&head{root, blk, st, blk.Block().Slot(), false}); err != nil {
    return errors.Wrap(err, "could not set head")
}
return nil

Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: we should avoid using positional struct fields where possible.

nitpick: It's also odd that setHead takes a struct pointer, when the pointer seems like a hack to make the func signature smaller - everywhere this is called, the struct is constructed. Looking at setHead, I would suggest breaking these fields out into individual args.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a copy paste from develop, not sure what you want me to do here. I'll merge all the other suggestion and will take whatever you want on this one.

Copy link
Contributor

Choose a reason for hiding this comment

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

For now suggestion is just to replace the highlighted lines with:

if err := s.setHead(&head{root, blk, st, blk.Block().Slot(), false}); err != nil {
    return errors.Wrap(err, "could not set head")
}
return nil

I'll send a PR later for how I'd like to change setHead.

@potuz potuz added this pull request to the merge queue Mar 10, 2025
Merged via the queue into develop with commit 863eee7 Mar 10, 2025
17 checks passed
@potuz potuz deleted the sync_from_head branch March 10, 2025 16:55
rkapka pushed a commit that referenced this pull request Mar 19, 2025
* Add feature flag to start from any beacon block in db

The new feature flag called --sync-from takes a string that can take
values:

- `head` or
- a 0x-prefixed hex encoded beacon block root.

The beacon block root or the head block root has to be known in db and
has to be a descendant of the current justified checkpoint.

* Fix Bugs In Sync From Head (#15006)

* Fix Bugs

* Remove log

* missing save

* add tests

* Kasey review #1

* Kasey's review #2

* Kasey's review #3

---------

Co-authored-by: Nishant Das <nishdas93@gmail.com>
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.

3 participants