2020-01-22 08:50:16 -08:00
|
|
|
package forkchoice
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-01-26 12:25:33 -08:00
|
|
|
|
2024-02-14 21:46:47 -08:00
|
|
|
forkchoicetypes "github.com/prysmaticlabs/prysm/v5/beacon-chain/forkchoice/types"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
|
|
|
|
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
|
|
|
|
forkchoice2 "github.com/prysmaticlabs/prysm/v5/consensus-types/forkchoice"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
|
2020-01-22 08:50:16 -08:00
|
|
|
)
|
|
|
|
|
2023-01-26 15:40:12 +01:00
|
|
|
// BalancesByRooter is a handler to obtain the effective balances of the state
|
2022-09-30 06:39:07 -03:00
|
|
|
// with the given block root
|
|
|
|
type BalancesByRooter func(context.Context, [32]byte) ([]uint64, error)
|
|
|
|
|
2022-02-11 19:33:46 -08:00
|
|
|
// ForkChoicer represents the full fork choice interface composed of all the sub-interfaces.
|
2020-01-25 12:22:25 -08:00
|
|
|
type ForkChoicer interface {
|
2023-12-04 15:01:39 -06:00
|
|
|
RLocker // separate interface isolates read locking for ROForkChoice.
|
2023-03-02 09:10:52 -03:00
|
|
|
Lock()
|
|
|
|
Unlock()
|
2020-01-22 08:50:16 -08:00
|
|
|
HeadRetriever // to compute head.
|
|
|
|
BlockProcessor // to track new block for fork choice.
|
|
|
|
AttestationProcessor // to track new attestation for fork choice.
|
2020-01-26 12:25:33 -08:00
|
|
|
Getter // to retrieve fork choice information.
|
2022-03-09 00:05:51 -03:00
|
|
|
Setter // to set fork choice information.
|
2020-01-22 08:50:16 -08:00
|
|
|
}
|
|
|
|
|
2023-12-04 15:01:39 -06:00
|
|
|
// RLocker represents forkchoice's internal RWMutex read-only lock/unlock methods.
|
|
|
|
type RLocker interface {
|
|
|
|
RLock()
|
|
|
|
RUnlock()
|
|
|
|
}
|
|
|
|
|
2022-02-03 13:30:07 -08:00
|
|
|
// HeadRetriever retrieves head root and optimistic info of the current chain.
|
2020-01-22 08:50:16 -08:00
|
|
|
type HeadRetriever interface {
|
2023-02-15 11:19:46 -03:00
|
|
|
Head(context.Context) ([32]byte, error)
|
2023-03-04 20:19:23 -03:00
|
|
|
GetProposerHead() [32]byte
|
2022-06-25 00:57:52 -03:00
|
|
|
CachedHeadRoot() [32]byte
|
2020-01-22 08:50:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// BlockProcessor processes the block that's used for accounting fork choice.
|
|
|
|
type BlockProcessor interface {
|
2022-06-29 20:37:21 -03:00
|
|
|
InsertNode(context.Context, state.BeaconState, [32]byte) error
|
2023-02-17 14:36:52 -03:00
|
|
|
InsertChain(context.Context, []*forkchoicetypes.BlockAndCheckpoints) error
|
2020-01-22 08:50:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// AttestationProcessor processes the attestation that's used for accounting fork choice.
|
|
|
|
type AttestationProcessor interface {
|
2023-01-26 15:40:12 +01:00
|
|
|
ProcessAttestation(context.Context, []uint64, [32]byte, primitives.Epoch)
|
2020-01-22 08:50:16 -08:00
|
|
|
}
|
|
|
|
|
2020-01-26 12:25:33 -08:00
|
|
|
// Getter returns fork choice related information.
|
|
|
|
type Getter interface {
|
2023-12-04 15:01:39 -06:00
|
|
|
FastGetter
|
2023-01-26 15:40:12 +01:00
|
|
|
AncestorRoot(ctx context.Context, root [32]byte, slot primitives.Slot) ([32]byte, error)
|
|
|
|
CommonAncestor(ctx context.Context, root1 [32]byte, root2 [32]byte) ([32]byte, primitives.Slot, error)
|
2023-12-04 15:01:39 -06:00
|
|
|
ForkChoiceDump(context.Context) (*forkchoice2.Dump, error)
|
|
|
|
Tips() ([][32]byte, []primitives.Slot)
|
|
|
|
}
|
|
|
|
|
|
|
|
type FastGetter interface {
|
2022-06-09 19:28:30 -03:00
|
|
|
FinalizedCheckpoint() *forkchoicetypes.Checkpoint
|
2022-06-25 00:57:52 -03:00
|
|
|
FinalizedPayloadBlockHash() [32]byte
|
2023-12-04 15:01:39 -06:00
|
|
|
HasNode([32]byte) bool
|
|
|
|
HighestReceivedBlockSlot() primitives.Slot
|
2024-01-17 12:39:28 -03:00
|
|
|
HighestReceivedBlockDelay() primitives.Slot
|
2023-12-04 15:01:39 -06:00
|
|
|
IsCanonical(root [32]byte) bool
|
|
|
|
IsOptimistic(root [32]byte) (bool, error)
|
|
|
|
IsViableForCheckpoint(*forkchoicetypes.Checkpoint) (bool, error)
|
2022-06-09 19:28:30 -03:00
|
|
|
JustifiedCheckpoint() *forkchoicetypes.Checkpoint
|
2022-06-25 00:57:52 -03:00
|
|
|
JustifiedPayloadBlockHash() [32]byte
|
2023-12-04 15:01:39 -06:00
|
|
|
LastRoot(primitives.Epoch) [32]byte
|
2022-03-09 00:05:51 -03:00
|
|
|
NodeCount() int
|
2023-12-04 15:01:39 -06:00
|
|
|
PreviousJustifiedCheckpoint() *forkchoicetypes.Checkpoint
|
|
|
|
ProposerBoost() [fieldparams.RootLength]byte
|
2022-08-10 08:58:52 -07:00
|
|
|
ReceivedBlocksLastEpoch() (uint64, error)
|
2023-03-04 20:19:23 -03:00
|
|
|
ShouldOverrideFCU() bool
|
2023-05-12 13:55:33 -03:00
|
|
|
Slot([32]byte) (primitives.Slot, error)
|
2023-12-04 07:31:18 -08:00
|
|
|
TargetRootForEpoch([32]byte, primitives.Epoch) ([32]byte, error)
|
2023-12-04 15:01:39 -06:00
|
|
|
UnrealizedJustifiedPayloadBlockHash() [32]byte
|
|
|
|
Weight(root [32]byte) (uint64, error)
|
2020-01-26 12:25:33 -08:00
|
|
|
}
|
2022-02-06 10:00:47 -08:00
|
|
|
|
2022-03-09 00:05:51 -03:00
|
|
|
// Setter allows to set forkchoice information
|
|
|
|
type Setter interface {
|
|
|
|
SetOptimisticToValid(context.Context, [fieldparams.RootLength]byte) error
|
2022-05-02 10:53:22 -03:00
|
|
|
SetOptimisticToInvalid(context.Context, [fieldparams.RootLength]byte, [fieldparams.RootLength]byte, [fieldparams.RootLength]byte) ([][32]byte, error)
|
2023-02-15 11:19:46 -03:00
|
|
|
UpdateJustifiedCheckpoint(context.Context, *forkchoicetypes.Checkpoint) error
|
2022-06-09 19:28:30 -03:00
|
|
|
UpdateFinalizedCheckpoint(*forkchoicetypes.Checkpoint) error
|
2022-06-16 15:21:40 -03:00
|
|
|
SetGenesisTime(uint64)
|
|
|
|
SetOriginRoot([32]byte)
|
2023-01-26 15:40:12 +01:00
|
|
|
NewSlot(context.Context, primitives.Slot) error
|
2022-09-30 06:39:07 -03:00
|
|
|
SetBalancesByRooter(BalancesByRooter)
|
2023-03-06 09:01:36 -08:00
|
|
|
InsertSlashedIndex(context.Context, primitives.ValidatorIndex)
|
2022-02-06 10:00:47 -08:00
|
|
|
}
|