mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-06 09:42:19 +00:00
2536195be0
* Change forkchoice API doubly-linked-tree changes * protoarray changes * blockchain tests * rebase and fix conflicts * More blockchain fixes * blockchain test fixes * doubly linked tree changes again * protoarray changes v2 * blockchain packages v2 * Radek's review * Fix on batch processing * Terence's review * fill in at start * Revert "fill in at start" This reverts commit 8c11db063a02a59df8e0ac6d0af0c8923921dc76. * wrap error message * fill in before mutating the state * wrap nil node errors * handle unknown optimistic status on init sync * rename insert function * prune on batches only after forkchoice insertion Co-authored-by: terencechain <terence@prysmaticlabs.com>
75 lines
3.0 KiB
Go
75 lines
3.0 KiB
Go
package forkchoice
|
|
|
|
import (
|
|
"context"
|
|
|
|
forkchoicetypes "github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/types"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/state"
|
|
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
|
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
)
|
|
|
|
// ForkChoicer represents the full fork choice interface composed of all the sub-interfaces.
|
|
type ForkChoicer interface {
|
|
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.
|
|
Getter // to retrieve fork choice information.
|
|
Setter // to set fork choice information.
|
|
ProposerBooster // ability to boost timely-proposed block roots.
|
|
}
|
|
|
|
// HeadRetriever retrieves head root and optimistic info of the current chain.
|
|
type HeadRetriever interface {
|
|
Head(context.Context, [32]byte, []uint64) ([32]byte, error)
|
|
Tips() ([][32]byte, []types.Slot)
|
|
IsOptimistic(root [32]byte) (bool, error)
|
|
}
|
|
|
|
// BlockProcessor processes the block that's used for accounting fork choice.
|
|
type BlockProcessor interface {
|
|
InsertNode(context.Context, state.ReadOnlyBeaconState, [32]byte) error
|
|
InsertOptimisticChain(context.Context, []*forkchoicetypes.BlockAndCheckpoints) error
|
|
}
|
|
|
|
// AttestationProcessor processes the attestation that's used for accounting fork choice.
|
|
type AttestationProcessor interface {
|
|
ProcessAttestation(context.Context, []uint64, [32]byte, types.Epoch)
|
|
InsertSlashedIndex(context.Context, types.ValidatorIndex)
|
|
}
|
|
|
|
// Pruner prunes the fork choice upon new finalization. This is used to keep fork choice sane.
|
|
type Pruner interface {
|
|
Prune(context.Context, [32]byte) error
|
|
}
|
|
|
|
// ProposerBooster is able to boost the proposer's root score during fork choice.
|
|
type ProposerBooster interface {
|
|
BoostProposerRoot(ctx context.Context, args *forkchoicetypes.ProposerBoostRootArgs) error
|
|
ResetBoostedProposerRoot(ctx context.Context) error
|
|
}
|
|
|
|
// Getter returns fork choice related information.
|
|
type Getter interface {
|
|
HasNode([32]byte) bool
|
|
ProposerBoost() [fieldparams.RootLength]byte
|
|
HasParent(root [32]byte) bool
|
|
AncestorRoot(ctx context.Context, root [32]byte, slot types.Slot) ([]byte, error)
|
|
CommonAncestorRoot(ctx context.Context, root1 [32]byte, root2 [32]byte) ([32]byte, error)
|
|
IsCanonical(root [32]byte) bool
|
|
FinalizedEpoch() types.Epoch
|
|
JustifiedEpoch() types.Epoch
|
|
ForkChoiceNodes() []*ethpb.ForkChoiceNode
|
|
NodeCount() int
|
|
}
|
|
|
|
// Setter allows to set forkchoice information
|
|
type Setter interface {
|
|
SetOptimisticToValid(context.Context, [fieldparams.RootLength]byte) error
|
|
SetOptimisticToInvalid(context.Context, [fieldparams.RootLength]byte, [fieldparams.RootLength]byte, [fieldparams.RootLength]byte) ([][32]byte, error)
|
|
UpdateJustifiedCheckpoint(*ethpb.Checkpoint) error
|
|
UpdateFinalizedCheckpoint(*ethpb.Checkpoint) error
|
|
}
|