mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Add Remaining Gossip Changes (#9553)
* add changes * add changes here in * rem duplicate import * fix topic not being set in test * terence's review Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
This commit is contained in:
@@ -20,8 +20,12 @@ func (s *Service) decodePubsubMessage(msg *pubsub.Message) (ssz.Unmarshaler, err
|
||||
return nil, errNilPubsubMessage
|
||||
}
|
||||
topic := *msg.Topic
|
||||
fDigest, err := p2p.ExtractGossipDigest(topic)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "extraction failed for topic: %s", topic)
|
||||
}
|
||||
topic = strings.TrimSuffix(topic, s.cfg.P2P.Encoding().ProtocolSuffix())
|
||||
topic, err := s.replaceForkDigest(topic)
|
||||
topic, err = s.replaceForkDigest(topic)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -43,6 +47,13 @@ func (s *Service) decodePubsubMessage(msg *pubsub.Message) (ssz.Unmarshaler, err
|
||||
if !ok {
|
||||
return nil, errors.Errorf("message of %T does not support marshaller interface", base)
|
||||
}
|
||||
// Handle different message types across forks.
|
||||
if topic == p2p.BlockSubnetTopicFormat {
|
||||
m, err = extractBlockDataType(fDigest[:], s.cfg.Chain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if err := s.cfg.P2P.Encoding().DecodeGossip(msg.Data, m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -2,25 +2,34 @@ package sync
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/d4l3k/messagediff"
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
pb "github.com/libp2p/go-libp2p-pubsub/pb"
|
||||
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
||||
p2ptesting "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
)
|
||||
|
||||
func TestService_decodePubsubMessage(t *testing.T) {
|
||||
digest, err := helpers.ComputeForkDigest(params.BeaconConfig().GenesisForkVersion, make([]byte, 32))
|
||||
require.NoError(t, err)
|
||||
tests := []struct {
|
||||
name string
|
||||
topic string
|
||||
input *pubsub.Message
|
||||
want proto.Message
|
||||
want interface{}
|
||||
wantErr error
|
||||
}{
|
||||
{
|
||||
@@ -44,12 +53,12 @@ func TestService_decodePubsubMessage(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "topic not mapped to any message type",
|
||||
topic: "/eth2/abcdef/foo",
|
||||
topic: "/eth2/abababab/foo/ssz_snappy",
|
||||
wantErr: p2p.ErrMessageNotMapped,
|
||||
},
|
||||
{
|
||||
name: "valid message -- beacon block",
|
||||
topic: p2p.GossipTypeMapping[reflect.TypeOf(ðpb.SignedBeaconBlock{})],
|
||||
topic: fmt.Sprintf(p2p.GossipTypeMapping[reflect.TypeOf(ðpb.SignedBeaconBlock{})], digest),
|
||||
input: &pubsub.Message{
|
||||
Message: &pb.Message{
|
||||
Data: func() []byte {
|
||||
@@ -62,13 +71,13 @@ func TestService_decodePubsubMessage(t *testing.T) {
|
||||
},
|
||||
},
|
||||
wantErr: nil,
|
||||
want: testutil.NewBeaconBlock(),
|
||||
want: wrapper.WrappedPhase0SignedBeaconBlock(testutil.NewBeaconBlock()),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := &Service{
|
||||
cfg: &Config{P2P: p2ptesting.NewTestP2P(t)},
|
||||
cfg: &Config{P2P: p2ptesting.NewTestP2P(t), Chain: &mock.ChainService{ValidatorsRoot: [32]byte{}, Genesis: time.Now()}},
|
||||
}
|
||||
if tt.topic != "" {
|
||||
if tt.input == nil {
|
||||
@@ -79,7 +88,7 @@ func TestService_decodePubsubMessage(t *testing.T) {
|
||||
tt.input.Message.Topic = &tt.topic
|
||||
}
|
||||
got, err := s.decodePubsubMessage(tt.input)
|
||||
if err != tt.wantErr {
|
||||
if err != tt.wantErr && !strings.Contains(err.Error(), tt.wantErr.Error()) {
|
||||
t.Errorf("decodePubsubMessage() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2,22 +2,23 @@ package sync
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/transition/interop"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block"
|
||||
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
|
||||
wrapperv2 "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
|
||||
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
func (s *Service) beaconBlockSubscriber(ctx context.Context, msg proto.Message) error {
|
||||
rBlock, ok := msg.(*ethpb.SignedBeaconBlock)
|
||||
if !ok {
|
||||
return errors.New("message is not type *ethpb.SignedBeaconBlock")
|
||||
signed, err := blockFromProto(msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
signed := wrapper.WrappedPhase0SignedBeaconBlock(rBlock)
|
||||
|
||||
if signed.IsNil() || signed.Block().IsNil() {
|
||||
return errors.New("nil block")
|
||||
@@ -65,3 +66,14 @@ func (s *Service) deleteAttsInPool(atts []*ethpb.Attestation) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func blockFromProto(msg proto.Message) (block.SignedBeaconBlock, error) {
|
||||
switch t := msg.(type) {
|
||||
case *ethpb.SignedBeaconBlock:
|
||||
return wrapper.WrappedPhase0SignedBeaconBlock(t), nil
|
||||
case *ethpb.SignedBeaconBlockAltair:
|
||||
return wrapperv2.WrappedAltairSignedBeaconBlock(t)
|
||||
default:
|
||||
return nil, errors.Errorf("message has invalid underlying type: %T", msg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package sync
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
@@ -10,6 +11,8 @@ import (
|
||||
dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block"
|
||||
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
@@ -108,3 +111,53 @@ func TestService_beaconBlockSubscriber(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBlockFromProto(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
msgCreator func(t *testing.T) proto.Message
|
||||
want block.SignedBeaconBlock
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "invalid type provided",
|
||||
msgCreator: func(t *testing.T) proto.Message {
|
||||
return ðpb.SignedAggregateAttestationAndProof{}
|
||||
},
|
||||
want: nil,
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "phase 0 type provided",
|
||||
msgCreator: func(t *testing.T) proto.Message {
|
||||
return ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 100}}
|
||||
},
|
||||
want: wrapper.WrappedPhase0SignedBeaconBlock(ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 100}}),
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "altair type provided",
|
||||
msgCreator: func(t *testing.T) proto.Message {
|
||||
return ðpb.SignedBeaconBlockAltair{Block: ðpb.BeaconBlockAltair{Slot: 100}}
|
||||
},
|
||||
want: func() block.SignedBeaconBlock {
|
||||
wsb, err := wrapper.WrappedAltairSignedBeaconBlock(ðpb.SignedBeaconBlockAltair{Block: ðpb.BeaconBlockAltair{Slot: 100}})
|
||||
require.NoError(t, err)
|
||||
return wsb
|
||||
}(),
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := blockFromProto(tt.msgCreator(t))
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("blockFromProto() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("blockFromProto() got = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// skipcq: SCC-U1000
|
||||
func (s *Service) syncCommitteeMessageSubscriber(_ context.Context, msg proto.Message) error {
|
||||
m, ok := msg.(*ethpb.SyncCommitteeMessage)
|
||||
if !ok {
|
||||
|
||||
@@ -371,6 +371,9 @@ func TestValidateAggregateAndProof_CanValidate(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
topic := p2p.GossipTypeMapping[reflect.TypeOf(signedAggregateAndProof)]
|
||||
d, err := r.currentForkDigest()
|
||||
assert.NoError(t, err)
|
||||
topic = r.addDigestToTopic(topic, d)
|
||||
msg := &pubsub.Message{
|
||||
Message: &pubsubpb.Message{
|
||||
Data: buf.Bytes(),
|
||||
@@ -462,6 +465,9 @@ func TestVerifyIndexInCommittee_SeenAggregatorEpoch(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
topic := p2p.GossipTypeMapping[reflect.TypeOf(signedAggregateAndProof)]
|
||||
d, err := r.currentForkDigest()
|
||||
assert.NoError(t, err)
|
||||
topic = r.addDigestToTopic(topic, d)
|
||||
msg := &pubsub.Message{
|
||||
Message: &pubsubpb.Message{
|
||||
Data: buf.Bytes(),
|
||||
|
||||
@@ -82,10 +82,11 @@ func TestValidateAttesterSlashing_ValidSlashing(t *testing.T) {
|
||||
r := &Service{
|
||||
cfg: &Config{
|
||||
P2P: p,
|
||||
Chain: &mock.ChainService{State: s},
|
||||
Chain: &mock.ChainService{State: s, Genesis: time.Now()},
|
||||
InitialSync: &mockSync.Sync{IsSyncing: false},
|
||||
},
|
||||
seenAttesterSlashingCache: make(map[uint64]bool),
|
||||
subHandler: newSubTopicHandler(),
|
||||
}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
@@ -93,6 +94,9 @@ func TestValidateAttesterSlashing_ValidSlashing(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
topic := p2p.GossipTypeMapping[reflect.TypeOf(slashing)]
|
||||
d, err := r.currentForkDigest()
|
||||
assert.NoError(t, err)
|
||||
topic = r.addDigestToTopic(topic, d)
|
||||
msg := &pubsub.Message{
|
||||
Message: &pubsubpb.Message{
|
||||
Data: buf.Bytes(),
|
||||
@@ -113,16 +117,21 @@ func TestValidateAttesterSlashing_CanFilter(t *testing.T) {
|
||||
cfg: &Config{
|
||||
P2P: p,
|
||||
InitialSync: &mockSync.Sync{IsSyncing: false},
|
||||
Chain: &mock.ChainService{Genesis: time.Now()},
|
||||
},
|
||||
seenAttesterSlashingCache: make(map[uint64]bool),
|
||||
subHandler: newSubTopicHandler(),
|
||||
}
|
||||
|
||||
r.setAttesterSlashingIndicesSeen([]uint64{1, 2, 3, 4}, []uint64{3, 4, 5, 6})
|
||||
|
||||
// The below attestations should be filtered hence bad signature is ok.
|
||||
topic := p2p.GossipTypeMapping[reflect.TypeOf(ðpb.AttesterSlashing{})]
|
||||
d, err := r.currentForkDigest()
|
||||
assert.NoError(t, err)
|
||||
topic = r.addDigestToTopic(topic, d)
|
||||
buf := new(bytes.Buffer)
|
||||
_, err := p.Encoding().EncodeGossip(buf, ðpb.AttesterSlashing{
|
||||
_, err = p.Encoding().EncodeGossip(buf, ðpb.AttesterSlashing{
|
||||
Attestation_1: testutil.HydrateIndexedAttestation(ðpb.IndexedAttestation{
|
||||
AttestingIndices: []uint64{3},
|
||||
}),
|
||||
|
||||
@@ -44,19 +44,12 @@ func (s *Service) validateCommitteeIndexBeaconAttestation(ctx context.Context, p
|
||||
return pubsub.ValidationReject
|
||||
}
|
||||
|
||||
// Override topic for decoding.
|
||||
originalTopic := msg.Topic
|
||||
format := p2p.GossipTypeMapping[reflect.TypeOf(ð.Attestation{})]
|
||||
msg.Topic = &format
|
||||
|
||||
m, err := s.decodePubsubMessage(msg)
|
||||
if err != nil {
|
||||
log.WithError(err).Debug("Could not decode message")
|
||||
traceutil.AnnotateError(span, err)
|
||||
return pubsub.ValidationReject
|
||||
}
|
||||
// Restore topic.
|
||||
msg.Topic = originalTopic
|
||||
|
||||
att, ok := m.(*eth.Attestation)
|
||||
if !ok {
|
||||
@@ -99,7 +92,7 @@ func (s *Service) validateCommitteeIndexBeaconAttestation(ctx context.Context, p
|
||||
return pubsub.ValidationReject
|
||||
}
|
||||
|
||||
// Verify the block being voted and the processed state is in DB and. The block should have passed validation if it's in the DB.
|
||||
// Verify the block being voted and the processed state is in DB and the block has passed validation if it's in the DB.
|
||||
blockRoot := bytesutil.ToBytes32(att.Data.BeaconBlockRoot)
|
||||
if !s.hasBlockAndState(ctx, blockRoot) {
|
||||
// A node doesn't have the block, it'll request from peer while saving the pending attestation to a queue.
|
||||
@@ -123,7 +116,7 @@ func (s *Service) validateCommitteeIndexBeaconAttestation(ctx context.Context, p
|
||||
return pubsub.ValidationIgnore
|
||||
}
|
||||
|
||||
validationRes := s.validateUnaggregatedAttTopic(ctx, att, preState, *originalTopic)
|
||||
validationRes := s.validateUnaggregatedAttTopic(ctx, att, preState, *msg.Topic)
|
||||
if validationRes != pubsub.ValidationAccept {
|
||||
return validationRes
|
||||
}
|
||||
|
||||
@@ -15,9 +15,7 @@ import (
|
||||
blockfeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/block"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/transition"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block"
|
||||
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
@@ -55,12 +53,11 @@ func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, ms
|
||||
s.validateBlockLock.Lock()
|
||||
defer s.validateBlockLock.Unlock()
|
||||
|
||||
rblk, ok := m.(*ethpb.SignedBeaconBlock)
|
||||
blk, ok := m.(block.SignedBeaconBlock)
|
||||
if !ok {
|
||||
log.WithError(errors.New("msg is not ethpb.SignedBeaconBlock")).Debug("Rejected block")
|
||||
return pubsub.ValidationReject
|
||||
}
|
||||
blk := wrapper.WrappedPhase0SignedBeaconBlock(rblk)
|
||||
|
||||
if blk.IsNil() || blk.Block().IsNil() {
|
||||
log.WithError(errors.New("block.Block is nil")).Debug("Rejected block")
|
||||
@@ -158,12 +155,14 @@ func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, ms
|
||||
}
|
||||
|
||||
if err := s.validateBeaconBlock(ctx, blk, blockRoot); err != nil {
|
||||
log.WithError(err).WithField("blockSlot", blk.Block().Slot()).Warn("Rejected block")
|
||||
log.WithError(err).WithFields(logrus.Fields{
|
||||
"blockSlot": blk.Block().Slot(),
|
||||
"blockRoot": fmt.Sprintf("%#x", blockRoot)}).Warn("Rejected block")
|
||||
return pubsub.ValidationReject
|
||||
}
|
||||
// Record attribute of valid block.
|
||||
span.AddAttributes(trace.Int64Attribute("slotInEpoch", int64(blk.Block().Slot()%params.BeaconConfig().SlotsPerEpoch)))
|
||||
msg.ValidatorData = rblk // Used in downstream subscriber
|
||||
msg.ValidatorData = blk.Proto() // Used in downstream subscriber
|
||||
|
||||
// Log the arrival time of the accepted block
|
||||
startTime, err := core.SlotToTime(genesisTime, blk.Block().Slot())
|
||||
@@ -199,7 +198,7 @@ func (s *Service) validateBeaconBlock(ctx context.Context, blk block.SignedBeaco
|
||||
return err
|
||||
}
|
||||
|
||||
if err := blocks.VerifyBlockSignature(parentState, blk.Block().ProposerIndex(), blk.Signature(), blk.Block().HashTreeRoot); err != nil {
|
||||
if err := blocks.VerifyBlockSignatureUsingCurrentFork(parentState, blk); err != nil {
|
||||
s.setBadBlock(ctx, blockRoot)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
|
||||
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
|
||||
"github.com/prysmaticlabs/prysm/shared/abool"
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
@@ -50,7 +49,7 @@ func TestValidateBeaconBlockPubSub_InvalidSignature(t *testing.T) {
|
||||
bRoot, err := parentBlock.Block.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.SaveState(ctx, beaconState, bRoot))
|
||||
require.NoError(t, db.SaveStateSummary(ctx, &statepb.StateSummary{Root: bRoot[:]}))
|
||||
require.NoError(t, db.SaveStateSummary(ctx, ðpb.StateSummary{Root: bRoot[:]}))
|
||||
copied := beaconState.Copy()
|
||||
require.NoError(t, copied.SetSlot(1))
|
||||
proposerIdx, err := helpers.BeaconProposerIndex(copied)
|
||||
@@ -179,6 +178,9 @@ func TestValidateBeaconBlockPubSub_CanRecoverStateSummary(t *testing.T) {
|
||||
_, err = p.Encoding().EncodeGossip(buf, msg)
|
||||
require.NoError(t, err)
|
||||
topic := p2p.GossipTypeMapping[reflect.TypeOf(msg)]
|
||||
digest, err := r.currentForkDigest()
|
||||
assert.NoError(t, err)
|
||||
topic = r.addDigestToTopic(topic, digest)
|
||||
m := &pubsub.Message{
|
||||
Message: &pubsubpb.Message{
|
||||
Data: buf.Bytes(),
|
||||
@@ -200,7 +202,7 @@ func TestValidateBeaconBlockPubSub_ValidProposerSignature(t *testing.T) {
|
||||
bRoot, err := parentBlock.Block.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.SaveState(ctx, beaconState, bRoot))
|
||||
require.NoError(t, db.SaveStateSummary(ctx, &statepb.StateSummary{Root: bRoot[:]}))
|
||||
require.NoError(t, db.SaveStateSummary(ctx, ðpb.StateSummary{Root: bRoot[:]}))
|
||||
copied := beaconState.Copy()
|
||||
require.NoError(t, copied.SetSlot(1))
|
||||
proposerIdx, err := helpers.BeaconProposerIndex(copied)
|
||||
@@ -238,6 +240,9 @@ func TestValidateBeaconBlockPubSub_ValidProposerSignature(t *testing.T) {
|
||||
_, err = p.Encoding().EncodeGossip(buf, msg)
|
||||
require.NoError(t, err)
|
||||
topic := p2p.GossipTypeMapping[reflect.TypeOf(msg)]
|
||||
digest, err := r.currentForkDigest()
|
||||
assert.NoError(t, err)
|
||||
topic = r.addDigestToTopic(topic, digest)
|
||||
m := &pubsub.Message{
|
||||
Message: &pubsubpb.Message{
|
||||
Data: buf.Bytes(),
|
||||
@@ -259,7 +264,7 @@ func TestValidateBeaconBlockPubSub_WithLookahead(t *testing.T) {
|
||||
bRoot, err := parentBlock.Block.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.SaveState(ctx, beaconState, bRoot))
|
||||
require.NoError(t, db.SaveStateSummary(ctx, &statepb.StateSummary{Root: bRoot[:]}))
|
||||
require.NoError(t, db.SaveStateSummary(ctx, ðpb.StateSummary{Root: bRoot[:]}))
|
||||
copied := beaconState.Copy()
|
||||
// The next block is only 1 epoch ahead so as to not induce a new seed.
|
||||
blkSlot := params.BeaconConfig().SlotsPerEpoch.Mul(uint64(core.NextEpoch(copied)))
|
||||
@@ -294,11 +299,15 @@ func TestValidateBeaconBlockPubSub_WithLookahead(t *testing.T) {
|
||||
badBlockCache: lruwrpr.New(10),
|
||||
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
|
||||
seenPendingBlocks: make(map[[32]byte]bool),
|
||||
subHandler: newSubTopicHandler(),
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
_, err = p.Encoding().EncodeGossip(buf, msg)
|
||||
require.NoError(t, err)
|
||||
topic := p2p.GossipTypeMapping[reflect.TypeOf(msg)]
|
||||
digest, err := r.currentForkDigest()
|
||||
assert.NoError(t, err)
|
||||
topic = r.addDigestToTopic(topic, digest)
|
||||
m := &pubsub.Message{
|
||||
Message: &pubsubpb.Message{
|
||||
Data: buf.Bytes(),
|
||||
@@ -320,7 +329,7 @@ func TestValidateBeaconBlockPubSub_AdvanceEpochsForState(t *testing.T) {
|
||||
bRoot, err := parentBlock.Block.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.SaveState(ctx, beaconState, bRoot))
|
||||
require.NoError(t, db.SaveStateSummary(ctx, &statepb.StateSummary{Root: bRoot[:]}))
|
||||
require.NoError(t, db.SaveStateSummary(ctx, ðpb.StateSummary{Root: bRoot[:]}))
|
||||
copied := beaconState.Copy()
|
||||
// The next block is at least 2 epochs ahead to induce shuffling and a new seed.
|
||||
blkSlot := params.BeaconConfig().SlotsPerEpoch * 2
|
||||
@@ -360,6 +369,9 @@ func TestValidateBeaconBlockPubSub_AdvanceEpochsForState(t *testing.T) {
|
||||
_, err = p.Encoding().EncodeGossip(buf, msg)
|
||||
require.NoError(t, err)
|
||||
topic := p2p.GossipTypeMapping[reflect.TypeOf(msg)]
|
||||
digest, err := r.currentForkDigest()
|
||||
assert.NoError(t, err)
|
||||
topic = r.addDigestToTopic(topic, digest)
|
||||
m := &pubsub.Message{
|
||||
Message: &pubsubpb.Message{
|
||||
Data: buf.Bytes(),
|
||||
@@ -422,7 +434,7 @@ func TestValidateBeaconBlockPubSub_AcceptBlocksFromNearFuture(t *testing.T) {
|
||||
bRoot, err := parentBlock.Block.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.SaveState(ctx, beaconState, bRoot))
|
||||
require.NoError(t, db.SaveStateSummary(ctx, &statepb.StateSummary{Root: bRoot[:]}))
|
||||
require.NoError(t, db.SaveStateSummary(ctx, ðpb.StateSummary{Root: bRoot[:]}))
|
||||
copied := beaconState.Copy()
|
||||
require.NoError(t, copied.SetSlot(1))
|
||||
proposerIdx, err := helpers.BeaconProposerIndex(copied)
|
||||
@@ -461,6 +473,9 @@ func TestValidateBeaconBlockPubSub_AcceptBlocksFromNearFuture(t *testing.T) {
|
||||
_, err = p.Encoding().EncodeGossip(buf, msg)
|
||||
require.NoError(t, err)
|
||||
topic := p2p.GossipTypeMapping[reflect.TypeOf(msg)]
|
||||
digest, err := r.currentForkDigest()
|
||||
assert.NoError(t, err)
|
||||
topic = r.addDigestToTopic(topic, digest)
|
||||
m := &pubsub.Message{
|
||||
Message: &pubsubpb.Message{
|
||||
Data: buf.Bytes(),
|
||||
@@ -689,7 +704,7 @@ func TestValidateBeaconBlockPubSub_ParentNotFinalizedDescendant(t *testing.T) {
|
||||
bRoot, err := parentBlock.Block.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.SaveState(ctx, beaconState, bRoot))
|
||||
require.NoError(t, db.SaveStateSummary(ctx, &statepb.StateSummary{Root: bRoot[:]}))
|
||||
require.NoError(t, db.SaveStateSummary(ctx, ðpb.StateSummary{Root: bRoot[:]}))
|
||||
copied := beaconState.Copy()
|
||||
require.NoError(t, copied.SetSlot(1))
|
||||
proposerIdx, err := helpers.BeaconProposerIndex(copied)
|
||||
@@ -728,6 +743,9 @@ func TestValidateBeaconBlockPubSub_ParentNotFinalizedDescendant(t *testing.T) {
|
||||
_, err = p.Encoding().EncodeGossip(buf, msg)
|
||||
require.NoError(t, err)
|
||||
topic := p2p.GossipTypeMapping[reflect.TypeOf(msg)]
|
||||
digest, err := r.currentForkDigest()
|
||||
assert.NoError(t, err)
|
||||
topic = r.addDigestToTopic(topic, digest)
|
||||
m := &pubsub.Message{
|
||||
Message: &pubsubpb.Message{
|
||||
Data: buf.Bytes(),
|
||||
@@ -748,7 +766,7 @@ func TestValidateBeaconBlockPubSub_InvalidParentBlock(t *testing.T) {
|
||||
bRoot, err := parentBlock.Block.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.SaveState(ctx, beaconState, bRoot))
|
||||
require.NoError(t, db.SaveStateSummary(ctx, &statepb.StateSummary{Root: bRoot[:]}))
|
||||
require.NoError(t, db.SaveStateSummary(ctx, ðpb.StateSummary{Root: bRoot[:]}))
|
||||
copied := beaconState.Copy()
|
||||
require.NoError(t, copied.SetSlot(1))
|
||||
proposerIdx, err := helpers.BeaconProposerIndex(copied)
|
||||
@@ -833,7 +851,7 @@ func TestValidateBeaconBlockPubSub_RejectEvilBlocksFromFuture(t *testing.T) {
|
||||
bRoot, err := parentBlock.Block.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.SaveState(ctx, beaconState, bRoot))
|
||||
require.NoError(t, db.SaveStateSummary(ctx, &statepb.StateSummary{Root: bRoot[:]}))
|
||||
require.NoError(t, db.SaveStateSummary(ctx, ðpb.StateSummary{Root: bRoot[:]}))
|
||||
|
||||
copied := beaconState.Copy()
|
||||
// The next block is at least 2 epochs ahead to induce shuffling and a new seed.
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
|
||||
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
lruwrpr "github.com/prysmaticlabs/prysm/shared/lru"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
@@ -46,11 +45,11 @@ func setupValidProposerSlashing(t *testing.T) (*ethpb.ProposerSlashing, state.Be
|
||||
}
|
||||
|
||||
currentSlot := types.Slot(0)
|
||||
state, err := v1.InitializeFromProto(&statepb.BeaconState{
|
||||
state, err := v1.InitializeFromProto(ðpb.BeaconState{
|
||||
Validators: validators,
|
||||
Slot: currentSlot,
|
||||
Balances: validatorBalances,
|
||||
Fork: &statepb.Fork{
|
||||
Fork: ðpb.Fork{
|
||||
CurrentVersion: params.BeaconConfig().GenesisForkVersion,
|
||||
PreviousVersion: params.BeaconConfig().GenesisForkVersion,
|
||||
Epoch: 0,
|
||||
@@ -117,7 +116,7 @@ func TestValidateProposerSlashing_ValidSlashing(t *testing.T) {
|
||||
r := &Service{
|
||||
cfg: &Config{
|
||||
P2P: p,
|
||||
Chain: &mock.ChainService{State: s},
|
||||
Chain: &mock.ChainService{State: s, Genesis: time.Now()},
|
||||
InitialSync: &mockSync.Sync{IsSyncing: false},
|
||||
},
|
||||
seenProposerSlashingCache: lruwrpr.New(10),
|
||||
@@ -127,6 +126,9 @@ func TestValidateProposerSlashing_ValidSlashing(t *testing.T) {
|
||||
_, err := p.Encoding().EncodeGossip(buf, slashing)
|
||||
require.NoError(t, err)
|
||||
topic := p2p.GossipTypeMapping[reflect.TypeOf(slashing)]
|
||||
d, err := r.currentForkDigest()
|
||||
assert.NoError(t, err)
|
||||
topic = r.addDigestToTopic(topic, d)
|
||||
m := &pubsub.Message{
|
||||
Message: &pubsubpb.Message{
|
||||
Data: buf.Bytes(),
|
||||
|
||||
@@ -276,7 +276,11 @@ func TestService_ValidateSyncCommitteeMessage(t *testing.T) {
|
||||
msg.ValidatorIndex = types.ValidatorIndex(chosenVal)
|
||||
msg.Slot = core.PrevSlot(hState.Slot())
|
||||
|
||||
return s, topic
|
||||
digest, err := s.currentForkDigest()
|
||||
assert.NoError(t, err)
|
||||
actualTopic := fmt.Sprintf(defaultTopic, digest, 1)
|
||||
|
||||
return s, actualTopic
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"crypto/rand"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
pubsubpb "github.com/libp2p/go-libp2p-pubsub/pb"
|
||||
@@ -18,7 +19,6 @@ import (
|
||||
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
|
||||
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
lruwrpr "github.com/prysmaticlabs/prysm/shared/lru"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
@@ -39,9 +39,9 @@ func setupValidExit(t *testing.T) (*ethpb.SignedVoluntaryExit, state.BeaconState
|
||||
ActivationEpoch: 0,
|
||||
},
|
||||
}
|
||||
state, err := v1.InitializeFromProto(&statepb.BeaconState{
|
||||
state, err := v1.InitializeFromProto(ðpb.BeaconState{
|
||||
Validators: registry,
|
||||
Fork: &statepb.Fork{
|
||||
Fork: ðpb.Fork{
|
||||
CurrentVersion: params.BeaconConfig().GenesisForkVersion,
|
||||
PreviousVersion: params.BeaconConfig().GenesisForkVersion,
|
||||
},
|
||||
@@ -78,7 +78,8 @@ func TestValidateVoluntaryExit_ValidExit(t *testing.T) {
|
||||
cfg: &Config{
|
||||
P2P: p,
|
||||
Chain: &mock.ChainService{
|
||||
State: s,
|
||||
State: s,
|
||||
Genesis: time.Now(),
|
||||
},
|
||||
InitialSync: &mockSync.Sync{IsSyncing: false},
|
||||
},
|
||||
@@ -89,6 +90,9 @@ func TestValidateVoluntaryExit_ValidExit(t *testing.T) {
|
||||
_, err := p.Encoding().EncodeGossip(buf, exit)
|
||||
require.NoError(t, err)
|
||||
topic := p2p.GossipTypeMapping[reflect.TypeOf(exit)]
|
||||
d, err := r.currentForkDigest()
|
||||
assert.NoError(t, err)
|
||||
topic = r.addDigestToTopic(topic, d)
|
||||
m := &pubsub.Message{
|
||||
Message: &pubsubpb.Message{
|
||||
Data: buf.Bytes(),
|
||||
|
||||
Reference in New Issue
Block a user