Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions cl/phase1/forkchoice/forkchoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,11 +543,6 @@ func (f *ForkChoiceStore) JustifiedCheckpoint() solid.Checkpoint {
return f.justifiedCheckpoint.Load().(solid.Checkpoint)
}

// FinalizedCheckpoint returns justified checkpoint
func (f *ForkChoiceStore) JustifiedSlot() uint64 {
return f.computeStartSlotAtEpoch(f.justifiedCheckpoint.Load().(solid.Checkpoint).Epoch)
}

// getUnrealizedJustification returns the per-block unrealized justified checkpoint
// (spec: store.unrealized_justifications[block_root])
func (f *ForkChoiceStore) getUnrealizedJustification(blockRoot common.Hash) (solid.Checkpoint, bool) {
Expand Down
5 changes: 0 additions & 5 deletions cl/phase1/forkchoice/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ type ForkChoiceStorageReader interface {
GetHead(auxilliaryState *state.CachingBeaconState) (common.Hash, uint64, error)
HighestSeen() uint64
JustifiedCheckpoint() solid.Checkpoint
JustifiedSlot() uint64
ProposerBoostRoot() common.Hash
GetStateAtBlockRoot(
blockRoot common.Hash,
Expand Down Expand Up @@ -90,9 +89,6 @@ type ForkChoiceStorageReader interface {
// [New in Gloas:EIP7732] GetHeadPayloadStatus returns the payload status of the current
// head node (FULL, EMPTY, or PENDING). Must be called after GetHead.
GetHeadPayloadStatus() cltypes.PayloadStatus
// [New in Gloas:EIP7732] ShouldExtendPayload returns whether the payload for the given
// root should be extended. Used by prepare_execution_payload to decide FULL vs EMPTY path.
ShouldExtendPayload(root common.Hash) bool
// [New in Gloas:EIP7732] ShouldBuildOnFull returns whether the proposer should build on
// the full payload for the given head node. Used for proposer reorg of unavailable blocks.
ShouldBuildOnFull(head ForkChoiceNode) bool
Expand All @@ -109,7 +105,6 @@ type ForkChoiceStorageReader interface {
GetPendingPartialWithdrawals(blockRoot common.Hash) (*solid.ListSSZ[*solid.PendingPartialWithdrawal], bool)
GetProposerLookahead(slot uint64) (solid.Uint64VectorSSZ, bool)

ValidateOnAttestation(attestation *solid.Attestation) error
IsRootOptimistic(root common.Hash) bool
IsHeadOptimistic() bool
GetPeerDas() das.PeerDas
Expand Down
26 changes: 2 additions & 24 deletions cl/phase1/forkchoice/mock_services/forkchoice_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import (

// Make mocks with maps and simple setters and getters, panic on methods from ForkChoiceStorageWriter

var _ forkchoice.ForkChoiceStorage = (*ForkChoiceStorageMock)(nil)

type ForkChoiceStorageMock struct {
Ancestors map[uint64]forkchoice.ForkChoiceNode
AnchorSlotVal uint64
Expand All @@ -51,7 +53,6 @@ type ForkChoiceStorageMock struct {
HeadPayloadStatusVal cltypes.PayloadStatus
HighestSeenVal uint64
JustifiedCheckpointVal solid.Checkpoint
JustifiedSlotVal uint64
ProposerBoostRootVal common.Hash
SlotVal uint64
TimeVal uint64
Expand Down Expand Up @@ -86,8 +87,6 @@ type ForkChoiceStorageMock struct {
// Mock for PeerDas
MockPeerDas *mock_services.MockPeerDas

ShouldExtendPayloadVal bool

// [New in Gloas:EIP7732] Execution payload status by execution block hash
ExecutionPayloadStatusMap map[common.Hash]execution_client.PayloadStatus
PayloadStatusByRootMap map[common.Hash]execution_client.PayloadStatus
Expand Down Expand Up @@ -203,7 +202,6 @@ func NewForkChoiceStorageMock(t *testing.T) *ForkChoiceStorageMock {
HeadPayloadStatusVal: cltypes.PayloadStatusFull,
HighestSeenVal: 0,
JustifiedCheckpointVal: solid.Checkpoint{},
JustifiedSlotVal: 0,
ProposerBoostRootVal: common.Hash{},
SlotVal: 0,
TimeVal: 0,
Expand All @@ -218,7 +216,6 @@ func NewForkChoiceStorageMock(t *testing.T) *ForkChoiceStorageMock {
Envelopes: make(map[common.Hash]*cltypes.SignedExecutionPayloadEnvelope),
GetBeaconCommitteeMock: nil,
Eth1Hashes: make(map[common.Hash]common.Hash),
ShouldExtendPayloadVal: true,
SyncContributionPool: makeSyncContributionPoolMock(t),
MockPeerDas: mockPeerDas,
ExecutionPayloadStatusMap: make(map[common.Hash]execution_client.PayloadStatus),
Expand Down Expand Up @@ -278,10 +275,6 @@ func (f *ForkChoiceStorageMock) JustifiedCheckpoint() solid.Checkpoint {
return f.JustifiedCheckpointVal
}

func (f *ForkChoiceStorageMock) JustifiedSlot() uint64 {
return f.JustifiedSlotVal
}

func (f *ForkChoiceStorageMock) ProposerBoostRoot() common.Hash {
return f.ProposerBoostRootVal
}
Expand Down Expand Up @@ -462,10 +455,6 @@ func (f *ForkChoiceStorageMock) GetHeadPayloadStatus() cltypes.PayloadStatus {
return f.HeadPayloadStatusVal
}

func (f *ForkChoiceStorageMock) ShouldExtendPayload(root common.Hash) bool {
return f.ShouldExtendPayloadVal
}

func (f *ForkChoiceStorageMock) ShouldBuildOnFull(head forkchoice.ForkChoiceNode) bool {
return true
}
Expand Down Expand Up @@ -498,13 +487,6 @@ func (f *ForkChoiceStorageMock) GetCurrentParticipationIndicies(
panic("implement me")
}

func (f *ForkChoiceStorageMock) GetPublicKeyForValidator(
blockRoot common.Hash,
idx uint64,
) (common.Bytes48, error) {
panic("implement me")
}

// func (f *ForkChoiceStorageMock) OnSignedContributionAndProof(signedContribution *cltypes.SignedContributionAndProof, test bool) error {
// f.SyncContributionPool.AddSyncContribution(nil, signedContribution.Message.Contribution)
// return nil
Expand All @@ -514,10 +496,6 @@ func (f *ForkChoiceStorageMock) AddPreverifiedBlobSidecar(msg *cltypes.BlobSidec
return nil
}

func (f *ForkChoiceStorageMock) ValidateOnAttestation(attestation *solid.Attestation) error {
panic("implement me")
}

func (f *ForkChoiceStorageMock) ProcessAttestingIndicies(
attestation *solid.Attestation,
attestionIndicies []uint64,
Expand Down
6 changes: 3 additions & 3 deletions cl/sentinel/handlers/blobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ import (
"github.com/erigontech/erigon/cl/cltypes"
"github.com/erigontech/erigon/cl/cltypes/solid"
"github.com/erigontech/erigon/cl/persistence/blob_storage"
"github.com/erigontech/erigon/cl/phase1/forkchoice/mock_services"
"github.com/erigontech/erigon/cl/sentinel/communication"
"github.com/erigontech/erigon/cl/sentinel/communication/ssz_snappy"
"github.com/erigontech/erigon/cl/sentinel/handlers/mock_services"
"github.com/erigontech/erigon/cl/sentinel/peers"
"github.com/erigontech/erigon/cl/utils"
"github.com/erigontech/erigon/common"
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestBlobsByRangeHandler(t *testing.T) {
nil,
beaconCfg,
ethClock,
nil, &mock_services.ForkChoiceStorageMock{}, blobStorage, nil, nil, true,
nil, &mock_services.ChainDataReaderMock{}, blobStorage, nil, nil, true,
)
c.Start()
req := &cltypes.BlobsByRangeRequest{
Expand Down Expand Up @@ -236,7 +236,7 @@ func TestBlobsByIdentifiersHandler(t *testing.T) {
nil,
beaconCfg,
ethClock,
nil, &mock_services.ForkChoiceStorageMock{}, blobStorage, nil, nil, true,
nil, &mock_services.ChainDataReaderMock{}, blobStorage, nil, nil, true,
)
c.Start()
req := solid.NewStaticListSSZ[*cltypes.BlobIdentifier](40269, 40)
Expand Down
5 changes: 2 additions & 3 deletions cl/sentinel/handlers/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,9 @@ func (c *ConsensusHandlers) beaconBlocksByRootHandler(s network.Stream) error {
if err != nil {
return false
}
// If the block is not in the database, check the fork choice store.
// Recently received blocks (e.g. via gossip) may not have been persisted yet.
if block == nil && c.forkChoiceReader != nil {
block, _ = c.forkChoiceReader.GetBlock(blockRoot)
if block == nil && c.chainDataReader != nil {
block, _ = c.chainDataReader.GetBlock(blockRoot)
}
if block == nil {
log.Debug("[Sentinel] beaconBlocksByRoot: block not found", "root", blockRoot)
Expand Down
4 changes: 2 additions & 2 deletions cl/sentinel/handlers/blocks_by_head.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ func (c *ConsensusHandlers) beaconBlocksByHeadHandler(s network.Stream) error {
if err != nil {
return err
}
if block == nil && c.forkChoiceReader != nil {
block, _ = c.forkChoiceReader.GetBlock(currentRoot)
if block == nil && c.chainDataReader != nil {
block, _ = c.chainDataReader.GetBlock(currentRoot)
}
if block == nil {
log.Debug("[Sentinel] beaconBlocksByHead: block not found", "root", currentRoot)
Expand Down
18 changes: 9 additions & 9 deletions cl/sentinel/handlers/blocks_by_head_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import (
"github.com/erigontech/erigon/cl/antiquary/tests"
"github.com/erigontech/erigon/cl/clparams"
"github.com/erigontech/erigon/cl/cltypes"
"github.com/erigontech/erigon/cl/phase1/forkchoice/mock_services"
"github.com/erigontech/erigon/cl/sentinel/communication"
"github.com/erigontech/erigon/cl/sentinel/communication/ssz_snappy"
"github.com/erigontech/erigon/cl/sentinel/handlers/mock_services"
"github.com/erigontech/erigon/cl/sentinel/peers"
"github.com/erigontech/erigon/cl/utils"
"github.com/erigontech/erigon/common"
Expand Down Expand Up @@ -76,11 +76,11 @@ func TestBlocksByHeadParentChainTraversal(t *testing.T) {
require.Equal(t, roots[0], got[2].Block.ParentRoot)
}

func TestBlocksByHeadForkChoiceFallback(t *testing.T) {
func TestBlocksByHeadChainDataFallback(t *testing.T) {
blocks, roots := makeBlocksByHeadChain(t, 300, 1)
forkChoice := mock_services.NewForkChoiceStorageMock(t)
forkChoice.Blocks[roots[0]] = blocks[0]
_, stream := setupBlocksByHeadTest(t, nil, forkChoice)
chainData := mock_services.NewChainDataReaderMock()
chainData.Blocks[roots[0]] = blocks[0]
_, stream := setupBlocksByHeadTest(t, nil, chainData)

writeBlocksByHeadRequest(t, stream, roots[0], 1)

Expand Down Expand Up @@ -109,7 +109,7 @@ func TestBlocksByHeadZeroCount(t *testing.T) {
func setupBlocksByHeadTest(
t *testing.T,
blocks []*cltypes.SignedBeaconBlock,
forkChoice *mock_services.ForkChoiceStorageMock,
chainData *mock_services.ChainDataReaderMock,
) (*tests.MockBlockReader, network.Stream) {
t.Helper()

Expand All @@ -136,8 +136,8 @@ func setupBlocksByHeadTest(
for _, block := range blocks {
store.U[block.Block.Slot] = block
}
if forkChoice == nil {
forkChoice = mock_services.NewForkChoiceStorageMock(t)
if chainData == nil {
chainData = mock_services.NewChainDataReaderMock()
}

ethClock := getEthClock(t)
Expand All @@ -152,7 +152,7 @@ func setupBlocksByHeadTest(
nil,
beaconCfg,
ethClock,
nil, forkChoice, nil, nil, nil, true,
nil, chainData, nil, nil, nil, true,
)
c.Start()

Expand Down
4 changes: 2 additions & 2 deletions cl/sentinel/handlers/blocks_by_range_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import (
"github.com/erigontech/erigon/cl/antiquary/tests"
"github.com/erigontech/erigon/cl/clparams"
"github.com/erigontech/erigon/cl/cltypes"
"github.com/erigontech/erigon/cl/phase1/forkchoice/mock_services"
"github.com/erigontech/erigon/cl/sentinel/communication"
"github.com/erigontech/erigon/cl/sentinel/communication/ssz_snappy"
"github.com/erigontech/erigon/cl/sentinel/handlers/mock_services"
"github.com/erigontech/erigon/cl/sentinel/peers"
"github.com/erigontech/erigon/cl/utils"
)
Expand Down Expand Up @@ -84,7 +84,7 @@ func TestBlocksByRootHandler(t *testing.T) {
nil,
beaconCfg,
ethClock,
nil, &mock_services.ForkChoiceStorageMock{}, nil, nil, nil, true,
nil, &mock_services.ChainDataReaderMock{}, nil, nil, nil, true,
)
c.Start()
req := &cltypes.BeaconBlocksByRangeRequest{
Expand Down
4 changes: 2 additions & 2 deletions cl/sentinel/handlers/blocks_by_root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import (
"github.com/erigontech/erigon/cl/cltypes"
"github.com/erigontech/erigon/cl/cltypes/solid"
"github.com/erigontech/erigon/cl/persistence/beacon_indicies"
"github.com/erigontech/erigon/cl/phase1/forkchoice/mock_services"
"github.com/erigontech/erigon/cl/sentinel/communication"
"github.com/erigontech/erigon/cl/sentinel/communication/ssz_snappy"
"github.com/erigontech/erigon/cl/sentinel/handlers/mock_services"
"github.com/erigontech/erigon/cl/sentinel/peers"
"github.com/erigontech/erigon/cl/utils"
"github.com/erigontech/erigon/common"
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestBlocksByRangeHandler(t *testing.T) {
nil,
beaconCfg,
ethClock,
nil, &mock_services.ForkChoiceStorageMock{}, nil, nil, nil, true,
nil, &mock_services.ChainDataReaderMock{}, nil, nil, nil, true,
)
c.Start()
var req solid.HashListSSZ = solid.NewHashList(len(expBlocks))
Expand Down
33 changes: 33 additions & 0 deletions cl/sentinel/handlers/chain_data_reader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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 handlers

import (
"github.com/erigontech/erigon/cl/cltypes"
"github.com/erigontech/erigon/common"
)

// ChainDataReader is the chain data the req/resp handlers serve to peers:
// recent blocks, light-client objects and execution payload envelopes.
type ChainDataReader interface {
GetBlock(blockRoot common.Hash) (*cltypes.SignedBeaconBlock, bool)
GetLightClientBootstrap(blockRoot common.Hash) (*cltypes.LightClientBootstrap, bool)
NewestLightClientUpdate() *cltypes.LightClientUpdate
GetLightClientUpdate(period uint64) (*cltypes.LightClientUpdate, bool)
HasEnvelope(blockRoot common.Hash) bool
ReadEnvelopeFromDisk(blockRoot common.Hash) (*cltypes.SignedExecutionPayloadEnvelope, error)
}
4 changes: 2 additions & 2 deletions cl/sentinel/handlers/data_column_sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ import (
"github.com/erigontech/erigon/cl/cltypes"
"github.com/erigontech/erigon/cl/cltypes/solid"
"github.com/erigontech/erigon/cl/persistence/blob_storage"
"github.com/erigontech/erigon/cl/phase1/forkchoice/mock_services"
"github.com/erigontech/erigon/cl/sentinel/communication"
"github.com/erigontech/erigon/cl/sentinel/communication/ssz_snappy"
"github.com/erigontech/erigon/cl/sentinel/handlers/mock_services"
"github.com/erigontech/erigon/cl/sentinel/peers"
"github.com/erigontech/erigon/common"
"github.com/erigontech/erigon/db/kv"
Expand Down Expand Up @@ -481,7 +481,7 @@ func setupDataColumnSidecarHandlerTestWithStore(t *testing.T, fuluForkEpoch uint
nil,
&beaconCfg,
ethClock,
nil, &mock_services.ForkChoiceStorageMock{}, nil, columnStorage, nil, true,
nil, &mock_services.ChainDataReaderMock{}, nil, columnStorage, nil, true,
)
c.Start()

Expand Down
8 changes: 4 additions & 4 deletions cl/sentinel/handlers/execution_payload_envelopes.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ func (c *ConsensusHandlers) executionPayloadEnvelopesByRangeHandler(s network.St
continue
}

if !c.forkChoiceReader.HasEnvelope(blockRoot) {
if !c.chainDataReader.HasEnvelope(blockRoot) {
continue
}

envelope, err := c.forkChoiceReader.ReadEnvelopeFromDisk(blockRoot)
envelope, err := c.chainDataReader.ReadEnvelopeFromDisk(blockRoot)
if err != nil {
log.Debug("failed to read envelope from disk", "blockRoot", blockRoot, "error", err)
continue
Expand Down Expand Up @@ -208,11 +208,11 @@ func (c *ConsensusHandlers) executionPayloadEnvelopesByRootHandler(s network.Str
return true
}

if !c.forkChoiceReader.HasEnvelope(blockRoot) {
if !c.chainDataReader.HasEnvelope(blockRoot) {
return true
}

envelope, err := c.forkChoiceReader.ReadEnvelopeFromDisk(blockRoot)
envelope, err := c.chainDataReader.ReadEnvelopeFromDisk(blockRoot)
if err != nil {
log.Debug("failed to read envelope from disk", "blockRoot", blockRoot, "error", err)
return true
Expand Down
Loading
Loading