-
Notifications
You must be signed in to change notification settings - Fork 1.5k
cl: fix Gloas checkpoint sync with external execution clients #22683
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
Open
domiwei
wants to merge
12
commits into
main
Choose a base branch
from
kewei/gloas-external-el-sync
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8091464
cl/forkchoice: fix skipped checkpoint state root
domiwei 46e7de2
cl/stages: validate Gloas payloads with external EL
domiwei fc97d57
cl/execution_client, engine_types: encode empty transactions as array
domiwei 25df829
cl/checkpoint_sync, forkchoice, stages: harden external EL validation
domiwei 2f042fd
cl/services: bound payload attestation validation
domiwei f867805
cl/forkchoice, cl/services: share payload attestation validation context
domiwei fc350db
cl/das: start PeerDAS after gossip registration
domiwei 9699259
cl: harden Gloas payload recovery and validation
domiwei f1762fe
cl: recover missing head envelopes safely
domiwei c005feb
cl: bound Gloas head recovery waits
domiwei fad8eb9
cl/forkchoice: expire unusable pending envelopes
domiwei a49b7c8
Merge main and fix Gloas recovery retries
domiwei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Copyright 2026 The Erigon Authors | ||
| // This file is part of Erigon. | ||
| // | ||
| // Erigon is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Lesser General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // Erigon is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Lesser General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Lesser General Public License | ||
| // along with Erigon. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| package das | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "go.uber.org/mock/gomock" | ||
|
|
||
| "github.com/erigontech/erigon/cl/clparams" | ||
| peerdasstate "github.com/erigontech/erigon/cl/das/state" | ||
| gossipmock "github.com/erigontech/erigon/cl/phase1/network/gossip/mock_services" | ||
| ) | ||
|
|
||
| func TestPeerDasSubscribesOnlyAfterStart(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| gossipManager := gossipmock.NewMockGossip(ctrl) | ||
| beaconConfig := clparams.MainnetBeaconConfig | ||
| beaconConfig.DataColumnSidecarSubnetCount = 2 | ||
| caplinConfig := clparams.CaplinConfig{ArchiveBlobs: true} | ||
| peerDasState := peerdasstate.NewPeerDasState(&beaconConfig, &clparams.NetworkConfig{}) | ||
|
|
||
| peerDas := NewPeerDas(nil, &beaconConfig, &caplinConfig, nil, nil, nil, [32]byte{}, nil, peerDasState, gossipManager, nil, nil) | ||
|
|
||
| gossipManager.EXPECT().SubscribeWithExpiry(gomock.Any(), gomock.Any()).Times(2) | ||
| ctx, cancel := context.WithCancel(context.Background()) | ||
| peerDas.Start(ctx) | ||
| peerDas.Start(ctx) | ||
| cancel() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| package checkpoint_sync | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "crypto/sha256" | ||
| "encoding/hex" | ||
| "errors" | ||
| "fmt" | ||
| "io/fs" | ||
| "path/filepath" | ||
|
|
||
| "github.com/erigontech/erigon/cl/clparams" | ||
| "github.com/erigontech/erigon/cl/phase1/core/state" | ||
| "github.com/erigontech/erigon/common" | ||
| "github.com/erigontech/erigon/common/dir" | ||
| "github.com/spf13/afero" | ||
| ) | ||
|
|
||
| const finalizedStateRootPrefix = ".finalized-state-root-" | ||
|
|
||
| var ErrFinalizedGloasStateRootMissing = errors.New("finalized Gloas state is missing its authoritative state root") | ||
|
|
||
| func FinalizedStateRootFileName(snappyState []byte) string { | ||
| digest := sha256.Sum256(snappyState) | ||
| return finalizedStateRootPrefix + hex.EncodeToString(digest[:]) | ||
| } | ||
|
|
||
| func RemoveObsoleteFinalizedStateRoots(directory, keepPath string) error { | ||
| rootFiles, err := filepath.Glob(filepath.Join(directory, finalizedStateRootPrefix+"*")) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| for _, rootPath := range rootFiles { | ||
| if rootPath == keepPath { | ||
| continue | ||
| } | ||
| if err := dir.RemoveFile(rootPath); err != nil && !errors.Is(err, fs.ErrNotExist) { | ||
| return err | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func RestoreFinalizedStateRoot(storage afero.Fs, snappyState []byte, st *state.CachingBeaconState) error { | ||
| if st.Version() < clparams.GloasVersion { | ||
| return nil | ||
| } | ||
| record, err := afero.ReadFile(storage, FinalizedStateRootFileName(snappyState)) | ||
| if err != nil { | ||
| if errors.Is(err, fs.ErrNotExist) { | ||
| header := st.LatestBlockHeader() | ||
| if st.Version() >= clparams.GloasVersion && header.Slot == st.Slot() && header.Root == (common.Hash{}) { | ||
| return ErrFinalizedGloasStateRootMissing | ||
| } | ||
| return nil | ||
| } | ||
| return fmt.Errorf("read finalized state root: %w", err) | ||
| } | ||
| if len(record) != 2*len(common.Hash{}) { | ||
| return fmt.Errorf("invalid finalized state root record length %d", len(record)) | ||
| } | ||
| digest := sha256.Sum256(snappyState) | ||
| checksumInput := make([]byte, 0, len(digest)+len(common.Hash{})) | ||
| checksumInput = append(checksumInput, digest[:]...) | ||
| checksumInput = append(checksumInput, record[:len(common.Hash{})]...) | ||
| wantChecksum := sha256.Sum256(checksumInput) | ||
| if !bytes.Equal(wantChecksum[:], record[len(common.Hash{}):]) { | ||
| return errors.New("invalid finalized state root checksum") | ||
| } | ||
| st.SetPreviousStateRoot(common.BytesToHash(record[:len(common.Hash{})])) | ||
| return nil | ||
| } | ||
|
|
||
| func EncodeFinalizedStateRoot(snappyState []byte, root common.Hash) []byte { | ||
| digest := sha256.Sum256(snappyState) | ||
| checksumInput := make([]byte, 0, len(digest)+len(root)) | ||
| checksumInput = append(checksumInput, digest[:]...) | ||
| checksumInput = append(checksumInput, root[:]...) | ||
| checksum := sha256.Sum256(checksumInput) | ||
| record := make([]byte, 0, 2*len(root)) | ||
| record = append(record, root[:]...) | ||
| return append(record, checksum[:]...) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.