mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 22:07:59 -05:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
29d1959b81 | ||
|
|
878bc15229 | ||
|
|
e39ce36f1c | ||
|
|
b4648f1df9 | ||
|
|
f4adc0ea86 | ||
|
|
658cbf5631 | ||
|
|
b400098296 | ||
|
|
c3f875bf65 | ||
|
|
5db5ca7056 | ||
|
|
f0eb843138 | ||
|
|
d44c27ec63 | ||
|
|
0625a6906c | ||
|
|
4d28d5e4d2 | ||
|
|
08b938982b | ||
|
|
6ee290a9af | ||
|
|
4da7a7797e |
@@ -16,3 +16,7 @@ enabled = true
|
||||
[[analyzers]]
|
||||
name = "shell"
|
||||
enabled = true
|
||||
|
||||
[[analyzers]]
|
||||
name = "secrets"
|
||||
enabled = true
|
||||
|
||||
@@ -60,10 +60,10 @@ bazel_skylib_workspace()
|
||||
|
||||
http_archive(
|
||||
name = "bazel_gazelle",
|
||||
sha256 = "1f4fc1d91826ec436ae04833430626f4cc02c20bb0a813c0c2f3c4c421307b1d",
|
||||
strip_prefix = "bazel-gazelle-e368a11b76e92932122d824970dc0ce5feb9c349",
|
||||
sha256 = "222e49f034ca7a1d1231422cdb67066b885819885c356673cb1f72f748a3c9d4",
|
||||
urls = [
|
||||
"https://github.com/bazelbuild/bazel-gazelle/archive/e368a11b76e92932122d824970dc0ce5feb9c349.tar.gz",
|
||||
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.3/bazel-gazelle-v0.22.3.tar.gz",
|
||||
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.3/bazel-gazelle-v0.22.3.tar.gz",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -156,7 +156,7 @@ load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_depe
|
||||
go_rules_dependencies()
|
||||
|
||||
go_register_toolchains(
|
||||
go_version = "1.15.7",
|
||||
go_version = "1.16",
|
||||
nogo = "@//:nogo",
|
||||
)
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ type Service struct {
|
||||
chainStartFetcher powchain.ChainStartFetcher
|
||||
attPool attestations.Pool
|
||||
slashingPool slashings.PoolManager
|
||||
exitPool *voluntaryexits.Pool
|
||||
exitPool voluntaryexits.PoolManager
|
||||
genesisTime time.Time
|
||||
p2p p2p.Broadcaster
|
||||
maxRoutines int
|
||||
@@ -88,7 +88,7 @@ type Config struct {
|
||||
BeaconDB db.HeadAccessDatabase
|
||||
DepositCache *depositcache.DepositCache
|
||||
AttPool attestations.Pool
|
||||
ExitPool *voluntaryexits.Pool
|
||||
ExitPool voluntaryexits.PoolManager
|
||||
SlashingPool slashings.PoolManager
|
||||
P2p p2p.Broadcaster
|
||||
MaxRoutines int
|
||||
|
||||
19
beacon-chain/cache/subnet_ids.go
vendored
19
beacon-chain/cache/subnet_ids.go
vendored
@@ -133,3 +133,22 @@ func (s *subnetIDs) AddPersistentCommittee(pubkey []byte, comIndex []uint64, dur
|
||||
|
||||
s.persistentSubnets.Set(string(pubkey), comIndex, duration)
|
||||
}
|
||||
|
||||
// EmptyAllCaches empties out all the related caches and flushes any stored
|
||||
// entries on them. This should only ever be used for testing, in normal
|
||||
// production, handling of the relevant subnets for each role is done
|
||||
// separately.
|
||||
func (s *subnetIDs) EmptyAllCaches() {
|
||||
// Clear the caches.
|
||||
s.attesterLock.Lock()
|
||||
s.attester.Purge()
|
||||
s.attesterLock.Unlock()
|
||||
|
||||
s.aggregatorLock.Lock()
|
||||
s.aggregator.Purge()
|
||||
s.aggregatorLock.Unlock()
|
||||
|
||||
s.subnetsLock.Lock()
|
||||
s.persistentSubnets.Flush()
|
||||
s.subnetsLock.Unlock()
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ go_test(
|
||||
name = "go_default_test",
|
||||
size = "small",
|
||||
srcs = ["validator_index_map_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//beacon-chain/state:go_default_library",
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//shared/bytesutil:go_default_library",
|
||||
|
||||
@@ -67,7 +67,7 @@ type BeaconNode struct {
|
||||
stop chan struct{} // Channel to wait for termination notifications.
|
||||
db db.Database
|
||||
attestationPool attestations.Pool
|
||||
exitPool *voluntaryexits.Pool
|
||||
exitPool voluntaryexits.PoolManager
|
||||
slashingsPool slashings.PoolManager
|
||||
depositCache *depositcache.DepositCache
|
||||
stateFeed *event.Feed
|
||||
|
||||
@@ -9,35 +9,37 @@ import (
|
||||
|
||||
// PoolMock is a fake implementation of PoolManager.
|
||||
type PoolMock struct {
|
||||
PendingAttSlashings []*ethpb.AttesterSlashing
|
||||
PendingAttSlashings []*ethpb.AttesterSlashing
|
||||
PendingPropSlashings []*ethpb.ProposerSlashing
|
||||
}
|
||||
|
||||
// PendingAttesterSlashings --
|
||||
func (m *PoolMock) PendingAttesterSlashings(ctx context.Context, state *state.BeaconState, noLimit bool) []*ethpb.AttesterSlashing {
|
||||
func (m *PoolMock) PendingAttesterSlashings(_ context.Context, _ *state.BeaconState, _ bool) []*ethpb.AttesterSlashing {
|
||||
return m.PendingAttSlashings
|
||||
}
|
||||
|
||||
// PendingProposerSlashings --
|
||||
func (m *PoolMock) PendingProposerSlashings(ctx context.Context, state *state.BeaconState, noLimit bool) []*ethpb.ProposerSlashing {
|
||||
panic("implement me")
|
||||
func (m *PoolMock) PendingProposerSlashings(_ context.Context, _ *state.BeaconState, _ bool) []*ethpb.ProposerSlashing {
|
||||
return m.PendingPropSlashings
|
||||
}
|
||||
|
||||
// InsertAttesterSlashing --
|
||||
func (m *PoolMock) InsertAttesterSlashing(ctx context.Context, state *state.BeaconState, slashing *ethpb.AttesterSlashing) error {
|
||||
panic("implement me")
|
||||
func (m *PoolMock) InsertAttesterSlashing(_ context.Context, _ *state.BeaconState, slashing *ethpb.AttesterSlashing) error {
|
||||
m.PendingAttSlashings = append(m.PendingAttSlashings, slashing)
|
||||
return nil
|
||||
}
|
||||
|
||||
// InsertProposerSlashing --
|
||||
func (m *PoolMock) InsertProposerSlashing(ctx context.Context, state *state.BeaconState, slashing *ethpb.ProposerSlashing) error {
|
||||
func (m *PoolMock) InsertProposerSlashing(_ context.Context, _ *state.BeaconState, _ *ethpb.ProposerSlashing) error {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
// MarkIncludedAttesterSlashing --
|
||||
func (m *PoolMock) MarkIncludedAttesterSlashing(as *ethpb.AttesterSlashing) {
|
||||
func (m *PoolMock) MarkIncludedAttesterSlashing(_ *ethpb.AttesterSlashing) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
// MarkIncludedProposerSlashing --
|
||||
func (m *PoolMock) MarkIncludedProposerSlashing(ps *ethpb.ProposerSlashing) {
|
||||
func (m *PoolMock) MarkIncludedProposerSlashing(_ *ethpb.ProposerSlashing) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"doc.go",
|
||||
"mock.go",
|
||||
"service.go",
|
||||
],
|
||||
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/operations/voluntaryexits",
|
||||
|
||||
29
beacon-chain/operations/voluntaryexits/mock.go
Normal file
29
beacon-chain/operations/voluntaryexits/mock.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package voluntaryexits
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
)
|
||||
|
||||
// PoolMock is a fake implementation of PoolManager.
|
||||
type PoolMock struct {
|
||||
Exits []*eth.SignedVoluntaryExit
|
||||
}
|
||||
|
||||
// PendingExits --
|
||||
func (m *PoolMock) PendingExits(_ *beaconstate.BeaconState, _ types.Slot, _ bool) []*eth.SignedVoluntaryExit {
|
||||
return m.Exits
|
||||
}
|
||||
|
||||
// InsertVoluntaryExit --
|
||||
func (*PoolMock) InsertVoluntaryExit(_ context.Context, _ *beaconstate.BeaconState, _ *eth.SignedVoluntaryExit) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
// MarkIncluded --
|
||||
func (*PoolMock) MarkIncluded(_ *eth.SignedVoluntaryExit) {
|
||||
panic("implement me")
|
||||
}
|
||||
@@ -13,8 +13,15 @@ import (
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
// Pool implements a struct to maintain pending and seen voluntary exits. This pool
|
||||
// is used by proposers to insert into new blocks.
|
||||
// PoolManager maintains pending and seen voluntary exits.
|
||||
// This pool is used by proposers to insert voluntary exits into new blocks.
|
||||
type PoolManager interface {
|
||||
PendingExits(state *beaconstate.BeaconState, slot types.Slot, noLimit bool) []*ethpb.SignedVoluntaryExit
|
||||
InsertVoluntaryExit(ctx context.Context, state *beaconstate.BeaconState, exit *ethpb.SignedVoluntaryExit)
|
||||
MarkIncluded(exit *ethpb.SignedVoluntaryExit)
|
||||
}
|
||||
|
||||
// Pool is a concrete implementation of PoolManager.
|
||||
type Pool struct {
|
||||
lock sync.RWMutex
|
||||
pending []*ethpb.SignedVoluntaryExit
|
||||
|
||||
@@ -83,11 +83,13 @@ go_library(
|
||||
"@com_github_libp2p_go_libp2p_noise//:go_default_library",
|
||||
"@com_github_libp2p_go_libp2p_pubsub//:go_default_library",
|
||||
"@com_github_libp2p_go_libp2p_pubsub//pb:go_default_library",
|
||||
"@com_github_libp2p_go_tcp_transport//:go_default_library",
|
||||
"@com_github_multiformats_go_multiaddr//:go_default_library",
|
||||
"@com_github_multiformats_go_multiaddr//net:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/libp2p/go-libp2p"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
noise "github.com/libp2p/go-libp2p-noise"
|
||||
"github.com/libp2p/go-tcp-transport"
|
||||
ma "github.com/multiformats/go-multiaddr"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/shared/version"
|
||||
@@ -34,6 +35,7 @@ func (s *Service) buildOptions(ip net.IP, priKey *ecdsa.PrivateKey) []libp2p.Opt
|
||||
libp2p.ListenAddrs(listen),
|
||||
libp2p.UserAgent(version.BuildData()),
|
||||
libp2p.ConnectionGater(s),
|
||||
libp2p.Transport(tcp.NewTCPTransport),
|
||||
}
|
||||
|
||||
options = append(options, libp2p.Security(noise.ID, noise.New))
|
||||
|
||||
@@ -20,8 +20,8 @@ go_library(
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["store_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"@com_github_libp2p_go_libp2p_core//peer:go_default_library",
|
||||
|
||||
@@ -36,8 +36,8 @@ go_test(
|
||||
"scorers_test.go",
|
||||
"service_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//beacon-chain/flags:go_default_library",
|
||||
"//beacon-chain/p2p/peers:go_default_library",
|
||||
"//beacon-chain/p2p/peers/peerdata:go_default_library",
|
||||
|
||||
@@ -656,7 +656,9 @@ func (p *Status) BestNonFinalized(minPeers int, ourHeadEpoch types.Epoch) (types
|
||||
// to determine the most suitable peers to take out.
|
||||
func (p *Status) PeersToPrune() []peer.ID {
|
||||
connLimit := p.ConnectedPeerLimit()
|
||||
inBoundLimit := p.InboundLimit()
|
||||
activePeers := p.Active()
|
||||
numInboundPeers := len(p.InboundConnected())
|
||||
// Exit early if we are still below our max
|
||||
// limit.
|
||||
if len(activePeers) <= int(connLimit) {
|
||||
@@ -672,7 +674,8 @@ func (p *Status) PeersToPrune() []peer.ID {
|
||||
peersToPrune := make([]*peerResp, 0)
|
||||
// Select connected and inbound peers to prune.
|
||||
for pid, peerData := range p.store.Peers() {
|
||||
if peerData.ConnState == PeerConnected && peerData.Direction == network.DirInbound {
|
||||
if peerData.ConnState == PeerConnected &&
|
||||
peerData.Direction == network.DirInbound {
|
||||
peersToPrune = append(peersToPrune, &peerResp{
|
||||
pid: pid,
|
||||
badResp: peerData.BadResponses,
|
||||
@@ -690,6 +693,16 @@ func (p *Status) PeersToPrune() []peer.ID {
|
||||
// max connection limit.
|
||||
amountToPrune := len(activePeers) - int(connLimit)
|
||||
|
||||
// Also check for inbound peers above our limit.
|
||||
excessInbound := 0
|
||||
if numInboundPeers > inBoundLimit {
|
||||
excessInbound = numInboundPeers - inBoundLimit
|
||||
}
|
||||
// Prune the largest amount between excess peers and
|
||||
// excess inbound peers.
|
||||
if excessInbound > amountToPrune {
|
||||
amountToPrune = excessInbound
|
||||
}
|
||||
if amountToPrune < len(peersToPrune) {
|
||||
peersToPrune = peersToPrune[:amountToPrune]
|
||||
}
|
||||
|
||||
@@ -4,7 +4,8 @@ import (
|
||||
"reflect"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
)
|
||||
|
||||
@@ -31,7 +32,7 @@ var RPCTopicMappings = map[string]interface{}{
|
||||
RPCStatusTopic: new(pb.Status),
|
||||
RPCGoodByeTopic: new(types.SSZUint64),
|
||||
RPCBlocksByRangeTopic: new(pb.BeaconBlocksByRangeRequest),
|
||||
RPCBlocksByRootTopic: new(types.BeaconBlockByRootsReq),
|
||||
RPCBlocksByRootTopic: new(p2ptypes.BeaconBlockByRootsReq),
|
||||
RPCPingTopic: new(types.SSZUint64),
|
||||
RPCMetaDataTopic: new(interface{}),
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@ go_library(
|
||||
"//validator/client:__pkg__",
|
||||
],
|
||||
deps = [
|
||||
"//shared/htrutils:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"@com_github_ferranbt_fastssz//:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
)
|
||||
|
||||
// RPCGoodbyeCode represents goodbye code, used in sync package.
|
||||
type RPCGoodbyeCode = SSZUint64
|
||||
type RPCGoodbyeCode = types.SSZUint64
|
||||
|
||||
const (
|
||||
// Spec defined codes.
|
||||
|
||||
@@ -6,7 +6,6 @@ package types
|
||||
import (
|
||||
ssz "github.com/ferranbt/fastssz"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/shared/htrutils"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
)
|
||||
|
||||
@@ -14,53 +13,7 @@ const rootLength = 32
|
||||
|
||||
const maxErrorLength = 256
|
||||
|
||||
// SSZUint64 is a uint64 type that satisfies the fast-ssz interface.
|
||||
type SSZUint64 uint64
|
||||
|
||||
// SizeSSZ returns the size of the serialized representation.
|
||||
func (s *SSZUint64) SizeSSZ() int {
|
||||
return 8
|
||||
}
|
||||
|
||||
// MarshalSSZTo marshals the uint64 with the provided byte slice.
|
||||
func (s *SSZUint64) MarshalSSZTo(dst []byte) ([]byte, error) {
|
||||
marshalledObj, err := s.MarshalSSZ()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return append(dst, marshalledObj...), nil
|
||||
}
|
||||
|
||||
// MarshalSSZ Marshals the uint64 type into the serialized object.
|
||||
func (s *SSZUint64) MarshalSSZ() ([]byte, error) {
|
||||
marshalledObj := ssz.MarshalUint64([]byte{}, uint64(*s))
|
||||
return marshalledObj, nil
|
||||
}
|
||||
|
||||
// UnmarshalSSZ unmarshals the provided bytes buffer into the
|
||||
// uint64 object.
|
||||
func (s *SSZUint64) UnmarshalSSZ(buf []byte) error {
|
||||
if len(buf) != s.SizeSSZ() {
|
||||
return errors.Errorf("expected buffer with length of %d but received length %d", s.SizeSSZ(), len(buf))
|
||||
}
|
||||
*s = SSZUint64(ssz.UnmarshallUint64(buf))
|
||||
return nil
|
||||
}
|
||||
|
||||
// HashTreeRoot hashes the uint64 object following the SSZ standard.
|
||||
func (s *SSZUint64) HashTreeRoot() ([32]byte, error) {
|
||||
return htrutils.Uint64Root(uint64(*s)), nil
|
||||
}
|
||||
|
||||
// HashTreeRootWith hashes the uint64 object with the given hasher.
|
||||
func (s *SSZUint64) HashTreeRootWith(hh *ssz.Hasher) error {
|
||||
indx := hh.Index()
|
||||
hh.PutUint64(uint64(*s))
|
||||
hh.Merkleize(indx)
|
||||
return nil
|
||||
}
|
||||
|
||||
// SSZUint64 is a bytes slice that satisfies the fast-ssz interface.
|
||||
// SSZBytes is a bytes slice that satisfies the fast-ssz interface.
|
||||
type SSZBytes []byte
|
||||
|
||||
// HashTreeRoot hashes the uint64 object following the SSZ standard.
|
||||
|
||||
@@ -9,12 +9,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
)
|
||||
|
||||
func TestSSZUint64_Limit(t *testing.T) {
|
||||
sszType := SSZUint64(0)
|
||||
serializedObj := [7]byte{}
|
||||
require.ErrorContains(t, "expected buffer with length", sszType.UnmarshalSSZ(serializedObj[:]))
|
||||
}
|
||||
|
||||
func TestBeaconBlockByRootsReq_Limit(t *testing.T) {
|
||||
fixedRoots := make([][32]byte, 0)
|
||||
for i := uint64(0); i < params.BeaconNetworkConfig().MaxRequestBlocks+100; i++ {
|
||||
@@ -45,24 +39,10 @@ func TestErrorResponse_Limit(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRoundTripSerialization(t *testing.T) {
|
||||
roundTripTestSSZUint64(t)
|
||||
roundTripTestBlocksByRootReq(t)
|
||||
roundTripTestErrorMessage(t)
|
||||
}
|
||||
|
||||
func roundTripTestSSZUint64(t *testing.T) {
|
||||
fixedVal := uint64(8)
|
||||
sszVal := SSZUint64(fixedVal)
|
||||
|
||||
marshalledObj, err := sszVal.MarshalSSZ()
|
||||
require.NoError(t, err)
|
||||
newVal := SSZUint64(0)
|
||||
|
||||
err = newVal.UnmarshalSSZ(marshalledObj)
|
||||
require.NoError(t, err)
|
||||
assert.DeepEqual(t, fixedVal, uint64(newVal))
|
||||
}
|
||||
|
||||
func roundTripTestBlocksByRootReq(t *testing.T) {
|
||||
fixedRoots := make([][32]byte, 0)
|
||||
for i := 0; i < 200; i++ {
|
||||
@@ -91,55 +71,6 @@ func roundTripTestErrorMessage(t *testing.T) {
|
||||
assert.DeepEqual(t, []byte(newVal), errMsg)
|
||||
}
|
||||
|
||||
func TestSSZUint64(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
serializedBytes []byte
|
||||
actualValue uint64
|
||||
root []byte
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "max",
|
||||
serializedBytes: hexDecodeOrDie(t, "ffffffffffffffff"),
|
||||
actualValue: 18446744073709551615,
|
||||
root: hexDecodeOrDie(t, "ffffffffffffffff000000000000000000000000000000000000000000000000"),
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "random",
|
||||
serializedBytes: hexDecodeOrDie(t, "357c8de9d7204577"),
|
||||
actualValue: 8594311575614880821,
|
||||
root: hexDecodeOrDie(t, "357c8de9d7204577000000000000000000000000000000000000000000000000"),
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "zero",
|
||||
serializedBytes: hexDecodeOrDie(t, "0000000000000000"),
|
||||
actualValue: 0,
|
||||
root: hexDecodeOrDie(t, "0000000000000000000000000000000000000000000000000000000000000000"),
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var s SSZUint64
|
||||
if err := s.UnmarshalSSZ(tt.serializedBytes); (err != nil) != tt.wantErr {
|
||||
t.Errorf("UnmarshalSSZ() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
require.Equal(t, uint64(s), tt.actualValue)
|
||||
|
||||
serializedBytes, err := s.MarshalSSZ()
|
||||
require.NoError(t, err)
|
||||
require.DeepEqual(t, tt.serializedBytes, serializedBytes)
|
||||
|
||||
htr, err := s.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
require.DeepEqual(t, tt.root, htr[:])
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSSZBytes_HashTreeRoot(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
@@ -27,7 +27,7 @@ func (bs *Server) SubmitProposerSlashing(
|
||||
}
|
||||
if !featureconfig.Get().DisableBroadcastSlashings {
|
||||
if err := bs.Broadcaster.Broadcast(ctx, req); err != nil {
|
||||
return nil, err
|
||||
return nil, status.Errorf(codes.Internal, "Could not broadcast slashing object: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func (bs *Server) SubmitAttesterSlashing(
|
||||
}
|
||||
if !featureconfig.Get().DisableBroadcastSlashings {
|
||||
if err := bs.Broadcaster.Broadcast(ctx, req); err != nil {
|
||||
return nil, err
|
||||
return nil, status.Errorf(codes.Internal, "Could not broadcast slashing object: %v", err)
|
||||
}
|
||||
}
|
||||
indices := sliceutil.IntersectionUint64(req.Attestation_1.AttestingIndices, req.Attestation_2.AttestingIndices)
|
||||
|
||||
@@ -17,6 +17,7 @@ go_library(
|
||||
deps = [
|
||||
"//beacon-chain/blockchain:go_default_library",
|
||||
"//beacon-chain/cache/depositcache:go_default_library",
|
||||
"//beacon-chain/core/blocks:go_default_library",
|
||||
"//beacon-chain/core/feed:go_default_library",
|
||||
"//beacon-chain/core/feed/block:go_default_library",
|
||||
"//beacon-chain/core/feed/operation:go_default_library",
|
||||
@@ -26,6 +27,7 @@ go_library(
|
||||
"//beacon-chain/db/filters:go_default_library",
|
||||
"//beacon-chain/operations/attestations:go_default_library",
|
||||
"//beacon-chain/operations/slashings:go_default_library",
|
||||
"//beacon-chain/operations/voluntaryexits:go_default_library",
|
||||
"//beacon-chain/p2p:go_default_library",
|
||||
"//beacon-chain/powchain:go_default_library",
|
||||
"//beacon-chain/state:go_default_library",
|
||||
@@ -34,6 +36,7 @@ go_library(
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//proto/migration:go_default_library",
|
||||
"//shared/bytesutil:go_default_library",
|
||||
"//shared/featureconfig:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
|
||||
"@com_github_gogo_protobuf//types:go_default_library",
|
||||
@@ -60,14 +63,17 @@ go_test(
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//beacon-chain/blockchain/testing:go_default_library",
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
"//beacon-chain/db:go_default_library",
|
||||
"//beacon-chain/db/testing:go_default_library",
|
||||
"//beacon-chain/operations/slashings:go_default_library",
|
||||
"//beacon-chain/operations/voluntaryexits:go_default_library",
|
||||
"//beacon-chain/p2p/testing:go_default_library",
|
||||
"//beacon-chain/powchain/testing:go_default_library",
|
||||
"//beacon-chain/state/stategen:go_default_library",
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//proto/migration:go_default_library",
|
||||
"//shared/bls:go_default_library",
|
||||
"//shared/bytesutil:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/testutil:go_default_library",
|
||||
|
||||
@@ -6,7 +6,9 @@ import (
|
||||
|
||||
ptypes "github.com/gogo/protobuf/types"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
"github.com/prysmaticlabs/prysm/proto/migration"
|
||||
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
||||
"go.opencensus.io/trace"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
@@ -34,7 +36,7 @@ func (bs *Server) ListPoolAttesterSlashings(ctx context.Context, req *ptypes.Emp
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not get head state: %v", err)
|
||||
}
|
||||
sourceSlashings := bs.SlashingsPool.PendingAttesterSlashings(ctx, headState, true)
|
||||
sourceSlashings := bs.SlashingsPool.PendingAttesterSlashings(ctx, headState, true /* return unlimited slashings */)
|
||||
|
||||
slashings := make([]*ethpb.AttesterSlashing, len(sourceSlashings))
|
||||
for i, s := range sourceSlashings {
|
||||
@@ -49,13 +51,53 @@ func (bs *Server) ListPoolAttesterSlashings(ctx context.Context, req *ptypes.Emp
|
||||
// SubmitAttesterSlashing submits AttesterSlashing object to node's pool and
|
||||
// if passes validation node MUST broadcast it to network.
|
||||
func (bs *Server) SubmitAttesterSlashing(ctx context.Context, req *ethpb.AttesterSlashing) (*ptypes.Empty, error) {
|
||||
return nil, errors.New("unimplemented")
|
||||
ctx, span := trace.StartSpan(ctx, "beaconv1.SubmitAttesterSlashing")
|
||||
defer span.End()
|
||||
|
||||
headState, err := bs.ChainInfoFetcher.HeadState(ctx)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not get head state: %v", err)
|
||||
}
|
||||
|
||||
v1Slashing := migration.V1AttSlashingToV1Alpha1(req)
|
||||
err = blocks.VerifyAttesterSlashing(ctx, headState, v1Slashing)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Invalid attester slashing: %v", err)
|
||||
}
|
||||
|
||||
err = bs.SlashingsPool.InsertAttesterSlashing(ctx, headState, v1Slashing)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not insert attester slashing into pool: %v", err)
|
||||
}
|
||||
if !featureconfig.Get().DisableBroadcastSlashings {
|
||||
if err := bs.Broadcaster.Broadcast(ctx, req); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not broadcast slashing object: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return &ptypes.Empty{}, nil
|
||||
}
|
||||
|
||||
// ListPoolProposerSlashings retrieves proposer slashings known by the node
|
||||
// but not necessarily incorporated into any block.
|
||||
func (bs *Server) ListPoolProposerSlashings(ctx context.Context, req *ptypes.Empty) (*ethpb.ProposerSlashingPoolResponse, error) {
|
||||
return nil, errors.New("unimplemented")
|
||||
ctx, span := trace.StartSpan(ctx, "beaconv1.ListPoolProposerSlashings")
|
||||
defer span.End()
|
||||
|
||||
headState, err := bs.ChainInfoFetcher.HeadState(ctx)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not get head state: %v", err)
|
||||
}
|
||||
sourceSlashings := bs.SlashingsPool.PendingProposerSlashings(ctx, headState, true /* return unlimited slashings */)
|
||||
|
||||
slashings := make([]*ethpb.ProposerSlashing, len(sourceSlashings))
|
||||
for i, s := range sourceSlashings {
|
||||
slashings[i] = migration.V1Alpha1ProposerSlashingToV1(s)
|
||||
}
|
||||
|
||||
return ðpb.ProposerSlashingPoolResponse{
|
||||
Data: slashings,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// SubmitProposerSlashing submits AttesterSlashing object to node's pool and if
|
||||
@@ -67,7 +109,24 @@ func (bs *Server) SubmitProposerSlashing(ctx context.Context, req *ethpb.Propose
|
||||
// ListPoolVoluntaryExits retrieves voluntary exits known by the node but
|
||||
// not necessarily incorporated into any block.
|
||||
func (bs *Server) ListPoolVoluntaryExits(ctx context.Context, req *ptypes.Empty) (*ethpb.VoluntaryExitsPoolResponse, error) {
|
||||
return nil, errors.New("unimplemented")
|
||||
ctx, span := trace.StartSpan(ctx, "beaconv1.ListPoolVoluntaryExits")
|
||||
defer span.End()
|
||||
|
||||
headState, err := bs.ChainInfoFetcher.HeadState(ctx)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not get head state: %v", err)
|
||||
}
|
||||
|
||||
sourceExits := bs.VoluntaryExitsPool.PendingExits(headState, headState.Slot(), true /* return unlimited exits */)
|
||||
|
||||
exits := make([]*ethpb.SignedVoluntaryExit, len(sourceExits))
|
||||
for i, s := range sourceExits {
|
||||
exits[i] = migration.V1Alpha1ExitToV1(s)
|
||||
}
|
||||
|
||||
return ðpb.VoluntaryExitsPoolResponse{
|
||||
Data: exits,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// SubmitVoluntaryExit submits SignedVoluntaryExit object to node's pool
|
||||
|
||||
@@ -5,11 +5,18 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/gogo/protobuf/types"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1"
|
||||
eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
chainMock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/operations/slashings"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/operations/voluntaryexits"
|
||||
p2pMock "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/proto/migration"
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
@@ -102,3 +109,208 @@ func TestListPoolAttesterSlashings(t *testing.T) {
|
||||
assert.DeepEqual(t, migration.V1Alpha1AttSlashingToV1(slashing1), resp.Data[0])
|
||||
assert.DeepEqual(t, migration.V1Alpha1AttSlashingToV1(slashing2), resp.Data[1])
|
||||
}
|
||||
|
||||
func TestListPoolProposerSlashings(t *testing.T) {
|
||||
state, err := testutil.NewBeaconState()
|
||||
require.NoError(t, err)
|
||||
slashing1 := ð.ProposerSlashing{
|
||||
Header_1: ð.SignedBeaconBlockHeader{
|
||||
Header: ð.BeaconBlockHeader{
|
||||
Slot: 1,
|
||||
ProposerIndex: 1,
|
||||
ParentRoot: bytesutil.PadTo([]byte("parentroot1"), 32),
|
||||
StateRoot: bytesutil.PadTo([]byte("stateroot1"), 32),
|
||||
BodyRoot: bytesutil.PadTo([]byte("bodyroot1"), 32),
|
||||
},
|
||||
Signature: bytesutil.PadTo([]byte("signature1"), 96),
|
||||
},
|
||||
Header_2: ð.SignedBeaconBlockHeader{
|
||||
Header: ð.BeaconBlockHeader{
|
||||
Slot: 2,
|
||||
ProposerIndex: 2,
|
||||
ParentRoot: bytesutil.PadTo([]byte("parentroot2"), 32),
|
||||
StateRoot: bytesutil.PadTo([]byte("stateroot2"), 32),
|
||||
BodyRoot: bytesutil.PadTo([]byte("bodyroot2"), 32),
|
||||
},
|
||||
Signature: bytesutil.PadTo([]byte("signature2"), 96),
|
||||
},
|
||||
}
|
||||
slashing2 := ð.ProposerSlashing{
|
||||
Header_1: ð.SignedBeaconBlockHeader{
|
||||
Header: ð.BeaconBlockHeader{
|
||||
Slot: 3,
|
||||
ProposerIndex: 3,
|
||||
ParentRoot: bytesutil.PadTo([]byte("parentroot3"), 32),
|
||||
StateRoot: bytesutil.PadTo([]byte("stateroot3"), 32),
|
||||
BodyRoot: bytesutil.PadTo([]byte("bodyroot3"), 32),
|
||||
},
|
||||
Signature: bytesutil.PadTo([]byte("signature3"), 96),
|
||||
},
|
||||
Header_2: ð.SignedBeaconBlockHeader{
|
||||
Header: ð.BeaconBlockHeader{
|
||||
Slot: 4,
|
||||
ProposerIndex: 4,
|
||||
ParentRoot: bytesutil.PadTo([]byte("parentroot4"), 32),
|
||||
StateRoot: bytesutil.PadTo([]byte("stateroot4"), 32),
|
||||
BodyRoot: bytesutil.PadTo([]byte("bodyroot4"), 32),
|
||||
},
|
||||
Signature: bytesutil.PadTo([]byte("signature4"), 96),
|
||||
},
|
||||
}
|
||||
|
||||
s := &Server{
|
||||
ChainInfoFetcher: &chainMock.ChainService{State: state},
|
||||
SlashingsPool: &slashings.PoolMock{PendingPropSlashings: []*eth.ProposerSlashing{slashing1, slashing2}},
|
||||
}
|
||||
|
||||
resp, err := s.ListPoolProposerSlashings(context.Background(), &types.Empty{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 2, len(resp.Data))
|
||||
assert.DeepEqual(t, migration.V1Alpha1ProposerSlashingToV1(slashing1), resp.Data[0])
|
||||
assert.DeepEqual(t, migration.V1Alpha1ProposerSlashingToV1(slashing2), resp.Data[1])
|
||||
}
|
||||
|
||||
func TestListPoolVoluntaryExits(t *testing.T) {
|
||||
state, err := testutil.NewBeaconState()
|
||||
require.NoError(t, err)
|
||||
exit1 := ð.SignedVoluntaryExit{
|
||||
Exit: ð.VoluntaryExit{
|
||||
Epoch: 1,
|
||||
ValidatorIndex: 1,
|
||||
},
|
||||
Signature: bytesutil.PadTo([]byte("signature1"), 96),
|
||||
}
|
||||
exit2 := ð.SignedVoluntaryExit{
|
||||
Exit: ð.VoluntaryExit{
|
||||
Epoch: 2,
|
||||
ValidatorIndex: 2,
|
||||
},
|
||||
Signature: bytesutil.PadTo([]byte("signature2"), 96),
|
||||
}
|
||||
|
||||
s := &Server{
|
||||
ChainInfoFetcher: &chainMock.ChainService{State: state},
|
||||
VoluntaryExitsPool: &voluntaryexits.PoolMock{Exits: []*eth.SignedVoluntaryExit{exit1, exit2}},
|
||||
}
|
||||
|
||||
resp, err := s.ListPoolVoluntaryExits(context.Background(), &types.Empty{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 2, len(resp.Data))
|
||||
assert.DeepEqual(t, migration.V1Alpha1ExitToV1(exit1), resp.Data[0])
|
||||
assert.DeepEqual(t, migration.V1Alpha1ExitToV1(exit2), resp.Data[1])
|
||||
}
|
||||
|
||||
func TestSubmitAttesterSlashing_Ok(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
_, keys, err := testutil.DeterministicDepositsAndKeys(1)
|
||||
require.NoError(t, err)
|
||||
validator := ð.Validator{
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
PublicKey: keys[0].PublicKey().Marshal(),
|
||||
WithdrawalCredentials: make([]byte, 32),
|
||||
}
|
||||
state, err := testutil.NewBeaconState(func(state *pb.BeaconState) {
|
||||
state.Validators = []*eth.Validator{validator}
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
slashing := ðpb.AttesterSlashing{
|
||||
Attestation_1: ðpb.IndexedAttestation{
|
||||
AttestingIndices: []uint64{0},
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
CommitteeIndex: 1,
|
||||
BeaconBlockRoot: bytesutil.PadTo([]byte("blockroot1"), 32),
|
||||
Source: ðpb.Checkpoint{
|
||||
Epoch: 1,
|
||||
Root: bytesutil.PadTo([]byte("sourceroot1"), 32),
|
||||
},
|
||||
Target: ðpb.Checkpoint{
|
||||
Epoch: 10,
|
||||
Root: bytesutil.PadTo([]byte("targetroot1"), 32),
|
||||
},
|
||||
},
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
Attestation_2: ðpb.IndexedAttestation{
|
||||
AttestingIndices: []uint64{0},
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
CommitteeIndex: 1,
|
||||
BeaconBlockRoot: bytesutil.PadTo([]byte("blockroot2"), 32),
|
||||
Source: ðpb.Checkpoint{
|
||||
Epoch: 1,
|
||||
Root: bytesutil.PadTo([]byte("sourceroot2"), 32),
|
||||
},
|
||||
Target: ðpb.Checkpoint{
|
||||
Epoch: 10,
|
||||
Root: bytesutil.PadTo([]byte("targetroot2"), 32),
|
||||
},
|
||||
},
|
||||
Signature: make([]byte, 96),
|
||||
},
|
||||
}
|
||||
|
||||
for _, att := range []*ethpb.IndexedAttestation{slashing.Attestation_1, slashing.Attestation_2} {
|
||||
sb, err := helpers.ComputeDomainAndSign(state, att.Data.Target.Epoch, att.Data, params.BeaconConfig().DomainBeaconAttester, keys[0])
|
||||
require.NoError(t, err)
|
||||
sig, err := bls.SignatureFromBytes(sb)
|
||||
require.NoError(t, err)
|
||||
att.Signature = sig.Marshal()
|
||||
}
|
||||
|
||||
broadcaster := &p2pMock.MockBroadcaster{}
|
||||
s := &Server{
|
||||
ChainInfoFetcher: &chainMock.ChainService{State: state},
|
||||
SlashingsPool: &slashings.PoolMock{},
|
||||
Broadcaster: broadcaster,
|
||||
}
|
||||
|
||||
_, err = s.SubmitAttesterSlashing(ctx, slashing)
|
||||
require.NoError(t, err)
|
||||
pendingSlashings := s.SlashingsPool.PendingAttesterSlashings(ctx, state, true)
|
||||
require.Equal(t, 1, len(pendingSlashings))
|
||||
assert.DeepEqual(t, migration.V1AttSlashingToV1Alpha1(slashing), pendingSlashings[0])
|
||||
assert.Equal(t, true, broadcaster.BroadcastCalled)
|
||||
}
|
||||
|
||||
func TestSubmitAttesterSlashing_InvalidSlashing(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
state, err := testutil.NewBeaconState()
|
||||
require.NoError(t, err)
|
||||
|
||||
attestation := ðpb.IndexedAttestation{
|
||||
AttestingIndices: []uint64{0},
|
||||
Data: ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
CommitteeIndex: 1,
|
||||
BeaconBlockRoot: bytesutil.PadTo([]byte("blockroot1"), 32),
|
||||
Source: ðpb.Checkpoint{
|
||||
Epoch: 1,
|
||||
Root: bytesutil.PadTo([]byte("sourceroot1"), 32),
|
||||
},
|
||||
Target: ðpb.Checkpoint{
|
||||
Epoch: 10,
|
||||
Root: bytesutil.PadTo([]byte("targetroot1"), 32),
|
||||
},
|
||||
},
|
||||
Signature: make([]byte, 96),
|
||||
}
|
||||
|
||||
slashing := ðpb.AttesterSlashing{
|
||||
Attestation_1: attestation,
|
||||
Attestation_2: attestation,
|
||||
}
|
||||
|
||||
broadcaster := &p2pMock.MockBroadcaster{}
|
||||
s := &Server{
|
||||
ChainInfoFetcher: &chainMock.ChainService{State: state},
|
||||
SlashingsPool: &slashings.PoolMock{},
|
||||
Broadcaster: broadcaster,
|
||||
}
|
||||
|
||||
_, err = s.SubmitAttesterSlashing(ctx, slashing)
|
||||
require.ErrorContains(t, "Invalid attester slashing", err)
|
||||
assert.Equal(t, false, broadcaster.BroadcastCalled)
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/operations/slashings"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/operations/voluntaryexits"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/powchain"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
|
||||
@@ -40,6 +41,7 @@ type Server struct {
|
||||
Broadcaster p2p.Broadcaster
|
||||
AttestationsPool attestations.Pool
|
||||
SlashingsPool slashings.PoolManager
|
||||
VoluntaryExitsPool voluntaryexits.PoolManager
|
||||
CanonicalStateChan chan *pbp2p.BeaconState
|
||||
ChainStartChan chan time.Time
|
||||
StateGenService stategen.StateManager
|
||||
|
||||
@@ -70,7 +70,7 @@ type Service struct {
|
||||
mockEth1Votes bool
|
||||
enableDebugRPCEndpoints bool
|
||||
attestationsPool attestations.Pool
|
||||
exitPool *voluntaryexits.Pool
|
||||
exitPool voluntaryexits.PoolManager
|
||||
slashingsPool slashings.PoolManager
|
||||
syncService chainSync.Checker
|
||||
host string
|
||||
@@ -122,7 +122,7 @@ type Config struct {
|
||||
EnableDebugRPCEndpoints bool
|
||||
MockEth1Votes bool
|
||||
AttestationsPool attestations.Pool
|
||||
ExitPool *voluntaryexits.Pool
|
||||
ExitPool voluntaryexits.PoolManager
|
||||
SlashingsPool slashings.PoolManager
|
||||
SyncService chainSync.Checker
|
||||
Broadcaster p2p.Broadcaster
|
||||
|
||||
@@ -56,7 +56,7 @@ type Server struct {
|
||||
P2P p2p.Broadcaster
|
||||
AttPool attestations.Pool
|
||||
SlashingsPool slashings.PoolManager
|
||||
ExitPool *voluntaryexits.Pool
|
||||
ExitPool voluntaryexits.PoolManager
|
||||
BlockReceiver blockchain.BlockReceiver
|
||||
MockEth1Votes bool
|
||||
Eth1BlockFetcher powchain.POWBlockFetcher
|
||||
|
||||
@@ -136,6 +136,7 @@ go_test(
|
||||
shard_count = 4,
|
||||
deps = [
|
||||
"//beacon-chain/blockchain/testing:go_default_library",
|
||||
"//beacon-chain/cache:go_default_library",
|
||||
"//beacon-chain/core/feed:go_default_library",
|
||||
"//beacon-chain/core/feed/state:go_default_library",
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers"
|
||||
p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
|
||||
p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/abool"
|
||||
"github.com/prysmaticlabs/prysm/shared/attestationutil"
|
||||
@@ -95,7 +94,7 @@ func TestProcessPendingAtts_HasBlockSaveUnAggregatedAtt(t *testing.T) {
|
||||
|
||||
// Arbitrary aggregator index for testing purposes.
|
||||
aggregatorIndex := committee[0]
|
||||
sszUint := p2ptypes.SSZUint64(att.Data.Slot)
|
||||
sszUint := types.SSZUint64(att.Data.Slot)
|
||||
sig, err := helpers.ComputeDomainAndSign(beaconState, 0, &sszUint, params.BeaconConfig().DomainSelectionProof, privKeys[aggregatorIndex])
|
||||
require.NoError(t, err)
|
||||
aggregateAndProof := ðpb.AggregateAttestationAndProof{
|
||||
@@ -210,7 +209,7 @@ func TestProcessPendingAtts_NoBroadcastWithBadSignature(t *testing.T) {
|
||||
|
||||
// Arbitrary aggregator index for testing purposes.
|
||||
aggregatorIndex := committee[0]
|
||||
sszSlot := p2ptypes.SSZUint64(att.Data.Slot)
|
||||
sszSlot := types.SSZUint64(att.Data.Slot)
|
||||
sig, err := helpers.ComputeDomainAndSign(s, 0, &sszSlot, params.BeaconConfig().DomainSelectionProof, privKeys[aggregatorIndex])
|
||||
require.NoError(t, err)
|
||||
aggregateAndProof := ðpb.AggregateAttestationAndProof{
|
||||
@@ -287,7 +286,7 @@ func TestProcessPendingAtts_HasBlockSaveAggregatedAtt(t *testing.T) {
|
||||
|
||||
// Arbitrary aggregator index for testing purposes.
|
||||
aggregatorIndex := committee[0]
|
||||
sszUint := p2ptypes.SSZUint64(att.Data.Slot)
|
||||
sszUint := types.SSZUint64(att.Data.Slot)
|
||||
sig, err := helpers.ComputeDomainAndSign(beaconState, 0, &sszUint, params.BeaconConfig().DomainSelectionProof, privKeys[aggregatorIndex])
|
||||
require.NoError(t, err)
|
||||
aggregateAndProof := ðpb.AggregateAttestationAndProof{
|
||||
|
||||
@@ -8,8 +8,9 @@ import (
|
||||
libp2pcore "github.com/libp2p/go-libp2p-core"
|
||||
"github.com/libp2p/go-libp2p-core/network"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
|
||||
p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
|
||||
"github.com/prysmaticlabs/prysm/shared/mputil"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
@@ -17,18 +18,18 @@ import (
|
||||
var backOffTime = map[types.SSZUint64]time.Duration{
|
||||
// Do not dial peers which are from a different/unverifiable
|
||||
// network.
|
||||
types.GoodbyeCodeWrongNetwork: 24 * time.Hour,
|
||||
types.GoodbyeCodeUnableToVerifyNetwork: 24 * time.Hour,
|
||||
p2ptypes.GoodbyeCodeWrongNetwork: 24 * time.Hour,
|
||||
p2ptypes.GoodbyeCodeUnableToVerifyNetwork: 24 * time.Hour,
|
||||
// If local peer is banned, we back off for
|
||||
// 2 hours to let the remote peer score us
|
||||
// back up again.
|
||||
types.GoodbyeCodeBadScore: 2 * time.Hour,
|
||||
types.GoodbyeCodeBanned: 2 * time.Hour,
|
||||
types.GoodbyeCodeClientShutdown: 1 * time.Hour,
|
||||
p2ptypes.GoodbyeCodeBadScore: 2 * time.Hour,
|
||||
p2ptypes.GoodbyeCodeBanned: 2 * time.Hour,
|
||||
p2ptypes.GoodbyeCodeClientShutdown: 1 * time.Hour,
|
||||
// Wait 5 minutes before dialing a peer who is
|
||||
// 'full'
|
||||
types.GoodbyeCodeTooManyPeers: 5 * time.Minute,
|
||||
types.GoodbyeCodeGenericError: 2 * time.Minute,
|
||||
p2ptypes.GoodbyeCodeTooManyPeers: 5 * time.Minute,
|
||||
p2ptypes.GoodbyeCodeGenericError: 2 * time.Minute,
|
||||
}
|
||||
|
||||
// goodbyeRPCHandler reads the incoming goodbye rpc message from the peer.
|
||||
@@ -56,7 +57,7 @@ func (s *Service) disconnectBadPeer(ctx context.Context, id peer.ID) {
|
||||
if !s.p2p.Peers().IsBad(id) {
|
||||
return
|
||||
}
|
||||
goodbyeCode := types.ErrToGoodbyeCode(s.p2p.Peers().Scorers().ValidationError(id))
|
||||
goodbyeCode := p2ptypes.ErrToGoodbyeCode(s.p2p.Peers().Scorers().ValidationError(id))
|
||||
if err := s.sendGoodByeAndDisconnect(ctx, goodbyeCode, id); err != nil {
|
||||
log.Debugf("Error when disconnecting with bad peer: %v", err)
|
||||
}
|
||||
@@ -65,10 +66,10 @@ func (s *Service) disconnectBadPeer(ctx context.Context, id peer.ID) {
|
||||
// A custom goodbye method that is used by our connection handler, in the
|
||||
// event we receive bad peers.
|
||||
func (s *Service) sendGoodbye(ctx context.Context, id peer.ID) error {
|
||||
return s.sendGoodByeAndDisconnect(ctx, types.GoodbyeCodeGenericError, id)
|
||||
return s.sendGoodByeAndDisconnect(ctx, p2ptypes.GoodbyeCodeGenericError, id)
|
||||
}
|
||||
|
||||
func (s *Service) sendGoodByeAndDisconnect(ctx context.Context, code types.RPCGoodbyeCode, id peer.ID) error {
|
||||
func (s *Service) sendGoodByeAndDisconnect(ctx context.Context, code p2ptypes.RPCGoodbyeCode, id peer.ID) error {
|
||||
lock := mputil.NewMultilock(id.String())
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
@@ -86,7 +87,7 @@ func (s *Service) sendGoodByeAndDisconnect(ctx context.Context, code types.RPCGo
|
||||
return s.p2p.Disconnect(id)
|
||||
}
|
||||
|
||||
func (s *Service) sendGoodByeMessage(ctx context.Context, code types.RPCGoodbyeCode, id peer.ID) error {
|
||||
func (s *Service) sendGoodByeMessage(ctx context.Context, code p2ptypes.RPCGoodbyeCode, id peer.ID) error {
|
||||
ctx, cancel := context.WithTimeout(ctx, respTimeout)
|
||||
defer cancel()
|
||||
|
||||
@@ -113,8 +114,8 @@ func (s *Service) sendGoodByeMessage(ctx context.Context, code types.RPCGoodbyeC
|
||||
return nil
|
||||
}
|
||||
|
||||
func goodbyeMessage(num types.RPCGoodbyeCode) string {
|
||||
reason, ok := types.GoodbyeCodeMessages[num]
|
||||
func goodbyeMessage(num p2ptypes.RPCGoodbyeCode) string {
|
||||
reason, ok := p2ptypes.GoodbyeCodeMessages[num]
|
||||
if ok {
|
||||
return reason
|
||||
}
|
||||
@@ -123,7 +124,7 @@ func goodbyeMessage(num types.RPCGoodbyeCode) string {
|
||||
|
||||
// determines which backoff time to use depending on the
|
||||
// goodbye code provided.
|
||||
func goodByeBackoff(num types.RPCGoodbyeCode) time.Time {
|
||||
func goodByeBackoff(num p2ptypes.RPCGoodbyeCode) time.Time {
|
||||
duration, ok := backOffTime[num]
|
||||
if !ok {
|
||||
return time.Time{}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/kevinms/leakybucket-go"
|
||||
"github.com/libp2p/go-libp2p-core/network"
|
||||
"github.com/libp2p/go-libp2p-core/protocol"
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
db "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
|
||||
p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
|
||||
@@ -156,7 +157,7 @@ func TestSendGoodbye_SendsMessage(t *testing.T) {
|
||||
wg.Add(1)
|
||||
p2.BHost.SetStreamHandler(pcl, func(stream network.Stream) {
|
||||
defer wg.Done()
|
||||
out := new(p2ptypes.SSZUint64)
|
||||
out := new(types.SSZUint64)
|
||||
assert.NoError(t, r.p2p.Encoding().DecodeWithMaxLength(stream, out))
|
||||
assert.Equal(t, failureCode, *out)
|
||||
assert.NoError(t, stream.Close())
|
||||
@@ -198,7 +199,7 @@ func TestSendGoodbye_DisconnectWithPeer(t *testing.T) {
|
||||
wg.Add(1)
|
||||
p2.BHost.SetStreamHandler(pcl, func(stream network.Stream) {
|
||||
defer wg.Done()
|
||||
out := new(p2ptypes.SSZUint64)
|
||||
out := new(types.SSZUint64)
|
||||
assert.NoError(t, r.p2p.Encoding().DecodeWithMaxLength(stream, out))
|
||||
assert.Equal(t, failureCode, *out)
|
||||
assert.NoError(t, stream.Close())
|
||||
|
||||
@@ -8,8 +8,9 @@ import (
|
||||
|
||||
libp2pcore "github.com/libp2p/go-libp2p-core"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
|
||||
p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
)
|
||||
|
||||
@@ -28,9 +29,9 @@ func (s *Service) pingHandler(_ context.Context, msg interface{}, stream libp2pc
|
||||
valid, err := s.validateSequenceNum(*m, stream.Conn().RemotePeer())
|
||||
if err != nil {
|
||||
// Descore peer for giving us a bad sequence number.
|
||||
if errors.Is(err, types.ErrInvalidSequenceNum) {
|
||||
if errors.Is(err, p2ptypes.ErrInvalidSequenceNum) {
|
||||
s.p2p.Peers().Scorers().BadResponsesScorer().Increment(stream.Conn().RemotePeer())
|
||||
s.writeErrorResponseToStream(responseCodeInvalidRequest, types.ErrInvalidSequenceNum.Error(), stream)
|
||||
s.writeErrorResponseToStream(responseCodeInvalidRequest, p2ptypes.ErrInvalidSequenceNum.Error(), stream)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -59,7 +60,7 @@ func (s *Service) pingHandler(_ context.Context, msg interface{}, stream libp2pc
|
||||
// We cannot compare errors directly as the stream muxer error
|
||||
// type isn't compatible with the error we have, so a direct
|
||||
// equality checks fails.
|
||||
if !strings.Contains(err.Error(), types.ErrIODeadline.Error()) {
|
||||
if !strings.Contains(err.Error(), p2ptypes.ErrIODeadline.Error()) {
|
||||
log.WithField("peer", stream.Conn().RemotePeer()).WithError(err).Debug("Could not send metadata request")
|
||||
}
|
||||
return
|
||||
@@ -101,7 +102,7 @@ func (s *Service) sendPingRequest(ctx context.Context, id peer.ID) error {
|
||||
valid, err := s.validateSequenceNum(*msg, stream.Conn().RemotePeer())
|
||||
if err != nil {
|
||||
// Descore peer for giving us a bad sequence number.
|
||||
if errors.Is(err, types.ErrInvalidSequenceNum) {
|
||||
if errors.Is(err, p2ptypes.ErrInvalidSequenceNum) {
|
||||
s.p2p.Peers().Scorers().BadResponsesScorer().Increment(stream.Conn().RemotePeer())
|
||||
}
|
||||
return err
|
||||
@@ -130,7 +131,7 @@ func (s *Service) validateSequenceNum(seq types.SSZUint64, id peer.ID) (bool, er
|
||||
}
|
||||
// Return error on invalid sequence number.
|
||||
if md.SeqNumber > uint64(seq) {
|
||||
return false, types.ErrInvalidSequenceNum
|
||||
return false, p2ptypes.ErrInvalidSequenceNum
|
||||
}
|
||||
return md.SeqNumber == uint64(seq), nil
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/kevinms/leakybucket-go"
|
||||
"github.com/libp2p/go-libp2p-core/network"
|
||||
"github.com/libp2p/go-libp2p-core/protocol"
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
db "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
|
||||
p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
|
||||
@@ -54,13 +55,13 @@ func TestPingRPCHandler_ReceivesPing(t *testing.T) {
|
||||
p2.BHost.SetStreamHandler(pcl, func(stream network.Stream) {
|
||||
defer wg.Done()
|
||||
expectSuccess(t, stream)
|
||||
out := new(p2ptypes.SSZUint64)
|
||||
out := new(types.SSZUint64)
|
||||
assert.NoError(t, r.p2p.Encoding().DecodeWithMaxLength(stream, out))
|
||||
assert.Equal(t, uint64(2), uint64(*out))
|
||||
})
|
||||
stream1, err := p1.BHost.NewStream(context.Background(), p2.BHost.ID(), pcl)
|
||||
require.NoError(t, err)
|
||||
seqNumber := p2ptypes.SSZUint64(2)
|
||||
seqNumber := types.SSZUint64(2)
|
||||
|
||||
assert.NoError(t, r.pingHandler(context.Background(), &seqNumber, stream1))
|
||||
|
||||
@@ -117,7 +118,7 @@ func TestPingRPCHandler_SendsPing(t *testing.T) {
|
||||
wg.Add(1)
|
||||
p2.BHost.SetStreamHandler(pcl, func(stream network.Stream) {
|
||||
defer wg.Done()
|
||||
out := new(p2ptypes.SSZUint64)
|
||||
out := new(types.SSZUint64)
|
||||
assert.NoError(t, r2.p2p.Encoding().DecodeWithMaxLength(stream, out))
|
||||
assert.Equal(t, uint64(2), uint64(*out))
|
||||
assert.NoError(t, r2.pingHandler(context.Background(), out, stream))
|
||||
@@ -180,7 +181,7 @@ func TestPingRPCHandler_BadSequenceNumber(t *testing.T) {
|
||||
stream1, err := p1.BHost.NewStream(context.Background(), p2.BHost.ID(), pcl)
|
||||
require.NoError(t, err)
|
||||
|
||||
wantedSeq := p2ptypes.SSZUint64(p2.LocalMetadata.SeqNumber)
|
||||
wantedSeq := types.SSZUint64(p2.LocalMetadata.SeqNumber)
|
||||
err = r.pingHandler(context.Background(), &wantedSeq, stream1)
|
||||
assert.ErrorContains(t, p2ptypes.ErrInvalidSequenceNum.Error(), err)
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ func (s *Service) maintainPeerStatuses() {
|
||||
// pruning excess peers.
|
||||
wg.Wait()
|
||||
peerIds := s.p2p.Peers().PeersToPrune()
|
||||
peerIds = s.filterNeededPeers(peerIds)
|
||||
for _, id := range peerIds {
|
||||
if err := s.sendGoodByeAndDisconnect(s.ctx, p2ptypes.GoodbyeCodeTooManyPeers, id); err != nil {
|
||||
log.WithField("peer", id).WithError(err).Debug("Could not disconnect with peer")
|
||||
|
||||
@@ -75,7 +75,7 @@ func TestStatusRPCHandler_Disconnects_OnForkVersionMismatch(t *testing.T) {
|
||||
wg2.Add(1)
|
||||
p2.BHost.SetStreamHandler(pcl2, func(stream network.Stream) {
|
||||
defer wg2.Done()
|
||||
msg := new(p2ptypes.SSZUint64)
|
||||
msg := new(types.SSZUint64)
|
||||
assert.NoError(t, r.p2p.Encoding().DecodeWithMaxLength(stream, msg))
|
||||
assert.Equal(t, p2ptypes.GoodbyeCodeWrongNetwork, *msg)
|
||||
assert.NoError(t, stream.Close())
|
||||
@@ -321,7 +321,7 @@ func TestHandshakeHandlers_Roundtrip(t *testing.T) {
|
||||
wg2.Add(1)
|
||||
p2.BHost.SetStreamHandler(pcl, func(stream network.Stream) {
|
||||
defer wg2.Done()
|
||||
out := new(p2ptypes.SSZUint64)
|
||||
out := new(types.SSZUint64)
|
||||
assert.NoError(t, r.p2p.Encoding().DecodeWithMaxLength(stream, out))
|
||||
assert.Equal(t, uint64(2), uint64(*out))
|
||||
assert.NoError(t, r2.pingHandler(context.Background(), out, stream))
|
||||
|
||||
@@ -53,7 +53,7 @@ type Config struct {
|
||||
P2P p2p.P2P
|
||||
DB db.NoHeadAccessDatabase
|
||||
AttPool attestations.Pool
|
||||
ExitPool *voluntaryexits.Pool
|
||||
ExitPool voluntaryexits.PoolManager
|
||||
SlashingPool slashings.PoolManager
|
||||
Chain blockchainService
|
||||
InitialSync Checker
|
||||
@@ -83,7 +83,7 @@ type Service struct {
|
||||
p2p p2p.P2P
|
||||
db db.NoHeadAccessDatabase
|
||||
attPool attestations.Pool
|
||||
exitPool *voluntaryexits.Pool
|
||||
exitPool voluntaryexits.PoolManager
|
||||
slashingPool slashings.PoolManager
|
||||
chain blockchainService
|
||||
slotToPendingBlocks *gcache.Cache
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
pb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/flags"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
||||
@@ -264,14 +265,7 @@ func (s *Service) subscribeDynamicWithSubnets(
|
||||
if s.chainStarted.IsSet() && s.initialSync.Syncing() {
|
||||
continue
|
||||
}
|
||||
|
||||
// Persistent subscriptions from validators
|
||||
persistentSubs := s.persistentSubnetIndices()
|
||||
// Update desired topic indices for aggregator
|
||||
wantedSubs := s.aggregatorSubnetIndices(currentSlot)
|
||||
|
||||
// Combine subscriptions to get all requested subscriptions
|
||||
wantedSubs = sliceutil.SetUint64(append(persistentSubs, wantedSubs...))
|
||||
wantedSubs := s.retrievePersistentSubs(currentSlot)
|
||||
// Resize as appropriate.
|
||||
s.reValidateSubscriptions(subscriptions, wantedSubs, topicFormat, digest)
|
||||
|
||||
@@ -358,6 +352,65 @@ func (s *Service) validPeersExist(subnetTopic string) bool {
|
||||
return uint64(len(numOfPeers)) >= params.BeaconNetworkConfig().MinimumPeersInSubnet
|
||||
}
|
||||
|
||||
func (s *Service) retrievePersistentSubs(currSlot types.Slot) []uint64 {
|
||||
// Persistent subscriptions from validators
|
||||
persistentSubs := s.persistentSubnetIndices()
|
||||
// Update desired topic indices for aggregator
|
||||
wantedSubs := s.aggregatorSubnetIndices(currSlot)
|
||||
|
||||
// Combine subscriptions to get all requested subscriptions
|
||||
return sliceutil.SetUint64(append(persistentSubs, wantedSubs...))
|
||||
}
|
||||
|
||||
// filters out required peers for the node to function, not
|
||||
// pruning peers who are in our attestation subnets.
|
||||
func (s *Service) filterNeededPeers(pids []peer.ID) []peer.ID {
|
||||
// Exit early if nothing to filter.
|
||||
if len(pids) == 0 {
|
||||
return pids
|
||||
}
|
||||
digest, err := s.forkDigest()
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Could not compute fork digest")
|
||||
return pids
|
||||
}
|
||||
currSlot := s.chain.CurrentSlot()
|
||||
wantedSubs := s.retrievePersistentSubs(currSlot)
|
||||
wantedSubs = sliceutil.SetUint64(append(wantedSubs, s.attesterSubnetIndices(currSlot)...))
|
||||
topic := p2p.GossipTypeMapping[reflect.TypeOf(&pb.Attestation{})]
|
||||
|
||||
// Map of peers in subnets
|
||||
peerMap := make(map[peer.ID]bool)
|
||||
|
||||
for _, sub := range wantedSubs {
|
||||
subnetTopic := fmt.Sprintf(topic, digest, sub) + s.p2p.Encoding().ProtocolSuffix()
|
||||
peers := s.p2p.PubSub().ListPeers(subnetTopic)
|
||||
if len(peers) > int(params.BeaconNetworkConfig().MinimumPeersInSubnet) {
|
||||
// In the event we have more than the minimum, we can
|
||||
// mark the remaining as viable for pruning.
|
||||
peers = peers[:params.BeaconNetworkConfig().MinimumPeersInSubnet]
|
||||
}
|
||||
// Add peer to peer map.
|
||||
for _, p := range peers {
|
||||
// Even if the peer id has
|
||||
// already been seen we still set
|
||||
// it, as the outcome is the same.
|
||||
peerMap[p] = true
|
||||
}
|
||||
}
|
||||
|
||||
// Clear out necessary peers from the peers to prune.
|
||||
newPeers := make([]peer.ID, 0, len(pids))
|
||||
|
||||
for _, pid := range pids {
|
||||
if peerMap[pid] {
|
||||
continue
|
||||
}
|
||||
newPeers = append(newPeers, pid)
|
||||
}
|
||||
return newPeers
|
||||
}
|
||||
|
||||
// Add fork digest to topic.
|
||||
func (s *Service) addDigestToTopic(topic string) string {
|
||||
if !strings.Contains(topic, "%x") {
|
||||
|
||||
@@ -13,8 +13,10 @@ import (
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
pubsubpb "github.com/libp2p/go-libp2p-pubsub/pb"
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
pb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
mockChain "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
db "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/operations/slashings"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
||||
@@ -356,3 +358,77 @@ func Test_wrapAndReportValidation(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterSubnetPeers(t *testing.T) {
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
currSlot := types.Slot(100)
|
||||
r := Service{
|
||||
ctx: ctx,
|
||||
chain: &mockChain.ChainService{
|
||||
Genesis: time.Now(),
|
||||
ValidatorsRoot: [32]byte{'A'},
|
||||
Slot: &currSlot,
|
||||
},
|
||||
p2p: p,
|
||||
chainStarted: abool.New(),
|
||||
}
|
||||
// Empty cache at the end of the test.
|
||||
defer cache.SubnetIDs.EmptyAllCaches()
|
||||
|
||||
defaultTopic := "/eth2/%x/beacon_attestation_%d" + r.p2p.Encoding().ProtocolSuffix()
|
||||
subnet10 := r.addDigestAndIndexToTopic(defaultTopic, 10)
|
||||
cache.SubnetIDs.AddAggregatorSubnetID(currSlot, 10)
|
||||
|
||||
subnet20 := r.addDigestAndIndexToTopic(defaultTopic, 20)
|
||||
cache.SubnetIDs.AddAttesterSubnetID(currSlot, 20)
|
||||
|
||||
p1 := createPeer(t, subnet10)
|
||||
p2 := createPeer(t, subnet10, subnet20)
|
||||
p3 := createPeer(t)
|
||||
|
||||
// Connect to all
|
||||
// peers.
|
||||
p.Connect(p1)
|
||||
p.Connect(p2)
|
||||
p.Connect(p3)
|
||||
|
||||
// Sleep a while to allow peers to connect.
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
wantedPeers := []peer.ID{p1.PeerID(), p2.PeerID(), p3.PeerID()}
|
||||
// Expect Peer 3 to be marked as suitable.
|
||||
recPeers := r.filterNeededPeers(wantedPeers)
|
||||
assert.DeepEqual(t, []peer.ID{p3.PeerID()}, recPeers)
|
||||
|
||||
// Try with only peers from subnet 20.
|
||||
wantedPeers = []peer.ID{p2.BHost.ID()}
|
||||
// Connect an excess amount of peers in the particular subnet.
|
||||
for i := uint64(1); i <= params.BeaconNetworkConfig().MinimumPeersInSubnet; i++ {
|
||||
nPeer := createPeer(t, subnet20)
|
||||
p.Connect(nPeer)
|
||||
wantedPeers = append(wantedPeers, nPeer.BHost.ID())
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
|
||||
recPeers = r.filterNeededPeers(wantedPeers)
|
||||
assert.DeepEqual(t, 1, len(recPeers), "expected at least 1 suitable peer to prune")
|
||||
|
||||
cancel()
|
||||
}
|
||||
|
||||
// Create peer and register them to provided topics.
|
||||
func createPeer(t *testing.T, topics ...string) *p2ptest.TestP2P {
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
for _, tp := range topics {
|
||||
jTop, err := p.PubSub().Join(tp)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = jTop.Subscribe()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
||||
p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
@@ -263,7 +262,7 @@ func validateSelectionIndex(ctx context.Context, bs *stateTrie.BeaconState, data
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sszUint := p2ptypes.SSZUint64(data.Slot)
|
||||
sszUint := types.SSZUint64(data.Slot)
|
||||
root, err := helpers.ComputeSigningRoot(&sszUint, d)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -19,7 +19,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
||||
p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
|
||||
p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
|
||||
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
|
||||
"github.com/prysmaticlabs/prysm/shared/attestationutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
@@ -334,7 +333,7 @@ func TestValidateAggregateAndProof_CanValidate(t *testing.T) {
|
||||
}
|
||||
att.Signature = bls.AggregateSignatures(sigs).Marshal()
|
||||
ai := committee[0]
|
||||
sszUint := p2ptypes.SSZUint64(att.Data.Slot)
|
||||
sszUint := types.SSZUint64(att.Data.Slot)
|
||||
sig, err := helpers.ComputeDomainAndSign(beaconState, 0, &sszUint, params.BeaconConfig().DomainSelectionProof, privKeys[ai])
|
||||
require.NoError(t, err)
|
||||
aggregateAndProof := ðpb.AggregateAttestationAndProof{
|
||||
@@ -423,7 +422,7 @@ func TestVerifyIndexInCommittee_SeenAggregatorEpoch(t *testing.T) {
|
||||
}
|
||||
att.Signature = bls.AggregateSignatures(sigs).Marshal()
|
||||
ai := committee[0]
|
||||
sszUint := p2ptypes.SSZUint64(att.Data.Slot)
|
||||
sszUint := types.SSZUint64(att.Data.Slot)
|
||||
sig, err := helpers.ComputeDomainAndSign(beaconState, 0, &sszUint, params.BeaconConfig().DomainSelectionProof, privKeys[ai])
|
||||
require.NoError(t, err)
|
||||
aggregateAndProof := ðpb.AggregateAttestationAndProof{
|
||||
@@ -531,7 +530,7 @@ func TestValidateAggregateAndProof_BadBlock(t *testing.T) {
|
||||
}
|
||||
att.Signature = bls.AggregateSignatures(sigs).Marshal()
|
||||
ai := committee[0]
|
||||
sszUint := p2ptypes.SSZUint64(att.Data.Slot)
|
||||
sszUint := types.SSZUint64(att.Data.Slot)
|
||||
sig, err := helpers.ComputeDomainAndSign(beaconState, 0, &sszUint, params.BeaconConfig().DomainSelectionProof, privKeys[ai])
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -621,7 +620,7 @@ func TestValidateAggregateAndProof_RejectWhenAttEpochDoesntEqualTargetEpoch(t *t
|
||||
}
|
||||
att.Signature = bls.AggregateSignatures(sigs).Marshal()
|
||||
ai := committee[0]
|
||||
sszUint := p2ptypes.SSZUint64(att.Data.Slot)
|
||||
sszUint := types.SSZUint64(att.Data.Slot)
|
||||
sig, err := helpers.ComputeDomainAndSign(beaconState, 0, &sszUint, params.BeaconConfig().DomainSelectionProof, privKeys[ai])
|
||||
require.NoError(t, err)
|
||||
aggregateAndProof := ðpb.AggregateAttestationAndProof{
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
"github.com/prysmaticlabs/prysm/shared/traceutil"
|
||||
"github.com/sirupsen/logrus"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
@@ -26,6 +27,7 @@ import (
|
||||
// Blocks that have already been seen are ignored. If the BLS signature is any valid signature,
|
||||
// this method rebroadcasts the message.
|
||||
func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, msg *pubsub.Message) pubsub.ValidationResult {
|
||||
receivedTime := timeutils.Now()
|
||||
// Validation runs on publish (not just subscriptions), so we should approve any message from
|
||||
// ourselves.
|
||||
if pid == s.p2p.PeerID() {
|
||||
@@ -104,7 +106,8 @@ func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, ms
|
||||
}
|
||||
|
||||
// Add metrics for block arrival time subtracts slot start time.
|
||||
if err := captureArrivalTimeMetric(uint64(s.chain.GenesisTime().Unix()), blk.Block.Slot); err != nil {
|
||||
genesisTime := uint64(s.chain.GenesisTime().Unix())
|
||||
if err := captureArrivalTimeMetric(genesisTime, blk.Block.Slot); err != nil {
|
||||
log.WithError(err).WithField("blockSlot", blk.Block.Slot).Debug("Ignored block")
|
||||
return pubsub.ValidationIgnore
|
||||
}
|
||||
@@ -140,6 +143,17 @@ func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, ms
|
||||
// Record attribute of valid block.
|
||||
span.AddAttributes(trace.Int64Attribute("slotInEpoch", int64(blk.Block.Slot%params.BeaconConfig().SlotsPerEpoch)))
|
||||
msg.ValidatorData = blk // Used in downstream subscriber
|
||||
|
||||
// Log the arrival time of the accepted block
|
||||
startTime, err := helpers.SlotToTime(genesisTime, blk.Block.Slot)
|
||||
if err != nil {
|
||||
log.WithError(err).WithField("blockSlot", blk.Block.Slot).Debug("Couldn't get slot start time")
|
||||
return pubsub.ValidationIgnore
|
||||
}
|
||||
log.WithFields(logrus.Fields{
|
||||
"blockSlot": blk.Block.Slot,
|
||||
"sinceSlotStartTime": receivedTime.Sub(startTime),
|
||||
}).Debug("Received block")
|
||||
return pubsub.ValidationAccept
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ go_test(
|
||||
"depositContract_test.go",
|
||||
"deposit_tree_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//shared/interop:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
|
||||
11
deps.bzl
11
deps.bzl
@@ -168,6 +168,7 @@ def prysm_deps():
|
||||
sum = "h1:pv34s756C4pEXnjgPfGYgdhg/ZdajGhyOvzx8k+23nw=",
|
||||
version = "v0.0.0-20170710044230-e206f873d14a",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_aws_aws_lambda_go",
|
||||
importpath = "github.com/aws/aws-lambda-go",
|
||||
@@ -1059,6 +1060,10 @@ def prysm_deps():
|
||||
importpath = "github.com/googleapis/gnostic",
|
||||
sum = "h1:rVsPeBmXbYv4If/cumu1AzZPwV58q433hvONV1UEZoI=",
|
||||
version = "v0.1.0",
|
||||
build_naming_convention = "go_default_library",
|
||||
build_directives = [
|
||||
"gazelle:resolve go github.com/googleapis/gnostic/extensions //extensions:go_default_library",
|
||||
],
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_gophercloud_gophercloud",
|
||||
@@ -2571,8 +2576,8 @@ def prysm_deps():
|
||||
go_repository(
|
||||
name = "com_github_prysmaticlabs_eth2_types",
|
||||
importpath = "github.com/prysmaticlabs/eth2-types",
|
||||
sum = "h1:6ooFkN9g9oAJq+VZWseIpj/tQqyVU0DuLFs66Ro43BQ=",
|
||||
version = "v0.0.0-20210210115503-cf4ec6600a2d",
|
||||
sum = "h1:b4WxLSz1KzkEdF/DPcog9gIKN9d9YAFgbZO1hqjNrW0=",
|
||||
version = "v0.0.0-20210219172114-1da477c09a06",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_prysmaticlabs_ethereumapis",
|
||||
@@ -2860,6 +2865,7 @@ def prysm_deps():
|
||||
sum = "h1:njlZPzLwU639dk2kqnCPPv+wNjq7Xb6EfUxe/oX0/NM=",
|
||||
version = "v0.0.0-20180906055917-c99c65617cd3",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_streadway_amqp",
|
||||
importpath = "github.com/streadway/amqp",
|
||||
@@ -3394,6 +3400,7 @@ def prysm_deps():
|
||||
importpath = "k8s.io/client-go",
|
||||
sum = "h1:QaJzz92tsN67oorwzmoB0a9r9ZVHuD5ryjbCKP0U22k=",
|
||||
version = "v0.18.3",
|
||||
build_naming_convention = "go_default_library",
|
||||
)
|
||||
go_repository(
|
||||
name = "io_k8s_gengo",
|
||||
|
||||
6
go.mod
6
go.mod
@@ -1,6 +1,6 @@
|
||||
module github.com/prysmaticlabs/prysm
|
||||
|
||||
go 1.15
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
contrib.go.opencensus.io/exporter/jaeger v0.2.1
|
||||
@@ -34,7 +34,6 @@ require (
|
||||
github.com/golang/snappy v0.0.2
|
||||
github.com/google/gofuzz v1.2.0
|
||||
github.com/google/gopacket v1.1.19 // indirect
|
||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
|
||||
github.com/google/uuid v1.2.0
|
||||
github.com/graph-gophers/graphql-go v0.0.0-20200309224638-dae41bde9ef9 // indirect
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2
|
||||
@@ -65,6 +64,7 @@ require (
|
||||
github.com/libp2p/go-libp2p-yamux v0.4.1 // indirect
|
||||
github.com/libp2p/go-netroute v0.1.4 // indirect
|
||||
github.com/libp2p/go-sockaddr v0.1.0 // indirect
|
||||
github.com/libp2p/go-tcp-transport v0.2.1
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible
|
||||
github.com/lunixbochs/vtclean v1.0.0 // indirect
|
||||
github.com/manifoldco/promptui v0.7.0
|
||||
@@ -83,7 +83,7 @@ require (
|
||||
github.com/prometheus/client_golang v1.9.0
|
||||
github.com/prometheus/procfs v0.3.0 // indirect
|
||||
github.com/prometheus/tsdb v0.10.0 // indirect
|
||||
github.com/prysmaticlabs/eth2-types v0.0.0-20210210115503-cf4ec6600a2d
|
||||
github.com/prysmaticlabs/eth2-types v0.0.0-20210219172114-1da477c09a06
|
||||
github.com/prysmaticlabs/ethereumapis v0.0.0-20210218195742-a393edb60549
|
||||
github.com/prysmaticlabs/go-bitfield v0.0.0-20210202205921-7fcea7c45dc8
|
||||
github.com/prysmaticlabs/prombbolt v0.0.0-20210126082820-9b7adba6db7c
|
||||
|
||||
7
go.sum
7
go.sum
@@ -375,8 +375,6 @@ github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hf
|
||||
github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
||||
github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
|
||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
|
||||
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
@@ -1026,8 +1024,8 @@ github.com/prometheus/tsdb v0.10.0/go.mod h1:oi49uRhEe9dPUTlS3JRZOwJuVi6tmh10QSg
|
||||
github.com/prysmaticlabs/bazel-go-ethereum v0.0.0-20210222122116-71d15f72c132 h1:UB0glz/7DDQQvx8uh6CEpZ++dYa6G6WzjQe6Ev3PI2g=
|
||||
github.com/prysmaticlabs/bazel-go-ethereum v0.0.0-20210222122116-71d15f72c132/go.mod h1:JIfVb6esrqALTExdz9hRYvrP0xBDf6wCncIu1hNwHpM=
|
||||
github.com/prysmaticlabs/eth2-types v0.0.0-20210127031309-22cbe426eba6/go.mod h1:kOmQ/zdobQf7HUohDTifDNFEZfNaSCIY5fkONPL+dWU=
|
||||
github.com/prysmaticlabs/eth2-types v0.0.0-20210210115503-cf4ec6600a2d h1:6ooFkN9g9oAJq+VZWseIpj/tQqyVU0DuLFs66Ro43BQ=
|
||||
github.com/prysmaticlabs/eth2-types v0.0.0-20210210115503-cf4ec6600a2d/go.mod h1:kOmQ/zdobQf7HUohDTifDNFEZfNaSCIY5fkONPL+dWU=
|
||||
github.com/prysmaticlabs/eth2-types v0.0.0-20210219172114-1da477c09a06 h1:b4WxLSz1KzkEdF/DPcog9gIKN9d9YAFgbZO1hqjNrW0=
|
||||
github.com/prysmaticlabs/eth2-types v0.0.0-20210219172114-1da477c09a06/go.mod h1:kOmQ/zdobQf7HUohDTifDNFEZfNaSCIY5fkONPL+dWU=
|
||||
github.com/prysmaticlabs/ethereumapis v0.0.0-20210218195742-a393edb60549 h1:GhzZ3sO2ZiuJxxm3dyBps+tDaVu3q7xMdJD2yJXyuDs=
|
||||
github.com/prysmaticlabs/ethereumapis v0.0.0-20210218195742-a393edb60549/go.mod h1:YS3iOCGE+iVDE007GHWtj+UoPK9hyYA7Fo4mSDNTtiY=
|
||||
github.com/prysmaticlabs/go-bitfield v0.0.0-20200322041314-62c2aee71669/go.mod h1:hCwmef+4qXWjv0jLDbQdWnL0Ol7cS7/lCSS26WR+u6s=
|
||||
@@ -1659,7 +1657,6 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
|
||||
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
|
||||
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
|
||||
@@ -93,3 +93,88 @@ func V1Alpha1AttSlashingToV1(v1alpha1Slashing *ethpb_alpha.AttesterSlashing) *et
|
||||
Attestation_2: V1Alpha1IndexedAttToV1(v1alpha1Slashing.Attestation_2),
|
||||
}
|
||||
}
|
||||
|
||||
// V1Alpha1SignedHeaderToV1 converts a v1alpha1 signed beacon block header to v1.
|
||||
func V1Alpha1SignedHeaderToV1(v1alpha1Hdr *ethpb_alpha.SignedBeaconBlockHeader) *ethpb.SignedBeaconBlockHeader {
|
||||
if v1alpha1Hdr == nil || v1alpha1Hdr.Header == nil {
|
||||
return ðpb.SignedBeaconBlockHeader{}
|
||||
}
|
||||
return ðpb.SignedBeaconBlockHeader{
|
||||
Header: ðpb.BeaconBlockHeader{
|
||||
Slot: v1alpha1Hdr.Header.Slot,
|
||||
ProposerIndex: v1alpha1Hdr.Header.ProposerIndex,
|
||||
ParentRoot: v1alpha1Hdr.Header.ParentRoot,
|
||||
StateRoot: v1alpha1Hdr.Header.StateRoot,
|
||||
BodyRoot: v1alpha1Hdr.Header.BodyRoot,
|
||||
},
|
||||
Signature: v1alpha1Hdr.Signature,
|
||||
}
|
||||
}
|
||||
|
||||
// V1Alpha1ProposerSlashingToV1 converts a v1alpha1 proposer slashing to v1.
|
||||
func V1Alpha1ProposerSlashingToV1(v1alpha1Slashing *ethpb_alpha.ProposerSlashing) *ethpb.ProposerSlashing {
|
||||
if v1alpha1Slashing == nil {
|
||||
return ðpb.ProposerSlashing{}
|
||||
}
|
||||
return ðpb.ProposerSlashing{
|
||||
Header_1: V1Alpha1SignedHeaderToV1(v1alpha1Slashing.Header_1),
|
||||
Header_2: V1Alpha1SignedHeaderToV1(v1alpha1Slashing.Header_2),
|
||||
}
|
||||
}
|
||||
|
||||
// V1Alpha1ExitToV1 converts a v1alpha1 SignedVoluntaryExit to v1.
|
||||
func V1Alpha1ExitToV1(v1alpha1Exit *ethpb_alpha.SignedVoluntaryExit) *ethpb.SignedVoluntaryExit {
|
||||
if v1alpha1Exit == nil || v1alpha1Exit.Exit == nil {
|
||||
return ðpb.SignedVoluntaryExit{}
|
||||
}
|
||||
return ðpb.SignedVoluntaryExit{
|
||||
Exit: ðpb.VoluntaryExit{
|
||||
Epoch: v1alpha1Exit.Exit.Epoch,
|
||||
ValidatorIndex: v1alpha1Exit.Exit.ValidatorIndex,
|
||||
},
|
||||
Signature: v1alpha1Exit.Signature,
|
||||
}
|
||||
}
|
||||
|
||||
// V1IndexedAttToV1Alpha1 converts a v1 indexed attestation to v1alpha1.
|
||||
func V1IndexedAttToV1Alpha1(v1Att *ethpb.IndexedAttestation) *ethpb_alpha.IndexedAttestation {
|
||||
if v1Att == nil {
|
||||
return ðpb_alpha.IndexedAttestation{}
|
||||
}
|
||||
return ðpb_alpha.IndexedAttestation{
|
||||
AttestingIndices: v1Att.AttestingIndices,
|
||||
Data: V1AttDataToV1Alpha1(v1Att.Data),
|
||||
Signature: v1Att.Signature,
|
||||
}
|
||||
}
|
||||
|
||||
// V1AttDataToV1Alpha1 converts a v1 attestation data to v1alpha1.
|
||||
func V1AttDataToV1Alpha1(v1AttData *ethpb.AttestationData) *ethpb_alpha.AttestationData {
|
||||
if v1AttData == nil || v1AttData.Source == nil || v1AttData.Target == nil {
|
||||
return ðpb_alpha.AttestationData{}
|
||||
}
|
||||
return ðpb_alpha.AttestationData{
|
||||
Slot: v1AttData.Slot,
|
||||
CommitteeIndex: v1AttData.CommitteeIndex,
|
||||
BeaconBlockRoot: v1AttData.BeaconBlockRoot,
|
||||
Source: ðpb_alpha.Checkpoint{
|
||||
Root: v1AttData.Source.Root,
|
||||
Epoch: v1AttData.Source.Epoch,
|
||||
},
|
||||
Target: ðpb_alpha.Checkpoint{
|
||||
Root: v1AttData.Target.Root,
|
||||
Epoch: v1AttData.Target.Epoch,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// V1AttSlashingToV1Alpha1 converts a v1 attester slashing to v1alpha1.
|
||||
func V1AttSlashingToV1Alpha1(v1Slashing *ethpb.AttesterSlashing) *ethpb_alpha.AttesterSlashing {
|
||||
if v1Slashing == nil {
|
||||
return ðpb_alpha.AttesterSlashing{}
|
||||
}
|
||||
return ðpb_alpha.AttesterSlashing{
|
||||
Attestation_1: V1IndexedAttToV1Alpha1(v1Slashing.Attestation_1),
|
||||
Attestation_2: V1IndexedAttToV1Alpha1(v1Slashing.Attestation_2),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ go_library(
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["attestation_utils_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
|
||||
@@ -6,7 +6,6 @@ go_library(
|
||||
srcs = ["browser.go"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/shared/browser",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@com_github_google_shlex//:go_default_library"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
|
||||
@@ -8,8 +8,6 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/google/shlex"
|
||||
)
|
||||
|
||||
// ForOS produces an exec.Cmd to open the web browser for different OS
|
||||
@@ -32,16 +30,3 @@ func ForOS(goos, url string) *exec.Cmd {
|
||||
cmd.Stderr = os.Stderr
|
||||
return cmd
|
||||
}
|
||||
|
||||
// FromLauncher parses the launcher string based on shell splitting rules
|
||||
func FromLauncher(launcher, url string) (*exec.Cmd, error) {
|
||||
args, err := shlex.Split(launcher)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
args = append(args, url)
|
||||
cmd := exec.Command(args[0], args[1:]...)
|
||||
cmd.Stderr = os.Stderr
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ go_test(
|
||||
name = "go_default_test",
|
||||
size = "small",
|
||||
srcs = ["bytes_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
|
||||
|
||||
@@ -326,11 +326,6 @@ func BytesToEpochBigEndian(b []byte) types.Epoch {
|
||||
return types.Epoch(BytesToUint64BigEndian(b))
|
||||
}
|
||||
|
||||
// SlotToBytesLittleEndian conversion.
|
||||
func SlotToBytesLittleEndian(i types.Slot) []byte {
|
||||
return Uint64ToBytesLittleEndian(uint64(i))
|
||||
}
|
||||
|
||||
// SlotToBytesBigEndian conversion.
|
||||
func SlotToBytesBigEndian(i types.Slot) []byte {
|
||||
return Uint64ToBytesBigEndian(uint64(i))
|
||||
|
||||
@@ -22,8 +22,8 @@ go_library(
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["deposit_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//shared/bls:go_default_library",
|
||||
|
||||
@@ -16,8 +16,8 @@ go_library(
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["fileutil_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
|
||||
@@ -131,6 +131,37 @@ func FileExists(filename string) bool {
|
||||
return info != nil && !info.IsDir()
|
||||
}
|
||||
|
||||
// RecursiveFileFind returns true, and the path, if a file is not a directory and exists
|
||||
// at dir or any of its subdirectories. Finds the first instant based on the Walk order and returns.
|
||||
// Define non-fatal error to stop the recursive directory walk
|
||||
var stopWalk = errors.New("stop walking")
|
||||
|
||||
func RecursiveFileFind(filename, dir string) (bool, string, error) {
|
||||
var found bool
|
||||
var fpath string
|
||||
dir = filepath.Clean(dir)
|
||||
found = false
|
||||
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// checks if its a file and has the exact name as the filename
|
||||
// need to break the walk function by using a non-fatal error
|
||||
if !info.IsDir() && filename == info.Name() {
|
||||
found = true
|
||||
fpath = path
|
||||
return stopWalk
|
||||
}
|
||||
|
||||
// no errors or file found
|
||||
return nil
|
||||
})
|
||||
if err != nil && err != stopWalk {
|
||||
return false, "", err
|
||||
}
|
||||
return found, fpath, nil
|
||||
}
|
||||
|
||||
// ReadFileAsBytes expands a file name's absolute path and reads it as bytes from disk.
|
||||
func ReadFileAsBytes(filename string) ([]byte, error) {
|
||||
filePath, err := ExpandPath(filename)
|
||||
|
||||
@@ -240,6 +240,56 @@ func TestDirFiles(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecursiveFileFind(t *testing.T) {
|
||||
tmpDir, _ := tmpDirWithContentsForRecursiveFind(t)
|
||||
tests := []struct {
|
||||
name string
|
||||
root string
|
||||
path string
|
||||
found bool
|
||||
}{
|
||||
{
|
||||
name: "file1",
|
||||
root: tmpDir,
|
||||
path: "subfolder1/subfolder11/file1",
|
||||
found: true,
|
||||
},
|
||||
{
|
||||
name: "file2",
|
||||
root: tmpDir,
|
||||
path: "subfolder2/file2",
|
||||
found: true,
|
||||
},
|
||||
{
|
||||
name: "file1",
|
||||
root: tmpDir + "/subfolder1",
|
||||
path: "subfolder11/file1",
|
||||
found: true,
|
||||
},
|
||||
{
|
||||
name: "file3",
|
||||
root: tmpDir,
|
||||
path: "file3",
|
||||
found: true,
|
||||
},
|
||||
{
|
||||
name: "file4",
|
||||
root: tmpDir,
|
||||
path: "",
|
||||
found: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
found, _, err := fileutil.RecursiveFileFind(tt.name, tt.root)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.DeepEqual(t, tt.found, found)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func deepCompare(t *testing.T, file1, file2 string) bool {
|
||||
sf, err := os.Open(file1)
|
||||
assert.NoError(t, err)
|
||||
@@ -281,6 +331,24 @@ func tmpDirWithContents(t *testing.T) (string, []string) {
|
||||
return dir, fnames
|
||||
}
|
||||
|
||||
// tmpDirWithContentsForRecursiveFind returns path to temporary directory having some folders/files in it.
|
||||
// Directory is automatically removed by internal testing cleanup methods.
|
||||
func tmpDirWithContentsForRecursiveFind(t *testing.T) (string, []string) {
|
||||
dir := t.TempDir()
|
||||
fnames := []string{
|
||||
"subfolder1/subfolder11/file1",
|
||||
"subfolder2/file2",
|
||||
"file3",
|
||||
}
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(dir, "subfolder1", "subfolder11"), 0777))
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(dir, "subfolder2"), 0777))
|
||||
for _, fname := range fnames {
|
||||
require.NoError(t, ioutil.WriteFile(filepath.Join(dir, fname), []byte(fname), 0777))
|
||||
}
|
||||
sort.Strings(fnames)
|
||||
return dir, fnames
|
||||
}
|
||||
|
||||
func TestHasReadWritePermissions(t *testing.T) {
|
||||
type args struct {
|
||||
itemPath string
|
||||
|
||||
@@ -26,8 +26,8 @@ go_test(
|
||||
"hash_test.go",
|
||||
"merkleRoot_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//proto/testing:go_default_library",
|
||||
"//shared/bls:go_default_library",
|
||||
"//shared/bytesutil:go_default_library",
|
||||
|
||||
@@ -33,8 +33,8 @@ go_test(
|
||||
"htrutils_test.go",
|
||||
"merkleize_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//shared/hashutil:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
|
||||
@@ -33,8 +33,8 @@ go_test(
|
||||
data = [
|
||||
"keygen_test_vector.yaml",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//beacon-chain/core/state:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
|
||||
@@ -12,9 +12,9 @@ go_test(
|
||||
name = "go_default_test",
|
||||
size = "small",
|
||||
srcs = ["external_ip_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
tags = ["requires-network"],
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
],
|
||||
|
||||
@@ -33,14 +33,6 @@ import (
|
||||
const (
|
||||
keyHeaderKDF = "scrypt"
|
||||
|
||||
// StandardScryptN is the N parameter of Scrypt encryption algorithm, using 256MB
|
||||
// memory and taking approximately 1s CPU time on a modern processor.
|
||||
StandardScryptN = 1 << 18
|
||||
|
||||
// StandardScryptP is the P parameter of Scrypt encryption algorithm, using 256MB
|
||||
// memory and taking approximately 1s CPU time on a modern processor.
|
||||
StandardScryptP = 1
|
||||
|
||||
// LightScryptN is the N parameter of Scrypt encryption algorithm, using 4MB
|
||||
// memory and taking approximately 100ms CPU time on a modern processor.
|
||||
LightScryptN = 1 << 12
|
||||
|
||||
@@ -12,8 +12,6 @@ go_test(
|
||||
name = "go_default_test",
|
||||
size = "small",
|
||||
srcs = ["math_helper_test.go"],
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = ["//shared/testutil/require:go_default_library"],
|
||||
)
|
||||
|
||||
@@ -17,8 +17,8 @@ go_test(
|
||||
name = "go_default_test",
|
||||
size = "small",
|
||||
srcs = ["messagehandler_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
|
||||
@@ -15,8 +15,8 @@ go_library(
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["pagination_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
],
|
||||
|
||||
@@ -12,5 +12,5 @@ go_library(
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["every_test.go"],
|
||||
deps = [":go_default_library"],
|
||||
embed = [":go_default_library"],
|
||||
)
|
||||
|
||||
@@ -16,8 +16,6 @@ go_test(
|
||||
name = "go_default_test",
|
||||
size = "small",
|
||||
srcs = ["slice_test.go"],
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = ["@com_github_prysmaticlabs_eth2_types//:go_default_library"],
|
||||
)
|
||||
|
||||
@@ -16,8 +16,8 @@ go_test(
|
||||
name = "go_default_test",
|
||||
size = "small",
|
||||
srcs = ["deep_equal_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
|
||||
@@ -18,7 +18,6 @@ go_library(
|
||||
deps = [
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
"//beacon-chain/core/state:go_default_library",
|
||||
"//beacon-chain/p2p/types:go_default_library",
|
||||
"//beacon-chain/state:go_default_library",
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//shared/bls:go_default_library",
|
||||
@@ -56,7 +55,6 @@ go_test(
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
"//beacon-chain/core/state:go_default_library",
|
||||
"//beacon-chain/core/state/stateutils:go_default_library",
|
||||
"//beacon-chain/p2p/types:go_default_library",
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//shared/bytesutil:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
|
||||
@@ -17,8 +17,8 @@ go_library(
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["assertions_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
||||
p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
@@ -28,7 +27,7 @@ func RandaoReveal(beaconState *stateTrie.BeaconState, epoch types.Epoch, privKey
|
||||
binary.LittleEndian.PutUint64(buf, uint64(epoch))
|
||||
|
||||
// We make the previous validator's index sign the message instead of the proposer.
|
||||
sszEpoch := p2ptypes.SSZUint64(epoch)
|
||||
sszEpoch := types.SSZUint64(epoch)
|
||||
return helpers.ComputeDomainAndSign(beaconState, epoch, &sszEpoch, params.BeaconConfig().DomainRandao, privKeys[proposerIdx])
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"encoding/binary"
|
||||
"testing"
|
||||
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
@@ -46,7 +46,7 @@ func TestRandaoReveal(t *testing.T) {
|
||||
buf := make([]byte, 32)
|
||||
binary.LittleEndian.PutUint64(buf, uint64(epoch))
|
||||
// We make the previous validator's index sign the message instead of the proposer.
|
||||
sszUint := p2ptypes.SSZUint64(epoch)
|
||||
sszUint := types.SSZUint64(epoch)
|
||||
epochSignature, err := helpers.ComputeDomainAndSign(beaconState, epoch, &sszUint, params.BeaconConfig().DomainRandao, privKeys[proposerIdx])
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ go_test(
|
||||
"epoch_store_test.go",
|
||||
"types_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"//slasher/db/testing:go_default_library",
|
||||
|
||||
@@ -37,6 +37,7 @@ go_library(
|
||||
"//shared/petnames:go_default_library",
|
||||
"//shared/promptutil:go_default_library",
|
||||
"//shared/tos:go_default_library",
|
||||
"//validator/accounts/iface:go_default_library",
|
||||
"//validator/accounts/prompt:go_default_library",
|
||||
"//validator/accounts/wallet:go_default_library",
|
||||
"//validator/client:go_default_library",
|
||||
@@ -86,6 +87,7 @@ go_test(
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//validator/accounts/iface:go_default_library",
|
||||
"//validator/accounts/wallet:go_default_library",
|
||||
"//validator/flags:go_default_library",
|
||||
"//validator/keymanager:go_default_library",
|
||||
@@ -96,6 +98,7 @@ go_test(
|
||||
"@com_github_golang_mock//gomock:go_default_library",
|
||||
"@com_github_google_uuid//:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/fileutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/petnames"
|
||||
"github.com/prysmaticlabs/prysm/shared/promptutil"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/iface"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/prompt"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
||||
"github.com/prysmaticlabs/prysm/validator/flags"
|
||||
@@ -51,7 +52,7 @@ func BackupAccountsCli(cliCtx *cli.Context) error {
|
||||
"remote wallets cannot backup accounts",
|
||||
)
|
||||
}
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context)
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context, iface.InitKeymanagerConfig{ListenForChanges: false})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, ErrCouldNotInitializeKeymanager)
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/iface"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
||||
"github.com/prysmaticlabs/prysm/validator/keymanager"
|
||||
"github.com/prysmaticlabs/prysm/validator/keymanager/derived"
|
||||
@@ -63,7 +64,7 @@ func TestBackupAccounts_Noninteractive_Derived(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context)
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context, iface.InitKeymanagerConfig{ListenForChanges: false})
|
||||
require.NoError(t, err)
|
||||
// Create 2 accounts
|
||||
derivedKM, ok := km.(*derived.Keymanager)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/promptutil"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/iface"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/prompt"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
||||
"github.com/prysmaticlabs/prysm/validator/flags"
|
||||
@@ -27,7 +28,7 @@ func DeleteAccountCli(cliCtx *cli.Context) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not open wallet")
|
||||
}
|
||||
kManager, err := w.InitializeKeymanager(cliCtx.Context)
|
||||
kManager, err := w.InitializeKeymanager(cliCtx.Context, iface.InitKeymanagerConfig{ListenForChanges: false})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, ErrCouldNotInitializeKeymanager)
|
||||
}
|
||||
|
||||
@@ -63,7 +63,8 @@ func TestDeleteAccounts_Noninteractive(t *testing.T) {
|
||||
keymanager, err := imported.NewKeymanager(
|
||||
cliCtx.Context,
|
||||
&imported.SetupConfig{
|
||||
Wallet: w,
|
||||
Wallet: w,
|
||||
ListenForChanges: false,
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/promptutil"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/iface"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/prompt"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
||||
"github.com/prysmaticlabs/prysm/validator/flags"
|
||||
@@ -23,7 +24,7 @@ func DisableAccountsCli(cliCtx *cli.Context) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not open wallet")
|
||||
}
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context)
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context, iface.InitKeymanagerConfig{ListenForChanges: false})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, ErrCouldNotInitializeKeymanager)
|
||||
}
|
||||
@@ -100,7 +101,7 @@ func EnableAccountsCli(cliCtx *cli.Context) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not open wallet")
|
||||
}
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context)
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context, iface.InitKeymanagerConfig{ListenForChanges: false})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, ErrCouldNotInitializeKeymanager)
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/iface"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
||||
"github.com/prysmaticlabs/prysm/validator/keymanager"
|
||||
)
|
||||
@@ -63,7 +64,7 @@ func TestDisableAccounts_Noninteractive(t *testing.T) {
|
||||
// We attempt to disable the accounts specified.
|
||||
require.NoError(t, DisableAccountsCli(cliCtx))
|
||||
|
||||
keymanager, err := w.InitializeKeymanager(cliCtx.Context)
|
||||
keymanager, err := w.InitializeKeymanager(cliCtx.Context, iface.InitKeymanagerConfig{ListenForChanges: false})
|
||||
require.NoError(t, err)
|
||||
remainingAccounts, err := keymanager.FetchValidatingPublicKeys(cliCtx.Context)
|
||||
require.NoError(t, err)
|
||||
@@ -119,7 +120,7 @@ func TestEnableAccounts_Noninteractive(t *testing.T) {
|
||||
// We attempt to disable the accounts specified.
|
||||
require.NoError(t, DisableAccountsCli(cliCtx))
|
||||
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context)
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context, iface.InitKeymanagerConfig{ListenForChanges: false})
|
||||
require.NoError(t, err)
|
||||
remainingAccounts, err := km.FetchValidatingPublicKeys(cliCtx.Context)
|
||||
require.NoError(t, err)
|
||||
@@ -128,7 +129,7 @@ func TestEnableAccounts_Noninteractive(t *testing.T) {
|
||||
// We attempt to enable the accounts specified.
|
||||
require.NoError(t, EnableAccountsCli(cliCtx))
|
||||
|
||||
km, err = w.InitializeKeymanager(cliCtx.Context)
|
||||
km, err = w.InitializeKeymanager(cliCtx.Context, iface.InitKeymanagerConfig{ListenForChanges: false})
|
||||
require.NoError(t, err)
|
||||
remainingAccounts, err = km.FetchValidatingPublicKeys(cliCtx.Context)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/grpcutils"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/promptutil"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/iface"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/prompt"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
||||
"github.com/prysmaticlabs/prysm/validator/client"
|
||||
@@ -79,7 +80,7 @@ func prepareWallet(cliCtx *cli.Context) (validatingPublicKeys [][48]byte, km key
|
||||
return nil, nil, errors.Wrap(err, "could not open wallet")
|
||||
}
|
||||
|
||||
km, err = w.InitializeKeymanager(cliCtx.Context)
|
||||
km, err = w.InitializeKeymanager(cliCtx.Context, iface.InitKeymanagerConfig{ListenForChanges: false})
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, ErrCouldNotInitializeKeymanager)
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/fileutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/promptutil"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/iface"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/prompt"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
||||
"github.com/prysmaticlabs/prysm/validator/flags"
|
||||
@@ -99,7 +100,7 @@ func ImportAccountsCli(cliCtx *cli.Context) error {
|
||||
return errors.Wrap(err, "could not initialize wallet")
|
||||
}
|
||||
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context)
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context, iface.InitKeymanagerConfig{ListenForChanges: false})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/iface"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
||||
"github.com/prysmaticlabs/prysm/validator/keymanager"
|
||||
"github.com/prysmaticlabs/prysm/validator/keymanager/imported"
|
||||
@@ -50,7 +51,8 @@ func TestImport_Noninteractive(t *testing.T) {
|
||||
keymanager, err := imported.NewKeymanager(
|
||||
cliCtx.Context,
|
||||
&imported.SetupConfig{
|
||||
Wallet: w,
|
||||
Wallet: w,
|
||||
ListenForChanges: false,
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
@@ -72,7 +74,7 @@ func TestImport_Noninteractive(t *testing.T) {
|
||||
WalletPassword: password,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context)
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context, iface.InitKeymanagerConfig{ListenForChanges: false})
|
||||
require.NoError(t, err)
|
||||
keys, err := km.FetchValidatingPublicKeys(cliCtx.Context)
|
||||
require.NoError(t, err)
|
||||
@@ -120,7 +122,7 @@ func TestImport_DuplicateKeys(t *testing.T) {
|
||||
WalletPassword: password,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context)
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context, iface.InitKeymanagerConfig{ListenForChanges: false})
|
||||
require.NoError(t, err)
|
||||
keys, err := km.FetchValidatingPublicKeys(cliCtx.Context)
|
||||
require.NoError(t, err)
|
||||
@@ -181,7 +183,8 @@ func TestImport_Noninteractive_RandomName(t *testing.T) {
|
||||
keymanager, err := imported.NewKeymanager(
|
||||
cliCtx.Context,
|
||||
&imported.SetupConfig{
|
||||
Wallet: w,
|
||||
Wallet: w,
|
||||
ListenForChanges: false,
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
@@ -203,7 +206,7 @@ func TestImport_Noninteractive_RandomName(t *testing.T) {
|
||||
WalletPassword: password,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context)
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context, iface.InitKeymanagerConfig{ListenForChanges: false})
|
||||
require.NoError(t, err)
|
||||
keys, err := km.FetchValidatingPublicKeys(cliCtx.Context)
|
||||
require.NoError(t, err)
|
||||
@@ -237,7 +240,8 @@ func TestImport_Noninteractive_Filepath(t *testing.T) {
|
||||
keymanager, err := imported.NewKeymanager(
|
||||
cliCtx.Context,
|
||||
&imported.SetupConfig{
|
||||
Wallet: w,
|
||||
Wallet: w,
|
||||
ListenForChanges: false,
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
@@ -254,7 +258,7 @@ func TestImport_Noninteractive_Filepath(t *testing.T) {
|
||||
WalletPassword: password,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context)
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context, iface.InitKeymanagerConfig{ListenForChanges: false})
|
||||
require.NoError(t, err)
|
||||
keys, err := km.FetchValidatingPublicKeys(cliCtx.Context)
|
||||
require.NoError(t, err)
|
||||
@@ -358,7 +362,8 @@ func Test_importPrivateKeyAsAccount(t *testing.T) {
|
||||
keymanager, err := imported.NewKeymanager(
|
||||
cliCtx.Context,
|
||||
&imported.SetupConfig{
|
||||
Wallet: wallet,
|
||||
Wallet: wallet,
|
||||
ListenForChanges: false,
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
@@ -368,7 +373,8 @@ func Test_importPrivateKeyAsAccount(t *testing.T) {
|
||||
keymanager, err = imported.NewKeymanager(
|
||||
cliCtx.Context,
|
||||
&imported.SetupConfig{
|
||||
Wallet: wallet,
|
||||
Wallet: wallet,
|
||||
ListenForChanges: false,
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -3,6 +3,8 @@ package accounts
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"math"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -10,6 +12,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/petnames"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/iface"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
||||
"github.com/prysmaticlabs/prysm/validator/flags"
|
||||
"github.com/prysmaticlabs/prysm/validator/keymanager"
|
||||
@@ -27,7 +30,7 @@ func ListAccountsCli(cliCtx *cli.Context) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not open wallet")
|
||||
}
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context)
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context, iface.InitKeymanagerConfig{ListenForChanges: false})
|
||||
if err != nil && strings.Contains(err.Error(), "invalid checksum") {
|
||||
return errors.New("wrong wallet password entered")
|
||||
}
|
||||
@@ -36,6 +39,16 @@ func ListAccountsCli(cliCtx *cli.Context) error {
|
||||
}
|
||||
showDepositData := cliCtx.Bool(flags.ShowDepositDataFlag.Name)
|
||||
showPrivateKeys := cliCtx.Bool(flags.ShowPrivateKeysFlag.Name)
|
||||
listIndices := cliCtx.Bool(flags.ListValidatorIndices.Name)
|
||||
|
||||
if listIndices {
|
||||
client, _, err := prepareClients(cliCtx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return listValidatorIndices(cliCtx.Context, km, *client)
|
||||
}
|
||||
|
||||
switch w.KeymanagerKind() {
|
||||
case keymanager.Imported:
|
||||
km, ok := km.(*imported.Keymanager)
|
||||
@@ -220,3 +233,26 @@ func listRemoteKeymanagerAccounts(
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func listValidatorIndices(ctx context.Context, km keymanager.IKeymanager, client ethpb.BeaconNodeValidatorClient) error {
|
||||
pubKeys, err := km.FetchValidatingPublicKeys(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not get validating public keys")
|
||||
}
|
||||
var pks [][]byte
|
||||
for i := range pubKeys {
|
||||
pks = append(pks, pubKeys[i][:])
|
||||
}
|
||||
req := ðpb.MultipleValidatorStatusRequest{PublicKeys: pks}
|
||||
resp, err := client.MultipleValidatorStatus(ctx, req)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not request validator indices")
|
||||
}
|
||||
fmt.Println(au.BrightGreen("Validator indices:").Bold())
|
||||
for i, idx := range resp.Indices {
|
||||
if idx != math.MaxUint64 {
|
||||
fmt.Printf("%#x: %d\n", pubKeys[i][0:4], idx)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -3,7 +3,12 @@ package accounts
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/golang/mock/gomock"
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/shared/mock"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -83,7 +88,8 @@ func TestListAccounts_ImportedKeymanager(t *testing.T) {
|
||||
km, err := imported.NewKeymanager(
|
||||
cliCtx.Context,
|
||||
&imported.SetupConfig{
|
||||
Wallet: w,
|
||||
Wallet: w,
|
||||
ListenForChanges: false,
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
@@ -236,7 +242,8 @@ func TestListAccounts_DerivedKeymanager(t *testing.T) {
|
||||
keymanager, err := derived.NewKeymanager(
|
||||
cliCtx.Context,
|
||||
&derived.SetupConfig{
|
||||
Wallet: w,
|
||||
Wallet: w,
|
||||
ListenForChanges: false,
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
@@ -470,3 +477,55 @@ func TestListAccounts_RemoteKeymanager(t *testing.T) {
|
||||
assert.Equal(t, true, keyFound, "Public Key %s not found on line number %d", keyString, lineNumber)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListAccounts_ListValidatorIndices(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
numAccounts := 3
|
||||
pubKeys := make([][48]byte, numAccounts)
|
||||
pks := make([][]byte, numAccounts)
|
||||
|
||||
for i := 0; i < numAccounts; i++ {
|
||||
key := make([]byte, 48)
|
||||
copy(key, strconv.Itoa(i))
|
||||
pubKeys[i] = bytesutil.ToBytes48(key)
|
||||
pks[i] = key
|
||||
}
|
||||
|
||||
km := &mockRemoteKeymanager{
|
||||
publicKeys: pubKeys,
|
||||
}
|
||||
|
||||
rescueStdout := os.Stdout
|
||||
r, writer, err := os.Pipe()
|
||||
require.NoError(t, err)
|
||||
os.Stdout = writer
|
||||
|
||||
m := mock.NewMockBeaconNodeValidatorClient(ctrl)
|
||||
|
||||
req := ðpb.MultipleValidatorStatusRequest{PublicKeys: pks}
|
||||
resp := ðpb.MultipleValidatorStatusResponse{Indices: []types.ValidatorIndex{1, math.MaxUint64, 2}}
|
||||
|
||||
m.
|
||||
EXPECT().
|
||||
MultipleValidatorStatus(gomock.Eq(context.Background()), gomock.Eq(req)).
|
||||
Return(resp, nil)
|
||||
|
||||
require.NoError(
|
||||
t,
|
||||
listValidatorIndices(
|
||||
context.Background(),
|
||||
km,
|
||||
m,
|
||||
),
|
||||
)
|
||||
|
||||
require.NoError(t, writer.Close())
|
||||
out, err := ioutil.ReadAll(r)
|
||||
require.NoError(t, err)
|
||||
os.Stdout = rescueStdout
|
||||
|
||||
expectedStdout := au.BrightGreen("Validator indices:").Bold().String() + "\n0x30000000: 1\n0x32000000: 2\n"
|
||||
require.Equal(t, expectedStdout, string(out))
|
||||
}
|
||||
|
||||
@@ -50,6 +50,13 @@ var AccountCommands = &cli.Command{
|
||||
flags.WalletPasswordFileFlag,
|
||||
flags.ShowDepositDataFlag,
|
||||
flags.ShowPrivateKeysFlag,
|
||||
flags.ListValidatorIndices,
|
||||
flags.BeaconRPCProviderFlag,
|
||||
cmd.GrpcMaxCallRecvMsgSizeFlag,
|
||||
flags.CertFlag,
|
||||
flags.GrpcHeadersFlag,
|
||||
flags.GrpcRetriesFlag,
|
||||
flags.GrpcRetryDelayFlag,
|
||||
featureconfig.Mainnet,
|
||||
featureconfig.PyrmontTestnet,
|
||||
featureconfig.ToledoTestnet,
|
||||
|
||||
@@ -6,6 +6,11 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/validator/keymanager"
|
||||
)
|
||||
|
||||
// InitKeymanagerConfig defines configuration options for initializing a keymanager.
|
||||
type InitKeymanagerConfig struct {
|
||||
ListenForChanges bool
|
||||
}
|
||||
|
||||
// Wallet defines a struct which has capabilities and knowledge of how
|
||||
// to read and write important accounts-related files to the filesystem.
|
||||
// Useful for keymanagers to have persistent capabilities for accounts on-disk.
|
||||
@@ -18,5 +23,5 @@ type Wallet interface {
|
||||
// Write methods to persist important wallet and accounts-related files to disk.
|
||||
WriteFileAtPath(ctx context.Context, pathName string, fileName string, data []byte) error
|
||||
// Method for initializing a new keymanager.
|
||||
InitializeKeymanager(ctx context.Context) (keymanager.IKeymanager, error)
|
||||
InitializeKeymanager(ctx context.Context, cfg InitKeymanagerConfig) (keymanager.IKeymanager, error)
|
||||
}
|
||||
|
||||
@@ -9,5 +9,8 @@ go_library(
|
||||
"//validator:__pkg__",
|
||||
"//validator:__subpackages__",
|
||||
],
|
||||
deps = ["//validator/keymanager:go_default_library"],
|
||||
deps = [
|
||||
"//validator/accounts/iface:go_default_library",
|
||||
"//validator/keymanager:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/iface"
|
||||
"github.com/prysmaticlabs/prysm/validator/keymanager"
|
||||
)
|
||||
|
||||
@@ -71,6 +72,6 @@ func (w *Wallet) ReadFileAtPath(_ context.Context, pathName, fileName string) ([
|
||||
}
|
||||
|
||||
// InitializeKeymanager --
|
||||
func (w *Wallet) InitializeKeymanager(_ context.Context) (keymanager.IKeymanager, error) {
|
||||
func (w *Wallet) InitializeKeymanager(_ context.Context, _ iface.InitKeymanagerConfig) (keymanager.IKeymanager, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ go_library(
|
||||
deps = [
|
||||
"//shared/fileutil:go_default_library",
|
||||
"//shared/promptutil:go_default_library",
|
||||
"//validator/accounts/iface:go_default_library",
|
||||
"//validator/accounts/prompt:go_default_library",
|
||||
"//validator/flags:go_default_library",
|
||||
"//validator/keymanager:go_default_library",
|
||||
@@ -27,8 +28,8 @@ go_library(
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["wallet_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/shared/fileutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/promptutil"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/iface"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/prompt"
|
||||
"github.com/prysmaticlabs/prysm/validator/flags"
|
||||
"github.com/prysmaticlabs/prysm/validator/keymanager"
|
||||
@@ -253,20 +254,22 @@ func (w *Wallet) Password() string {
|
||||
|
||||
// InitializeKeymanager reads a keymanager config from disk at the wallet path,
|
||||
// unmarshals it based on the wallet's keymanager kind, and returns its value.
|
||||
func (w *Wallet) InitializeKeymanager(ctx context.Context) (keymanager.IKeymanager, error) {
|
||||
func (w *Wallet) InitializeKeymanager(ctx context.Context, cfg iface.InitKeymanagerConfig) (keymanager.IKeymanager, error) {
|
||||
var km keymanager.IKeymanager
|
||||
var err error
|
||||
switch w.KeymanagerKind() {
|
||||
case keymanager.Imported:
|
||||
km, err = imported.NewKeymanager(ctx, &imported.SetupConfig{
|
||||
Wallet: w,
|
||||
Wallet: w,
|
||||
ListenForChanges: cfg.ListenForChanges,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not initialize imported keymanager")
|
||||
}
|
||||
case keymanager.Derived:
|
||||
km, err = derived.NewKeymanager(ctx, &derived.SetupConfig{
|
||||
Wallet: w,
|
||||
Wallet: w,
|
||||
ListenForChanges: cfg.ListenForChanges,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not initialize derived keymanager")
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/manifoldco/promptui"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/shared/promptutil"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/iface"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/prompt"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
||||
"github.com/prysmaticlabs/prysm/validator/flags"
|
||||
@@ -22,11 +23,11 @@ import (
|
||||
|
||||
// CreateWalletConfig defines the parameters needed to call the create wallet functions.
|
||||
type CreateWalletConfig struct {
|
||||
WalletCfg *wallet.Config
|
||||
RemoteKeymanagerOpts *remote.KeymanagerOpts
|
||||
SkipMnemonicConfirm bool
|
||||
Mnemonic25thWord string
|
||||
NumAccounts int
|
||||
RemoteKeymanagerOpts *remote.KeymanagerOpts
|
||||
WalletCfg *wallet.Config
|
||||
Mnemonic25thWord string
|
||||
}
|
||||
|
||||
// CreateAndSaveWalletCli from user input with a desired keymanager. If a
|
||||
@@ -72,7 +73,7 @@ func CreateWalletWithKeymanager(ctx context.Context, cfg *CreateWalletConfig) (*
|
||||
if err = createImportedKeymanagerWallet(ctx, w); err != nil {
|
||||
return nil, errors.Wrap(err, "could not initialize wallet")
|
||||
}
|
||||
km, err := w.InitializeKeymanager(ctx)
|
||||
km, err := w.InitializeKeymanager(ctx, iface.InitKeymanagerConfig{ListenForChanges: false})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, ErrCouldNotInitializeKeymanager)
|
||||
}
|
||||
@@ -219,7 +220,8 @@ func createDerivedKeymanagerWallet(
|
||||
return errors.Wrap(err, "could not save wallet to disk")
|
||||
}
|
||||
km, err := derived.NewKeymanager(ctx, &derived.SetupConfig{
|
||||
Wallet: wallet,
|
||||
Wallet: wallet,
|
||||
ListenForChanges: true,
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not initialize HD keymanager")
|
||||
|
||||
@@ -129,7 +129,8 @@ func RecoverWallet(ctx context.Context, cfg *RecoverWalletConfig) (*wallet.Walle
|
||||
return nil, errors.Wrap(err, "could not save wallet to disk")
|
||||
}
|
||||
km, err := derived.NewKeymanager(ctx, &derived.SetupConfig{
|
||||
Wallet: w,
|
||||
Wallet: w,
|
||||
ListenForChanges: false,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not make keymanager for given phrase")
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/iface"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
||||
"github.com/prysmaticlabs/prysm/validator/flags"
|
||||
"github.com/prysmaticlabs/prysm/validator/keymanager"
|
||||
@@ -71,7 +72,7 @@ func TestRecoverDerivedWallet(t *testing.T) {
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context)
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context, iface.InitKeymanagerConfig{ListenForChanges: false})
|
||||
require.NoError(t, err)
|
||||
derivedKM, ok := km.(*derived.Keymanager)
|
||||
if !ok {
|
||||
|
||||
@@ -22,7 +22,6 @@ go_library(
|
||||
visibility = ["//validator:__subpackages__"],
|
||||
deps = [
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
"//beacon-chain/p2p/types:go_default_library",
|
||||
"//proto/validator/accounts/v2:go_default_library",
|
||||
"//shared/blockutil:go_default_library",
|
||||
"//shared/bls:go_default_library",
|
||||
@@ -39,6 +38,7 @@ go_library(
|
||||
"//shared/slotutil:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//shared/traceutil:go_default_library",
|
||||
"//validator/accounts/iface:go_default_library",
|
||||
"//validator/accounts/wallet:go_default_library",
|
||||
"//validator/db:go_default_library",
|
||||
"//validator/db/kv:go_default_library",
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
|
||||
validatorpb "github.com/prysmaticlabs/prysm/proto/validator/accounts/v2"
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
@@ -125,7 +124,7 @@ func (v *validator) signSlot(ctx context.Context, pubKey [48]byte, slot types.Sl
|
||||
}
|
||||
|
||||
var sig bls.Signature
|
||||
sszUint := p2ptypes.SSZUint64(slot)
|
||||
sszUint := types.SSZUint64(slot)
|
||||
root, err := helpers.ComputeSigningRoot(&sszUint, domain.SignatureDomain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
|
||||
validatorpb "github.com/prysmaticlabs/prysm/proto/validator/accounts/v2"
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
@@ -202,7 +201,7 @@ func (v *validator) signRandaoReveal(ctx context.Context, pubKey [48]byte, epoch
|
||||
}
|
||||
|
||||
var randaoReveal bls.Signature
|
||||
sszUint := p2ptypes.SSZUint64(epoch)
|
||||
sszUint := types.SSZUint64(epoch)
|
||||
root, err := helpers.ComputeSigningRoot(&sszUint, domain.SignatureDomain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -305,7 +304,18 @@ func (v *validator) getGraffiti(ctx context.Context, pubKey [48]byte) ([]byte, e
|
||||
return []byte(g), nil
|
||||
}
|
||||
|
||||
// When specified, a graffiti from the random list in the file take third priority.
|
||||
// When specified, a graffiti from the ordered list in the file take third priority.
|
||||
if v.graffitiOrderedIndex < uint64(len(v.graffitiStruct.Ordered)) {
|
||||
graffiti := v.graffitiStruct.Ordered[v.graffitiOrderedIndex]
|
||||
v.graffitiOrderedIndex = v.graffitiOrderedIndex + 1
|
||||
err := v.db.SaveGraffitiOrderedIndex(ctx, v.graffitiOrderedIndex)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to update graffiti ordered index")
|
||||
}
|
||||
return []byte(graffiti), nil
|
||||
}
|
||||
|
||||
// When specified, a graffiti from the random list in the file take fourth priority.
|
||||
if len(v.graffitiStruct.Random) != 0 {
|
||||
r := rand.NewGenerator()
|
||||
r.Seed(time.Now().Unix())
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
ptypes "github.com/gogo/protobuf/types"
|
||||
"github.com/golang/mock/gomock"
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
"github.com/prysmaticlabs/eth2-types"
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
validatorpb "github.com/prysmaticlabs/prysm/proto/validator/accounts/v2"
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
@@ -744,3 +744,30 @@ func TestGetGraffiti_Ok(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetGraffitiOrdered_Ok(t *testing.T) {
|
||||
pubKey := [48]byte{'a'}
|
||||
valDB := testing2.SetupDB(t, [][48]byte{pubKey})
|
||||
ctrl := gomock.NewController(t)
|
||||
m := &mocks{
|
||||
validatorClient: mock.NewMockBeaconNodeValidatorClient(ctrl),
|
||||
}
|
||||
m.validatorClient.EXPECT().
|
||||
ValidatorIndex(gomock.Any(), ðpb.ValidatorIndexRequest{PublicKey: pubKey[:]}).
|
||||
Times(5).
|
||||
Return(ðpb.ValidatorIndexResponse{Index: 2}, nil)
|
||||
|
||||
v := &validator{
|
||||
db: valDB,
|
||||
validatorClient: m.validatorClient,
|
||||
graffitiStruct: &graffiti.Graffiti{
|
||||
Ordered: []string{"a", "b", "c"},
|
||||
Default: "d",
|
||||
},
|
||||
}
|
||||
for _, want := range [][]byte{{'a'}, {'b'}, {'c'}, {'d'}, {'d'}} {
|
||||
got, err := v.getGraffiti(context.Background(), pubKey)
|
||||
require.NoError(t, err)
|
||||
require.DeepEqual(t, want, got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/event"
|
||||
"github.com/prysmaticlabs/prysm/shared/grpcutils"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
accountsiface "github.com/prysmaticlabs/prysm/validator/accounts/iface"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
||||
"github.com/prysmaticlabs/prysm/validator/db"
|
||||
"github.com/prysmaticlabs/prysm/validator/graffiti"
|
||||
@@ -175,6 +176,12 @@ func (v *ValidatorService) Start() {
|
||||
slashablePublicKeys[pubKey] = true
|
||||
}
|
||||
|
||||
graffitiOrderedIndex, err := v.db.GraffitiOrderedIndex(v.ctx, v.graffitiStruct.Hash)
|
||||
if err != nil {
|
||||
log.Errorf("Could not read graffiti ordered index from disk: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
v.validator = &validator{
|
||||
db: v.db,
|
||||
validatorClient: ethpb.NewBeaconNodeValidatorClient(v.conn),
|
||||
@@ -195,6 +202,7 @@ func (v *ValidatorService) Start() {
|
||||
walletInitializedFeed: v.walletInitializedFeed,
|
||||
blockFeed: new(event.Feed),
|
||||
graffitiStruct: v.graffitiStruct,
|
||||
graffitiOrderedIndex: graffitiOrderedIndex,
|
||||
eipImportBlacklistedPublicKeys: slashablePublicKeys,
|
||||
logDutyCountDown: v.logDutyCountDown,
|
||||
}
|
||||
@@ -229,7 +237,7 @@ func (v *ValidatorService) recheckKeys(ctx context.Context) {
|
||||
cleanup := sub.Unsubscribe
|
||||
defer cleanup()
|
||||
w := <-initializedChan
|
||||
keyManager, err := w.InitializeKeymanager(ctx)
|
||||
keyManager, err := w.InitializeKeymanager(ctx, accountsiface.InitKeymanagerConfig{ListenForChanges: true})
|
||||
if err != nil {
|
||||
// log.Fatalf will prevent defer from being called
|
||||
cleanup()
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/hashutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
accountsiface "github.com/prysmaticlabs/prysm/validator/accounts/iface"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
||||
vdb "github.com/prysmaticlabs/prysm/validator/db"
|
||||
"github.com/prysmaticlabs/prysm/validator/graffiti"
|
||||
@@ -90,6 +91,7 @@ type validator struct {
|
||||
graffiti []byte
|
||||
voteStats voteStats
|
||||
graffitiStruct *graffiti.Graffiti
|
||||
graffitiOrderedIndex uint64
|
||||
eipImportBlacklistedPublicKeys map[[48]byte]bool
|
||||
}
|
||||
|
||||
@@ -114,7 +116,7 @@ func (v *validator) WaitForWalletInitialization(ctx context.Context) error {
|
||||
for {
|
||||
select {
|
||||
case w := <-walletChan:
|
||||
keyManager, err := w.InitializeKeymanager(ctx)
|
||||
keyManager, err := w.InitializeKeymanager(ctx, accountsiface.InitKeymanagerConfig{ListenForChanges: true})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not read keymanager")
|
||||
}
|
||||
|
||||
@@ -323,7 +323,8 @@ func TestWaitForActivation_AccountsChanged(t *testing.T) {
|
||||
}
|
||||
ctx := context.Background()
|
||||
km, err := derived.NewKeymanager(ctx, &derived.SetupConfig{
|
||||
Wallet: wallet,
|
||||
Wallet: wallet,
|
||||
ListenForChanges: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
err = km.RecoverAccountsFromMnemonic(ctx, mnemonic, "", 1)
|
||||
|
||||
@@ -57,4 +57,8 @@ type ValidatorDB interface {
|
||||
AttestationHistoryForPubKey(
|
||||
ctx context.Context, pubKey [48]byte,
|
||||
) ([]*kv.AttestationRecord, error)
|
||||
|
||||
// Graffiti ordered index related methods
|
||||
SaveGraffitiOrderedIndex(ctx context.Context, index uint64) error
|
||||
GraffitiOrderedIndex(ctx context.Context, fileHash [32]byte) (uint64, error)
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user