diff --git a/beacon-chain/blockchain/info_test.go b/beacon-chain/blockchain/info_test.go index 2435561f488c..cfe63ba650d8 100644 --- a/beacon-chain/blockchain/info_test.go +++ b/beacon-chain/blockchain/info_test.go @@ -33,6 +33,7 @@ func TestService_TreeHandler(t *testing.T) { StateGen: stategen.New(db, sCache), } s, err := NewService(ctx, cfg) + require.NoError(t, err) require.NoError(t, s.forkChoiceStore.ProcessBlock(ctx, 0, [32]byte{'a'}, [32]byte{'g'}, [32]byte{'c'}, 0, 0)) require.NoError(t, s.forkChoiceStore.ProcessBlock(ctx, 1, [32]byte{'b'}, [32]byte{'a'}, [32]byte{'c'}, 0, 0)) s.setHead([32]byte{'a'}, testutil.NewBeaconBlock(), headState) diff --git a/beacon-chain/blockchain/process_block.go b/beacon-chain/blockchain/process_block.go index e8b7090e73ce..de1eb8d9abda 100644 --- a/beacon-chain/blockchain/process_block.go +++ b/beacon-chain/blockchain/process_block.go @@ -235,7 +235,7 @@ func (s *Service) onBlockBatch(ctx context.Context, blks []*ethpb.SignedBeaconBl PublicKeys: []bls.PublicKey{}, Messages: [][32]byte{}, } - set := new(bls.SignatureSet) + var set *bls.SignatureSet boundaries := make(map[[32]byte]*stateTrie.BeaconState) for i, b := range blks { set, preState, err = state.ExecuteStateTransitionNoVerifyAnySig(ctx, preState, b) diff --git a/beacon-chain/blockchain/receive_block_test.go b/beacon-chain/blockchain/receive_block_test.go index ff43c750c155..dced00a2956e 100644 --- a/beacon-chain/blockchain/receive_block_test.go +++ b/beacon-chain/blockchain/receive_block_test.go @@ -139,6 +139,7 @@ func TestService_ReceiveBlock(t *testing.T) { gBlk, err := s.beaconDB.GenesisBlock(ctx) require.NoError(t, err) gRoot, err := gBlk.Block.HashTreeRoot() + require.NoError(t, err) s.finalizedCheckpt = ðpb.Checkpoint{Root: gRoot[:]} root, err := tt.args.block.Block.HashTreeRoot() require.NoError(t, err) @@ -179,6 +180,7 @@ func TestService_ReceiveBlockUpdateHead(t *testing.T) { gBlk, err := s.beaconDB.GenesisBlock(ctx) require.NoError(t, err) gRoot, err := gBlk.Block.HashTreeRoot() + require.NoError(t, err) s.finalizedCheckpt = ðpb.Checkpoint{Root: gRoot[:]} root, err := b.Block.HashTreeRoot() require.NoError(t, err) @@ -261,6 +263,7 @@ func TestService_ReceiveBlockInitialSync(t *testing.T) { require.NoError(t, err) gRoot, err := gBlk.Block.HashTreeRoot() + require.NoError(t, err) s.finalizedCheckpt = ðpb.Checkpoint{Root: gRoot[:]} root, err := tt.args.block.Block.HashTreeRoot() require.NoError(t, err) @@ -341,6 +344,7 @@ func TestService_ReceiveBlockBatch(t *testing.T) { require.NoError(t, err) gRoot, err := gBlk.Block.HashTreeRoot() + require.NoError(t, err) s.finalizedCheckpt = ðpb.Checkpoint{Root: gRoot[:]} root, err := tt.args.block.Block.HashTreeRoot() require.NoError(t, err) diff --git a/beacon-chain/blockchain/service_test.go b/beacon-chain/blockchain/service_test.go index 684e038cb6bc..12d709e4e66d 100644 --- a/beacon-chain/blockchain/service_test.go +++ b/beacon-chain/blockchain/service_test.go @@ -204,6 +204,7 @@ func TestChainService_InitializeBeaconChain(t *testing.T) { DepositCount: uint64(len(deposits)), BlockHash: make([]byte, 32), }) + require.NoError(t, err) genState, err = b.ProcessPreGenesisDeposits(ctx, genState, deposits) require.NoError(t, err) diff --git a/beacon-chain/cache/committee_test.go b/beacon-chain/cache/committee_test.go index 3a503412141c..903b1d02dc04 100644 --- a/beacon-chain/cache/committee_test.go +++ b/beacon-chain/cache/committee_test.go @@ -89,9 +89,7 @@ func TestCommitteeCache_ActiveCount(t *testing.T) { func TestCommitteeCache_AddProposerIndicesList(t *testing.T) { cache := NewCommitteesCache() - seed := [32]byte{'A'} - indices := []uint64{1, 2, 3, 4, 5} indices, err := cache.ProposerIndices(seed) require.NoError(t, err) if indices != nil { diff --git a/beacon-chain/core/blocks/attestation_test.go b/beacon-chain/core/blocks/attestation_test.go index 0d9a489f3563..1ca5f5333b32 100644 --- a/beacon-chain/core/blocks/attestation_test.go +++ b/beacon-chain/core/blocks/attestation_test.go @@ -807,6 +807,7 @@ func TestVerifyAttestations_HandlesPlannedFork(t *testing.T) { Signature: make([]byte, 96), } currDomain, err := helpers.Domain(st.Fork(), st.Fork().Epoch, params.BeaconConfig().DomainBeaconAttester, st.GenesisValidatorRoot()) + require.NoError(t, err) root, err = helpers.ComputeSigningRoot(att2.Data, currDomain) require.NoError(t, err) sigs = nil diff --git a/beacon-chain/core/blocks/block_operations_fuzz_test.go b/beacon-chain/core/blocks/block_operations_fuzz_test.go index 5332362d2ea3..e3433a4d024c 100644 --- a/beacon-chain/core/blocks/block_operations_fuzz_test.go +++ b/beacon-chain/core/blocks/block_operations_fuzz_test.go @@ -6,13 +6,12 @@ import ( fuzz "github.com/google/gofuzz" eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" + beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state" stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" + ethereum_beacon_p2p_v1 "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" "github.com/prysmaticlabs/prysm/shared/params" - - //"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" - beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state" - ethereum_beacon_p2p_v1 "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" + "github.com/prysmaticlabs/prysm/shared/testutil/require" ) func TestFuzzProcessAttestationNoVerify_10000(t *testing.T) { @@ -25,6 +24,7 @@ func TestFuzzProcessAttestationNoVerify_10000(t *testing.T) { fuzzer.Fuzz(state) fuzzer.Fuzz(att) s, err := beaconstate.InitializeFromProtoUnsafe(state) + require.NoError(t, err) _, err = ProcessAttestationNoVerifySignature(ctx, s, att) _ = err } @@ -40,6 +40,7 @@ func TestFuzzProcessBlockHeader_10000(t *testing.T) { fuzzer.Fuzz(block) s, err := beaconstate.InitializeFromProtoUnsafe(state) + require.NoError(t, err) _, err = ProcessBlockHeader(context.Background(), s, block) _ = err } @@ -63,6 +64,7 @@ func TestFuzzverifyDepositDataSigningRoot_10000(t *testing.T) { fuzzer.Fuzz(&s) fuzzer.Fuzz(&d) err := verifySignature(ba, pubkey[:], sig[:], domain[:]) + _ = err err = verifySignature(ba, p, s, d) _ = err } @@ -105,6 +107,7 @@ func TestFuzzEth1DataHasEnoughSupport_10000(t *testing.T) { s, err := beaconstate.InitializeFromProto(ðereum_beacon_p2p_v1.BeaconState{ Eth1DataVotes: stateVotes, }) + require.NoError(t, err) _, err = Eth1DataHasEnoughSupport(s, eth1data) _ = err } @@ -120,6 +123,7 @@ func TestFuzzProcessBlockHeaderNoVerify_10000(t *testing.T) { fuzzer.Fuzz(state) fuzzer.Fuzz(block) s, err := beaconstate.InitializeFromProtoUnsafe(state) + require.NoError(t, err) _, err = ProcessBlockHeaderNoVerify(s, block) _ = err } @@ -134,6 +138,7 @@ func TestFuzzProcessRandao_10000(t *testing.T) { fuzzer.Fuzz(state) fuzzer.Fuzz(b) s, err := beaconstate.InitializeFromProtoUnsafe(state) + require.NoError(t, err) r, err := ProcessRandao(context.Background(), s, b) if err != nil && r != nil { t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, b) @@ -150,6 +155,7 @@ func TestFuzzProcessRandaoNoVerify_10000(t *testing.T) { fuzzer.Fuzz(state) fuzzer.Fuzz(blockBody) s, err := beaconstate.InitializeFromProtoUnsafe(state) + require.NoError(t, err) r, err := ProcessRandaoNoVerify(s, blockBody) if err != nil && r != nil { t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, blockBody) @@ -166,6 +172,7 @@ func TestFuzzProcessProposerSlashings_10000(t *testing.T) { fuzzer.Fuzz(state) fuzzer.Fuzz(b) s, err := beaconstate.InitializeFromProtoUnsafe(state) + require.NoError(t, err) r, err := ProcessProposerSlashings(ctx, s, b) if err != nil && r != nil { t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, b) @@ -181,6 +188,7 @@ func TestFuzzVerifyProposerSlashing_10000(t *testing.T) { fuzzer.Fuzz(state) fuzzer.Fuzz(proposerSlashing) s, err := beaconstate.InitializeFromProtoUnsafe(state) + require.NoError(t, err) err = VerifyProposerSlashing(s, proposerSlashing) _ = err } @@ -195,6 +203,7 @@ func TestFuzzProcessAttesterSlashings_10000(t *testing.T) { fuzzer.Fuzz(state) fuzzer.Fuzz(b) s, err := beaconstate.InitializeFromProtoUnsafe(state) + require.NoError(t, err) r, err := ProcessAttesterSlashings(ctx, s, b) if err != nil && r != nil { t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, b) @@ -211,6 +220,7 @@ func TestFuzzVerifyAttesterSlashing_10000(t *testing.T) { fuzzer.Fuzz(state) fuzzer.Fuzz(attesterSlashing) s, err := beaconstate.InitializeFromProtoUnsafe(state) + require.NoError(t, err) err = VerifyAttesterSlashing(ctx, s, attesterSlashing) _ = err } @@ -247,6 +257,7 @@ func TestFuzzProcessAttestations_10000(t *testing.T) { fuzzer.Fuzz(state) fuzzer.Fuzz(b) s, err := beaconstate.InitializeFromProtoUnsafe(state) + require.NoError(t, err) r, err := ProcessAttestations(ctx, s, b) if err != nil && r != nil { t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, b) @@ -263,6 +274,7 @@ func TestFuzzProcessAttestationsNoVerify_10000(t *testing.T) { fuzzer.Fuzz(state) fuzzer.Fuzz(b) s, err := beaconstate.InitializeFromProtoUnsafe(state) + require.NoError(t, err) r, err := ProcessAttestationsNoVerifySignature(ctx, s, b) if err != nil && r != nil { t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, b) @@ -279,6 +291,7 @@ func TestFuzzProcessAttestation_10000(t *testing.T) { fuzzer.Fuzz(state) fuzzer.Fuzz(attestation) s, err := beaconstate.InitializeFromProtoUnsafe(state) + require.NoError(t, err) r, err := ProcessAttestation(ctx, s, attestation) if err != nil && r != nil { t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, attestation) @@ -295,6 +308,7 @@ func TestFuzzVerifyIndexedAttestationn_10000(t *testing.T) { fuzzer.Fuzz(state) fuzzer.Fuzz(idxAttestation) s, err := beaconstate.InitializeFromProtoUnsafe(state) + require.NoError(t, err) err = VerifyIndexedAttestation(ctx, s, idxAttestation) _ = err } @@ -309,6 +323,7 @@ func TestFuzzVerifyAttestation_10000(t *testing.T) { fuzzer.Fuzz(state) fuzzer.Fuzz(attestation) s, err := beaconstate.InitializeFromProtoUnsafe(state) + require.NoError(t, err) err = VerifyAttestationSignature(ctx, s, attestation) _ = err } @@ -323,6 +338,7 @@ func TestFuzzProcessDeposits_10000(t *testing.T) { fuzzer.Fuzz(state) fuzzer.Fuzz(b) s, err := beaconstate.InitializeFromProtoUnsafe(state) + require.NoError(t, err) r, err := ProcessDeposits(ctx, s, b) if err != nil && r != nil { t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, b) @@ -340,6 +356,7 @@ func TestFuzzProcessPreGenesisDeposit_10000(t *testing.T) { fuzzer.Fuzz(state) fuzzer.Fuzz(deposit) s, err := beaconstate.InitializeFromProtoUnsafe(state) + require.NoError(t, err) r, err := ProcessPreGenesisDeposits(ctx, s, []*eth.Deposit{deposit}) if err != nil && r != nil { t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, deposit) @@ -356,6 +373,7 @@ func TestFuzzProcessDeposit_10000(t *testing.T) { fuzzer.Fuzz(state) fuzzer.Fuzz(deposit) s, err := beaconstate.InitializeFromProtoUnsafe(state) + require.NoError(t, err) r, err := ProcessDeposit(s, deposit, true) if err != nil && r != nil { t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, deposit) @@ -371,6 +389,7 @@ func TestFuzzverifyDeposit_10000(t *testing.T) { fuzzer.Fuzz(state) fuzzer.Fuzz(deposit) s, err := beaconstate.InitializeFromProtoUnsafe(state) + require.NoError(t, err) err = verifyDeposit(s, deposit) _ = err } @@ -385,6 +404,7 @@ func TestFuzzProcessVoluntaryExits_10000(t *testing.T) { fuzzer.Fuzz(state) fuzzer.Fuzz(b) s, err := beaconstate.InitializeFromProtoUnsafe(state) + require.NoError(t, err) r, err := ProcessVoluntaryExits(ctx, s, b) if err != nil && r != nil { t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, b) @@ -400,6 +420,7 @@ func TestFuzzProcessVoluntaryExitsNoVerify_10000(t *testing.T) { fuzzer.Fuzz(state) fuzzer.Fuzz(b) s, err := beaconstate.InitializeFromProtoUnsafe(state) + require.NoError(t, err) r, err := ProcessVoluntaryExits(context.Background(), s, b) if err != nil && r != nil { t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, b) diff --git a/beacon-chain/core/epoch/epoch_processing_fuzz_test.go b/beacon-chain/core/epoch/epoch_processing_fuzz_test.go index d605f02e7d52..8b3cfea0ff41 100644 --- a/beacon-chain/core/epoch/epoch_processing_fuzz_test.go +++ b/beacon-chain/core/epoch/epoch_processing_fuzz_test.go @@ -18,5 +18,6 @@ func TestFuzzFinalUpdates_10000(t *testing.T) { s, err := beaconstate.InitializeFromProtoUnsafe(base) require.NoError(t, err) _, err = ProcessFinalUpdates(s) + _ = err } } diff --git a/beacon-chain/core/epoch/epoch_processing_test.go b/beacon-chain/core/epoch/epoch_processing_test.go index 62ed6c7e50a6..3bacea559f3b 100644 --- a/beacon-chain/core/epoch/epoch_processing_test.go +++ b/beacon-chain/core/epoch/epoch_processing_test.go @@ -333,6 +333,7 @@ func TestProcessRegistryUpdates_EligibleToActivate(t *testing.T) { }) } state, err := state.InitializeFromProto(base) + require.NoError(t, err) currentEpoch := helpers.CurrentEpoch(state) newState, err := epoch.ProcessRegistryUpdates(state) require.NoError(t, err) diff --git a/beacon-chain/core/epoch/precompute/attestation_test.go b/beacon-chain/core/epoch/precompute/attestation_test.go index 441e2e5ddfa2..bcbafdac81a2 100644 --- a/beacon-chain/core/epoch/precompute/attestation_test.go +++ b/beacon-chain/core/epoch/precompute/attestation_test.go @@ -178,8 +178,7 @@ func TestProcessAttestations(t *testing.T) { for i := 0; i < len(pVals); i++ { pVals[i] = &precompute.Validator{CurrentEpochEffectiveBalance: 100} } - pBal := &precompute.Balance{} - pVals, pBal, err = precompute.ProcessAttestations(context.Background(), beaconState, pVals, pBal) + pVals, _, err = precompute.ProcessAttestations(context.Background(), beaconState, pVals, &precompute.Balance{}) require.NoError(t, err) committee, err := helpers.BeaconCommitteeFromState(beaconState, att1.Data.Slot, att1.Data.CommitteeIndex) diff --git a/beacon-chain/core/epoch/precompute/reward_penalty_test.go b/beacon-chain/core/epoch/precompute/reward_penalty_test.go index 3f615d54e920..a71686f333f9 100644 --- a/beacon-chain/core/epoch/precompute/reward_penalty_test.go +++ b/beacon-chain/core/epoch/precompute/reward_penalty_test.go @@ -202,7 +202,7 @@ func TestAttestationDeltas_ZeroInclusionDelay(t *testing.T) { pVals, pBal, err := New(context.Background(), state) require.NoError(t, err) - pVals, pBal, err = ProcessAttestations(context.Background(), state, pVals, pBal) + _, _, err = ProcessAttestations(context.Background(), state, pVals, pBal) require.ErrorContains(t, "attestation with inclusion delay of 0", err) } diff --git a/beacon-chain/core/helpers/signing_root_test.go b/beacon-chain/core/helpers/signing_root_test.go index 54e9c9f6f836..1515cc148c4a 100644 --- a/beacon-chain/core/helpers/signing_root_test.go +++ b/beacon-chain/core/helpers/signing_root_test.go @@ -76,6 +76,7 @@ func TestFuzzverifySigningRoot_10000(t *testing.T) { fuzzer.Fuzz(&s) fuzzer.Fuzz(&d) err := helpers.VerifySigningRoot(state, pubkey[:], sig[:], domain[:]) + _ = err err = helpers.VerifySigningRoot(state, p, s, d) _ = err } diff --git a/beacon-chain/forkchoice/protoarray/no_vote_test.go b/beacon-chain/forkchoice/protoarray/no_vote_test.go index 937981fca1e3..3ce187affdd3 100644 --- a/beacon-chain/forkchoice/protoarray/no_vote_test.go +++ b/beacon-chain/forkchoice/protoarray/no_vote_test.go @@ -81,7 +81,7 @@ func TestNoVote_CanFindHead(t *testing.T) { // head -> 4 3 // | // 5 <- starting from 5 with justified epoch 0 should error - r, err = f.Head(context.Background(), 1, indexToHash(5), balances, 1) + _, err = f.Head(context.Background(), 1, indexToHash(5), balances, 1) wanted := "head at slot 0 with weight 0 is not eligible, finalizedEpoch 1 != 1, justifiedEpoch 2 != 1" require.ErrorContains(t, wanted, err) diff --git a/beacon-chain/forkchoice/protoarray/nodes.go b/beacon-chain/forkchoice/protoarray/nodes.go index c798d7cfc0fa..0d411a332039 100644 --- a/beacon-chain/forkchoice/protoarray/nodes.go +++ b/beacon-chain/forkchoice/protoarray/nodes.go @@ -209,7 +209,7 @@ func (s *Store) updateBestChildAndDescendant(parentIndex uint64, childIndex uint } changeToChild := []uint64{childIndex, bestDescendant} noChange := []uint64{parent.bestChild, parent.bestDescendant} - newParentChild := make([]uint64, 0) + var newParentChild []uint64 if parent.bestChild != NonExistentNode { if parent.bestChild == childIndex && !childLeadsToViableHead { diff --git a/beacon-chain/p2p/connection_gater_test.go b/beacon-chain/p2p/connection_gater_test.go index accef1bce071..2934e463b92a 100644 --- a/beacon-chain/p2p/connection_gater_test.go +++ b/beacon-chain/p2p/connection_gater_test.go @@ -53,6 +53,7 @@ func TestPeer_AtMaxLimit(t *testing.T) { require.NoError(t, err) }() multiAddress, err := multiaddr.NewMultiaddr(fmt.Sprintf("/ip4/%s/tcp/%d/p2p/%s", ipAddr, 2000, h1.ID())) + require.NoError(t, err) addrInfo, err := peer.AddrInfoFromP2pAddr(multiAddress) require.NoError(t, err) err = h2.Connect(context.Background(), *addrInfo) @@ -121,6 +122,7 @@ func TestPeer_BelowMaxLimit(t *testing.T) { require.NoError(t, err) }() multiAddress, err := multiaddr.NewMultiaddr(fmt.Sprintf("/ip4/%s/tcp/%d/p2p/%s", ipAddr, 2000, h1.ID())) + require.NoError(t, err) addrInfo, err := peer.AddrInfoFromP2pAddr(multiAddress) require.NoError(t, err) err = h2.Connect(context.Background(), *addrInfo) @@ -162,6 +164,7 @@ func TestPeerAllowList(t *testing.T) { require.NoError(t, err) }() multiAddress, err := multiaddr.NewMultiaddr(fmt.Sprintf("/ip4/%s/tcp/%d/p2p/%s", ipAddr2, 3000, h2.ID())) + require.NoError(t, err) addrInfo, err := peer.AddrInfoFromP2pAddr(multiAddress) require.NoError(t, err) err = h1.Connect(context.Background(), *addrInfo) @@ -204,6 +207,7 @@ func TestPeerDenyList(t *testing.T) { require.NoError(t, err) }() multiAddress, err := multiaddr.NewMultiaddr(fmt.Sprintf("/ip4/%s/tcp/%d/p2p/%s", ipAddr2, 3000, h2.ID())) + require.NoError(t, err) addrInfo, err := peer.AddrInfoFromP2pAddr(multiAddress) require.NoError(t, err) err = h1.Connect(context.Background(), *addrInfo) diff --git a/beacon-chain/p2p/encoder/ssz.go b/beacon-chain/p2p/encoder/ssz.go index 2a399dc7282f..5a1e6ad28176 100644 --- a/beacon-chain/p2p/encoder/ssz.go +++ b/beacon-chain/p2p/encoder/ssz.go @@ -88,6 +88,9 @@ func (e SszNetworkEncoder) doDecode(b []byte, to interface{}) error { // DecodeGossip decodes the bytes to the protobuf gossip message provided. func (e SszNetworkEncoder) DecodeGossip(b []byte, to interface{}) error { size, err := snappy.DecodedLen(b) + if err != nil { + return err + } if uint64(size) > MaxGossipSize { return errors.Errorf("gossip message exceeds max gossip size: %d bytes > %d bytes", size, MaxGossipSize) } diff --git a/beacon-chain/p2p/fork.go b/beacon-chain/p2p/fork.go index d63e284b8fe5..118076a7412a 100644 --- a/beacon-chain/p2p/fork.go +++ b/beacon-chain/p2p/fork.go @@ -88,7 +88,7 @@ func addForkEntry( currentSlot := helpers.SlotsSince(genesisTime) currentEpoch := helpers.SlotToEpoch(currentSlot) if timeutils.Now().Before(genesisTime) { - currentSlot, currentEpoch = 0, 0 + currentEpoch = 0 } fork, err := p2putils.Fork(currentEpoch) if err != nil { diff --git a/beacon-chain/p2p/options_test.go b/beacon-chain/p2p/options_test.go index 07ed64e07c8b..56f30f5be132 100644 --- a/beacon-chain/p2p/options_test.go +++ b/beacon-chain/p2p/options_test.go @@ -53,6 +53,7 @@ func TestPrivateKeyLoading(t *testing.T) { func TestIPV6Support(t *testing.T) { key, err := gethCrypto.GenerateKey() + require.NoError(t, err) db, err := enode.OpenDB("") if err != nil { log.Error("could not open node's peer database") diff --git a/beacon-chain/p2p/peers/status_test.go b/beacon-chain/p2p/peers/status_test.go index a80ca6f95908..a951c971fa7b 100644 --- a/beacon-chain/p2p/peers/status_test.go +++ b/beacon-chain/p2p/peers/status_test.go @@ -460,12 +460,12 @@ func TestPrune(t *testing.T) { // Not so good peer is pruned away so that we can reduce the // total size of the handler. - badRes, err = scorer.Count(secondPID) - assert.NotNil(t, err, "error is supposed to be not nil") + _, err = scorer.Count(secondPID) + assert.ErrorContains(t, "peer unknown", err) // Last peer has been removed. - badRes, err = scorer.Count(thirdPID) - assert.NotNil(t, err, "error is supposed to be not nil") + _, err = scorer.Count(thirdPID) + assert.ErrorContains(t, "peer unknown", err) } func TestTrimmedOrderedPeers(t *testing.T) { diff --git a/beacon-chain/p2p/service_test.go b/beacon-chain/p2p/service_test.go index e8b740df04b2..f7436caf8450 100644 --- a/beacon-chain/p2p/service_test.go +++ b/beacon-chain/p2p/service_test.go @@ -61,8 +61,8 @@ func (mockListener) RandomNodes() enode.Iterator { } func createHost(t *testing.T, port int) (host.Host, *ecdsa.PrivateKey, net.IP) { - ipAddr, pkey := createAddrAndPrivKey(t) - ipAddr = net.ParseIP("127.0.0.1") + _, pkey := createAddrAndPrivKey(t) + ipAddr := net.ParseIP("127.0.0.1") listen, err := multiaddr.NewMultiaddr(fmt.Sprintf("/ip4/%s/tcp/%d", ipAddr, port)) require.NoError(t, err, "Failed to p2p listen") h, err := libp2p.New(context.Background(), []libp2p.Option{privKeyOption(pkey), libp2p.ListenAddrs(listen)}...) diff --git a/beacon-chain/p2p/testing/mock_peersprovider.go b/beacon-chain/p2p/testing/mock_peersprovider.go index a7e80bede0ce..936226ad52c1 100644 --- a/beacon-chain/p2p/testing/mock_peersprovider.go +++ b/beacon-chain/p2p/testing/mock_peersprovider.go @@ -63,6 +63,9 @@ func (m *MockPeersProvider) Peers() *peers.Status { func createENR() *enr.Record { key, err := crypto.GenerateKey() + if err != nil { + log.Error(err) + } db, err := enode.OpenDB("") if err != nil { log.Error("could not open node's peer database") diff --git a/beacon-chain/rpc/beacon/attestations.go b/beacon-chain/rpc/beacon/attestations.go index 3c8941dd57ca..261a7ae8b14b 100644 --- a/beacon-chain/rpc/beacon/attestations.go +++ b/beacon-chain/rpc/beacon/attestations.go @@ -114,7 +114,7 @@ func (bs *Server) ListAttestations( func (bs *Server) ListIndexedAttestations( ctx context.Context, req *ethpb.ListIndexedAttestationsRequest, ) (*ethpb.ListIndexedAttestationsResponse, error) { - blocks := make([]*ethpb.SignedBeaconBlock, 0) + var blocks []*ethpb.SignedBeaconBlock var err error switch q := req.QueryFilter.(type) { case *ethpb.ListIndexedAttestationsRequest_GenesisEpoch: diff --git a/beacon-chain/rpc/beacon/blocks_test.go b/beacon-chain/rpc/beacon/blocks_test.go index dca5d26d01a2..f7fd17f31628 100644 --- a/beacon-chain/rpc/beacon/blocks_test.go +++ b/beacon-chain/rpc/beacon/blocks_test.go @@ -497,6 +497,7 @@ func TestServer_StreamChainHead_OnHeadUpdated(t *testing.T) { b := testutil.NewBeaconBlock() b.Block.Slot, err = helpers.StartSlot(s.PreviousJustifiedCheckpoint().Epoch) + require.NoError(t, err) hRoot, err := b.Block.HashTreeRoot() require.NoError(t, err) diff --git a/beacon-chain/rpc/beacon/validators.go b/beacon-chain/rpc/beacon/validators.go index 2e45be2cd25c..8b120d2c0777 100644 --- a/beacon-chain/rpc/beacon/validators.go +++ b/beacon-chain/rpc/beacon/validators.go @@ -41,8 +41,6 @@ func (bs *Server) ListValidatorBalances( requestedEpoch = q.Epoch case *ethpb.ListValidatorBalancesRequest_Genesis: requestedEpoch = 0 - default: - requestedEpoch = currentEpoch } if requestedEpoch > currentEpoch { @@ -193,7 +191,8 @@ func (bs *Server) ListValidators( var reqState *statetrie.BeaconState var err error if requestedEpoch != currentEpoch { - s, err := helpers.StartSlot(requestedEpoch) + var s uint64 + s, err = helpers.StartSlot(requestedEpoch) if err != nil { return nil, err } @@ -382,11 +381,6 @@ func (bs *Server) GetValidatorActiveSetChanges( ) } - activatedIndices := make([]uint64, 0) - exitedIndices := make([]uint64, 0) - slashedIndices := make([]uint64, 0) - ejectedIndices := make([]uint64, 0) - s, err := helpers.StartSlot(requestedEpoch) if err != nil { return nil, err @@ -401,13 +395,13 @@ func (bs *Server) GetValidatorActiveSetChanges( return nil, status.Errorf(codes.Internal, "Could not get active validator count: %v", err) } vs := requestedState.Validators() - activatedIndices = validators.ActivatedValidatorIndices(helpers.CurrentEpoch(requestedState), vs) - exitedIndices, err = validators.ExitedValidatorIndices(helpers.CurrentEpoch(requestedState), vs, activeValidatorCount) + activatedIndices := validators.ActivatedValidatorIndices(helpers.CurrentEpoch(requestedState), vs) + exitedIndices, err := validators.ExitedValidatorIndices(helpers.CurrentEpoch(requestedState), vs, activeValidatorCount) if err != nil { return nil, status.Errorf(codes.Internal, "Could not determine exited validator indices: %v", err) } - slashedIndices = validators.SlashedValidatorIndices(helpers.CurrentEpoch(requestedState), vs) - ejectedIndices, err = validators.EjectedValidatorIndices(helpers.CurrentEpoch(requestedState), vs, activeValidatorCount) + slashedIndices := validators.SlashedValidatorIndices(helpers.CurrentEpoch(requestedState), vs) + ejectedIndices, err := validators.EjectedValidatorIndices(helpers.CurrentEpoch(requestedState), vs, activeValidatorCount) if err != nil { return nil, status.Errorf(codes.Internal, "Could not determine ejected validator indices: %v", err) } @@ -552,7 +546,6 @@ func (bs *Server) GetValidatorQueue( }) // Only activate just enough validators according to the activation churn limit. - activationQueueChurn := uint64(len(activationQ)) activeValidatorCount, err := helpers.ActiveValidatorCount(headState, helpers.CurrentEpoch(headState)) if err != nil { return nil, status.Errorf(codes.Internal, "Could not get active validator count: %v", err) @@ -575,13 +568,9 @@ func (bs *Server) GetValidatorQueue( } } // Prevent churn limit from causing index out of bound issues. - if churnLimit < activationQueueChurn { - activationQueueChurn = churnLimit - } if churnLimit < exitQueueChurn { // If we are above the churn limit, we simply increase the churn by one. exitQueueEpoch++ - exitQueueChurn = churnLimit } // We use the exit queue churn to determine if we have passed a churn limit. @@ -786,11 +775,11 @@ func (bs *Server) GetIndividualVotes( return filteredIndices[i] < filteredIndices[j] }) - v, b, err := precompute.New(ctx, requestedState) + v, bal, err := precompute.New(ctx, requestedState) if err != nil { return nil, status.Errorf(codes.Internal, "Could not set up pre compute instance: %v", err) } - v, b, err = precompute.ProcessAttestations(ctx, requestedState, v, b) + v, _, err = precompute.ProcessAttestations(ctx, requestedState, v, bal) if err != nil { return nil, status.Errorf(codes.Internal, "Could not pre compute attestations: %v", err) } diff --git a/beacon-chain/rpc/beacon/validators_test.go b/beacon-chain/rpc/beacon/validators_test.go index abd7360db9af..5b1763d6d8b0 100644 --- a/beacon-chain/rpc/beacon/validators_test.go +++ b/beacon-chain/rpc/beacon/validators_test.go @@ -1608,7 +1608,7 @@ func TestGetValidatorPerformance_Indices(t *testing.T) { require.NoError(t, err) vp, bp, err = precompute.ProcessAttestations(ctx, c, vp, bp) require.NoError(t, err) - c, err = precompute.ProcessRewardsAndPenaltiesPrecompute(c, bp, vp) + _, err = precompute.ProcessRewardsAndPenaltiesPrecompute(c, bp, vp) require.NoError(t, err) farFuture := params.BeaconConfig().FarFutureEpoch want := ðpb.ValidatorPerformanceResponse{ @@ -1679,7 +1679,7 @@ func TestGetValidatorPerformance_IndicesPubkeys(t *testing.T) { require.NoError(t, err) vp, bp, err = precompute.ProcessAttestations(ctx, c, vp, bp) require.NoError(t, err) - c, err = precompute.ProcessRewardsAndPenaltiesPrecompute(c, bp, vp) + _, err = precompute.ProcessRewardsAndPenaltiesPrecompute(c, bp, vp) require.NoError(t, err) farFuture := params.BeaconConfig().FarFutureEpoch want := ðpb.ValidatorPerformanceResponse{ diff --git a/beacon-chain/rpc/node/server.go b/beacon-chain/rpc/node/server.go index b82e3fd2af2d..834323f20fb3 100644 --- a/beacon-chain/rpc/node/server.go +++ b/beacon-chain/rpc/node/server.go @@ -102,7 +102,7 @@ func (ns *Server) GetHost(ctx context.Context, _ *ptypes.Empty) (*ethpb.HostData } record := ns.PeerManager.ENR() enr := "" - err := error(nil) + var err error if record != nil { enr, err = p2p.SerializeENR(record) if err != nil { diff --git a/beacon-chain/rpc/node/server_test.go b/beacon-chain/rpc/node/server_test.go index 7abb54279690..0ca1a3e7ae07 100644 --- a/beacon-chain/rpc/node/server_test.go +++ b/beacon-chain/rpc/node/server_test.go @@ -96,6 +96,7 @@ func TestNodeServer_GetHost(t *testing.T) { peersProvider := &mockP2p.MockPeersProvider{} mP2P := mockP2p.NewTestP2P(t) key, err := crypto.GenerateKey() + require.NoError(t, err) db, err := enode.OpenDB("") require.NoError(t, err) lNode := enode.NewLocalNode(db, key) diff --git a/beacon-chain/rpc/validator/attester.go b/beacon-chain/rpc/validator/attester.go index 5e80bb135b50..80111f5d70da 100644 --- a/beacon-chain/rpc/validator/attester.go +++ b/beacon-chain/rpc/validator/attester.go @@ -108,7 +108,7 @@ func (vs *Server) GetAttestationData(ctx context.Context, req *ethpb.Attestation if err != nil { return nil, err } - targetRoot := make([]byte, 32) + var targetRoot []byte if epochStartSlot == headState.Slot() { targetRoot = headRoot } else { diff --git a/beacon-chain/rpc/validator/server_test.go b/beacon-chain/rpc/validator/server_test.go index 8f7e411fe6df..d16490476ab1 100644 --- a/beacon-chain/rpc/validator/server_test.go +++ b/beacon-chain/rpc/validator/server_test.go @@ -282,8 +282,6 @@ func TestWaitForActivation_MultipleStatuses(t *testing.T) { func TestWaitForChainStart_ContextClosed(t *testing.T) { db, _ := dbutil.SetupDB(t) - ctx := context.Background() - ctx, cancel := context.WithCancel(context.Background()) chainService := &mockChain.ChainService{} Server := &Server{ @@ -427,8 +425,6 @@ func TestWaitForChainStart_NotStartedThenLogFired(t *testing.T) { func TestWaitForSynced_ContextClosed(t *testing.T) { db, _ := dbutil.SetupDB(t) - ctx := context.Background() - ctx, cancel := context.WithCancel(context.Background()) chainService := &mockChain.ChainService{} Server := &Server{ diff --git a/beacon-chain/rpc/validator/status_test.go b/beacon-chain/rpc/validator/status_test.go index 0926144b5b55..40d0e700c6ec 100644 --- a/beacon-chain/rpc/validator/status_test.go +++ b/beacon-chain/rpc/validator/status_test.go @@ -521,6 +521,7 @@ func TestActivationStatus_OK(t *testing.T) { ctx := context.Background() deposits, _, err := testutil.DeterministicDepositsAndKeys(4) + require.NoError(t, err) pubKeys := [][]byte{deposits[0].Data.PublicKey, deposits[1].Data.PublicKey, deposits[2].Data.PublicKey, deposits[3].Data.PublicKey} stateObj, err := stateTrie.InitializeFromProtoUnsafe(&pbp2p.BeaconState{ Slot: 4000, @@ -543,6 +544,7 @@ func TestActivationStatus_OK(t *testing.T) { }, }, }) + require.NoError(t, err) block := testutil.NewBeaconBlock() genesisRoot, err := block.Block.HashTreeRoot() require.NoError(t, err, "Could not get signing root") @@ -837,6 +839,7 @@ func TestMultipleValidatorStatus_Pubkeys(t *testing.T) { ctx := context.Background() deposits, _, err := testutil.DeterministicDepositsAndKeys(6) + require.NoError(t, err) pubKeys := [][]byte{ deposits[0].Data.PublicKey, deposits[1].Data.PublicKey, @@ -877,6 +880,7 @@ func TestMultipleValidatorStatus_Pubkeys(t *testing.T) { }, }, }) + require.NoError(t, err) block := testutil.NewBeaconBlock() genesisRoot, err := block.Block.HashTreeRoot() require.NoError(t, err, "Could not get signing root") @@ -985,6 +989,7 @@ func TestMultipleValidatorStatus_Indices(t *testing.T) { }, } stateObj, err := stateTrie.InitializeFromProtoUnsafe(beaconState) + require.NoError(t, err) block := testutil.NewBeaconBlock() genesisRoot, err := block.Block.HashTreeRoot() require.NoError(t, err, "Could not get signing root") diff --git a/beacon-chain/state/field_trie_test.go b/beacon-chain/state/field_trie_test.go index 066d5ac1c403..8540d22d35d9 100644 --- a/beacon-chain/state/field_trie_test.go +++ b/beacon-chain/state/field_trie_test.go @@ -21,6 +21,7 @@ func TestFieldTrie_NewTrie(t *testing.T) { root, err := stateutil.RootsArrayHashTreeRoot(newState.StateRoots(), params.BeaconConfig().SlotsPerHistoricalRoot, "StateRoots") require.NoError(t, err) newRoot, err := trie.TrieRoot() + require.NoError(t, err) assert.Equal(t, root, newRoot) } diff --git a/beacon-chain/state/getters_test.go b/beacon-chain/state/getters_test.go index fc4ff0022a13..9045c5132d3a 100644 --- a/beacon-chain/state/getters_test.go +++ b/beacon-chain/state/getters_test.go @@ -47,6 +47,7 @@ func TestNilState_NoPanic(t *testing.T) { _ = st.ParentRoot() _ = st.BlockRoots() _, err := st.BlockRootAtIndex(0) + _ = err _ = st.StateRoots() _ = st.HistoricalRoots() _ = st.Eth1Data() @@ -54,16 +55,20 @@ func TestNilState_NoPanic(t *testing.T) { _ = st.Eth1DepositIndex() _ = st.ValidatorsReadOnly() _, err = st.ValidatorAtIndex(0) + _ = err _, err = st.ValidatorAtIndexReadOnly(0) + _ = err _, _ = st.ValidatorIndexByPubkey([48]byte{}) _ = st.validatorIndexMap() _ = st.PubkeyAtIndex(0) _ = st.NumValidators() _ = st.Balances() _, err = st.BalanceAtIndex(0) + _ = err _ = st.BalancesLength() _ = st.RandaoMixes() _, err = st.RandaoMixAtIndex(0) + _ = err _ = st.RandaoMixesLength() _ = st.Slashings() _ = st.PreviousEpochAttestations() @@ -72,7 +77,6 @@ func TestNilState_NoPanic(t *testing.T) { _ = st.PreviousJustifiedCheckpoint() _ = st.CurrentJustifiedCheckpoint() _ = st.FinalizedCheckpoint() - _ = err } func TestReadOnlyValidator_NoPanic(t *testing.T) { diff --git a/beacon-chain/state/state_trie.go b/beacon-chain/state/state_trie.go index 75efa4a06024..420730169ec7 100644 --- a/beacon-chain/state/state_trie.go +++ b/beacon-chain/state/state_trie.go @@ -436,9 +436,7 @@ func (b *BeaconState) recomputeFieldTrie(index fieldIndex, elements interface{}) } func (b *BeaconState) resetFieldTrie(index fieldIndex, elements interface{}, length uint64) error { - fTrie := b.stateFieldLeaves[index] - var err error - fTrie, err = NewFieldTrie(index, elements, length) + fTrie, err := NewFieldTrie(index, elements, length) if err != nil { return err } diff --git a/beacon-chain/state/stategen/getter.go b/beacon-chain/state/stategen/getter.go index 20fa91865c5c..228278e0bf2f 100644 --- a/beacon-chain/state/stategen/getter.go +++ b/beacon-chain/state/stategen/getter.go @@ -207,6 +207,9 @@ func (s *State) loadStateBySlot(ctx context.Context, slot uint64) (*state.Beacon // Gather last saved state, that is where node starts to replay the blocks. startState, err := s.lastSavedState(ctx, slot) + if err != nil { + return nil, err + } // Gather the last saved block root and the slot number. lastValidRoot, lastValidSlot, err := s.lastSavedBlock(ctx, slot) diff --git a/beacon-chain/state/stategen/replay_test.go b/beacon-chain/state/stategen/replay_test.go index 66ab31247a4d..539b05c6d701 100644 --- a/beacon-chain/state/stategen/replay_test.go +++ b/beacon-chain/state/stategen/replay_test.go @@ -738,5 +738,6 @@ func TestLoadFinalizedBlocks(t *testing.T) { require.NoError(t, s.beaconDB.SaveFinalizedCheckpoint(ctx, ðpb.Checkpoint{Root: roots[8][:]})) filteredBlocks, err = s.loadFinalizedBlocks(ctx, 0, 8) + require.NoError(t, err) require.Equal(t, 10, len(filteredBlocks)) } diff --git a/beacon-chain/sync/initial-sync/blocks_fetcher_test.go b/beacon-chain/sync/initial-sync/blocks_fetcher_test.go index 29cd4a86707d..743a1425f14f 100644 --- a/beacon-chain/sync/initial-sync/blocks_fetcher_test.go +++ b/beacon-chain/sync/initial-sync/blocks_fetcher_test.go @@ -497,7 +497,7 @@ func TestBlocksFetcher_requestBeaconBlocksByRange(t *testing.T) { // Test context cancellation. ctx, cancel = context.WithCancel(context.Background()) cancel() - blocks, err = fetcher.requestBlocks(ctx, req, peerIDs[0]) + _, err = fetcher.requestBlocks(ctx, req, peerIDs[0]) assert.ErrorContains(t, "context canceled", err) } diff --git a/beacon-chain/sync/pending_blocks_queue_test.go b/beacon-chain/sync/pending_blocks_queue_test.go index 68eaf934fe6f..92980bd5e821 100644 --- a/beacon-chain/sync/pending_blocks_queue_test.go +++ b/beacon-chain/sync/pending_blocks_queue_test.go @@ -106,6 +106,7 @@ func TestRegularSync_InsertDuplicateBlocks(t *testing.T) { b0r := [32]byte{'a'} require.NoError(t, r.db.SaveBlock(context.Background(), b0)) b0Root, err := b0.Block.HashTreeRoot() + require.NoError(t, err) b1 := testutil.NewBeaconBlock() b1.Block.Slot = 1 b1.Block.ParentRoot = b0Root[:] diff --git a/beacon-chain/sync/rpc_goodbye.go b/beacon-chain/sync/rpc_goodbye.go index 291f2fb5cf20..023870093e20 100644 --- a/beacon-chain/sync/rpc_goodbye.go +++ b/beacon-chain/sync/rpc_goodbye.go @@ -36,8 +36,6 @@ func (s *Service) goodbyeRPCHandler(ctx context.Context, msg interface{}, stream log.WithError(err).Error("Failed to close stream") } }() - ctx, cancel := context.WithTimeout(ctx, ttfbTimeout) - defer cancel() SetRPCStreamDeadlines(stream) m, ok := msg.(*uint64) diff --git a/beacon-chain/sync/rpc_metadata.go b/beacon-chain/sync/rpc_metadata.go index 4713b531c0e5..0ccc7a96f014 100644 --- a/beacon-chain/sync/rpc_metadata.go +++ b/beacon-chain/sync/rpc_metadata.go @@ -18,8 +18,6 @@ func (s *Service) metaDataHandler(ctx context.Context, msg interface{}, stream l log.WithError(err).Debug("Failed to close stream") } }() - ctx, cancel := context.WithTimeout(ctx, ttfbTimeout) - defer cancel() SetRPCStreamDeadlines(stream) if err := s.rateLimiter.validateRequest(stream, 1); err != nil { diff --git a/beacon-chain/sync/rpc_ping_test.go b/beacon-chain/sync/rpc_ping_test.go index 4dfcf2e5790c..351af14fd32f 100644 --- a/beacon-chain/sync/rpc_ping_test.go +++ b/beacon-chain/sync/rpc_ping_test.go @@ -187,5 +187,6 @@ func TestPingRPCHandler_BadSequenceNumber(t *testing.T) { } res, err := p1.Peers().Scorers().BadResponsesScorer().Count(p2.BHost.ID()) - assert.Equal(t, int(1), res, "Peer wasn't penalised for providing a bad sequence number") + assert.NoError(t, err) + assert.Equal(t, 1, res, "Peer wasn't penalised for providing a bad sequence number") } diff --git a/beacon-chain/sync/validate_beacon_blocks_test.go b/beacon-chain/sync/validate_beacon_blocks_test.go index 62139ce0ff03..c26c77c5d7f5 100644 --- a/beacon-chain/sync/validate_beacon_blocks_test.go +++ b/beacon-chain/sync/validate_beacon_blocks_test.go @@ -695,6 +695,7 @@ func TestValidateBeaconBlockPubSub_RejectEvilBlocksFromFuture(t *testing.T) { // valid block msg.Block.ParentRoot = bRoot[:] msg.Signature, err = helpers.ComputeDomainAndSign(beaconState, 0, msg.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx]) + require.NoError(t, err) genesisTime := time.Now() c, err := lru.New(10) diff --git a/shared/aggregation/attestations/naive.go b/shared/aggregation/attestations/naive.go index 209caa3212cc..4bd03affe3d9 100644 --- a/shared/aggregation/attestations/naive.go +++ b/shared/aggregation/attestations/naive.go @@ -46,7 +46,6 @@ func NaiveAttestationAggregation(atts []*ethpb.Attestation) ([]*ethpb.Attestatio } else if b.AggregationBits.Contains(a.AggregationBits) { // if a is fully contained in b, then a can be removed. atts = append(atts[:i], atts[i+1:]...) - i-- break // Stop the inner loop, advance a. } } diff --git a/shared/depositutil/deposit.go b/shared/depositutil/deposit.go index 9d647550a751..0d67720218bb 100644 --- a/shared/depositutil/deposit.go +++ b/shared/depositutil/deposit.go @@ -142,6 +142,9 @@ func GenerateDepositTransaction( depositData.Signature, depositRoot, ) + if err != nil { + return nil, nil, err + } return tx, depositData, nil } diff --git a/shared/slotutil/slotticker_test.go b/shared/slotutil/slotticker_test.go index 90aaa306865b..d08aab0449f2 100644 --- a/shared/slotutil/slotticker_test.go +++ b/shared/slotutil/slotticker_test.go @@ -125,7 +125,6 @@ func TestGetSlotTickerWithOffset_OK(t *testing.T) { if firstTicked != 1 { t.Fatal("Expected other ticker to tick first") } - firstTicked = 2 return case <-normalTicker.C(): if firstTicked != 0 { diff --git a/shared/testutil/block.go b/shared/testutil/block.go index e663ac4ae362..f6407024c247 100644 --- a/shared/testutil/block.go +++ b/shared/testutil/block.go @@ -360,7 +360,7 @@ func GenerateAttestations(bState *stateTrie.BeaconState, privs []bls.SecretKey, } targetRoot := make([]byte, 32) - headRoot := make([]byte, 32) + var headRoot []byte var err error // Only calculate head state if its an attestation for the current slot or future slot. if generateHeadState || slot == bState.Slot() { diff --git a/shared/trieutil/sparse_merkle.go b/shared/trieutil/sparse_merkle.go index c6174968c854..5a6697c412cd 100644 --- a/shared/trieutil/sparse_merkle.go +++ b/shared/trieutil/sparse_merkle.go @@ -102,7 +102,7 @@ func (m *SparseMerkleTrie) Insert(item []byte, index int) { for i := 0; i < int(m.depth); i++ { isLeft := currentIndex%2 == 0 neighborIdx := currentIndex ^ 1 - neighbor := make([]byte, 32) + var neighbor []byte if neighborIdx >= len(m.branches[i]) { neighbor = ZeroHashes[i][:] } else { diff --git a/slasher/db/kv/attester_slashings_test.go b/slasher/db/kv/attester_slashings_test.go index 953e6ca147f8..a6f1c6bd6c1a 100644 --- a/slasher/db/kv/attester_slashings_test.go +++ b/slasher/db/kv/attester_slashings_test.go @@ -164,6 +164,7 @@ func TestStore_UpdateAttesterSlashingStatus(t *testing.T) { require.Equal(t, tt.ss, st, "Failed to find attester slashing with the correct status: %v", tt.as) err = db.SaveAttesterSlashing(ctx, types.SlashingStatus(types.Included), tt.as) + require.NoError(t, err) has, st, err = db.HasAttesterSlashing(ctx, tt.as) require.NoError(t, err, "Failed to get attester slashing") require.Equal(t, true, has, "Failed to find attester slashing: %v", tt.as) diff --git a/slasher/db/kv/proposer_slashings_test.go b/slasher/db/kv/proposer_slashings_test.go index abcee5df4f16..ea4e45ff7f06 100644 --- a/slasher/db/kv/proposer_slashings_test.go +++ b/slasher/db/kv/proposer_slashings_test.go @@ -239,6 +239,7 @@ func TestStore_UpdateProposerSlashingStatus(t *testing.T) { require.Equal(t, tt.ss, st, "Failed to find proposer slashing with the correct status") err = db.SaveProposerSlashing(ctx, types.SlashingStatus(types.Included), tt.ps) + require.NoError(t, err) has, st, err = db.HasProposerSlashing(ctx, tt.ps) require.NoError(t, err, "Failed to get proposer slashing") require.Equal(t, true, has, "Failed to find proposer slashing") diff --git a/slasher/detection/attestations/types/epoch_store_test.go b/slasher/detection/attestations/types/epoch_store_test.go index 44eed42e8ed2..218c01d9a1f7 100644 --- a/slasher/detection/attestations/types/epoch_store_test.go +++ b/slasher/detection/attestations/types/epoch_store_test.go @@ -64,8 +64,10 @@ func TestEpochStore_GetValidatorSpan_Format(t *testing.T) { require.NoError(t, err) } span0, err := es.GetValidatorSpan(0) + assert.NoError(t, err) assert.DeepEqual(t, tt.expectedSpan[0], span0, "Unexpected span") span1, err := es.GetValidatorSpan(1) + assert.NoError(t, err) assert.DeepEqual(t, tt.expectedSpan[1], span1, "Unexpected span") }) } diff --git a/slasher/detection/detect_test.go b/slasher/detection/detect_test.go index bd2b1e8c56b3..24e53e657f87 100644 --- a/slasher/detection/detect_test.go +++ b/slasher/detection/detect_test.go @@ -182,6 +182,7 @@ func TestDetect_detectAttesterSlashings_Surround(t *testing.T) { require.NoError(t, err) require.Equal(t, tt.slashingsFound, len(slashings), "Unexpected amount of slashings found") attsl, err := db.AttesterSlashings(ctx, status.Active) + require.NoError(t, err) require.Equal(t, tt.slashingsFound, len(attsl), "Didnt save slashing to db") for _, ss := range slashings { slashingAtt1 := ss.Attestation_1 @@ -332,6 +333,7 @@ func TestDetect_detectAttesterSlashings_Double(t *testing.T) { require.NoError(t, err) require.Equal(t, tt.slashingsFound, len(slashings), "Unexpected amount of slashings found") savedSlashings, err := db.AttesterSlashings(ctx, status.Active) + require.NoError(t, err) require.Equal(t, tt.slashingsFound, len(savedSlashings), "Did not save slashing to db") for _, ss := range slashings { @@ -397,6 +399,7 @@ func TestDetect_detectProposerSlashing(t *testing.T) { require.NoError(t, err) assert.DeepEqual(t, tt.slashing, slashing) savedSlashings, err := db.ProposalSlashingsByStatus(ctx, status.Active) + require.NoError(t, err) if tt.slashing != nil { require.Equal(t, 1, len(savedSlashings), "Did not save slashing to db") } diff --git a/slasher/rpc/server_test.go b/slasher/rpc/server_test.go index 27576ba0af19..4206c2e37b28 100644 --- a/slasher/rpc/server_test.go +++ b/slasher/rpc/server_test.go @@ -63,6 +63,7 @@ func TestServer_IsSlashableAttestation(t *testing.T) { bcCfg := &beaconclient.Config{BeaconClient: bClient, NodeClient: nClient, SlasherDB: db} bs, err := beaconclient.NewService(ctx, bcCfg) + require.NoError(t, err) ds := detection.NewService(ctx, cfg) server := Server{ctx: ctx, detector: ds, slasherDB: db, beaconClient: bs} nClient.EXPECT().GetGenesis(gomock.Any(), gomock.Any()).Return(wantedGenesis, nil).AnyTimes() @@ -165,6 +166,7 @@ func TestServer_IsSlashableAttestationNoUpdate(t *testing.T) { bcCfg := &beaconclient.Config{BeaconClient: bClient, NodeClient: nClient, SlasherDB: db} bs, err := beaconclient.NewService(ctx, bcCfg) + require.NoError(t, err) ds := detection.NewService(ctx, cfg) server := Server{ctx: ctx, detector: ds, slasherDB: db, beaconClient: bs} slashings, err := server.IsSlashableAttestation(ctx, savedAttestation) @@ -223,6 +225,7 @@ func TestServer_IsSlashableBlock(t *testing.T) { bcCfg := &beaconclient.Config{BeaconClient: bClient, NodeClient: nClient, SlasherDB: db} bs, err := beaconclient.NewService(ctx, bcCfg) + require.NoError(t, err) ds := detection.NewService(ctx, cfg) server := Server{ctx: ctx, detector: ds, slasherDB: db, beaconClient: bs} @@ -311,6 +314,7 @@ func TestServer_IsSlashableBlockNoUpdate(t *testing.T) { savedBlock.Signature = marshalledSig bcCfg := &beaconclient.Config{BeaconClient: bClient, NodeClient: nClient, SlasherDB: db} bs, err := beaconclient.NewService(ctx, bcCfg) + require.NoError(t, err) ds := detection.NewService(ctx, cfg) server := Server{ctx: ctx, detector: ds, slasherDB: db, beaconClient: bs} slashings, err := server.IsSlashableBlock(ctx, savedBlock) diff --git a/tools/keystores/main.go b/tools/keystores/main.go index ab181ff6e0b4..2857c6424af1 100644 --- a/tools/keystores/main.go +++ b/tools/keystores/main.go @@ -102,6 +102,9 @@ func decrypt(cliCtx *cli.Context) error { // Any password is valid. return nil }) + if err != nil { + return err + } } isDir, err := fileutil.HasDir(fullPath) if err != nil { @@ -139,6 +142,9 @@ func encrypt(cliCtx *cli.Context) error { // Any password is valid. return nil }) + if err != nil { + return err + } } privateKeyString := cliCtx.String(privateKeyFlag.Name) if privateKeyString == "" { diff --git a/tools/pcli/main.go b/tools/pcli/main.go index bf92b1ebcc19..82c20c01c5d1 100644 --- a/tools/pcli/main.go +++ b/tools/pcli/main.go @@ -177,6 +177,9 @@ func main() { log.Fatal(err) } postRoot, err := postState.HashTreeRoot(context.Background()) + if err != nil { + log.Fatal(err) + } log.Infof("Finished state transition with post state root of %#x", postRoot) // Diff the state if a post state is provided. diff --git a/validator/accounts/v2/accounts_create_test.go b/validator/accounts/v2/accounts_create_test.go index 2155c25c3c9b..ddf4604c16bc 100644 --- a/validator/accounts/v2/accounts_create_test.go +++ b/validator/accounts/v2/accounts_create_test.go @@ -106,7 +106,7 @@ func Test_KeysConsistency_Direct(t *testing.T) { // Now we change the password to "SecoNDxyzPass__9!@#" require.NoError(t, ioutil.WriteFile(walletPasswordFile, []byte("SecoNDxyzPass__9!@#"), os.ModePerm)) - w, err = wallet.OpenWalletOrElseCli(cliCtx, CreateAndSaveWalletCli) + _, err = wallet.OpenWalletOrElseCli(cliCtx, CreateAndSaveWalletCli) require.ErrorContains(t, "wrong password for wallet", err) require.NoError(t, ioutil.WriteFile(walletPasswordFile, []byte("Pa$sW0rD0__Fo0xPr"), os.ModePerm)) diff --git a/validator/accounts/v2/wallet/wallet.go b/validator/accounts/v2/wallet/wallet.go index 5aef7db5812a..5ff6f4268634 100644 --- a/validator/accounts/v2/wallet/wallet.go +++ b/validator/accounts/v2/wallet/wallet.go @@ -184,6 +184,9 @@ func OpenWalletOrElseCli(cliCtx *cli.Context, otherwise func(cliCtx *cli.Context false, /* Do not confirm password */ ValidateExistingPass, ) + if err != nil { + return nil, err + } if fileutil.FileExists(filepath.Join(walletDir, HashedPasswordFileName)) { hashedPassword, err := fileutil.ReadFileAsBytes(filepath.Join(walletDir, HashedPasswordFileName)) if err != nil { diff --git a/validator/accounts/v2/wallet/wallet_test.go b/validator/accounts/v2/wallet/wallet_test.go index 006be70c17a6..af21711133a9 100644 --- a/validator/accounts/v2/wallet/wallet_test.go +++ b/validator/accounts/v2/wallet/wallet_test.go @@ -172,6 +172,7 @@ func Test_LockUnlockFile(t *testing.T) { WalletDir: walletDir, WalletPassword: password, }) + require.NoError(t, err) defer unlock(t, w) _, err = w.InitializeKeymanager(cliCtx.Context, true) require.NoError(t, err) diff --git a/validator/client/validator_test.go b/validator/client/validator_test.go index 0f505a41aeea..6355f3e77e29 100644 --- a/validator/client/validator_test.go +++ b/validator/client/validator_test.go @@ -680,8 +680,7 @@ func TestSaveProtections_OK(t *testing.T) { history1 := cleanHistories[pubKey1] history1 = markAttestationForTargetEpoch(history1, 0, 1) - history2 := cleanHistories[pubKey1] - history2 = markAttestationForTargetEpoch(history1, 2, 3) + history2 := markAttestationForTargetEpoch(history1, 2, 3) cleanHistories[pubKey1] = history1 cleanHistories[pubKey2] = history2 diff --git a/validator/keymanager/v2/derived/derived.go b/validator/keymanager/v2/derived/derived.go index 338427b043b5..8ed960eae1d8 100644 --- a/validator/keymanager/v2/derived/derived.go +++ b/validator/keymanager/v2/derived/derived.go @@ -294,6 +294,9 @@ func (dr *Keymanager) CreateAccount(ctx context.Context, logAccountInfo bool) ([ nil, /*forkVersion*/ nil, /*genesisValidatorsRoot*/ ) + if err != nil { + return nil, err + } if err := depositutil.VerifyDepositSignature(data, domain); err != nil { return nil, errors.Wrap(err, "failed to verify deposit signature, please make sure your account was created properly") } diff --git a/validator/keymanager/v2/direct/direct.go b/validator/keymanager/v2/direct/direct.go index a6a1b8aad9fe..c5d8225a0e8f 100644 --- a/validator/keymanager/v2/direct/direct.go +++ b/validator/keymanager/v2/direct/direct.go @@ -244,6 +244,9 @@ func (dr *Keymanager) CreateAccount(ctx context.Context) ([]byte, error) { nil, /*forkVersion*/ nil, /*genesisValidatorsRoot*/ ) + if err != nil { + return nil, err + } if err := depositutil.VerifyDepositSignature(data, domain); err != nil { return nil, errors.Wrap(err, "failed to verify deposit signature, please make sure your account was created properly") } diff --git a/validator/rpc/health.go b/validator/rpc/health.go index a869a9b1fd33..31bb718ce9d0 100644 --- a/validator/rpc/health.go +++ b/validator/rpc/health.go @@ -11,7 +11,6 @@ import ( // GetBeaconNodeConnection retrieves the current beacon node connection // information, as well as its sync status. func (s *Server) GetBeaconNodeConnection(ctx context.Context, _ *ptypes.Empty) (*pb.NodeConnectionResponse, error) { - genesis, err := s.genesisFetcher.GenesisInfo(ctx) syncStatus, err := s.syncChecker.Syncing(ctx) if err != nil || s.validatorService.Status() != nil { return &pb.NodeConnectionResponse{ @@ -21,6 +20,10 @@ func (s *Server) GetBeaconNodeConnection(ctx context.Context, _ *ptypes.Empty) ( Syncing: false, }, nil } + genesis, err := s.genesisFetcher.GenesisInfo(ctx) + if err != nil { + return nil, err + } return &pb.NodeConnectionResponse{ GenesisTime: uint64(time.Unix(genesis.GenesisTime.Seconds, 0).Unix()), DepositContractAddress: genesis.DepositContractAddress, diff --git a/validator/rpc/wallet_test.go b/validator/rpc/wallet_test.go index 3ef53c9f7469..b491056a19a9 100644 --- a/validator/rpc/wallet_test.go +++ b/validator/rpc/wallet_test.go @@ -195,6 +195,7 @@ func TestServer_WalletConfig(t *testing.T) { expectedConfig := direct.DefaultKeymanagerOpts() enc, err := json.Marshal(expectedConfig) + require.NoError(t, err) var jsonMap map[string]string require.NoError(t, json.Unmarshal(enc, &jsonMap)) assert.DeepEqual(t, resp, &pb.WalletResponse{