mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 21:38:05 -05:00
Finish error wrapping (#3135)
This commit is contained in:
@@ -75,7 +75,7 @@ func (c *ChainService) ReceiveBlock(ctx context.Context, block *ethpb.BeaconBloc
|
||||
}
|
||||
// We first verify the block's basic validity conditions.
|
||||
if err := c.VerifyBlockValidity(ctx, block, beaconState); err != nil {
|
||||
return beaconState, fmt.Errorf("block with slot %d is not ready for processing: %v", block.Slot, err)
|
||||
return beaconState, errors.Wrapf(err, "block with slot %d is not ready for processing", block.Slot)
|
||||
}
|
||||
|
||||
// We save the block to the DB and broadcast it to our peers.
|
||||
@@ -142,7 +142,7 @@ func (c *ChainService) VerifyBlockValidity(
|
||||
powBlockFetcher := c.web3Service.Client().BlockByHash
|
||||
if err := b.IsValidBlock(ctx, beaconState, block,
|
||||
c.beaconDB.HasBlock, powBlockFetcher, c.genesisTime); err != nil {
|
||||
return fmt.Errorf("block does not fulfill pre-processing conditions %v", err)
|
||||
return errors.Wrap(err, "block does not fulfill pre-processing conditions")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ func (c *ChainService) initializeBeaconChain(genesisTime time.Time, deposits []*
|
||||
return nil, errors.Wrap(err, "failed to save attestation target")
|
||||
}
|
||||
if err := c.beaconDB.UpdateChainHead(ctx, genBlock, beaconState); err != nil {
|
||||
return nil, fmt.Errorf("could not set chain head, %v", err)
|
||||
return nil, errors.Wrap(err, "could not set chain head")
|
||||
}
|
||||
if err := c.beaconDB.SaveJustifiedBlock(genBlock); err != nil {
|
||||
return nil, errors.Wrap(err, "could not save genesis block as justified block")
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
package blocks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
@@ -44,7 +43,7 @@ func HeaderFromBlock(block *ethpb.BeaconBlock) (*ethpb.BeaconBlockHeader, error)
|
||||
}
|
||||
root, err := ssz.HashTreeRoot(block.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not tree hash block body %v", err)
|
||||
return nil, errors.Wrap(err, "could not tree hash block body")
|
||||
}
|
||||
header.BodyRoot = root[:]
|
||||
return header, nil
|
||||
|
||||
@@ -344,14 +344,13 @@ func ProcessProposerSlashings(
|
||||
}
|
||||
proposer := beaconState.Validators[slashing.ProposerIndex]
|
||||
if err = verifyProposerSlashing(beaconState, proposer, slashing); err != nil {
|
||||
return nil, fmt.Errorf("could not verify proposer slashing %d: %v", idx, err)
|
||||
return nil, errors.Wrapf(err, "could not verify proposer slashing %d", idx)
|
||||
}
|
||||
beaconState, err = v.SlashValidator(
|
||||
beaconState, slashing.ProposerIndex, 0, /* proposer is whistleblower */
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not slash proposer index %d: %v",
|
||||
slashing.ProposerIndex, err)
|
||||
return nil, errors.Wrapf(err, "could not slash proposer index %d", slashing.ProposerIndex)
|
||||
}
|
||||
}
|
||||
return beaconState, nil
|
||||
@@ -413,7 +412,7 @@ func ProcessAttesterSlashings(
|
||||
) (*pb.BeaconState, error) {
|
||||
for idx, slashing := range body.AttesterSlashings {
|
||||
if err := verifyAttesterSlashing(beaconState, slashing); err != nil {
|
||||
return nil, fmt.Errorf("could not verify attester slashing #%d: %v", idx, err)
|
||||
return nil, errors.Wrapf(err, "could not verify attester slashing %d", idx)
|
||||
}
|
||||
slashableIndices := slashableAttesterIndices(slashing)
|
||||
sort.SliceStable(slashableIndices, func(i, j int) bool {
|
||||
@@ -494,7 +493,7 @@ func ProcessAttestations(
|
||||
for idx, attestation := range body.Attestations {
|
||||
beaconState, err = ProcessAttestation(beaconState, attestation)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not verify attestation at index %d in block: %v", idx, err)
|
||||
return nil, errors.Wrapf(err, "could not verify attestation at index %d in block", idx)
|
||||
}
|
||||
}
|
||||
return beaconState, nil
|
||||
@@ -853,7 +852,7 @@ func ProcessDeposits(
|
||||
for _, deposit := range deposits {
|
||||
beaconState, err = ProcessDeposit(beaconState, deposit, valIndexMap)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not process deposit from %#x: %v", bytesutil.Trunc(deposit.Data.PublicKey), err)
|
||||
return nil, errors.Wrapf(err, "could not process deposit from %#x", bytesutil.Trunc(deposit.Data.PublicKey))
|
||||
}
|
||||
}
|
||||
return beaconState, nil
|
||||
@@ -886,7 +885,7 @@ func ProcessDeposits(
|
||||
// if pubkey not in validator_pubkeys:
|
||||
// # Verify the deposit signature (proof of possession).
|
||||
// # Invalid signatures are allowed by the deposit contract, and hence included on-chain, but must not be processed.
|
||||
// if not bls_verify(pubkey, signing_root(deposit.data), deposit.data.signature, get_domain(state, DOMAIN_DEPOSIT)):
|
||||
// if not bls_verify(pubkey, signing_root(deposit.data), deposit.data.signature%d, get_domain(state, DOMAIN_DEPOSIT)):
|
||||
// return
|
||||
//
|
||||
// # Add validator and balance entries
|
||||
@@ -906,7 +905,7 @@ func ProcessDeposits(
|
||||
// increase_balance(state, index, amount)
|
||||
func ProcessDeposit(beaconState *pb.BeaconState, deposit *ethpb.Deposit, valIndexMap map[[32]byte]int) (*pb.BeaconState, error) {
|
||||
if err := verifyDeposit(beaconState, deposit); err != nil {
|
||||
return nil, fmt.Errorf("could not verify deposit from %#x: %v", bytesutil.Trunc(deposit.Data.PublicKey), err)
|
||||
return nil, errors.Wrapf(err, "could not verify deposit from %#x", bytesutil.Trunc(deposit.Data.PublicKey))
|
||||
}
|
||||
beaconState.Eth1DepositIndex++
|
||||
pubKey := deposit.Data.PublicKey
|
||||
@@ -997,7 +996,7 @@ func ProcessVoluntaryExits(
|
||||
|
||||
for idx, exit := range exits {
|
||||
if err := verifyExit(beaconState, exit); err != nil {
|
||||
return nil, fmt.Errorf("could not verify exit #%d: %v", idx, err)
|
||||
return nil, errors.Wrapf(err, "could not verify exit %d", idx)
|
||||
}
|
||||
beaconState, err = v.InitiateValidatorExit(beaconState, exit.ValidatorIndex)
|
||||
if err != nil {
|
||||
@@ -1084,7 +1083,7 @@ func ProcessTransfers(
|
||||
|
||||
for idx, transfer := range transfers {
|
||||
if err := verifyTransfer(beaconState, transfer); err != nil {
|
||||
return nil, fmt.Errorf("could not verify transfer %d: %v", idx, err)
|
||||
return nil, errors.Wrapf(err, "could not verify transfer %d", idx)
|
||||
}
|
||||
// Process the transfer between accounts.
|
||||
beaconState = helpers.DecreaseBalance(beaconState, transfer.SenderIndex, transfer.Amount+transfer.Fee)
|
||||
|
||||
@@ -68,7 +68,7 @@ func MatchAttestations(state *pb.BeaconState, epoch uint64) (*MatchedAttestation
|
||||
}
|
||||
targetRoot, err := helpers.BlockRoot(state, epoch)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get block root for epoch %d: %v", epoch, err)
|
||||
return nil, errors.Wrapf(err, "could not get block root for epoch %d", epoch)
|
||||
}
|
||||
|
||||
tgtAtts := make([]*pb.PendingAttestation, 0, len(srcAtts))
|
||||
@@ -88,7 +88,7 @@ func MatchAttestations(state *pb.BeaconState, epoch uint64) (*MatchedAttestation
|
||||
}
|
||||
headRoot, err := helpers.BlockRootAtSlot(state, slot)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get block root for slot %d: %v", slot, err)
|
||||
return nil, errors.Wrapf(err, "could not get block root for slot %d", slot)
|
||||
}
|
||||
if bytes.Equal(srcAtt.Data.BeaconBlockRoot, headRoot) {
|
||||
headAtts = append(headAtts, srcAtt)
|
||||
@@ -183,8 +183,7 @@ func ProcessJustificationAndFinalization(state *pb.BeaconState, prevAttestedBal
|
||||
if 3*prevAttestedBal >= 2*totalBal {
|
||||
blockRoot, err := helpers.BlockRoot(state, prevEpoch)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get block root for previous epoch %d: %v",
|
||||
prevEpoch, err)
|
||||
return nil, errors.Wrapf(err, "could not get block root for previous epoch %d", prevEpoch)
|
||||
}
|
||||
state.CurrentJustifiedCheckpoint = ðpb.Checkpoint{Epoch: prevEpoch, Root: blockRoot}
|
||||
state.JustificationBits.SetBitAt(1, true)
|
||||
@@ -194,8 +193,7 @@ func ProcessJustificationAndFinalization(state *pb.BeaconState, prevAttestedBal
|
||||
if 3*currAttestedBal >= 2*totalBal {
|
||||
blockRoot, err := helpers.BlockRoot(state, currentEpoch)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get block root for current epoch %d: %v",
|
||||
prevEpoch, err)
|
||||
return nil, errors.Wrapf(err, "could not get block root for current epoch %d", prevEpoch)
|
||||
}
|
||||
state.CurrentJustifiedCheckpoint = ðpb.Checkpoint{Epoch: currentEpoch, Root: blockRoot}
|
||||
state.JustificationBits.SetBitAt(0, true)
|
||||
@@ -294,11 +292,11 @@ func ProcessRewardsAndPenalties(state *pb.BeaconState) (*pb.BeaconState, error)
|
||||
}
|
||||
attsRewards, attsPenalties, err := attestationDelta(state)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get attestation delta: %v ", err)
|
||||
return nil, errors.Wrap(err, "could not get attestation delta")
|
||||
}
|
||||
clRewards, clPenalties, err := crosslinkDelta(state)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get crosslink delta: %v ", err)
|
||||
return nil, errors.Wrapf(err, "could not get crosslink delta")
|
||||
}
|
||||
for i := 0; i < len(state.Validators); i++ {
|
||||
state = helpers.IncreaseBalance(state, uint64(i), attsRewards[i]+clRewards[i])
|
||||
@@ -351,7 +349,7 @@ func ProcessRegistryUpdates(state *pb.BeaconState) (*pb.BeaconState, error) {
|
||||
if isActive && belowEjectionBalance {
|
||||
state, err = validators.InitiateValidatorExit(state, uint64(idx))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not initiate exit for validator %d: %v", idx, err)
|
||||
return nil, errors.Wrapf(err, "could not initiate exit for validator %d", idx)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -515,7 +513,7 @@ func ProcessFinalUpdates(state *pb.BeaconState) (*pb.BeaconState, error) {
|
||||
commRootPosition := nextEpoch % params.BeaconConfig().EpochsPerHistoricalVector
|
||||
comRoot, err := helpers.CompactCommitteesRoot(state, nextEpoch)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get compact committee root %v", err)
|
||||
return nil, errors.Wrap(err, "could not get compact committee root")
|
||||
}
|
||||
state.CompactCommitteesRoots[commRootPosition] = comRoot[:]
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ func ComputeCommittee(
|
||||
for i := start; i < end; i++ {
|
||||
permutedIndex, err := ShuffledIndex(i, validatorCount, seed)
|
||||
if err != nil {
|
||||
return []uint64{}, fmt.Errorf("could not get shuffled index at index %d: %v", i, err)
|
||||
return []uint64{}, errors.Wrapf(err, "could not get shuffled index at index %d", i)
|
||||
}
|
||||
shuffledIndices[i-start] = validatorIndices[permutedIndex]
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
@@ -148,7 +146,7 @@ func GenesisBeaconState(deposits []*ethpb.Deposit, genesisTime uint64, eth1Data
|
||||
|
||||
bodyRoot, err := ssz.HashTreeRoot(ðpb.BeaconBlockBody{})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not hash tree root: %v err: %v", bodyRoot, err)
|
||||
return nil, errors.Wrapf(err, "could not hash tree root %v", bodyRoot)
|
||||
}
|
||||
|
||||
state.LatestBlockHeader = ðpb.BeaconBlockHeader{
|
||||
@@ -186,7 +184,7 @@ func GenesisBeaconState(deposits []*ethpb.Deposit, genesisTime uint64, eth1Data
|
||||
for i, deposit := range deposits {
|
||||
state, err = b.ProcessDeposit(state, deposit, validatorMap)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not process validator deposit %d: %v", i, err)
|
||||
return nil, errors.Wrapf(err, "could not process validator deposit %d", i)
|
||||
}
|
||||
}
|
||||
// Process genesis activations
|
||||
@@ -211,7 +209,7 @@ func GenesisBeaconState(deposits []*ethpb.Deposit, genesisTime uint64, eth1Data
|
||||
}
|
||||
genesisCompactCommRoot, err := helpers.CompactCommitteesRoot(state, 0)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get compact committee root %v", err)
|
||||
return nil, errors.Wrap(err, "could not get compact committee root")
|
||||
}
|
||||
for i := uint64(0); i < params.BeaconConfig().EpochsPerHistoricalVector; i++ {
|
||||
state.ActiveIndexRoots[i] = genesisActiveIndexRoot[:]
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
package validators
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -147,7 +146,7 @@ func ExitValidator(state *pb.BeaconState, idx uint64) *pb.BeaconState {
|
||||
func SlashValidator(state *pb.BeaconState, slashedIdx uint64, whistleBlowerIdx uint64) (*pb.BeaconState, error) {
|
||||
state, err := InitiateValidatorExit(state, slashedIdx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not initiate validator %d exit: %v", slashedIdx, err)
|
||||
return nil, errors.Wrapf(err, "could not initiate validator %d exit", slashedIdx)
|
||||
}
|
||||
currentEpoch := helpers.CurrentEpoch(state)
|
||||
validator := state.Validators[slashedIdx]
|
||||
|
||||
@@ -311,7 +311,7 @@ func (db *BeaconDB) UpdateChainHead(ctx context.Context, block *ethpb.BeaconBloc
|
||||
mainChainBucket := tx.Bucket(mainChainBucket)
|
||||
|
||||
if blockBucket.Get(blockRoot[:]) == nil {
|
||||
return fmt.Errorf("expected block %#x to have already been saved before updating head: %v", blockRoot, err)
|
||||
return fmt.Errorf("expected block %#x to have already been saved before updating head", blockRoot)
|
||||
}
|
||||
|
||||
if err := chainInfo.Put(mainChainHeightKey, slotBinary); err != nil {
|
||||
|
||||
@@ -130,16 +130,16 @@ func (s *Service) AttestationPool(ctx context.Context, requestedSlot uint64) ([]
|
||||
var attestations []*ethpb.Attestation
|
||||
attestationsFromDB, err := s.beaconDB.Attestations()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not retrieve attestations from DB")
|
||||
return nil, errors.New("could not retrieve attestations from DB")
|
||||
}
|
||||
bState, err := s.beaconDB.HeadState(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not retrieve attestations from DB")
|
||||
return nil, errors.New("could not retrieve attestations from DB")
|
||||
}
|
||||
|
||||
bState, err = state.ProcessSlots(ctx, bState, requestedSlot)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not process slots up to %d: %v", requestedSlot, err)
|
||||
return nil, errors.Wrapf(err, "could not process slots up to %d", requestedSlot)
|
||||
}
|
||||
|
||||
sort.Slice(attestationsFromDB, func(i, j int) bool {
|
||||
@@ -288,10 +288,10 @@ func (s *Service) handleProcessedBlock(_ context.Context, message proto.Message)
|
||||
}
|
||||
state, err := s.beaconDB.HeadState(s.ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not retrieve attestations from DB")
|
||||
return errors.New("could not retrieve attestations from DB")
|
||||
}
|
||||
if err := s.removeEpochOldAttestations(state); err != nil {
|
||||
return fmt.Errorf("could not remove old attestations from DB at slot %d: %v", block.Slot, err)
|
||||
return errors.Wrapf(err, "could not remove old attestations from DB at slot %d", block.Slot)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func (w *Web3Service) processDeposit(
|
||||
deposit *ethpb.Deposit,
|
||||
) error {
|
||||
if err := verifyDeposit(eth1Data, deposit); err != nil {
|
||||
return fmt.Errorf("could not verify deposit from #%x: %v", bytesutil.Trunc(deposit.Data.PublicKey), err)
|
||||
return errors.Wrapf(err, "could not verify deposit from #%x", bytesutil.Trunc(deposit.Data.PublicKey))
|
||||
}
|
||||
pubKey := bytesutil.ToBytes48(deposit.Data.PublicKey)
|
||||
amount := deposit.Data.Amount
|
||||
|
||||
@@ -125,7 +125,7 @@ func NewWeb3Service(ctx context.Context, config *Web3ServiceConfig) (*Web3Servic
|
||||
|
||||
depositContractCaller, err := contracts.NewDepositContractCaller(config.DepositContract, config.ContractBackend)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not create deposit contract caller %v", err)
|
||||
return nil, errors.Wrap(err, "could not create deposit contract caller")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
@@ -258,7 +258,7 @@ func (w *Web3Service) AreAllDepositsProcessed() (bool, error) {
|
||||
defer w.processingLock.RUnlock()
|
||||
countByte, err := w.depositContractCaller.GetDepositCount(&bind.CallOpts{})
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("could not get deposit count %v", err)
|
||||
return false, errors.Wrap(err, "could not get deposit count")
|
||||
}
|
||||
count := bytesutil.FromBytes8(countByte)
|
||||
deposits := w.beaconDB.AllDeposits(w.ctx, nil)
|
||||
@@ -273,7 +273,7 @@ func (w *Web3Service) AreAllDepositsProcessed() (bool, error) {
|
||||
func (w *Web3Service) initDataFromContract() error {
|
||||
root, err := w.depositContractCaller.GetHashTreeRoot(&bind.CallOpts{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not retrieve deposit root %v", err)
|
||||
return errors.Wrap(err, "could not retrieve deposit root")
|
||||
}
|
||||
w.depositRoot = root[:]
|
||||
return nil
|
||||
|
||||
@@ -119,7 +119,7 @@ func (as *AttesterServer) RequestAttestation(ctx context.Context, req *pb.Attest
|
||||
|
||||
headState, err = state.ProcessSlots(ctx, headState, req.Slot)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not process slots up to %d: %v", req.Slot, err)
|
||||
return nil, errors.Wrapf(err, "could not process slots up to %d", req.Slot)
|
||||
}
|
||||
|
||||
targetEpoch := helpers.CurrentEpoch(headState)
|
||||
@@ -130,8 +130,7 @@ func (as *AttesterServer) RequestAttestation(ctx context.Context, req *pb.Attest
|
||||
} else {
|
||||
targetRoot, err = helpers.BlockRootAtSlot(headState, epochStartSlot)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get target block for slot %d: %v",
|
||||
epochStartSlot, err)
|
||||
return nil, errors.Wrapf(err, "could not get target block for slot %d", epochStartSlot)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ func (ps *ProposerServer) attestations(ctx context.Context, expectedSlot uint64)
|
||||
}
|
||||
atts, err := ps.operationService.AttestationPool(ctx, expectedSlot)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not retrieve pending attestations from operations service: %v", err)
|
||||
return nil, errors.Wrap(err, "could not retrieve pending attestations from operations service")
|
||||
}
|
||||
|
||||
// advance slot, if it is behind
|
||||
@@ -154,7 +154,7 @@ func (ps *ProposerServer) attestations(ctx context.Context, expectedSlot uint64)
|
||||
for _, att := range atts {
|
||||
slot, err := helpers.AttestationDataSlot(beaconState, att.Data)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get attestation slot: %v", err)
|
||||
return nil, errors.Wrap(err, "could not get attestation slot")
|
||||
}
|
||||
if slot+params.BeaconConfig().MinAttestationInclusionDelay <= beaconState.Slot &&
|
||||
beaconState.Slot <= slot+params.BeaconConfig().SlotsPerEpoch {
|
||||
@@ -166,7 +166,7 @@ func (ps *ProposerServer) attestations(ctx context.Context, expectedSlot uint64)
|
||||
for _, att := range attsReadyForInclusion {
|
||||
slot, err := helpers.AttestationDataSlot(beaconState, att.Data)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get attestation slot: %v", err)
|
||||
return nil, errors.Wrap(err, "could not get attestation slot")
|
||||
}
|
||||
|
||||
if _, err := blocks.ProcessAttestation(beaconState, att); err != nil {
|
||||
@@ -179,7 +179,7 @@ func (ps *ProposerServer) attestations(ctx context.Context, expectedSlot uint64)
|
||||
"headRoot": fmt.Sprintf("%#x", bytesutil.Trunc(att.Data.BeaconBlockRoot))}).Info(
|
||||
"Deleting failed pending attestation from DB")
|
||||
if err := ps.beaconDB.DeleteAttestation(att); err != nil {
|
||||
return nil, fmt.Errorf("could not delete failed attestation: %v", err)
|
||||
return nil, errors.Wrap(err, "could not delete failed attestation")
|
||||
}
|
||||
continue
|
||||
}
|
||||
@@ -187,9 +187,9 @@ func (ps *ProposerServer) attestations(ctx context.Context, expectedSlot uint64)
|
||||
if err != nil {
|
||||
// Delete attestation that failed to verify as canonical.
|
||||
if err := ps.beaconDB.DeleteAttestation(att); err != nil {
|
||||
return nil, fmt.Errorf("could not delete failed attestation: %v", err)
|
||||
return nil, errors.Wrap(err, "could not delete failed attestation")
|
||||
}
|
||||
return nil, fmt.Errorf("could not verify canonical attestation: %v", err)
|
||||
return nil, errors.Wrap(err, "could not verify canonical attestation")
|
||||
}
|
||||
// Skip the attestation if it's not canonical.
|
||||
if !canonical {
|
||||
@@ -226,7 +226,7 @@ func (ps *ProposerServer) eth1Data(ctx context.Context, slot uint64) (*ethpb.Eth
|
||||
func (ps *ProposerServer) computeStateRoot(ctx context.Context, block *ethpb.BeaconBlock) ([]byte, error) {
|
||||
beaconState, err := ps.beaconDB.HeadState(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get beacon state: %v", err)
|
||||
return nil, errors.Wrap(err, "could not get beacon state")
|
||||
}
|
||||
s, err := state.ExecuteStateTransitionNoVerify(
|
||||
ctx,
|
||||
@@ -234,12 +234,12 @@ func (ps *ProposerServer) computeStateRoot(ctx context.Context, block *ethpb.Bea
|
||||
block,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not execute state transition for state: %v at slot %d", err, beaconState.Slot)
|
||||
return nil, errors.Wrapf(err, "could not execute state transition for state at slot %d", beaconState.Slot)
|
||||
}
|
||||
|
||||
root, err := ssz.HashTreeRoot(s)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not tree hash beacon state: %v", err)
|
||||
return nil, errors.Wrap(err, "could not tree hash beacon state")
|
||||
}
|
||||
log.WithField("beaconStateRoot", fmt.Sprintf("%#x", root)).Debugf("Computed state hash")
|
||||
return root[:], nil
|
||||
@@ -266,7 +266,7 @@ func (ps *ProposerServer) deposits(ctx context.Context, currentVote *ethpb.Eth1D
|
||||
// the number of all deposits in this RPC call. If not, then we return nil.
|
||||
beaconState, err := ps.beaconDB.HeadState(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not fetch beacon state: %v", err)
|
||||
return nil, errors.Wrap(err, "could not fetch beacon state")
|
||||
}
|
||||
latestEth1DataHeight, err := ps.latestEth1Height(ctx, beaconState, currentVote)
|
||||
if err != nil {
|
||||
@@ -276,21 +276,21 @@ func (ps *ProposerServer) deposits(ctx context.Context, currentVote *ethpb.Eth1D
|
||||
// If this is more than the total number of deposits stored in our deposit cache, we return an error
|
||||
upToEth1DataDeposits := ps.beaconDB.AllDeposits(ctx, latestEth1DataHeight)
|
||||
if len(upToEth1DataDeposits) > len(allDeps) {
|
||||
return nil, fmt.Errorf("number of deposits referred to by the eth1data is more than the current "+
|
||||
return nil, errors.Wrapf(err, "number of deposits referred to by the eth1data is more than the current "+
|
||||
"number of deposits in the deposit cache. %d is more than %d", len(upToEth1DataDeposits), len(allDeps))
|
||||
}
|
||||
depositData := [][]byte{}
|
||||
for _, dep := range upToEth1DataDeposits {
|
||||
depHash, err := ssz.HashTreeRoot(dep.Data)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("coulf not hash deposit data %v", err)
|
||||
return nil, errors.Wrap(err, "could not hash deposit data")
|
||||
}
|
||||
depositData = append(depositData, depHash[:])
|
||||
}
|
||||
|
||||
depositTrie, err := trieutil.GenerateTrieFromItems(depositData, int(params.BeaconConfig().DepositContractTreeDepth))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not generate historical deposit trie from deposits: %v", err)
|
||||
return nil, errors.Wrap(err, "could not generate historical deposit trie from deposits")
|
||||
}
|
||||
|
||||
allPendingContainers := ps.beaconDB.PendingContainers(ctx, latestEth1DataHeight)
|
||||
@@ -332,7 +332,7 @@ func (ps *ProposerServer) latestEth1Height(ctx context.Context, beaconState *pbp
|
||||
beaconState.Eth1DataVotes = append(beaconState.Eth1DataVotes, currentVote)
|
||||
hasSupport, err := blocks.Eth1DataHasEnoughSupport(beaconState, currentVote)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not determine if current eth1data vote has enough support: %v", err)
|
||||
return nil, errors.Wrap(err, "could not determine if current eth1data vote has enough support")
|
||||
}
|
||||
if hasSupport {
|
||||
eth1BlockHash = bytesutil.ToBytes32(currentVote.BlockHash)
|
||||
@@ -341,7 +341,7 @@ func (ps *ProposerServer) latestEth1Height(ctx context.Context, beaconState *pbp
|
||||
}
|
||||
_, latestEth1DataHeight, err := ps.powChainService.BlockExists(ctx, eth1BlockHash)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not fetch eth1data height: %v", err)
|
||||
return nil, errors.Wrap(err, "could not fetch eth1data height")
|
||||
}
|
||||
return latestEth1DataHeight, nil
|
||||
}
|
||||
@@ -355,7 +355,7 @@ func (ps *ProposerServer) defaultEth1DataResponse(ctx context.Context, currentHe
|
||||
ancestorHeight := big.NewInt(0).Sub(currentHeight, big.NewInt(eth1FollowDistance))
|
||||
blockHash, err := ps.powChainService.BlockHashByHeight(ctx, ancestorHeight)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not fetch ETH1_FOLLOW_DISTANCE ancestor: %v", err)
|
||||
return nil, errors.Wrap(err, "could not fetch ETH1_FOLLOW_DISTANCE ancestor")
|
||||
}
|
||||
// Fetch all historical deposits up to an ancestor height.
|
||||
depositsTillHeight, depositRoot := ps.beaconDB.DepositsNumberAndRootAtHeight(ctx, ancestorHeight)
|
||||
|
||||
@@ -114,7 +114,7 @@ func (vs *ValidatorServer) ValidatorPerformance(
|
||||
|
||||
validatorBalances, err := vs.beaconDB.Balances(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not retrieve validator balances %v", err)
|
||||
return nil, errors.Wrap(err, "could not retrieve validator balances")
|
||||
}
|
||||
|
||||
avgBalance := float32(totalActiveBalance / activeCount)
|
||||
|
||||
@@ -522,7 +522,7 @@ func (rs *RegularSync) handleBatchedBlockRequest(msg p2p.Message) error {
|
||||
response, err := rs.respondBatchedBlocks(ctx, req.FinalizedRoot, req.CanonicalRoot)
|
||||
cancel()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not build canonical block list %v", err)
|
||||
return errors.Wrap(err, "could not build canonical block list")
|
||||
}
|
||||
log.WithField("peer", msg.Peer).Debug("Sending response for batch blocks")
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ package ethereum.beacon.p2p.v1;
|
||||
import "proto/beacon/p2p/v1/types.proto";
|
||||
import "proto/eth/v1alpha1/attestation.proto";
|
||||
import "proto/eth/v1alpha1/beacon_block.proto";
|
||||
import "proto/eth/v1alpha1/validator.proto";
|
||||
import "google/protobuf/timestamp.proto";
|
||||
|
||||
enum Topic {
|
||||
|
||||
@@ -3,7 +3,6 @@ syntax = "proto3";
|
||||
package ethereum.beacon.rpc.v1;
|
||||
|
||||
import "google/protobuf/empty.proto";
|
||||
import "proto/beacon/p2p/v1/types.proto";
|
||||
import "proto/eth/v1alpha1/beacon_block.proto";
|
||||
import "proto/eth/v1alpha1/attestation.proto";
|
||||
import "google/api/annotations.proto";
|
||||
|
||||
@@ -9,6 +9,7 @@ go_library(
|
||||
],
|
||||
importpath = "github.com/prysmaticlabs/prysm/shared/sliceutil",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@com_github_pkg_errors//:go_default_library"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package sliceutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func interfaceToSlice(slice interface{}) ([]interface{}, error) {
|
||||
s := reflect.ValueOf(slice)
|
||||
if s.Kind() != reflect.Slice {
|
||||
return nil, fmt.Errorf("slice error: not of type slice")
|
||||
return nil, errors.New("slice error: not of type slice")
|
||||
}
|
||||
ret := make([]interface{}, s.Len())
|
||||
for i := 0; i < s.Len(); i++ {
|
||||
@@ -20,17 +21,15 @@ func interfaceToSlice(slice interface{}) ([]interface{}, error) {
|
||||
// GenericIntersection returns a new set with elements that are common in
|
||||
// both sets a and b.
|
||||
func GenericIntersection(a, b interface{}) (reflect.Value, error) {
|
||||
|
||||
set := reflect.MakeSlice(reflect.TypeOf(a), 0, 0)
|
||||
set1, err1 := interfaceToSlice(a)
|
||||
set2, err2 := interfaceToSlice(b)
|
||||
|
||||
if err1 != nil {
|
||||
return set, fmt.Errorf("slice type is invalid %v", err1)
|
||||
set1, err := interfaceToSlice(a)
|
||||
if err != nil {
|
||||
return set, errors.Wrap(err, "slice type is invalid")
|
||||
}
|
||||
|
||||
if err2 != nil {
|
||||
return set, fmt.Errorf("slice type is invalid %v", err2)
|
||||
set2, err := interfaceToSlice(b)
|
||||
if err != nil {
|
||||
return set, errors.Wrap(err, "slice type is invalid")
|
||||
}
|
||||
if len(set1) == 0 || len(set2) == 0 {
|
||||
return set, nil
|
||||
@@ -60,15 +59,14 @@ func GenericIntersection(a, b interface{}) (reflect.Value, error) {
|
||||
func GenericUnion(a, b interface{}) (reflect.Value, error) {
|
||||
|
||||
set := reflect.MakeSlice(reflect.TypeOf(a), 0, 0)
|
||||
set1, err1 := interfaceToSlice(a)
|
||||
set2, err2 := interfaceToSlice(b)
|
||||
|
||||
if err1 != nil {
|
||||
return set, fmt.Errorf("slice type is invalid %v", err1)
|
||||
set1, err := interfaceToSlice(a)
|
||||
if err != nil {
|
||||
return set, errors.Wrap(err, "slice type is invalid")
|
||||
}
|
||||
|
||||
if err2 != nil {
|
||||
return set, fmt.Errorf("slice type is invalid %v", err2)
|
||||
set2, err := interfaceToSlice(b)
|
||||
if err != nil {
|
||||
return set, errors.Wrap(err, "slice type is invalid")
|
||||
}
|
||||
|
||||
if len(set1) == 0 {
|
||||
@@ -104,15 +102,14 @@ func GenericUnion(a, b interface{}) (reflect.Value, error) {
|
||||
// set b.
|
||||
func GenericNot(a, b interface{}) (reflect.Value, error) {
|
||||
set := reflect.MakeSlice(reflect.TypeOf(a), 0, 0)
|
||||
set1, err1 := interfaceToSlice(a)
|
||||
set2, err2 := interfaceToSlice(b)
|
||||
|
||||
if err1 != nil {
|
||||
return set, fmt.Errorf("slice type is invalid %v", err1)
|
||||
set1, err := interfaceToSlice(a)
|
||||
if err != nil {
|
||||
return set, errors.Wrap(err, "slice type is invalid")
|
||||
}
|
||||
|
||||
if err2 != nil {
|
||||
return set, fmt.Errorf("slice type is invalid %v", err2)
|
||||
set2, err := interfaceToSlice(b)
|
||||
if err != nil {
|
||||
return set, errors.Wrap(err, "slice type is invalid")
|
||||
}
|
||||
|
||||
if len(set1) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user