2020-01-22 16:50:16 +00:00
|
|
|
package forkchoice
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
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.
|
2020-01-22 16:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// HeadRetriever retrieves head root of the current chain.
|
|
|
|
type HeadRetriever interface {
|
2020-01-25 20:22:25 +00:00
|
|
|
Head(context.Context, uint64, [32]byte, []uint64, uint64) ([32]byte, error)
|
2020-01-22 16:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// BlockProcessor processes the block that's used for accounting fork choice.
|
|
|
|
type BlockProcessor interface {
|
|
|
|
ProcessBlock(context.Context, uint64, [32]byte, [32]byte, uint64, uint64) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// AttestationProcessor processes the attestation that's used for accounting fork choice.
|
|
|
|
type AttestationProcessor interface {
|
|
|
|
ProcessAttestation(context.Context, []uint64, [32]byte, uint64)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
// Getter returns fork choice related information.
|
|
|
|
type Getter interface {
|
|
|
|
Nodes() []*protoarray.Node
|
2020-02-05 17:05:51 +00:00
|
|
|
HasNode([32]byte) bool
|
2020-01-26 20:25:33 +00:00
|
|
|
}
|