2020-01-22 16:50:16 +00:00
|
|
|
package forkchoice
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-01-29 16:32:01 +00:00
|
|
|
"time"
|
2020-01-26 20:25:33 +00:00
|
|
|
|
2021-02-16 07:45:34 +00:00
|
|
|
types "github.com/prysmaticlabs/eth2-types"
|
2020-01-26 20:25:33 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray"
|
2020-01-22 16:50:16 +00:00
|
|
|
)
|
|
|
|
|
2020-01-25 20:22:25 +00:00
|
|
|
// ForkChoicer represents the full fork choice interface composed of all of the sub-interfaces.
|
|
|
|
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-01-29 16:32:01 +00:00
|
|
|
ProposerBooster // ability to boost timely-proposed block roots.
|
2022-02-06 18:00:47 +00:00
|
|
|
SyncTipper // to update and retrieve validated sync tips.
|
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 {
|
2021-02-09 10:05:22 +00:00
|
|
|
Head(context.Context, types.Epoch, [32]byte, []uint64, types.Epoch) ([32]byte, error)
|
2022-02-03 21:30:07 +00:00
|
|
|
Optimistic(ctx context.Context, root [32]byte, slot types.Slot) (bool, error)
|
2020-01-22 16:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// BlockProcessor processes the block that's used for accounting fork choice.
|
|
|
|
type BlockProcessor interface {
|
2021-02-16 07:45:34 +00:00
|
|
|
ProcessBlock(context.Context, types.Slot, [32]byte, [32]byte, [32]byte, types.Epoch, types.Epoch) 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)
|
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 {
|
|
|
|
BoostProposerRoot(ctx context.Context, blockSlot types.Slot, blockRoot [32]byte, genesisTime time.Time) error
|
|
|
|
ResetBoostedProposerRoot(ctx context.Context) error
|
|
|
|
}
|
|
|
|
|
2020-01-26 20:25:33 +00:00
|
|
|
// Getter returns fork choice related information.
|
|
|
|
type Getter interface {
|
|
|
|
Nodes() []*protoarray.Node
|
2020-02-10 19:09:12 +00:00
|
|
|
Node([32]byte) *protoarray.Node
|
2020-02-05 17:05:51 +00:00
|
|
|
HasNode([32]byte) bool
|
2020-05-26 23:24:38 +00:00
|
|
|
Store() *protoarray.Store
|
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
|
2020-01-26 20:25:33 +00:00
|
|
|
}
|
2022-02-06 18:00:47 +00:00
|
|
|
|
|
|
|
// SyncTipper returns sync tips related information.
|
|
|
|
type SyncTipper interface {
|
|
|
|
SyncedTips() map[[32]byte]types.Slot
|
|
|
|
UpdateSyncedTipsWithValidRoot(ctx context.Context, root [32]byte) error
|
|
|
|
UpdateSyncedTipsWithInvalidRoot(ctx context.Context, root [32]byte) error
|
|
|
|
}
|