Add feature flag to start from any beacon block in db (#15000)

* 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>
This commit is contained in:
Potuz
2025-03-10 12:51:25 -03:00
committed by GitHub
parent 6d89373583
commit 863eee7b40
14 changed files with 301 additions and 19 deletions

View File

@@ -22,12 +22,15 @@ func IsHex(b []byte) bool {
// DecodeHexWithLength takes a string and a length in bytes,
// and validates whether the string is a hex and has the correct length.
func DecodeHexWithLength(s string, length int) ([]byte, error) {
if len(s) > 2*length+2 {
return nil, fmt.Errorf("%s is greather than length %d bytes", s, length)
}
bytes, err := hexutil.Decode(s)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("%s is not a valid hex", s))
}
if len(bytes) != length {
return nil, fmt.Errorf("%s is not length %d bytes", s, length)
return nil, fmt.Errorf("length of %s is not %d bytes", s, length)
}
return bytes, nil
}