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:
terence tsao 2020-01-22 08:50:16 -08:00 committed by Raul Jordan
parent b030771174
commit 8d889f169e
10 changed files with 77 additions and 11 deletions

View File

@ -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"
)

View 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__"],
)

View 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

View 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)
}

View 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__"],
)

View 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

View File

@ -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"

View File

@ -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 {
@ -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])
}
}
}