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