2020-01-22 16:50:16 +00:00
|
|
|
package forkchoice
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-01-26 20:25:33 +00:00
|
|
|
|
2022-03-28 21:34:41 +00:00
|
|
|
forkchoicetypes "github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/types"
|
2022-03-09 03:05:51 +00:00
|
|
|
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
2022-04-29 14:32:11 +00:00
|
|
|
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
2022-05-22 18:37:01 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
2020-01-22 16:50:16 +00:00
|
|
|
)
|
|
|
|
|
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 {
|
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.
|
|
|
|
Pruner // to clean old data 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.
|
2022-01-29 16:32:01 +00:00
|
|
|
ProposerBooster // ability to boost timely-proposed block roots.
|
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 {
|
2022-05-22 18:37:01 +00:00
|
|
|
Head(context.Context, [32]byte, []uint64) ([32]byte, error)
|
2022-03-09 03:05:51 +00:00
|
|
|
Tips() ([][32]byte, []types.Slot)
|
2022-04-06 14:18:30 +00:00
|
|
|
IsOptimistic(root [32]byte) (bool, error)
|
2020-01-22 16:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// BlockProcessor processes the block that's used for accounting fork choice.
|
|
|
|
type BlockProcessor interface {
|
2022-03-12 17:32:04 +00:00
|
|
|
InsertOptimisticBlock(ctx context.Context,
|
2022-03-09 03:05:51 +00:00
|
|
|
slot types.Slot,
|
|
|
|
root [32]byte,
|
|
|
|
parentRoot [32]byte,
|
2022-03-22 01:20:42 +00:00
|
|
|
payloadHash [32]byte,
|
2022-03-09 03:05:51 +00:00
|
|
|
justifiedEpoch types.Epoch,
|
|
|
|
finalizedEpoch types.Epoch,
|
2022-03-12 17:32:04 +00:00
|
|
|
) error
|
2020-01-22 16:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AttestationProcessor processes the attestation that's used for accounting fork choice.
|
|
|
|
type AttestationProcessor interface {
|
2021-02-09 10:05:22 +00:00
|
|
|
ProcessAttestation(context.Context, []uint64, [32]byte, types.Epoch)
|
2022-05-02 19:19:03 +00:00
|
|
|
InsertSlashedIndex(context.Context, types.ValidatorIndex)
|
2020-01-22 16:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pruner prunes the fork choice upon new finalization. This is used to keep fork choice sane.
|
|
|
|
type Pruner interface {
|
2020-01-25 20:22:25 +00:00
|
|
|
Prune(context.Context, [32]byte) error
|
2020-01-22 16:50:16 +00:00
|
|
|
}
|
2020-01-26 20:25:33 +00:00
|
|
|
|
2022-01-29 16:32:01 +00:00
|
|
|
// ProposerBooster is able to boost the proposer's root score during fork choice.
|
|
|
|
type ProposerBooster interface {
|
2022-03-28 21:34:41 +00:00
|
|
|
BoostProposerRoot(ctx context.Context, args *forkchoicetypes.ProposerBoostRootArgs) error
|
2022-01-29 16:32:01 +00:00
|
|
|
ResetBoostedProposerRoot(ctx context.Context) error
|
|
|
|
}
|
|
|
|
|
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
|
2020-07-28 22:29:34 +00:00
|
|
|
HasParent(root [32]byte) bool
|
2021-02-16 07:45:34 +00:00
|
|
|
AncestorRoot(ctx context.Context, root [32]byte, slot types.Slot) ([]byte, error)
|
2020-10-23 01:32:13 +00:00
|
|
|
IsCanonical(root [32]byte) bool
|
2022-03-09 03:05:51 +00:00
|
|
|
FinalizedEpoch() types.Epoch
|
|
|
|
JustifiedEpoch() types.Epoch
|
2022-05-22 18:37:01 +00:00
|
|
|
ForkChoiceNodes() []*ethpb.ForkChoiceNode
|
2022-03-09 03:05:51 +00:00
|
|
|
NodeCount() int
|
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)
|
2022-05-22 18:37:01 +00:00
|
|
|
UpdateJustifiedCheckpoint(*ethpb.Checkpoint) error
|
|
|
|
UpdateFinalizedCheckpoint(*ethpb.Checkpoint) error
|
2022-02-06 18:00:47 +00:00
|
|
|
}
|