erigon-pulse/cl/phase1/forkchoice/forkchoice_mock.go
Giulio rebuffo 46ecf030f5
Added GET /eth/v1/beacon/rewards/blocks/{block_id} and POST /eth/v1/beacon/rewards/sync_committee/{block_id} (#9102)
* Changed slightly archive format (again)
* Added all of the remaining rewards endpoints
2023-12-30 20:51:28 +01:00

184 lines
6.5 KiB
Go

package forkchoice
import (
"github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon/cl/cltypes"
"github.com/ledgerwatch/erigon/cl/cltypes/solid"
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
"github.com/ledgerwatch/erigon/cl/phase1/execution_client"
"github.com/ledgerwatch/erigon/cl/transition/impl/eth2"
)
// type ForkChoiceStorage interface {
// ForkChoiceStorageWriter
// ForkChoiceStorageReader
// }
// type ForkChoiceStorageReader interface {
// Ancestor(root common.Hash, slot uint64) common.Hash
// AnchorSlot() uint64
// Engine() execution_client.ExecutionEngine
// FinalizedCheckpoint() solid.Checkpoint
// FinalizedSlot() uint64
// GetEth1Hash(eth2Root common.Hash) common.Hash
// GetHead() (common.Hash, uint64, error)
// HighestSeen() uint64
// JustifiedCheckpoint() solid.Checkpoint
// JustifiedSlot() uint64
// ProposerBoostRoot() common.Hash
// GetStateAtBlockRoot(blockRoot libcommon.Hash, alwaysCopy bool) (*state.CachingBeaconState, error)
// GetFinalityCheckpoints(blockRoot libcommon.Hash) (bool, solid.Checkpoint, solid.Checkpoint, solid.Checkpoint)
// GetSyncCommittees(blockRoot libcommon.Hash) (*solid.SyncCommittee, *solid.SyncCommittee, bool)
// Slot() uint64
// Time() uint64
// GetStateAtSlot(slot uint64, alwaysCopy bool) (*state.CachingBeaconState, error)
// GetStateAtStateRoot(root libcommon.Hash, alwaysCopy bool) (*state.CachingBeaconState, error)
// }
// type ForkChoiceStorageWriter interface {
// OnAttestation(attestation *solid.Attestation, fromBlock bool) error
// OnAttesterSlashing(attesterSlashing *cltypes.AttesterSlashing, test bool) error
// OnBlock(block *cltypes.SignedBeaconBlock, newPayload bool, fullValidation bool) error
// OnTick(time uint64)
// }
// Make mocks with maps and simple setters and getters, panic on methods from ForkChoiceStorageWriter
type ForkChoiceStorageMock struct {
Ancestors map[uint64]common.Hash
AnchorSlotVal uint64
FinalizedCheckpointVal solid.Checkpoint
FinalizedSlotVal uint64
HeadVal common.Hash
HeadSlotVal uint64
HighestSeenVal uint64
JustifiedCheckpointVal solid.Checkpoint
JustifiedSlotVal uint64
ProposerBoostRootVal common.Hash
SlotVal uint64
TimeVal uint64
StateAtBlockRootVal map[common.Hash]*state.CachingBeaconState
StateAtSlotVal map[uint64]*state.CachingBeaconState
GetSyncCommitteesVal map[common.Hash][2]*solid.SyncCommittee
GetFinalityCheckpointsVal map[common.Hash][3]solid.Checkpoint
}
func NewForkChoiceStorageMock() *ForkChoiceStorageMock {
return &ForkChoiceStorageMock{
Ancestors: make(map[uint64]common.Hash),
AnchorSlotVal: 0,
FinalizedCheckpointVal: solid.Checkpoint{},
FinalizedSlotVal: 0,
HeadVal: common.Hash{},
HighestSeenVal: 0,
JustifiedCheckpointVal: solid.Checkpoint{},
JustifiedSlotVal: 0,
ProposerBoostRootVal: common.Hash{},
SlotVal: 0,
TimeVal: 0,
StateAtBlockRootVal: make(map[common.Hash]*state.CachingBeaconState),
StateAtSlotVal: make(map[uint64]*state.CachingBeaconState),
GetSyncCommitteesVal: make(map[common.Hash][2]*solid.SyncCommittee),
GetFinalityCheckpointsVal: make(map[common.Hash][3]solid.Checkpoint),
}
}
func (f *ForkChoiceStorageMock) Ancestor(root common.Hash, slot uint64) common.Hash {
return f.Ancestors[slot]
}
func (f *ForkChoiceStorageMock) AnchorSlot() uint64 {
return f.AnchorSlotVal
}
func (f *ForkChoiceStorageMock) Engine() execution_client.ExecutionEngine {
panic("implement me")
}
func (f *ForkChoiceStorageMock) FinalizedCheckpoint() solid.Checkpoint {
return f.FinalizedCheckpointVal
}
func (f *ForkChoiceStorageMock) FinalizedSlot() uint64 {
return f.FinalizedSlotVal
}
func (f *ForkChoiceStorageMock) GetEth1Hash(eth2Root common.Hash) common.Hash {
panic("implement me")
}
func (f *ForkChoiceStorageMock) GetHead() (common.Hash, uint64, error) {
return f.HeadVal, f.HeadSlotVal, nil
}
func (f *ForkChoiceStorageMock) HighestSeen() uint64 {
return f.HighestSeenVal
}
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
}
func (f *ForkChoiceStorageMock) GetStateAtBlockRoot(blockRoot common.Hash, alwaysCopy bool) (*state.CachingBeaconState, error) {
return f.StateAtBlockRootVal[blockRoot], nil
}
func (f *ForkChoiceStorageMock) GetFinalityCheckpoints(blockRoot common.Hash) (bool, solid.Checkpoint, solid.Checkpoint, solid.Checkpoint) {
oneNil := f.GetFinalityCheckpointsVal[blockRoot][0] != nil && f.GetFinalityCheckpointsVal[blockRoot][1] != nil && f.GetFinalityCheckpointsVal[blockRoot][2] != nil
return oneNil, f.GetFinalityCheckpointsVal[blockRoot][0], f.GetFinalityCheckpointsVal[blockRoot][1], f.GetFinalityCheckpointsVal[blockRoot][2]
}
func (f *ForkChoiceStorageMock) GetSyncCommittees(blockRoot common.Hash) (*solid.SyncCommittee, *solid.SyncCommittee, bool) {
return f.GetSyncCommitteesVal[blockRoot][0], f.GetSyncCommitteesVal[blockRoot][1], f.GetSyncCommitteesVal[blockRoot][0] != nil && f.GetSyncCommitteesVal[blockRoot][1] != nil
}
func (f *ForkChoiceStorageMock) GetStateAtSlot(slot uint64, alwaysCopy bool) (*state.CachingBeaconState, error) {
return f.StateAtSlotVal[slot], nil
}
func (f *ForkChoiceStorageMock) Slot() uint64 {
return f.SlotVal
}
func (f *ForkChoiceStorageMock) Time() uint64 {
return f.TimeVal
}
func (f *ForkChoiceStorageMock) OnAttestation(attestation *solid.Attestation, fromBlock bool) error {
panic("implement me")
}
func (f *ForkChoiceStorageMock) OnAttesterSlashing(attesterSlashing *cltypes.AttesterSlashing, test bool) error {
panic("implement me")
}
func (f *ForkChoiceStorageMock) OnBlock(block *cltypes.SignedBeaconBlock, newPayload bool, fullValidation bool) error {
panic("implement me")
}
func (f *ForkChoiceStorageMock) OnTick(time uint64) {
panic("implement me")
}
func (f *ForkChoiceStorageMock) GetStateAtStateRoot(root common.Hash, alwaysCopy bool) (*state.CachingBeaconState, error) {
panic("implement me")
}
func (f *ForkChoiceStorageMock) BlockRewards(root common.Hash) (*eth2.BlockRewardsCollector, bool) {
panic("implement me")
}
func (f *ForkChoiceStorageMock) TotalActiveBalance(root common.Hash) (uint64, bool) {
panic("implement me")
}