Spans and check type (#4164)

* Spans and check type
* Typos
* Remove type checks
* Fixed a test bug
* Merge branch 'master' into subs-fixes
* Merge branch 'master' into subs-fixes
* Merge branch 'master' of https://github.com/prysmaticlabs/prysm into subs-fixes
* Revert back type assertions
* Merge branch 'master' into subs-fixes
* Merge branch 'subs-fixes' of https://github.com/prysmaticlabs/prysm into subs-fixes
* Merge branch 'master' into subs-fixes
This commit is contained in:
terence tsao
2019-12-03 11:15:01 -08:00
committed by prylabs-bulldozer[bot]
parent 32245a9062
commit 8bbc589edd
6 changed files with 29 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
"go.opencensus.io/trace"
)
// seenAttesterSlashings represents a cache of all the seen slashings
@@ -33,10 +34,14 @@ func (r *RegularSync) validateAttesterSlashing(ctx context.Context, msg proto.Me
return false, nil
}
ctx, span := trace.StartSpan(ctx, "sync.validateAttesterSlashing")
defer span.End()
slashing, ok := msg.(*ethpb.AttesterSlashing)
if !ok {
return false, nil
}
cacheKey, err := attSlashingCacheKey(slashing)
if err != nil {
return false, errors.Wrapf(err, "could not hash attestation slashing")

View File

@@ -157,7 +157,7 @@ func TestValidateAttesterSlashing_ContextTimeout(t *testing.T) {
initialSync: &mockSync.Sync{IsSyncing: false},
}
valid, _ := r.validateProposerSlashing(ctx, slashing, p2p, false /*fromSelf*/)
valid, _ := r.validateAttesterSlashing(ctx, slashing, p2p, false /*fromSelf*/)
if valid {
t.Error("slashing from the far distant future should have timed out and returned false")
}

View File

@@ -33,7 +33,10 @@ func (r *RegularSync) validateBeaconAttestation(ctx context.Context, msg proto.M
// TODO(1332): Add blocks.VerifyAttestation before processing further.
// Discussion: https://github.com/ethereum/eth2.0-specs/issues/1332
att := msg.(*ethpb.Attestation)
att, ok := msg.(*ethpb.Attestation)
if !ok {
return false, nil
}
attRoot, err := ssz.HashTreeRoot(att)
if err != nil {

View File

@@ -12,6 +12,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
"github.com/prysmaticlabs/prysm/shared/bls"
"go.opencensus.io/trace"
)
// recentlySeenBlockRoots cache with max size of ~3Mib
@@ -21,9 +22,16 @@ var recentlySeenRoots = ccache.New(ccache.Configure().MaxSize(100000))
// Blocks that have already been seen are ignored. If the BLS signature is any valid signature,
// this method rebroadcasts the message.
func (r *RegularSync) validateBeaconBlockPubSub(ctx context.Context, msg proto.Message, p p2p.Broadcaster, fromSelf bool) (bool, error) {
ctx, span := trace.StartSpan(ctx, "sync.validateBeaconBlockPubSub")
defer span.End()
r.validateBlockLock.Lock()
defer r.validateBlockLock.Unlock()
m := msg.(*ethpb.BeaconBlock)
m, ok := msg.(*ethpb.BeaconBlock)
if !ok {
return false, nil
}
blockRoot, err := ssz.SigningRoot(m)
if err != nil {

View File

@@ -11,6 +11,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"go.opencensus.io/trace"
)
// seenProposerSlashings represents a cache of all the seen slashings
@@ -32,10 +33,14 @@ func (r *RegularSync) validateProposerSlashing(ctx context.Context, msg proto.Me
return false, nil
}
ctx, span := trace.StartSpan(ctx, "sync.validateProposerSlashing")
defer span.End()
slashing, ok := msg.(*ethpb.ProposerSlashing)
if !ok {
return false, nil
}
cacheKey, err := propSlashingCacheKey(slashing)
if err != nil {
return false, errors.Wrapf(err, "could not hash proposer slashing")

View File

@@ -12,6 +12,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
"github.com/prysmaticlabs/prysm/shared/params"
"go.opencensus.io/trace"
)
// seenExits tracks exits we've already seen to prevent feedback loop.
@@ -29,10 +30,14 @@ func (r *RegularSync) validateVoluntaryExit(ctx context.Context, msg proto.Messa
return false, nil
}
ctx, span := trace.StartSpan(ctx, "sync.validateVoluntaryExit")
defer span.End()
exit, ok := msg.(*ethpb.VoluntaryExit)
if !ok {
return false, nil
}
cacheKey := exitCacheKey(exit)
invalidKey := invalid + cacheKey
if seenExits.Get(invalidKey) != nil {