mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 19:40:37 +00:00
Part 1 of proto array fork choice - docs and interfaces (#4615)
* Docs * Interface definitions * Fmt and gazelle * Rename interface to interfaces
This commit is contained in:
parent
b030771174
commit
8d889f169e
2
beacon-chain/cache/skip_slot_cache_test.go
vendored
2
beacon-chain/cache/skip_slot_cache_test.go
vendored
@ -5,8 +5,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
||||
)
|
||||
|
||||
|
11
beacon-chain/forkchoice/BUILD.bazel
Normal file
11
beacon-chain/forkchoice/BUILD.bazel
Normal file
@ -0,0 +1,11 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"doc.go",
|
||||
"interfaces.go",
|
||||
],
|
||||
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/forkchoice",
|
||||
visibility = ["//beacon-chain:__subpackages__"],
|
||||
)
|
7
beacon-chain/forkchoice/doc.go
Normal file
7
beacon-chain/forkchoice/doc.go
Normal file
@ -0,0 +1,7 @@
|
||||
/*
|
||||
Package forkchoice implements the service to support fork choice for the eth2 beacon chain. This contains the
|
||||
necessary components to track latest validators votes, and balances. Then a store object to be used
|
||||
to calculate head. High level fork choice summary:
|
||||
https://notes.ethereum.org/@vbuterin/rkhCgQteN?type=view#LMD-GHOST-fork-choice-rule
|
||||
*/
|
||||
package forkchoice
|
33
beacon-chain/forkchoice/interfaces.go
Normal file
33
beacon-chain/forkchoice/interfaces.go
Normal file
@ -0,0 +1,33 @@
|
||||
package forkchoice
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
// ForkChoice represents the full fork choice interface composed of all of the sub-interfaces.
|
||||
type ForkChoice 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.
|
||||
}
|
||||
|
||||
// HeadRetriever retrieves head root of the current chain.
|
||||
type HeadRetriever interface {
|
||||
Head(context.Context, uint64, [32]byte, uint64, []uint64) ([32]byte, error)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
Prune(context.Context, [32]byte)
|
||||
}
|
8
beacon-chain/forkchoice/protoarray/BUILD.bazel
Normal file
8
beacon-chain/forkchoice/protoarray/BUILD.bazel
Normal file
@ -0,0 +1,8 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["doc.go"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray",
|
||||
visibility = ["//beacon-chain:__subpackages__"],
|
||||
)
|
7
beacon-chain/forkchoice/protoarray/doc.go
Normal file
7
beacon-chain/forkchoice/protoarray/doc.go
Normal file
@ -0,0 +1,7 @@
|
||||
/*
|
||||
Package protoarray implements proto array fork choice as outlined:
|
||||
https://github.com/protolambda/lmd-ghost#array-based-stateful-dag-proto_array
|
||||
This was motivated by the following light house implementation:
|
||||
https://github.com/sigp/lighthouse/pull/804
|
||||
*/
|
||||
package protoarray
|
@ -9,12 +9,12 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/flags"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
"github.com/paulbellamy/ratecounter"
|
||||
"github.com/pkg/errors"
|
||||
eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/flags"
|
||||
prysmsync "github.com/prysmaticlabs/prysm/beacon-chain/sync"
|
||||
p2ppb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
|
@ -69,7 +69,7 @@ func (r *Service) processPendingBlocks(ctx context.Context) error {
|
||||
"parentRoot": hex.EncodeToString(b.Block.ParentRoot),
|
||||
}).Info("Requesting parent block")
|
||||
req := [][32]byte{bytesutil.ToBytes32(b.Block.ParentRoot)}
|
||||
|
||||
|
||||
// Start with a random peer to query, but choose the first peer in our unsorted list that claims to
|
||||
// have a head slot newer than the block slot we are requesting.
|
||||
pid := pids[rand.Int()%len(pids)]
|
||||
|
@ -171,7 +171,7 @@ var (
|
||||
Hidden: true,
|
||||
}
|
||||
deprecatedSaveDepositDataFlag = cli.BoolFlag{
|
||||
Name: "save-deposit-data",
|
||||
Name: "save-deposit-data",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ func TestSaveAttestationHistory_OK(t *testing.T) {
|
||||
newMap[1] = farFuture
|
||||
newMap[epoch] = 1
|
||||
history := &slashpb.AttestationHistory{
|
||||
TargetToSource: newMap,
|
||||
TargetToSource: newMap,
|
||||
LatestEpochWritten: 2,
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ func TestSaveAttestationHistory_OK(t *testing.T) {
|
||||
if savedHistory == nil || !reflect.DeepEqual(history, savedHistory) {
|
||||
t.Fatalf("Expected DB to keep object the same, received: %v", history)
|
||||
}
|
||||
if savedHistory.TargetToSource[epoch] != newMap[epoch]{
|
||||
if savedHistory.TargetToSource[epoch] != newMap[epoch] {
|
||||
t.Fatalf("Expected target epoch %d to have the same marked source epoch, received %d", epoch, savedHistory.TargetToSource[epoch])
|
||||
}
|
||||
if savedHistory.TargetToSource[epoch-1] != farFuture {
|
||||
@ -111,7 +111,7 @@ func TestSaveAttestationHistory_Overwrites(t *testing.T) {
|
||||
pubkey: []byte{0},
|
||||
epoch: uint64(1),
|
||||
history: &slashpb.AttestationHistory{
|
||||
TargetToSource: newMap1,
|
||||
TargetToSource: newMap1,
|
||||
LatestEpochWritten: 1,
|
||||
},
|
||||
},
|
||||
@ -119,7 +119,7 @@ func TestSaveAttestationHistory_Overwrites(t *testing.T) {
|
||||
pubkey: []byte{0},
|
||||
epoch: uint64(2),
|
||||
history: &slashpb.AttestationHistory{
|
||||
TargetToSource: newMap2,
|
||||
TargetToSource: newMap2,
|
||||
LatestEpochWritten: 2,
|
||||
},
|
||||
},
|
||||
@ -145,11 +145,11 @@ func TestSaveAttestationHistory_Overwrites(t *testing.T) {
|
||||
if history == nil || !reflect.DeepEqual(history, tt.history) {
|
||||
t.Fatalf("Expected DB to keep object the same, received: %v", history)
|
||||
}
|
||||
if history.TargetToSource[tt.epoch] != tt.epoch - 1 {
|
||||
if history.TargetToSource[tt.epoch] != tt.epoch-1 {
|
||||
t.Fatalf("Expected target epoch %d to be marked with correct source epoch %d", tt.epoch, history.TargetToSource[tt.epoch])
|
||||
}
|
||||
if history.TargetToSource[tt.epoch - 1] != farFuture {
|
||||
t.Fatalf("Expected target epoch %d to not be marked as attested for, received %d", tt.epoch-1, history.TargetToSource[tt.epoch - 1])
|
||||
if history.TargetToSource[tt.epoch-1] != farFuture {
|
||||
t.Fatalf("Expected target epoch %d to not be marked as attested for, received %d", tt.epoch-1, history.TargetToSource[tt.epoch-1])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user