mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 07:58:22 -05:00
Accept attestations when node is optimistic (#11319)
* Accept attestations when node is optimistic * Fix tests * Add regression tests * Fix tests * Fix more bad tests
This commit is contained in:
@@ -40,16 +40,6 @@ func (s *Service) validateAggregateAndProof(ctx context.Context, pid peer.ID, ms
|
||||
return pubsub.ValidationIgnore, nil
|
||||
}
|
||||
|
||||
// We should not attempt to process this message if the node is running in optimistic mode.
|
||||
// We just ignore in p2p so that the peer is not penalized.
|
||||
optimistic, err := s.cfg.chain.IsOptimistic(ctx)
|
||||
if err != nil {
|
||||
return pubsub.ValidationReject, err
|
||||
}
|
||||
if optimistic {
|
||||
return pubsub.ValidationIgnore, nil
|
||||
}
|
||||
|
||||
raw, err := s.decodePubsubMessage(msg)
|
||||
if err != nil {
|
||||
tracing.AnnotateError(span, err)
|
||||
|
||||
@@ -362,6 +362,7 @@ func TestValidateAggregateAndProof_CanValidate(t *testing.T) {
|
||||
beaconDB: db,
|
||||
initialSync: &mockSync.Sync{IsSyncing: false},
|
||||
chain: &mock.ChainService{Genesis: time.Now().Add(-oneEpoch()),
|
||||
Optimistic: true,
|
||||
DB: db,
|
||||
State: beaconState,
|
||||
ValidAttestation: true,
|
||||
@@ -697,35 +698,3 @@ func TestValidateAggregateAndProof_RejectWhenAttEpochDoesntEqualTargetEpoch(t *t
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, pubsub.ValidationReject, res)
|
||||
}
|
||||
|
||||
func TestValidateAggregateAndProof_Optimistic(t *testing.T) {
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
ctx := context.Background()
|
||||
|
||||
exit, s := setupValidExit(t)
|
||||
|
||||
r := &Service{
|
||||
cfg: &config{
|
||||
p2p: p,
|
||||
chain: &mock.ChainService{
|
||||
State: s,
|
||||
Optimistic: true,
|
||||
},
|
||||
initialSync: &mockSync.Sync{IsSyncing: false},
|
||||
},
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
_, err := p.Encoding().EncodeGossip(buf, exit)
|
||||
require.NoError(t, err)
|
||||
topic := p2p.GossipTypeMapping[reflect.TypeOf(exit)]
|
||||
m := &pubsub.Message{
|
||||
Message: &pubsubpb.Message{
|
||||
Data: buf.Bytes(),
|
||||
Topic: &topic,
|
||||
},
|
||||
}
|
||||
res, err := r.validateAggregateAndProof(ctx, "", m)
|
||||
assert.NoError(t, err)
|
||||
valid := res == pubsub.ValidationIgnore
|
||||
assert.Equal(t, true, valid, "Validation should have ignored the message")
|
||||
}
|
||||
|
||||
@@ -41,16 +41,6 @@ func (s *Service) validateCommitteeIndexBeaconAttestation(ctx context.Context, p
|
||||
return pubsub.ValidationIgnore, nil
|
||||
}
|
||||
|
||||
// We should not attempt to process this message if the node is running in optimistic mode.
|
||||
// We just ignore in p2p so that the peer is not penalized.
|
||||
optimistic, err := s.cfg.chain.IsOptimistic(ctx)
|
||||
if err != nil {
|
||||
return pubsub.ValidationReject, err
|
||||
}
|
||||
if optimistic {
|
||||
return pubsub.ValidationIgnore, nil
|
||||
}
|
||||
|
||||
ctx, span := trace.StartSpan(ctx, "sync.validateCommitteeIndexBeaconAttestation")
|
||||
defer span.End()
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -15,7 +14,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/signing"
|
||||
dbtest "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p"
|
||||
p2ptest "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/testing"
|
||||
mockSync "github.com/prysmaticlabs/prysm/v3/beacon-chain/sync/initial-sync/testing"
|
||||
lruwrpr "github.com/prysmaticlabs/prysm/v3/cache/lru"
|
||||
@@ -23,7 +21,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
||||
)
|
||||
@@ -38,6 +35,7 @@ func TestService_validateCommitteeIndexBeaconAttestation(t *testing.T) {
|
||||
ValidatorsRoot: [32]byte{'A'},
|
||||
ValidAttestation: true,
|
||||
DB: db,
|
||||
Optimistic: true,
|
||||
}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
@@ -306,37 +304,6 @@ func TestService_validateCommitteeIndexBeaconAttestation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestServiceValidateCommitteeIndexBeaconAttestation_Optimistic(t *testing.T) {
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
ctx := context.Background()
|
||||
|
||||
slashing, s := setupValidAttesterSlashing(t)
|
||||
|
||||
r := &Service{
|
||||
cfg: &config{
|
||||
p2p: p,
|
||||
chain: &mockChain.ChainService{State: s, Optimistic: true},
|
||||
initialSync: &mockSync.Sync{IsSyncing: false},
|
||||
},
|
||||
}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
_, err := p.Encoding().EncodeGossip(buf, slashing)
|
||||
require.NoError(t, err)
|
||||
|
||||
topic := p2p.GossipTypeMapping[reflect.TypeOf(slashing)]
|
||||
msg := &pubsub.Message{
|
||||
Message: &pubsubpb.Message{
|
||||
Data: buf.Bytes(),
|
||||
Topic: &topic,
|
||||
},
|
||||
}
|
||||
res, err := r.validateCommitteeIndexBeaconAttestation(ctx, "foobar", msg)
|
||||
assert.NoError(t, err)
|
||||
valid := res == pubsub.ValidationIgnore
|
||||
assert.Equal(t, true, valid, "Should have ignore this message")
|
||||
}
|
||||
|
||||
func TestService_setSeenCommitteeIndicesSlot(t *testing.T) {
|
||||
chainService := &mockChain.ChainService{
|
||||
Genesis: time.Now(),
|
||||
|
||||
@@ -588,7 +588,7 @@ func TestValidateSyncCommitteeMessage_Optimistic(t *testing.T) {
|
||||
Topic: &topic,
|
||||
},
|
||||
}
|
||||
res, err := r.validateCommitteeIndexBeaconAttestation(ctx, "foobar", msg)
|
||||
res, err := r.validateSyncCommitteeMessage(ctx, "foobar", msg)
|
||||
assert.NoError(t, err)
|
||||
valid := res == pubsub.ValidationIgnore
|
||||
assert.Equal(t, true, valid, "Should have ignore this message")
|
||||
|
||||
@@ -1054,7 +1054,7 @@ func TestValidateSyncContributionAndProof_Optimistic(t *testing.T) {
|
||||
Topic: &topic,
|
||||
},
|
||||
}
|
||||
res, err := r.validateCommitteeIndexBeaconAttestation(ctx, "foobar", msg)
|
||||
res, err := r.validateSyncContributionAndProof(ctx, "foobar", msg)
|
||||
assert.NoError(t, err)
|
||||
valid := res == pubsub.ValidationIgnore
|
||||
assert.Equal(t, true, valid, "Should have ignore this message")
|
||||
|
||||
Reference in New Issue
Block a user