From 74cca27b2f8f5ebc5d7602838d9132f786c7773c Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Mon, 6 Apr 2020 23:08:30 -0500 Subject: [PATCH] Nil Checks in Process Attestation v0.11 (#5331) * Started testing * Bunch of fixes * use-interop * Sync with v0.11 * Uncomment wait for activation * Move pending block queue from subscriber to validator pipeline * passing tests * nil checks to prevent panics * lint Co-authored-by: terence tsao --- beacon-chain/blockchain/process_attestation.go | 10 ++++++++++ .../blockchain/process_attestation_helpers.go | 16 ++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/beacon-chain/blockchain/process_attestation.go b/beacon-chain/blockchain/process_attestation.go index c20d6dc6623..6aa0d593c2a 100644 --- a/beacon-chain/blockchain/process_attestation.go +++ b/beacon-chain/blockchain/process_attestation.go @@ -125,6 +125,16 @@ func (s *Service) onAttestation(ctx context.Context, a *ethpb.Attestation) ([]ui } } + if indexedAtt.AttestingIndices == nil { + return nil, errors.New("nil attesting indices") + } + if a.Data == nil { + return nil, errors.New("nil att data") + } + if a.Data.Target == nil { + return nil, errors.New("nil att target") + } + // Update forkchoice store with the new attestation for updating weight. s.forkChoiceStore.ProcessAttestation(ctx, indexedAtt.AttestingIndices, bytesutil.ToBytes32(a.Data.BeaconBlockRoot), a.Data.Target.Epoch) diff --git a/beacon-chain/blockchain/process_attestation_helpers.go b/beacon-chain/blockchain/process_attestation_helpers.go index 3805b99555b..6f497a28f7e 100644 --- a/beacon-chain/blockchain/process_attestation_helpers.go +++ b/beacon-chain/blockchain/process_attestation_helpers.go @@ -130,14 +130,18 @@ func (s *Service) verifyAttestation(ctx context.Context, baseState *stateTrie.Be var err error if !featureconfig.Get().DisableNewStateMgmt { aState, err = s.stateGen.StateByRoot(ctx, bytesutil.ToBytes32(a.Data.BeaconBlockRoot)) - return nil, err + if err != nil { + return nil, err + } + } else { + aState, err = s.beaconDB.State(ctx, bytesutil.ToBytes32(a.Data.BeaconBlockRoot)) + if err != nil { + return nil, err + } } - - aState, err = s.beaconDB.State(ctx, bytesutil.ToBytes32(a.Data.BeaconBlockRoot)) - if err != nil { - return nil, err + if aState == nil { + return nil, fmt.Errorf("nil state for block root %#x", a.Data.BeaconBlockRoot) } - epoch := helpers.SlotToEpoch(a.Data.Slot) origSeed, err := helpers.Seed(baseState, epoch, params.BeaconConfig().DomainBeaconAttester) if err != nil {