Use eth2-types SSZUint64 (#8514)

This commit is contained in:
pinglamb
2021-02-25 21:51:26 +08:00
committed by GitHub
parent f0eb843138
commit 5db5ca7056
23 changed files with 62 additions and 177 deletions

View File

@@ -88,6 +88,7 @@ go_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",

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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 := &ethpb.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 := &ethpb.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 := &ethpb.AggregateAttestationAndProof{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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 := &ethpb.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 := &ethpb.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 := &ethpb.AggregateAttestationAndProof{

View File

@@ -2571,8 +2571,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",

2
go.mod
View File

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

4
go.sum
View File

@@ -1026,8 +1026,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=

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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