Wrap errors ()

This commit is contained in:
Preston Van Loon 2019-08-01 22:27:38 -04:00 committed by terence tsao
parent 7eca7ba43b
commit 953c59a302
73 changed files with 351 additions and 307 deletions

View File

@ -18,6 +18,7 @@ go_library(
"//shared/messagehandler:go_default_library",
"//shared/params:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",

View File

@ -7,6 +7,7 @@ import (
"sync"
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
@ -231,7 +232,7 @@ func (a *Service) updateAttestation(beaconState *pb.BeaconState, attestation *et
}
slot, err := helpers.AttestationDataSlot(beaconState, attestation.Data)
if err != nil {
return fmt.Errorf("could not get attestation slot: %v", err)
return errors.Wrap(err, "could not get attestation slot")
}
log.WithFields(logrus.Fields{
"attestationSlot": slot,

View File

@ -25,6 +25,7 @@ go_library(
"//shared/event:go_default_library",
"//shared/p2p:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",

View File

@ -2,9 +2,9 @@ package blockchain
import (
"context"
"errors"
"fmt"
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-ssz"
b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
@ -59,14 +59,14 @@ func (c *ChainService) ReceiveBlock(ctx context.Context, block *ethpb.BeaconBloc
parentRoot := bytesutil.ToBytes32(block.ParentRoot)
parent, err := c.beaconDB.Block(parentRoot)
if err != nil {
return nil, fmt.Errorf("failed to get parent block: %v", err)
return nil, errors.Wrap(err, "failed to get parent block")
}
if parent == nil {
return nil, errors.New("parent does not exist in DB")
}
beaconState, err := c.beaconDB.HistoricalStateFromSlot(ctx, parent.Slot, parentRoot)
if err != nil {
return nil, fmt.Errorf("could not retrieve beacon state: %v", err)
return nil, errors.Wrap(err, "could not retrieve beacon state")
}
blockRoot, err := ssz.SigningRoot(block)
@ -96,11 +96,11 @@ func (c *ChainService) ReceiveBlock(ctx context.Context, block *ethpb.BeaconBloc
// If the block fails processing, we mark it as blacklisted and delete it from our DB.
c.beaconDB.MarkEvilBlockHash(blockRoot)
if err := c.beaconDB.DeleteBlock(block); err != nil {
return nil, fmt.Errorf("could not delete bad block from db: %v", err)
return nil, errors.Wrap(err, "could not delete bad block from db")
}
return beaconState, err
default:
return beaconState, fmt.Errorf("could not apply block state transition: %v", err)
return beaconState, errors.Wrap(err, "could not apply block state transition")
}
}
@ -112,7 +112,7 @@ func (c *ChainService) ReceiveBlock(ctx context.Context, block *ethpb.BeaconBloc
// We process the block's contained deposits, attestations, and other operations
// and that may need to be stored or deleted from the beacon node's persistent storage.
if err := c.CleanupBlockOperations(ctx, block); err != nil {
return beaconState, fmt.Errorf("could not process block deposits, attestations, and other operations: %v", err)
return beaconState, errors.Wrap(err, "could not process block deposits, attestations, and other operations")
}
log.WithFields(logrus.Fields{
@ -153,17 +153,17 @@ func (c *ChainService) VerifyBlockValidity(
func (c *ChainService) SaveAndBroadcastBlock(ctx context.Context, block *ethpb.BeaconBlock) error {
blockRoot, err := ssz.SigningRoot(block)
if err != nil {
return fmt.Errorf("could not tree hash incoming block: %v", err)
return errors.Wrap(err, "could not tree hash incoming block")
}
if err := c.beaconDB.SaveBlock(block); err != nil {
return fmt.Errorf("failed to save block: %v", err)
return errors.Wrap(err, "failed to save block")
}
if err := c.beaconDB.SaveAttestationTarget(ctx, &pb.AttestationTarget{
Slot: block.Slot,
BeaconBlockRoot: blockRoot[:],
ParentRoot: block.ParentRoot,
}); err != nil {
return fmt.Errorf("failed to save attestation target: %v", err)
return errors.Wrap(err, "failed to save attestation target")
}
// Announce the new block to the network.
c.p2p.Broadcast(ctx, &pb.BeaconBlockAnnounce{
@ -184,7 +184,7 @@ func (c *ChainService) CleanupBlockOperations(ctx context.Context, block *ethpb.
}
if err := c.attsService.BatchUpdateLatestAttestation(ctx, block.Body.Attestations); err != nil {
return fmt.Errorf("failed to update latest attestation for store: %v", err)
return errors.Wrap(err, "failed to update latest attestation for store")
}
// Remove pending deposits from the deposit queue.
@ -232,22 +232,22 @@ func (c *ChainService) AdvanceState(
}
// Save Historical States.
if err := c.beaconDB.SaveHistoricalState(ctx, beaconState, blockRoot); err != nil {
return nil, fmt.Errorf("could not save historical state: %v", err)
return nil, errors.Wrap(err, "could not save historical state")
}
}
if helpers.IsEpochStart(newState.Slot) {
// Save activated validators of this epoch to public key -> index DB.
if err := c.saveValidatorIdx(newState); err != nil {
return newState, fmt.Errorf("could not save validator index: %v", err)
return newState, errors.Wrap(err, "could not save validator index")
}
// Delete exited validators of this epoch to public key -> index DB.
if err := c.deleteValidatorIdx(newState); err != nil {
return newState, fmt.Errorf("could not delete validator index: %v", err)
return newState, errors.Wrap(err, "could not delete validator index")
}
// Update FFG checkpoints in DB.
if err := c.updateFFGCheckPts(ctx, newState); err != nil {
return newState, fmt.Errorf("could not update FFG checkpts: %v", err)
return newState, errors.Wrap(err, "could not update FFG checkpts")
}
logEpochData(newState)
}
@ -270,7 +270,7 @@ func (c *ChainService) saveValidatorIdx(state *pb.BeaconState) error {
}
pubKey := state.Validators[idx].PublicKey
if err := c.beaconDB.SaveValidatorIndex(pubKey, int(idx)); err != nil {
return fmt.Errorf("could not save validator index: %v", err)
return errors.Wrap(err, "could not save validator index")
}
}
// Since we are processing next epoch, save the can't processed validator indices
@ -288,7 +288,7 @@ func (c *ChainService) deleteValidatorIdx(state *pb.BeaconState) error {
for _, idx := range exitedValidators {
pubKey := state.Validators[idx].PublicKey
if err := c.beaconDB.DeleteValidatorIndex(pubKey); err != nil {
return fmt.Errorf("could not delete validator index: %v", err)
return errors.Wrap(err, "could not delete validator index")
}
}
validators.DeleteExitedVal(helpers.CurrentEpoch(state))

View File

@ -6,6 +6,7 @@ import (
"fmt"
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prysmaticlabs/go-ssz"
@ -145,24 +146,24 @@ func (c *ChainService) ApplyForkChoiceRule(
justifiedState, err := c.beaconDB.JustifiedState()
if err != nil {
return fmt.Errorf("could not retrieve justified state: %v", err)
return errors.Wrap(err, "could not retrieve justified state")
}
attestationTargets, err := c.AttestationTargets(justifiedState)
if err != nil {
return fmt.Errorf("could not retrieve attestation target: %v", err)
return errors.Wrap(err, "could not retrieve attestation target")
}
justifiedHead, err := c.beaconDB.JustifiedBlock()
if err != nil {
return fmt.Errorf("could not retrieve justified head: %v", err)
return errors.Wrap(err, "could not retrieve justified head")
}
newHead, err := c.lmdGhost(ctx, justifiedHead, justifiedState, attestationTargets)
if err != nil {
return fmt.Errorf("could not run fork choice: %v", err)
return errors.Wrap(err, "could not run fork choice")
}
newHeadRoot, err := ssz.SigningRoot(newHead)
if err != nil {
return fmt.Errorf("could not hash new head block: %v", err)
return errors.Wrap(err, "could not hash new head block")
}
c.canonicalBlocksLock.Lock()
defer c.canonicalBlocksLock.Unlock()
@ -170,16 +171,16 @@ func (c *ChainService) ApplyForkChoiceRule(
currentHead, err := c.beaconDB.ChainHead()
if err != nil {
return fmt.Errorf("could not retrieve chain head: %v", err)
return errors.Wrap(err, "could not retrieve chain head")
}
currentHeadRoot, err := ssz.SigningRoot(currentHead)
if err != nil {
return fmt.Errorf("could not hash current head block: %v", err)
return errors.Wrap(err, "could not hash current head block")
}
isDescendant, err := c.isDescendant(currentHead, newHead)
if err != nil {
return fmt.Errorf("could not check if block is descendant: %v", err)
return errors.Wrap(err, "could not check if block is descendant")
}
newState := postState
@ -193,7 +194,7 @@ func (c *ChainService) ApplyForkChoiceRule(
// Only regenerate head state if there was a reorg.
newState, err = c.beaconDB.HistoricalStateFromSlot(ctx, newHead.Slot, newHeadRoot)
if err != nil {
return fmt.Errorf("could not gen state: %v", err)
return errors.Wrap(err, "could not gen state")
}
for revertedSlot := currentHead.Slot; revertedSlot > newHead.Slot; revertedSlot-- {
@ -213,16 +214,16 @@ func (c *ChainService) ApplyForkChoiceRule(
if newHead.Slot != newState.Slot {
newState, err = c.beaconDB.HistoricalStateFromSlot(ctx, newHead.Slot, newHeadRoot)
if err != nil {
return fmt.Errorf("could not gen state: %v", err)
return errors.Wrap(err, "could not gen state")
}
}
if err := c.beaconDB.UpdateChainHead(ctx, newHead, newState); err != nil {
return fmt.Errorf("failed to update chain: %v", err)
return errors.Wrap(err, "failed to update chain")
}
h, err := ssz.SigningRoot(newHead)
if err != nil {
return fmt.Errorf("could not hash head: %v", err)
return errors.Wrap(err, "could not hash head")
}
log.WithFields(logrus.Fields{
"headRoot": fmt.Sprintf("%#x", bytesutil.Trunc(h[:])),
@ -272,7 +273,7 @@ func (c *ChainService) lmdGhost(
for {
children, err := c.BlockChildren(ctx, head, highestSlot)
if err != nil {
return nil, fmt.Errorf("could not fetch block children: %v", err)
return nil, errors.Wrap(err, "could not fetch block children")
}
if len(children) == 0 {
return head, nil
@ -281,12 +282,12 @@ func (c *ChainService) lmdGhost(
maxChildVotes, err := VoteCount(maxChild, startState, voteTargets, c.beaconDB)
if err != nil {
return nil, fmt.Errorf("unable to determine vote count for block: %v", err)
return nil, errors.Wrap(err, "unable to determine vote count for block")
}
for i := 1; i < len(children); i++ {
candidateChildVotes, err := VoteCount(children[i], startState, voteTargets, c.beaconDB)
if err != nil {
return nil, fmt.Errorf("unable to determine vote count for block: %v", err)
return nil, errors.Wrap(err, "unable to determine vote count for block")
}
maxChildRoot, err := ssz.SigningRoot(maxChild)
if err != nil {
@ -327,7 +328,7 @@ func (c *ChainService) BlockChildren(ctx context.Context, block *ethpb.BeaconBlo
for i := startSlot; i <= highestSlot; i++ {
kids, err := c.beaconDB.BlocksBySlot(ctx, i)
if err != nil {
return nil, fmt.Errorf("could not get block by slot: %v", err)
return nil, errors.Wrap(err, "could not get block by slot")
}
children = append(children, kids...)
}
@ -376,7 +377,7 @@ func (c *ChainService) AttestationTargets(state *pb.BeaconState) (map[uint64]*pb
for i, index := range indices {
target, err := c.attsService.LatestAttestationTarget(state, index)
if err != nil {
return nil, fmt.Errorf("could not retrieve attestation target: %v", err)
return nil, errors.Wrap(err, "could not retrieve attestation target")
}
if target == nil {
continue
@ -450,10 +451,10 @@ func BlockAncestor(targetBlock *pb.AttestationTarget, slot uint64, beaconDB *db.
parentRoot := bytesutil.ToBytes32(targetBlock.ParentRoot)
parent, err := beaconDB.Block(parentRoot)
if err != nil {
return nil, fmt.Errorf("could not get parent block: %v", err)
return nil, errors.Wrap(err, "could not get parent block")
}
if parent == nil {
return nil, fmt.Errorf("parent block does not exist: %v", err)
return nil, errors.Wrap(err, "parent block does not exist")
}
newTarget := &pb.AttestationTarget{
Slot: parent.Slot,

View File

@ -11,6 +11,7 @@ import (
"sync"
"time"
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/attestation"
b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
@ -135,47 +136,47 @@ func (c *ChainService) initializeBeaconChain(genesisTime time.Time, deposits []*
c.genesisTime = genesisTime
unixTime := uint64(genesisTime.Unix())
if err := c.beaconDB.InitializeState(c.ctx, unixTime, deposits, eth1data); err != nil {
return nil, fmt.Errorf("could not initialize beacon state to disk: %v", err)
return nil, errors.Wrap(err, "could not initialize beacon state to disk")
}
beaconState, err := c.beaconDB.HeadState(c.ctx)
if err != nil {
return nil, fmt.Errorf("could not attempt fetch beacon state: %v", err)
return nil, errors.Wrap(err, "could not attempt fetch beacon state")
}
stateRoot, err := ssz.HashTreeRoot(beaconState)
if err != nil {
return nil, fmt.Errorf("could not hash beacon state: %v", err)
return nil, errors.Wrap(err, "could not hash beacon state")
}
genBlock := b.NewGenesisBlock(stateRoot[:])
genBlockRoot, err := ssz.SigningRoot(genBlock)
if err != nil {
return nil, fmt.Errorf("could not hash beacon block: %v", err)
return nil, errors.Wrap(err, "could not hash beacon block")
}
if err := c.beaconDB.SaveBlock(genBlock); err != nil {
return nil, fmt.Errorf("could not save genesis block to disk: %v", err)
return nil, errors.Wrap(err, "could not save genesis block to disk")
}
if err := c.beaconDB.SaveAttestationTarget(ctx, &pb.AttestationTarget{
Slot: genBlock.Slot,
BeaconBlockRoot: genBlockRoot[:],
ParentRoot: genBlock.ParentRoot,
}); err != nil {
return nil, fmt.Errorf("failed to save attestation target: %v", err)
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)
}
if err := c.beaconDB.SaveJustifiedBlock(genBlock); err != nil {
return nil, fmt.Errorf("could not save genesis block as justified block: %v", err)
return nil, errors.Wrap(err, "could not save genesis block as justified block")
}
if err := c.beaconDB.SaveFinalizedBlock(genBlock); err != nil {
return nil, fmt.Errorf("could not save genesis block as finalized block: %v", err)
return nil, errors.Wrap(err, "could not save genesis block as finalized block")
}
if err := c.beaconDB.SaveJustifiedState(beaconState); err != nil {
return nil, fmt.Errorf("could not save genesis state as justified state: %v", err)
return nil, errors.Wrap(err, "could not save genesis state as justified state")
}
if err := c.beaconDB.SaveFinalizedState(beaconState); err != nil {
return nil, fmt.Errorf("could not save genesis state as finalized state: %v", err)
return nil, errors.Wrap(err, "could not save genesis state as finalized state")
}
return beaconState, nil
}
@ -214,12 +215,12 @@ func (c *ChainService) StateInitializedFeed() *event.Feed {
func (c *ChainService) ChainHeadRoot() ([32]byte, error) {
head, err := c.beaconDB.ChainHead()
if err != nil {
return [32]byte{}, fmt.Errorf("could not retrieve chain head: %v", err)
return [32]byte{}, errors.Wrap(err, "could not retrieve chain head")
}
root, err := ssz.SigningRoot(head)
if err != nil {
return [32]byte{}, fmt.Errorf("could not tree hash parent block: %v", err)
return [32]byte{}, errors.Wrap(err, "could not tree hash parent block")
}
return root, nil
}

View File

@ -25,6 +25,7 @@ go_library(
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_ethereum_go_ethereum//core/types:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
],

View File

@ -3,11 +3,12 @@ package blocks
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"sort"
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
@ -31,15 +32,15 @@ var eth1DataCache = cache.NewEth1DataVoteCache()
func verifySigningRoot(obj interface{}, pub []byte, signature []byte, domain uint64) error {
publicKey, err := bls.PublicKeyFromBytes(pub)
if err != nil {
return fmt.Errorf("could not convert bytes to public key: %v", err)
return errors.Wrap(err, "could not convert bytes to public key")
}
sig, err := bls.SignatureFromBytes(signature)
if err != nil {
return fmt.Errorf("could not convert bytes to signature: %v", err)
return errors.Wrap(err, "could not convert bytes to signature")
}
root, err := ssz.SigningRoot(obj)
if err != nil {
return fmt.Errorf("could not get signing root: %v", err)
return errors.Wrap(err, "could not get signing root")
}
if !sig.Verify(root[:], publicKey, domain) {
return fmt.Errorf("signature did not verify")
@ -50,11 +51,11 @@ func verifySigningRoot(obj interface{}, pub []byte, signature []byte, domain uin
func verifySignature(signedData []byte, pub []byte, signature []byte, domain uint64) error {
publicKey, err := bls.PublicKeyFromBytes(pub)
if err != nil {
return fmt.Errorf("could not convert bytes to public key: %v", err)
return errors.Wrap(err, "could not convert bytes to public key")
}
sig, err := bls.SignatureFromBytes(signature)
if err != nil {
return fmt.Errorf("could not convert bytes to signature: %v", err)
return errors.Wrap(err, "could not convert bytes to signature")
}
if !sig.Verify(signedData, publicKey, domain) {
return fmt.Errorf("signature did not verify")
@ -93,11 +94,11 @@ func ProcessEth1DataInBlock(beaconState *pb.BeaconState, block *ethpb.BeaconBloc
func Eth1DataHasEnoughSupport(beaconState *pb.BeaconState, data *ethpb.Eth1Data) (bool, error) {
eth1DataHash, err := hashutil.HashProto(data)
if err != nil {
return false, fmt.Errorf("could not hash eth1data: %v", err)
return false, errors.Wrap(err, "could not hash eth1data")
}
voteCount, err := eth1DataCache.Eth1DataVote(eth1DataHash)
if err != nil {
return false, fmt.Errorf("could not retrieve eth1 data vote cache: %v", err)
return false, errors.Wrap(err, "could not retrieve eth1 data vote cache")
}
if voteCount == 0 {
@ -114,7 +115,7 @@ func Eth1DataHasEnoughSupport(beaconState *pb.BeaconState, data *ethpb.Eth1Data)
Eth1DataHash: eth1DataHash,
VoteCount: voteCount,
}); err != nil {
return false, fmt.Errorf("could not save eth1 data vote cache: %v", err)
return false, errors.Wrap(err, "could not save eth1 data vote cache")
}
// If 50+% majority converged on the same eth1data, then it has enough support to update the
@ -188,7 +189,7 @@ func ProcessBlockHeader(
currentEpoch := helpers.CurrentEpoch(beaconState)
domain := helpers.Domain(beaconState, currentEpoch, params.BeaconConfig().DomainBeaconProposer)
if err := verifySigningRoot(block, proposer.PublicKey, block.Signature, domain); err != nil {
return nil, fmt.Errorf("could not verify block signature: %v", err)
return nil, errors.Wrap(err, "could not verify block signature")
}
return beaconState, nil
@ -285,7 +286,7 @@ func ProcessRandao(
) (*pb.BeaconState, error) {
proposerIdx, err := helpers.BeaconProposerIndex(beaconState)
if err != nil {
return nil, fmt.Errorf("could not get beacon proposer index: %v", err)
return nil, errors.Wrap(err, "could not get beacon proposer index")
}
proposerPub := beaconState.Validators[proposerIdx].PublicKey
@ -295,7 +296,7 @@ func ProcessRandao(
domain := helpers.Domain(beaconState, currentEpoch, params.BeaconConfig().DomainRandao)
if err := verifySignature(buf, proposerPub, body.RandaoReveal, domain); err != nil {
return nil, fmt.Errorf("could not verify block randao: %v", err)
return nil, errors.Wrap(err, "could not verify block randao")
}
// If block randao passed verification, we XOR the state's latest randao mix with the block's
@ -377,7 +378,7 @@ func verifyProposerSlashing(
headers := append([]*ethpb.BeaconBlockHeader{slashing.Header_1}, slashing.Header_2)
for _, header := range headers {
if err := verifySigningRoot(header, proposer.PublicKey, header.Signature, domain); err != nil {
return fmt.Errorf("could not verify beacon block header: %v", err)
return errors.Wrap(err, "could not verify beacon block header")
}
}
return nil
@ -447,10 +448,10 @@ func verifyAttesterSlashing(beaconState *pb.BeaconState, slashing *ethpb.Atteste
return errors.New("attestations are not slashable")
}
if err := VerifyIndexedAttestation(beaconState, att1); err != nil {
return fmt.Errorf("could not validate indexed attestation: %v", err)
return errors.Wrap(err, "could not validate indexed attestation")
}
if err := VerifyIndexedAttestation(beaconState, att2); err != nil {
return fmt.Errorf("could not validate indexed attestation: %v", err)
return errors.Wrap(err, "could not validate indexed attestation")
}
return nil
}
@ -538,7 +539,7 @@ func ProcessAttestation(beaconState *pb.BeaconState, att *ethpb.Attestation) (*p
data := att.Data
attestationSlot, err := helpers.AttestationDataSlot(beaconState, 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")
}
minInclusionCheck := attestationSlot+params.BeaconConfig().MinAttestationInclusionDelay <= beaconState.Slot
epochInclusionCheck := beaconState.Slot <= attestationSlot+params.BeaconConfig().SlotsPerEpoch
@ -627,7 +628,7 @@ func ProcessAttestation(beaconState *pb.BeaconState, att *ethpb.Attestation) (*p
}
crosslinkParentRoot, err := ssz.HashTreeRoot(parentCrosslink)
if err != nil {
return nil, fmt.Errorf("could not tree hash parent crosslink: %v", err)
return nil, errors.Wrap(err, "could not tree hash parent crosslink")
}
if !bytes.Equal(data.Crosslink.ParentRoot, crosslinkParentRoot[:]) {
return nil, fmt.Errorf(
@ -642,10 +643,10 @@ func ProcessAttestation(beaconState *pb.BeaconState, att *ethpb.Attestation) (*p
}
indexedAtt, err := ConvertToIndexed(beaconState, att)
if err != nil {
return nil, fmt.Errorf("could not convert to indexed attestation: %v", err)
return nil, errors.Wrap(err, "could not convert to indexed attestation")
}
if err := VerifyIndexedAttestation(beaconState, indexedAtt); err != nil {
return nil, fmt.Errorf("could not verify indexed attestation: %v", err)
return nil, errors.Wrap(err, "could not verify indexed attestation")
}
return beaconState, nil
}
@ -671,7 +672,7 @@ func ProcessAttestation(beaconState *pb.BeaconState, att *ethpb.Attestation) (*p
func ConvertToIndexed(state *pb.BeaconState, attestation *ethpb.Attestation) (*ethpb.IndexedAttestation, error) {
attIndices, err := helpers.AttestingIndices(state, attestation.Data, attestation.AggregationBits)
if err != nil {
return nil, fmt.Errorf("could not get attesting indices: %v", err)
return nil, errors.Wrap(err, "could not get attesting indices")
}
cb1i, err := helpers.AttestingIndices(state, attestation.Data, attestation.CustodyBits)
if err != nil {
@ -783,12 +784,12 @@ func VerifyIndexedAttestation(beaconState *pb.BeaconState, indexedAtt *ethpb.Ind
if len(custodyBit0Indices) > 0 {
pubkey, err := bls.PublicKeyFromBytes(beaconState.Validators[custodyBit0Indices[0]].PublicKey)
if err != nil {
return fmt.Errorf("could not deserialize validator public key: %v", err)
return errors.Wrap(err, "could not deserialize validator public key")
}
for _, i := range custodyBit0Indices[1:] {
pk, err := bls.PublicKeyFromBytes(beaconState.Validators[i].PublicKey)
if err != nil {
return fmt.Errorf("could not deserialize validator public key: %v", err)
return errors.Wrap(err, "could not deserialize validator public key")
}
pubkey.Aggregate(pk)
}
@ -797,12 +798,12 @@ func VerifyIndexedAttestation(beaconState *pb.BeaconState, indexedAtt *ethpb.Ind
if len(custodyBit1Indices) > 0 {
pubkey, err := bls.PublicKeyFromBytes(beaconState.Validators[custodyBit1Indices[0]].PublicKey)
if err != nil {
return fmt.Errorf("could not deserialize validator public key: %v", err)
return errors.Wrap(err, "could not deserialize validator public key")
}
for _, i := range custodyBit1Indices[1:] {
pk, err := bls.PublicKeyFromBytes(beaconState.Validators[i].PublicKey)
if err != nil {
return fmt.Errorf("could not deserialize validator public key: %v", err)
return errors.Wrap(err, "could not deserialize validator public key")
}
pubkey.Aggregate(pk)
}
@ -813,17 +814,17 @@ func VerifyIndexedAttestation(beaconState *pb.BeaconState, indexedAtt *ethpb.Ind
cus1 := &pb.AttestationDataAndCustodyBit{Data: indexedAtt.Data, CustodyBit: true}
cus0Root, err := ssz.HashTreeRoot(cus0)
if err != nil {
return fmt.Errorf("could not tree hash att data and custody bit 0: %v", err)
return errors.Wrap(err, "could not tree hash att data and custody bit 0")
}
cus1Root, err := ssz.HashTreeRoot(cus1)
if err != nil {
return fmt.Errorf("could not tree hash att data and custody bit 1: %v", err)
return errors.Wrap(err, "could not tree hash att data and custody bit 1")
}
msgs := append(cus0Root[:], cus1Root[:]...)
sig, err := bls.SignatureFromBytes(indexedAtt.Signature)
if err != nil {
return fmt.Errorf("could not convert bytes to signature: %v", err)
return errors.Wrap(err, "could not convert bytes to signature")
}
hasVotes := len(custodyBit0Indices) > 0 || len(custodyBit1Indices) > 0
@ -947,7 +948,7 @@ func verifyDeposit(beaconState *pb.BeaconState, deposit *ethpb.Deposit) error {
receiptRoot := beaconState.Eth1Data.DepositRoot
leaf, err := ssz.HashTreeRoot(deposit.Data)
if err != nil {
return fmt.Errorf("could not tree hash deposit data: %v", err)
return errors.Wrap(err, "could not tree hash deposit data")
}
if ok := trieutil.VerifyMerkleProof(
receiptRoot,
@ -1035,7 +1036,7 @@ func verifyExit(beaconState *pb.BeaconState, exit *ethpb.VoluntaryExit) error {
}
domain := helpers.Domain(beaconState, exit.Epoch, params.BeaconConfig().DomainVoluntaryExit)
if err := verifySigningRoot(exit, validator.PublicKey, exit.Signature, domain); err != nil {
return fmt.Errorf("could not verify voluntary exit signature: %v", err)
return errors.Wrap(err, "could not verify voluntary exit signature")
}
return nil
}
@ -1090,7 +1091,7 @@ func ProcessTransfers(
beaconState = helpers.IncreaseBalance(beaconState, transfer.RecipientIndex, transfer.Amount)
proposerIndex, err := helpers.BeaconProposerIndex(beaconState)
if err != nil {
return nil, fmt.Errorf("could not determine beacon proposer index: %v", err)
return nil, errors.Wrap(err, "could not determine beacon proposer index")
}
beaconState = helpers.IncreaseBalance(beaconState, proposerIndex, transfer.Fee)
@ -1159,7 +1160,7 @@ func verifyTransfer(beaconState *pb.BeaconState, transfer *ethpb.Transfer) error
domain := helpers.Domain(beaconState, helpers.CurrentEpoch(beaconState), params.BeaconConfig().DomainTransfer)
if err := verifySigningRoot(transfer, transfer.SenderWithdrawalPublicKey, transfer.Signature, domain); err != nil {
return fmt.Errorf("could not verify transfer signature: %v", err)
return errors.Wrap(err, "could not verify transfer signature")
}
return nil
}

View File

@ -7,6 +7,7 @@ import (
"github.com/ethereum/go-ethereum/common"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/pkg/errors"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
@ -33,7 +34,7 @@ func IsValidBlock(
h := common.BytesToHash(state.Eth1Data.BlockHash)
powBlock, err := GetPOWBlock(ctx, h)
if err != nil {
return fmt.Errorf("unable to retrieve POW chain reference block: %v", err)
return errors.Wrap(err, "unable to retrieve POW chain reference block")
}
// Pre-Processing Condition 2:

View File

@ -13,6 +13,7 @@ go_library(
"//shared/mathutil:go_default_library",
"//shared/params:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
],
)

View File

@ -6,11 +6,11 @@ package epoch
import (
"bytes"
"errors"
"fmt"
"sort"
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/validators"
@ -84,7 +84,7 @@ func MatchAttestations(state *pb.BeaconState, epoch uint64) (*MatchedAttestation
// then we know this attestation has correctly voted for head.
slot, err := helpers.AttestationDataSlot(state, srcAtt.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")
}
headRoot, err := helpers.BlockRootAtSlot(state, slot)
if err != nil {
@ -114,7 +114,7 @@ func MatchAttestations(state *pb.BeaconState, epoch uint64) (*MatchedAttestation
func AttestingBalance(state *pb.BeaconState, atts []*pb.PendingAttestation) (uint64, error) {
indices, err := unslashedAttestingIndices(state, atts)
if err != nil {
return 0, fmt.Errorf("could not get attesting indices: %v", err)
return 0, errors.Wrap(err, "could not get attesting indices")
}
return helpers.TotalBalance(state, indices), nil
}
@ -169,7 +169,7 @@ func ProcessJustificationAndFinalization(state *pb.BeaconState, prevAttestedBal
totalBal, err := helpers.TotalActiveBalance(state)
if err != nil {
return nil, fmt.Errorf("could not get total balance: %v", err)
return nil, errors.Wrap(err, "could not get total balance")
}
// Process justifications
@ -246,21 +246,21 @@ func ProcessCrosslinks(state *pb.BeaconState) (*pb.BeaconState, error) {
for _, e := range epochs {
count, err := helpers.CommitteeCount(state, e)
if err != nil {
return nil, fmt.Errorf("could not get epoch committee count: %v", err)
return nil, errors.Wrap(err, "could not get epoch committee count")
}
startShard, err := helpers.StartShard(state, e)
if err != nil {
return nil, fmt.Errorf("could not get epoch start shards: %v", err)
return nil, errors.Wrap(err, "could not get epoch start shards")
}
for offset := uint64(0); offset < count; offset++ {
shard := (startShard + offset) % params.BeaconConfig().ShardCount
committee, err := helpers.CrosslinkCommittee(state, e, shard)
if err != nil {
return nil, fmt.Errorf("could not get crosslink committee: %v", err)
return nil, errors.Wrap(err, "could not get crosslink committee")
}
crosslink, indices, err := winningCrosslink(state, shard, e)
if err != nil {
return nil, fmt.Errorf("could not get winning crosslink: %v", err)
return nil, errors.Wrap(err, "could not get winning crosslink")
}
attestedBalance := helpers.TotalBalance(state, indices)
totalBalance := helpers.TotalBalance(state, committee)
@ -373,7 +373,7 @@ func ProcessRegistryUpdates(state *pb.BeaconState) (*pb.BeaconState, error) {
limit := len(activationQ)
churnLimit, err := helpers.ValidatorChurnLimit(state)
if err != nil {
return nil, fmt.Errorf("could not get churn limit: %v", err)
return nil, errors.Wrap(err, "could not get churn limit")
}
// Prevent churn limit cause index out of bound.
@ -404,7 +404,7 @@ func ProcessSlashings(state *pb.BeaconState) (*pb.BeaconState, error) {
currentEpoch := helpers.CurrentEpoch(state)
totalBalance, err := helpers.TotalActiveBalance(state)
if err != nil {
return nil, fmt.Errorf("could not get total active balance: %v", err)
return nil, errors.Wrap(err, "could not get total active balance")
}
// Compute slashed balances in the current epoch
@ -490,7 +490,7 @@ func ProcessFinalUpdates(state *pb.BeaconState) (*pb.BeaconState, error) {
// Update start shard.
delta, err := helpers.ShardDelta(state, currentEpoch)
if err != nil {
return nil, fmt.Errorf("could not get shard delta: %v", err)
return nil, errors.Wrap(err, "could not get shard delta")
}
state.StartShard = (state.StartShard + delta) %
params.BeaconConfig().ShardCount
@ -504,11 +504,11 @@ func ProcessFinalUpdates(state *pb.BeaconState) (*pb.BeaconState, error) {
idxRootPosition := (nextEpoch + activationDelay) % params.BeaconConfig().EpochsPerHistoricalVector
activeIndices, err := helpers.ActiveValidatorIndices(state, nextEpoch+activationDelay)
if err != nil {
return nil, fmt.Errorf("could not get active indices: %v", err)
return nil, errors.Wrap(err, "could not get active indices")
}
idxRoot, err := ssz.HashTreeRootWithCapacity(activeIndices, uint64(1099511627776))
if err != nil {
return nil, fmt.Errorf("could not tree hash active indices: %v", err)
return nil, errors.Wrap(err, "could not tree hash active indices")
}
state.ActiveIndexRoots[idxRootPosition] = idxRoot[:]
@ -537,7 +537,7 @@ func ProcessFinalUpdates(state *pb.BeaconState) (*pb.BeaconState, error) {
}
batchRoot, err := ssz.HashTreeRoot(historicalBatch)
if err != nil {
return nil, fmt.Errorf("could not hash historical batch: %v", err)
return nil, errors.Wrap(err, "could not hash historical batch")
}
state.HistoricalRoots = append(state.HistoricalRoots, batchRoot[:])
}
@ -563,7 +563,7 @@ func unslashedAttestingIndices(state *pb.BeaconState, atts []*pb.PendingAttestat
for _, att := range atts {
indices, err := helpers.AttestingIndices(state, att.Data, att.AggregationBits)
if err != nil {
return nil, fmt.Errorf("could not get attester indices: %v", err)
return nil, errors.Wrap(err, "could not get attester indices")
}
setIndices = append(setIndices, indices...)
}
@ -600,7 +600,7 @@ func winningCrosslink(state *pb.BeaconState, shard uint64, epoch uint64) (*ethpb
var shardAtts []*pb.PendingAttestation
matchedAtts, err := MatchAttestations(state, epoch)
if err != nil {
return nil, nil, fmt.Errorf("could not get matching attestations: %v", err)
return nil, nil, errors.Wrap(err, "could not get matching attestations")
}
// Filter out source attestations by shard.
@ -615,11 +615,11 @@ func winningCrosslink(state *pb.BeaconState, shard uint64, epoch uint64) (*ethpb
stateCrosslink := state.CurrentCrosslinks[shard]
stateCrosslinkRoot, err := ssz.HashTreeRoot(stateCrosslink)
if err != nil {
return nil, nil, fmt.Errorf("could not hash tree root crosslink from state: %v", err)
return nil, nil, errors.Wrap(err, "could not hash tree root crosslink from state")
}
attCrosslinkRoot, err := ssz.HashTreeRoot(a.Data.Crosslink)
if err != nil {
return nil, nil, fmt.Errorf("could not hash tree root crosslink from attestation: %v", err)
return nil, nil, errors.Wrap(err, "could not hash tree root crosslink from attestation")
}
currCrosslinkMatches := bytes.Equal(stateCrosslinkRoot[:], attCrosslinkRoot[:])
prevCrosslinkMatches := bytes.Equal(stateCrosslinkRoot[:], a.Data.Crosslink.ParentRoot)
@ -650,7 +650,7 @@ func winningCrosslink(state *pb.BeaconState, shard uint64, epoch uint64) (*ethpb
crosslinkAtts = attsForCrosslink(c, shardAtts)
attestingBalance, err := AttestingBalance(state, crosslinkAtts)
if err != nil {
return nil, nil, fmt.Errorf("could not get crosslink's attesting balance: %v", err)
return nil, nil, errors.Wrap(err, "could not get crosslink's attesting balance")
}
if attestingBalance > winnerBalance {
winnerCrosslink = c
@ -679,7 +679,7 @@ func winningCrosslink(state *pb.BeaconState, shard uint64, epoch uint64) (*ethpb
func baseReward(state *pb.BeaconState, index uint64) (uint64, error) {
totalBalance, err := helpers.TotalActiveBalance(state)
if err != nil {
return 0, fmt.Errorf("could not calculate active balance: %v", err)
return 0, errors.Wrap(err, "could not calculate active balance")
}
effectiveBalance := state.Validators[index].EffectiveBalance
baseReward := effectiveBalance * params.BeaconConfig().BaseRewardFactor /
@ -752,7 +752,7 @@ func attestationDelta(state *pb.BeaconState) ([]uint64, []uint64, error) {
prevEpoch := helpers.PrevEpoch(state)
totalBalance, err := helpers.TotalActiveBalance(state)
if err != nil {
return nil, nil, fmt.Errorf("could not get total active balance: %v", err)
return nil, nil, errors.Wrap(err, "could not get total active balance")
}
rewards := make([]uint64, len(state.Validators))
@ -773,7 +773,7 @@ func attestationDelta(state *pb.BeaconState) ([]uint64, []uint64, error) {
// Construct a attestations list contains source, target and head attestations.
atts, err := MatchAttestations(state, prevEpoch)
if err != nil {
return nil, nil, fmt.Errorf("could not get source, target and head attestations: %v", err)
return nil, nil, errors.Wrap(err, "could not get source, target and head attestations")
}
var attsPackage [][]*pb.PendingAttestation
attsPackage = append(attsPackage, atts.source)
@ -788,7 +788,7 @@ func attestationDelta(state *pb.BeaconState) ([]uint64, []uint64, error) {
for i, matchAtt := range attsPackage {
indices, err := unslashedAttestingIndices(state, matchAtt)
if err != nil {
return nil, nil, fmt.Errorf("could not get attestation indices: %v", err)
return nil, nil, errors.Wrap(err, "could not get attestation indices")
}
attested := make(map[uint64]bool)
@ -805,7 +805,7 @@ func attestationDelta(state *pb.BeaconState) ([]uint64, []uint64, error) {
for _, index := range eligible {
base, err := baseReward(state, index)
if err != nil {
return nil, nil, fmt.Errorf("could not get base reward: %v", err)
return nil, nil, errors.Wrap(err, "could not get base reward")
}
if _, ok := attested[index]; ok {
rewards[index] += base * attestedBalance / totalBalance
@ -820,7 +820,7 @@ func attestationDelta(state *pb.BeaconState) ([]uint64, []uint64, error) {
for _, att := range atts.source {
indices, err := helpers.AttestingIndices(state, att.Data, att.AggregationBits)
if err != nil {
return nil, nil, fmt.Errorf("could not get attester indices: %v", err)
return nil, nil, errors.Wrap(err, "could not get attester indices")
}
for _, i := range indices {
if _, ok := attestersVotedSoruce[i]; ok {
@ -836,7 +836,7 @@ func attestationDelta(state *pb.BeaconState) ([]uint64, []uint64, error) {
baseReward, err := baseReward(state, i)
if err != nil {
return nil, nil, fmt.Errorf("could not get proposer reward: %v", err)
return nil, nil, errors.Wrap(err, "could not get proposer reward")
}
proposerReward := baseReward / params.BeaconConfig().ProposerRewardQuotient
rewards[a.ProposerIndex] += proposerReward
@ -852,7 +852,7 @@ func attestationDelta(state *pb.BeaconState) ([]uint64, []uint64, error) {
if finalityDelay > params.BeaconConfig().MinEpochsToInactivityPenalty {
targetIndices, err := unslashedAttestingIndices(state, atts.Target)
if err != nil {
return nil, nil, fmt.Errorf("could not get attestation indices: %v", err)
return nil, nil, errors.Wrap(err, "could not get attestation indices")
}
attestedTarget := make(map[uint64]bool)
for _, index := range targetIndices {
@ -861,7 +861,7 @@ func attestationDelta(state *pb.BeaconState) ([]uint64, []uint64, error) {
for _, index := range eligible {
base, err := baseReward(state, index)
if err != nil {
return nil, nil, fmt.Errorf("could not get base reward: %v", err)
return nil, nil, errors.Wrap(err, "could not get base reward")
}
penalties[index] += params.BeaconConfig().BaseRewardsPerEpoch * base
if _, ok := attestedTarget[index]; !ok {
@ -904,21 +904,21 @@ func crosslinkDelta(state *pb.BeaconState) ([]uint64, []uint64, error) {
epoch := helpers.PrevEpoch(state)
count, err := helpers.CommitteeCount(state, epoch)
if err != nil {
return nil, nil, fmt.Errorf("could not get epoch committee count: %v", err)
return nil, nil, errors.Wrap(err, "could not get epoch committee count")
}
startShard, err := helpers.StartShard(state, epoch)
if err != nil {
return nil, nil, fmt.Errorf("could not get epoch start shard: %v", err)
return nil, nil, errors.Wrap(err, "could not get epoch start shard")
}
for i := uint64(0); i < count; i++ {
shard := (startShard + i) % params.BeaconConfig().ShardCount
committee, err := helpers.CrosslinkCommittee(state, epoch, shard)
if err != nil {
return nil, nil, fmt.Errorf("could not get crosslink's committee: %v", err)
return nil, nil, errors.Wrap(err, "could not get crosslink's committee")
}
_, attestingIndices, err := winningCrosslink(state, shard, epoch)
if err != nil {
return nil, nil, fmt.Errorf("could not get winning crosslink: %v", err)
return nil, nil, errors.Wrap(err, "could not get winning crosslink")
}
attested := make(map[uint64]bool)
@ -932,7 +932,7 @@ func crosslinkDelta(state *pb.BeaconState) ([]uint64, []uint64, error) {
for _, index := range committee {
base, err := baseReward(state, index)
if err != nil {
return nil, nil, fmt.Errorf("could not get base reward: %v", err)
return nil, nil, errors.Wrap(err, "could not get base reward")
}
if _, ok := attested[index]; ok {
rewards[index] += base * attestingBalance / committeeBalance

View File

@ -27,6 +27,7 @@ go_library(
"//shared/bytesutil:go_default_library",
"//shared/hashutil:go_default_library",
"//shared/params:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@org_golang_google_grpc//codes:go_default_library",

View File

@ -1,11 +1,10 @@
package helpers
import (
"errors"
"fmt"
"github.com/pkg/errors"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/params"
)
@ -43,7 +42,7 @@ func AttestationDataSlot(state *pb.BeaconState, data *ethpb.AttestationData) (ui
epochStartShardNumber, err := StartShard(state, data.Target.Epoch)
if err != nil { // This should never happen if CommitteeCount was successful
return 0, fmt.Errorf("could not determine epoch start shard: %v", err)
return 0, errors.Wrap(err, "could not determine epoch start shard")
}
offset := (data.Crosslink.Shard + params.BeaconConfig().ShardCount -
epochStartShardNumber) % params.BeaconConfig().ShardCount

View File

@ -1,8 +1,7 @@
package helpers
import (
"errors"
"github.com/pkg/errors"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/params"
)

View File

@ -4,6 +4,7 @@ package helpers
import (
"fmt"
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
@ -39,7 +40,7 @@ func CommitteeCount(state *pb.BeaconState, epoch uint64) (uint64, error) {
}
count, err := ActiveValidatorCount(state, epoch)
if err != nil {
return 0, fmt.Errorf("could not get active count: %v", err)
return 0, errors.Wrap(err, "could not get active count")
}
var currCommitteePerSlot = count / params.BeaconConfig().SlotsPerEpoch / params.BeaconConfig().TargetCommitteeSize
@ -69,24 +70,24 @@ func CommitteeCount(state *pb.BeaconState, epoch uint64) (uint64, error) {
func CrosslinkCommittee(state *pb.BeaconState, epoch uint64, shard uint64) ([]uint64, error) {
seed, err := Seed(state, epoch)
if err != nil {
return nil, fmt.Errorf("could not get seed: %v", err)
return nil, errors.Wrap(err, "could not get seed")
}
indices, err := ActiveValidatorIndices(state, epoch)
if err != nil {
return nil, fmt.Errorf("could not get active indices: %v", err)
return nil, errors.Wrap(err, "could not get active indices")
}
startShard, err := StartShard(state, epoch)
if err != nil {
return nil, fmt.Errorf("could not get start shard: %v", err)
return nil, errors.Wrap(err, "could not get start shard")
}
shardCount := params.BeaconConfig().ShardCount
currentShard := (shard + shardCount - startShard) % shardCount
committeeCount, err := CommitteeCount(state, epoch)
if err != nil {
return nil, fmt.Errorf("could not get committee count: %v", err)
return nil, errors.Wrap(err, "could not get committee count")
}
return ComputeCommittee(indices, seed, currentShard, committeeCount)
@ -139,7 +140,7 @@ func ComputeCommittee(
Seed: seed[:],
ShuffledIndices: shuffledIndices,
}); err != nil {
return []uint64{}, fmt.Errorf("could not add shuffled indices list to cache: %v", err)
return []uint64{}, errors.Wrap(err, "could not add shuffled indices list to cache")
}
return shuffledIndices, nil
}
@ -158,7 +159,7 @@ func ComputeCommittee(
func AttestingIndices(state *pb.BeaconState, data *ethpb.AttestationData, bf bitfield.Bitfield) ([]uint64, error) {
committee, err := CrosslinkCommittee(state, data.Target.Epoch, data.Crosslink.Shard)
if err != nil {
return nil, fmt.Errorf("could not get committee: %v", err)
return nil, errors.Wrap(err, "could not get committee")
}
indices := make([]uint64, 0, len(committee))
@ -227,7 +228,7 @@ func CommitteeAssignment(
committeeCount, err := CommitteeCount(state, epoch)
if err != nil {
return nil, 0, 0, false, fmt.Errorf("could not get committee count: %v", err)
return nil, 0, 0, false, errors.Wrap(err, "could not get committee count")
}
committeesPerSlot := committeeCount / params.BeaconConfig().SlotsPerEpoch
@ -280,7 +281,7 @@ func CommitteeAssignment(
func ShardDelta(beaconState *pb.BeaconState, epoch uint64) (uint64, error) {
committeeCount, err := CommitteeCount(beaconState, epoch)
if err != nil {
return 0, fmt.Errorf("could not get committee count: %v", err)
return 0, errors.Wrap(err, "could not get committee count")
}
return ShardDeltaFromCommitteeCount(committeeCount), nil
}
@ -317,7 +318,7 @@ func ShardDeltaFromCommitteeCount(committeeCount uint64) uint64 {
func StartShard(state *pb.BeaconState, epoch uint64) (uint64, error) {
startShard, err := startShardCache.StartShardInEpoch(epoch)
if err != nil {
return 0, fmt.Errorf("could not retrieve start shard from cache: %v", err)
return 0, errors.Wrap(err, "could not retrieve start shard from cache")
}
if startShard != params.BeaconConfig().FarFutureEpoch {
return startShard, nil
@ -333,7 +334,7 @@ func StartShard(state *pb.BeaconState, epoch uint64) (uint64, error) {
delta, err := ShardDelta(state, currentEpoch)
if err != nil {
return 0, fmt.Errorf("could not get shard delta: %v", err)
return 0, errors.Wrap(err, "could not get shard delta")
}
startShard = (state.StartShard + delta) % params.BeaconConfig().ShardCount
@ -341,7 +342,7 @@ func StartShard(state *pb.BeaconState, epoch uint64) (uint64, error) {
checkEpoch--
d, err := ShardDelta(state, checkEpoch)
if err != nil {
return 0, fmt.Errorf("could not get shard delta: %v", err)
return 0, errors.Wrap(err, "could not get shard delta")
}
startShard = (startShard + params.BeaconConfig().ShardCount - d) % params.BeaconConfig().ShardCount
}
@ -350,7 +351,7 @@ func StartShard(state *pb.BeaconState, epoch uint64) (uint64, error) {
Epoch: epoch,
StartShard: startShard,
}); err != nil {
return 0, fmt.Errorf("could not save start shard for cache: %v", err)
return 0, errors.Wrap(err, "could not save start shard for cache")
}
return startShard, nil
@ -361,7 +362,7 @@ func StartShard(state *pb.BeaconState, epoch uint64) (uint64, error) {
func VerifyAttestationBitfield(bState *pb.BeaconState, att *ethpb.Attestation) (bool, error) {
committee, err := CrosslinkCommittee(bState, att.Data.Target.Epoch, att.Data.Crosslink.Shard)
if err != nil {
return false, fmt.Errorf("could not retrieve crosslink committees at slot: %v", err)
return false, errors.Wrap(err, "could not retrieve crosslink committees at slot")
}
if committee == nil {

View File

@ -1,9 +1,9 @@
package helpers
import (
"fmt"
"math/big"
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-ssz"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/hashutil"
@ -38,7 +38,7 @@ func EmptyVoteHierarchyMap() *VoteHierarchyMap {
func CountVote(voteMap *VoteHierarchyMap, vote *ethpb.Eth1Data, blockHeight *big.Int) (*VoteHierarchyMap, error) {
encoded, err := ssz.Marshal(vote)
if err != nil {
return &VoteHierarchyMap{}, fmt.Errorf("could not get encoded hash of eth1data object: %v", err)
return &VoteHierarchyMap{}, errors.Wrap(err, "could not get encoded hash of eth1data object")
}
he := hashutil.Hash(encoded)
v, ok := voteMap.voteCountMap[string(he[:])]

View File

@ -1,9 +1,7 @@
package helpers
import (
"errors"
"fmt"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
@ -30,7 +28,7 @@ var ErrInvalidStateLatestActiveIndexRoots = errors.New("state does not have corr
func Seed(state *pb.BeaconState, epoch uint64) ([32]byte, error) {
seed, err := currentEpochSeed.SeedInEpoch(epoch)
if err != nil {
return [32]byte{}, fmt.Errorf("could not retrieve total balance from cache: %v", err)
return [32]byte{}, errors.Wrap(err, "could not retrieve total balance from cache")
}
if seed != nil {
return bytesutil.ToBytes32(seed), nil
@ -59,7 +57,7 @@ func Seed(state *pb.BeaconState, epoch uint64) ([32]byte, error) {
Epoch: epoch,
Seed: seed32[:],
}); err != nil {
return [32]byte{}, fmt.Errorf("could not save active balance for cache: %v", err)
return [32]byte{}, errors.Wrap(err, "could not save active balance for cache")
}
return seed32, nil

View File

@ -1,8 +1,7 @@
package helpers
import (
"fmt"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/params"
@ -46,7 +45,7 @@ func TotalActiveBalance(state *pb.BeaconState) (uint64, error) {
epoch := CurrentEpoch(state)
total, err := totalActiveBalanceCache.ActiveBalanceInEpoch(epoch)
if err != nil {
return 0, fmt.Errorf("could not retrieve total balance from cache: %v", err)
return 0, errors.Wrap(err, "could not retrieve total balance from cache")
}
if total != params.BeaconConfig().FarFutureEpoch {
return total, nil
@ -63,7 +62,7 @@ func TotalActiveBalance(state *pb.BeaconState) (uint64, error) {
Epoch: epoch,
ActiveBalance: total,
}); err != nil {
return 0, fmt.Errorf("could not save active balance for cache: %v", err)
return 0, errors.Wrap(err, "could not save active balance for cache")
}
return total, nil
}

View File

@ -3,6 +3,7 @@ package helpers
import (
"fmt"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
@ -63,7 +64,7 @@ func IsSlashableValidator(validator *ethpb.Validator, epoch uint64) bool {
func ActiveValidatorIndices(state *pb.BeaconState, epoch uint64) ([]uint64, error) {
indices, err := activeIndicesCache.ActiveIndicesInEpoch(epoch)
if err != nil {
return nil, fmt.Errorf("could not retrieve active indices from cache: %v", err)
return nil, errors.Wrap(err, "could not retrieve active indices from cache")
}
if indices != nil {
return indices, nil
@ -79,7 +80,7 @@ func ActiveValidatorIndices(state *pb.BeaconState, epoch uint64) ([]uint64, erro
Epoch: epoch,
ActiveIndices: indices,
}); err != nil {
return nil, fmt.Errorf("could not save active indices for cache: %v", err)
return nil, errors.Wrap(err, "could not save active indices for cache")
}
return indices, nil
@ -90,7 +91,7 @@ func ActiveValidatorIndices(state *pb.BeaconState, epoch uint64) ([]uint64, erro
func ActiveValidatorCount(state *pb.BeaconState, epoch uint64) (uint64, error) {
count, err := activeCountCache.ActiveCountInEpoch(epoch)
if err != nil {
return 0, fmt.Errorf("could not retrieve active count from cache: %v", err)
return 0, errors.Wrap(err, "could not retrieve active count from cache")
}
if count != params.BeaconConfig().FarFutureEpoch {
return count, nil
@ -107,7 +108,7 @@ func ActiveValidatorCount(state *pb.BeaconState, epoch uint64) (uint64, error) {
Epoch: epoch,
ActiveCount: count,
}); err != nil {
return 0, fmt.Errorf("could not save active count for cache: %v", err)
return 0, errors.Wrap(err, "could not save active count for cache")
}
return count, nil
@ -139,7 +140,7 @@ func DelayedActivationExitEpoch(epoch uint64) uint64 {
func ValidatorChurnLimit(state *pb.BeaconState) (uint64, error) {
validatorCount, err := ActiveValidatorCount(state, CurrentEpoch(state))
if err != nil {
return 0, fmt.Errorf("could not get validator count: %v", err)
return 0, errors.Wrap(err, "could not get validator count")
}
churnLimit := validatorCount / params.BeaconConfig().ChurnLimitQuotient
if churnLimit < params.BeaconConfig().MinPerEpochChurnLimit {
@ -184,7 +185,7 @@ func BeaconProposerIndex(state *pb.BeaconState) (uint64, error) {
// and the offset
startShard, err := StartShard(state, e)
if err != nil {
return 0, fmt.Errorf("could not get start shard: %v", err)
return 0, errors.Wrap(err, "could not get start shard")
}
shard := (startShard + offSet) % params.BeaconConfig().ShardCount
@ -192,7 +193,7 @@ func BeaconProposerIndex(state *pb.BeaconState) (uint64, error) {
// to select proposer
firstCommittee, err := CrosslinkCommittee(state, e, shard)
if err != nil {
return 0, fmt.Errorf("could not get first committee: %v", err)
return 0, errors.Wrap(err, "could not get first committee")
}
if len(firstCommittee) == 0 {
return 0, fmt.Errorf("empty first committee at slot %d", state.Slot)
@ -202,7 +203,7 @@ func BeaconProposerIndex(state *pb.BeaconState) (uint64, error) {
maxRandomByte := uint64(1<<8 - 1)
seed, err := Seed(state, e)
if err != nil {
return 0, fmt.Errorf("could not generate seed: %v", err)
return 0, errors.Wrap(err, "could not generate seed")
}
// Looping through the committee to select proposer that has enough

View File

@ -19,6 +19,7 @@ go_library(
"//shared/params:go_default_library",
"//shared/trieutil:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@io_opencensus_go//trace:go_default_library",
],

View File

@ -4,9 +4,9 @@
package state
import (
"errors"
"fmt"
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-ssz"
b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
@ -203,11 +203,11 @@ func GenesisBeaconState(deposits []*ethpb.Deposit, genesisTime uint64, eth1Data
// Populate latest_active_index_roots
activeIndices, err := helpers.ActiveValidatorIndices(state, 0)
if err != nil {
return nil, fmt.Errorf("could not get active validator indices: %v", err)
return nil, errors.Wrap(err, "could not get active validator indices")
}
genesisActiveIndexRoot, err := ssz.HashTreeRootWithCapacity(activeIndices, params.BeaconConfig().ValidatorRegistryLimit)
if err != nil {
return nil, fmt.Errorf("could not hash tree root active indices: %v", err)
return nil, errors.Wrap(err, "could not hash tree root active indices")
}
genesisCompactCommRoot, err := helpers.CompactCommitteesRoot(state, 0)
if err != nil {

View File

@ -9,6 +9,7 @@ import (
"fmt"
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-ssz"
b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
e "github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
@ -50,20 +51,20 @@ func ExecuteStateTransition(
// Execute per slots transition.
state, err = ProcessSlots(ctx, state, block.Slot)
if err != nil {
return nil, fmt.Errorf("could not process slot: %v", err)
return nil, errors.Wrap(err, "could not process slot")
}
// Execute per block transition.
if block != nil {
state, err = ProcessBlock(ctx, state, block)
if err != nil {
return nil, fmt.Errorf("could not process block: %v", err)
return nil, errors.Wrap(err, "could not process block")
}
}
postStateRoot, err := ssz.HashTreeRoot(state)
if err != nil {
return nil, fmt.Errorf("could not tree hash processed state: %v", err)
return nil, errors.Wrap(err, "could not tree hash processed state")
}
if !bytes.Equal(postStateRoot[:], block.StateRoot) {
return nil, fmt.Errorf("validate state root failed, wanted: %#x, received: %#x",
@ -108,14 +109,14 @@ func ExecuteStateTransitionNoVerify(
// Execute per slots transition.
stateCopy, err = ProcessSlots(ctx, stateCopy, block.Slot)
if err != nil {
return nil, fmt.Errorf("could not process slot: %v", err)
return nil, errors.Wrap(err, "could not process slot")
}
// Execute per block transition.
if block != nil {
stateCopy, err = processBlockNoVerify(ctx, stateCopy, block)
if err != nil {
return nil, fmt.Errorf("could not process block: %v", err)
return nil, errors.Wrap(err, "could not process block")
}
}
@ -143,7 +144,7 @@ func ProcessSlot(ctx context.Context, state *pb.BeaconState) (*pb.BeaconState, e
defer span.End()
prevStateRoot, err := ssz.HashTreeRoot(state)
if err != nil {
return nil, fmt.Errorf("could not tree hash prev state root: %v", err)
return nil, errors.Wrap(err, "could not tree hash prev state root")
}
state.StateRoots[state.Slot%params.BeaconConfig().SlotsPerHistoricalRoot] = prevStateRoot[:]
@ -154,7 +155,7 @@ func ProcessSlot(ctx context.Context, state *pb.BeaconState) (*pb.BeaconState, e
}
prevBlockRoot, err := ssz.SigningRoot(state.LatestBlockHeader)
if err != nil {
return nil, fmt.Errorf("could not determine prev block root: %v", err)
return nil, errors.Wrap(err, "could not determine prev block root")
}
// Cache the block root.
state.BlockRoots[state.Slot%params.BeaconConfig().SlotsPerHistoricalRoot] = prevBlockRoot[:]
@ -183,12 +184,12 @@ func ProcessSlots(ctx context.Context, state *pb.BeaconState, slot uint64) (*pb.
}
state, err := ProcessSlot(ctx, state)
if err != nil {
return nil, fmt.Errorf("could not process slot: %v", err)
return nil, errors.Wrap(err, "could not process slot")
}
if CanProcessEpoch(state) {
state, err = ProcessEpoch(ctx, state)
if err != nil {
return nil, fmt.Errorf("could not process epoch: %v", err)
return nil, errors.Wrap(err, "could not process epoch")
}
}
state.Slot++
@ -217,22 +218,22 @@ func ProcessBlock(
state, err := b.ProcessBlockHeader(state, block)
if err != nil {
return nil, fmt.Errorf("could not process block header: %v", err)
return nil, errors.Wrap(err, "could not process block header")
}
state, err = b.ProcessRandao(state, block.Body)
if err != nil {
return nil, fmt.Errorf("could not verify and process randao: %v", err)
return nil, errors.Wrap(err, "could not verify and process randao")
}
state, err = b.ProcessEth1DataInBlock(state, block)
if err != nil {
return nil, fmt.Errorf("could not process eth1 data: %v", err)
return nil, errors.Wrap(err, "could not process eth1 data")
}
state, err = ProcessOperations(ctx, state, block.Body)
if err != nil {
return nil, fmt.Errorf("could not process block operation: %v", err)
return nil, errors.Wrap(err, "could not process block operation")
}
return state, nil
@ -263,22 +264,22 @@ func processBlockNoVerify(
state, err := b.ProcessBlockHeaderNoVerify(state, block)
if err != nil {
return nil, fmt.Errorf("could not process block header: %v", err)
return nil, errors.Wrap(err, "could not process block header")
}
state, err = b.ProcessRandao(state, block.Body)
if err != nil {
return nil, fmt.Errorf("could not verify and process randao: %v", err)
return nil, errors.Wrap(err, "could not verify and process randao")
}
state, err = b.ProcessEth1DataInBlock(state, block)
if err != nil {
return nil, fmt.Errorf("could not process eth1 data: %v", err)
return nil, errors.Wrap(err, "could not process eth1 data")
}
state, err = ProcessOperations(ctx, state, block.Body)
if err != nil {
return nil, fmt.Errorf("could not process block operation: %v", err)
return nil, errors.Wrap(err, "could not process block operation")
}
return state, nil
@ -314,7 +315,7 @@ func ProcessOperations(
defer span.End()
if err := verifyOperationLengths(state, body); err != nil {
return nil, fmt.Errorf("could not verify operation lengths: %v", err)
return nil, errors.Wrap(err, "could not verify operation lengths")
}
// Verify that there are no duplicate transfers
@ -322,7 +323,7 @@ func ProcessOperations(
for _, transfer := range body.Transfers {
h, err := hashutil.HashProto(transfer)
if err != nil {
return nil, fmt.Errorf("could not hash transfer: %v", err)
return nil, errors.Wrap(err, "could not hash transfer")
}
if transferSet[h] {
return nil, fmt.Errorf("duplicate transfer: %v", transfer)
@ -332,27 +333,27 @@ func ProcessOperations(
state, err := b.ProcessProposerSlashings(state, body)
if err != nil {
return nil, fmt.Errorf("could not process block proposer slashings: %v", err)
return nil, errors.Wrap(err, "could not process block proposer slashings")
}
state, err = b.ProcessAttesterSlashings(state, body)
if err != nil {
return nil, fmt.Errorf("could not process block attester slashings: %v", err)
return nil, errors.Wrap(err, "could not process block attester slashings")
}
state, err = b.ProcessAttestations(state, body)
if err != nil {
return nil, fmt.Errorf("could not process block attestations: %v", err)
return nil, errors.Wrap(err, "could not process block attestations")
}
state, err = b.ProcessDeposits(state, body)
if err != nil {
return nil, fmt.Errorf("could not process block validator deposits: %v", err)
return nil, errors.Wrap(err, "could not process block validator deposits")
}
state, err = b.ProcessVoluntaryExits(state, body)
if err != nil {
return nil, fmt.Errorf("could not process validator exits: %v", err)
return nil, errors.Wrap(err, "could not process validator exits")
}
state, err = b.ProcessTransfers(state, body)
if err != nil {
return nil, fmt.Errorf("could not process block transfers: %v", err)
return nil, errors.Wrap(err, "could not process block transfers")
}
return state, nil
@ -452,41 +453,41 @@ func ProcessEpoch(ctx context.Context, state *pb.BeaconState) (*pb.BeaconState,
}
prevEpochAttestedBalance, err := e.AttestingBalance(state, prevEpochAtts.Target)
if err != nil {
return nil, fmt.Errorf("could not get attesting balance prev epoch: %v", err)
return nil, errors.Wrap(err, "could not get attesting balance prev epoch")
}
currentEpochAttestedBalance, err := e.AttestingBalance(state, currentEpochAtts.Target)
if err != nil {
return nil, fmt.Errorf("could not get attesting balance current epoch: %v", err)
return nil, errors.Wrap(err, "could not get attesting balance current epoch")
}
state, err = e.ProcessJustificationAndFinalization(state, prevEpochAttestedBalance, currentEpochAttestedBalance)
if err != nil {
return nil, fmt.Errorf("could not process justification: %v", err)
return nil, errors.Wrap(err, "could not process justification")
}
state, err = e.ProcessCrosslinks(state)
if err != nil {
return nil, fmt.Errorf("could not process crosslink: %v", err)
return nil, errors.Wrap(err, "could not process crosslink")
}
state, err = e.ProcessRewardsAndPenalties(state)
if err != nil {
return nil, fmt.Errorf("could not process rewards and penalties: %v", err)
return nil, errors.Wrap(err, "could not process rewards and penalties")
}
state, err = e.ProcessRegistryUpdates(state)
if err != nil {
return nil, fmt.Errorf("could not process registry updates: %v", err)
return nil, errors.Wrap(err, "could not process registry updates")
}
state, err = e.ProcessSlashings(state)
if err != nil {
return nil, fmt.Errorf("could not process slashings: %v", err)
return nil, errors.Wrap(err, "could not process slashings")
}
state, err = e.ProcessFinalUpdates(state)
if err != nil {
return nil, fmt.Errorf("could not process final updates: %v", err)
return nil, errors.Wrap(err, "could not process final updates")
}
return state, nil
}

View File

@ -10,6 +10,7 @@ go_library(
"//proto/beacon/p2p/v1:go_default_library",
"//shared/mathutil:go_default_library",
"//shared/params:go_default_library",
"@com_github_pkg_errors//:go_default_library",
],
)

View File

@ -8,6 +8,7 @@ import (
"fmt"
"sync"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/mathutil"
@ -81,7 +82,7 @@ func InitiateValidatorExit(state *pb.BeaconState, idx uint64) (*pb.BeaconState,
}
churn, err := helpers.ValidatorChurnLimit(state)
if err != nil {
return nil, fmt.Errorf("could not get churn limit: %v", err)
return nil, errors.Wrap(err, "could not get churn limit")
}
if uint64(exitQueueChurn) >= churn {
@ -158,7 +159,7 @@ func SlashValidator(state *pb.BeaconState, slashedIdx uint64, whistleBlowerIdx u
proposerIdx, err := helpers.BeaconProposerIndex(state)
if err != nil {
return nil, fmt.Errorf("could not get proposer idx: %v", err)
return nil, errors.Wrap(err, "could not get proposer idx")
}
if whistleBlowerIdx == 0 {

View File

@ -30,6 +30,7 @@ go_library(
"@com_github_boltdb_bolt//:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",

View File

@ -2,10 +2,10 @@ package db
import (
"context"
"fmt"
"github.com/boltdb/bolt"
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/hashutil"
@ -137,7 +137,7 @@ func (db *BeaconDB) HasAttestation(hash [32]byte) bool {
func createAttestation(enc []byte) (*ethpb.Attestation, error) {
protoAttestation := &ethpb.Attestation{}
if err := proto.Unmarshal(enc, protoAttestation); err != nil {
return nil, fmt.Errorf("failed to unmarshal encoding: %v", err)
return nil, errors.Wrap(err, "failed to unmarshal encoding")
}
return protoAttestation, nil
}
@ -145,7 +145,7 @@ func createAttestation(enc []byte) (*ethpb.Attestation, error) {
func createAttestationTarget(enc []byte) (*pb.AttestationTarget, error) {
protoAttTgt := &pb.AttestationTarget{}
if err := proto.Unmarshal(enc, protoAttTgt); err != nil {
return nil, fmt.Errorf("failed to unmarshal encoding: %v", err)
return nil, errors.Wrap(err, "failed to unmarshal encoding")
}
return protoAttTgt, nil
}

View File

@ -3,11 +3,11 @@ package db
import (
"bytes"
"context"
"errors"
"fmt"
"github.com/boltdb/bolt"
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prysmaticlabs/go-ssz"
@ -39,7 +39,7 @@ func createBlock(enc []byte) (*ethpb.BeaconBlock, error) {
protoBlock := &ethpb.BeaconBlock{}
err := proto.Unmarshal(enc, protoBlock)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal encoding: %v", err)
return nil, errors.Wrap(err, "failed to unmarshal encoding")
}
return protoBlock, nil
}
@ -137,7 +137,7 @@ func (db *BeaconDB) SaveBlock(block *ethpb.BeaconBlock) error {
signingRoot, err := ssz.SigningRoot(block)
if err != nil {
return fmt.Errorf("failed to tree hash header: %v", err)
return errors.Wrap(err, "failed to tree hash header")
}
// Skip saving block to DB if it exists in the cache.
@ -150,7 +150,7 @@ func (db *BeaconDB) SaveBlock(block *ethpb.BeaconBlock) error {
enc, err := proto.Marshal(block)
if err != nil {
return fmt.Errorf("failed to encode block: %v", err)
return errors.Wrap(err, "failed to encode block")
}
slotRootBinary := encodeSlotNumberRoot(block.Slot, signingRoot)
@ -161,7 +161,7 @@ func (db *BeaconDB) SaveBlock(block *ethpb.BeaconBlock) error {
return db.update(func(tx *bolt.Tx) error {
bucket := tx.Bucket(blockBucket)
if err := bucket.Put(slotRootBinary, enc); err != nil {
return fmt.Errorf("failed to include the block in the main chain bucket: %v", err)
return errors.Wrap(err, "failed to include the block in the main chain bucket")
}
return bucket.Put(signingRoot[:], enc)
})
@ -174,7 +174,7 @@ func (db *BeaconDB) DeleteBlock(block *ethpb.BeaconBlock) error {
signingRoot, err := ssz.SigningRoot(block)
if err != nil {
return fmt.Errorf("failed to tree hash block: %v", err)
return errors.Wrap(err, "failed to tree hash block")
}
// Delete the block from the cache.
@ -186,7 +186,7 @@ func (db *BeaconDB) DeleteBlock(block *ethpb.BeaconBlock) error {
return db.update(func(tx *bolt.Tx) error {
bucket := tx.Bucket(blockBucket)
if err := bucket.Delete(slotRootBinary); err != nil {
return fmt.Errorf("failed to include the block in the main chain bucket: %v", err)
return errors.Wrap(err, "failed to include the block in the main chain bucket")
}
return bucket.Delete(signingRoot[:])
})
@ -197,7 +197,7 @@ func (db *BeaconDB) SaveJustifiedBlock(block *ethpb.BeaconBlock) error {
return db.update(func(tx *bolt.Tx) error {
enc, err := proto.Marshal(block)
if err != nil {
return fmt.Errorf("failed to encode block: %v", err)
return errors.Wrap(err, "failed to encode block")
}
chainInfo := tx.Bucket(chainInfoBucket)
return chainInfo.Put(justifiedBlockLookupKey, enc)
@ -209,7 +209,7 @@ func (db *BeaconDB) SaveFinalizedBlock(block *ethpb.BeaconBlock) error {
return db.update(func(tx *bolt.Tx) error {
enc, err := proto.Marshal(block)
if err != nil {
return fmt.Errorf("failed to encode block: %v", err)
return errors.Wrap(err, "failed to encode block")
}
chainInfo := tx.Bucket(chainInfoBucket)
return chainInfo.Put(finalizedBlockLookupKey, enc)
@ -288,7 +288,7 @@ func (db *BeaconDB) UpdateChainHead(ctx context.Context, block *ethpb.BeaconBloc
blockRoot, err := ssz.SigningRoot(block)
if err != nil {
return fmt.Errorf("unable to determine block signing root: %v", err)
return errors.Wrap(err, "unable to determine block signing root")
}
slotBinary := encodeSlotNumber(block.Slot)
@ -297,7 +297,7 @@ func (db *BeaconDB) UpdateChainHead(ctx context.Context, block *ethpb.BeaconBloc
}
if err := db.SaveState(ctx, beaconState); err != nil {
return fmt.Errorf("failed to save beacon state as canonical: %v", err)
return errors.Wrap(err, "failed to save beacon state as canonical")
}
blockEnc, err := proto.Marshal(block)
@ -323,7 +323,7 @@ func (db *BeaconDB) UpdateChainHead(ctx context.Context, block *ethpb.BeaconBloc
}
if err := chainInfo.Put(canonicalHeadKey, blockRoot[:]); err != nil {
return fmt.Errorf("failed to record the block as the head of the main chain: %v", err)
return errors.Wrap(err, "failed to record the block as the head of the main chain")
}
return nil

View File

@ -1,13 +1,13 @@
package db
import (
"errors"
"os"
"path"
"sync"
"time"
"github.com/boltdb/bolt"
"github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
"github.com/sirupsen/logrus"
)

View File

@ -6,17 +6,19 @@ import (
"math/big"
"os"
"path"
"github.com/pkg/errors"
)
// SetupDB instantiates and returns a simulated backend BeaconDB instance.
func SetupDB() (*BeaconDB, error) {
randPath, err := rand.Int(rand.Reader, big.NewInt(1000000))
if err != nil {
return nil, fmt.Errorf("could not generate random file path: %v", err)
return nil, errors.Wrap(err, "could not generate random file path")
}
path := path.Join(os.TempDir(), fmt.Sprintf("/%d", randPath))
if err := os.RemoveAll(path); err != nil {
return nil, fmt.Errorf("failed to remove directory: %v", err)
return nil, errors.Wrap(err, "failed to remove directory")
}
return NewDB(path)
}

View File

@ -4,11 +4,11 @@ import (
"bytes"
"context"
"encoding/binary"
"errors"
"fmt"
"github.com/boltdb/bolt"
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prysmaticlabs/go-ssz"
@ -63,15 +63,15 @@ func (db *BeaconDB) InitializeState(ctx context.Context, genesisTime uint64, dep
chainInfo := tx.Bucket(chainInfoBucket)
if err := chainInfo.Put(mainChainHeightKey, zeroBinary); err != nil {
return fmt.Errorf("failed to record block height: %v", err)
return errors.Wrap(err, "failed to record block height")
}
if err := mainChain.Put(zeroBinary, blockEnc); err != nil {
return fmt.Errorf("failed to record block hash: %v", err)
return errors.Wrap(err, "failed to record block hash")
}
if err := chainInfo.Put(canonicalHeadKey, blockRoot[:]); err != nil {
return fmt.Errorf("failed to record block as canonical: %v", err)
return errors.Wrap(err, "failed to record block as canonical")
}
if err := blockBkt.Put(blockRoot[:], blockEnc); err != nil {
@ -464,7 +464,7 @@ func createState(enc []byte) (*pb.BeaconState, error) {
protoState := &pb.BeaconState{}
err := proto.Unmarshal(enc, protoState)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal encoding: %v", err)
return nil, errors.Wrap(err, "failed to unmarshal encoding")
}
return protoState, nil
}

View File

@ -34,6 +34,7 @@ go_library(
"@com_github_ethereum_go_ethereum//ethclient:go_default_library",
"@com_github_ethereum_go_ethereum//rpc:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_urfave_cli//:go_default_library",
],

View File

@ -13,6 +13,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
gethRPC "github.com/ethereum/go-ethereum/rpc"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/attestation"
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
@ -193,7 +194,7 @@ func (b *BeaconNode) startDB(ctx *cli.Context) error {
func (b *BeaconNode) registerP2P(ctx *cli.Context) error {
beaconp2p, err := configureP2P(ctx)
if err != nil {
return fmt.Errorf("could not register p2p service: %v", err)
return errors.Wrap(err, "could not register p2p service")
}
return b.services.RegisterService(beaconp2p)
@ -227,7 +228,7 @@ func (b *BeaconNode) registerBlockchainService(ctx *cli.Context) error {
MaxRoutines: maxRoutines,
})
if err != nil {
return fmt.Errorf("could not register blockchain service: %v", err)
return errors.Wrap(err, "could not register blockchain service")
}
return b.services.RegisterService(blockchainService)
}
@ -291,7 +292,7 @@ func (b *BeaconNode) registerPOWChainService(cliCtx *cli.Context) error {
}
web3Service, err := powchain.NewWeb3Service(ctx, cfg)
if err != nil {
return fmt.Errorf("could not register proof-of-work chain web3Service: %v", err)
return errors.Wrap(err, "could not register proof-of-work chain web3Service")
}
if err := b.db.VerifyContractAddress(ctx, cfg.DepositContract); err != nil {

View File

@ -18,6 +18,7 @@ go_library(
"//shared/p2p:go_default_library",
"//shared/params:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@io_opencensus_go//trace:go_default_library",

View File

@ -8,6 +8,7 @@ import (
"sort"
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
@ -149,7 +150,7 @@ func (s *Service) AttestationPool(ctx context.Context, requestedSlot uint64) ([]
for _, att := range attestationsFromDB {
slot, err := helpers.AttestationDataSlot(bState, 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")
}
// Delete the attestation if the attestation is one epoch older than head state,
// we don't want to pass these attestations to RPC for proposer to include.
@ -241,21 +242,21 @@ func (s *Service) HandleAttestations(ctx context.Context, message proto.Message)
func (s *Service) IsAttCanonical(ctx context.Context, att *ethpb.Attestation) (bool, error) {
votedBlk, err := s.beaconDB.Block(bytesutil.ToBytes32(att.Data.BeaconBlockRoot))
if err != nil {
return false, fmt.Errorf("could not hash block: %v", err)
return false, errors.Wrap(err, "could not hash block")
}
if votedBlk == nil {
return false, nil
}
canonicalBlk, err := s.beaconDB.CanonicalBlockBySlot(ctx, votedBlk.Slot)
if err != nil {
return false, fmt.Errorf("could not hash block: %v", err)
return false, errors.Wrap(err, "could not hash block")
}
if canonicalBlk == nil {
return false, nil
}
canonicalRoot, err := ssz.SigningRoot(canonicalBlk)
if err != nil {
return false, fmt.Errorf("could not hash block: %v", err)
return false, errors.Wrap(err, "could not hash block")
}
return bytes.Equal(att.Data.BeaconBlockRoot, canonicalRoot[:]), nil
}
@ -283,7 +284,7 @@ func (s *Service) handleProcessedBlock(_ context.Context, message proto.Message)
// Removes the attestations from the pool that have been included
// in the received block.
if err := s.removeAttestationsFromPool(block.Body.Attestations); err != nil {
return fmt.Errorf("could not remove processed attestations from DB: %v", err)
return errors.Wrap(err, "could not remove processed attestations from DB")
}
state, err := s.beaconDB.HeadState(s.ctx)
if err != nil {
@ -322,7 +323,7 @@ func (s *Service) removeEpochOldAttestations(beaconState *pb.BeaconState) error
for _, a := range attestations {
slot, err := helpers.AttestationDataSlot(beaconState, a.Data)
if err != nil {
return fmt.Errorf("could not get attestation slot: %v", err)
return errors.Wrap(err, "could not get attestation slot")
}
// Remove attestation from DB if it's one epoch older than slot.
if slot-params.BeaconConfig().SlotsPerEpoch >= slot {

View File

@ -27,6 +27,7 @@ go_library(
"@com_github_ethereum_go_ethereum//accounts/abi/bind:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_ethereum_go_ethereum//core/types:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",

View File

@ -2,10 +2,10 @@ package powchain
import (
"context"
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
"go.opencensus.io/trace"
)
@ -24,7 +24,7 @@ func (w *Web3Service) BlockExists(ctx context.Context, hash common.Hash) (bool,
span.AddAttributes(trace.BoolAttribute("blockCacheHit", false))
block, err := w.blockFetcher.BlockByHash(ctx, hash)
if err != nil {
return false, big.NewInt(0), fmt.Errorf("could not query block with given hash: %v", err)
return false, big.NewInt(0), errors.Wrap(err, "could not query block with given hash")
}
if err := w.blockCache.AddBlock(block); err != nil {
@ -49,7 +49,7 @@ func (w *Web3Service) BlockHashByHeight(ctx context.Context, height *big.Int) (c
span.AddAttributes(trace.BoolAttribute("blockCacheHit", false))
block, err := w.blockFetcher.BlockByNumber(w.ctx, height)
if err != nil {
return [32]byte{}, fmt.Errorf("could not query block with given height: %v", err)
return [32]byte{}, errors.Wrap(err, "could not query block with given height")
}
if err := w.blockCache.AddBlock(block); err != nil {
return [32]byte{}, err
@ -63,7 +63,7 @@ func (w *Web3Service) BlockTimeByHeight(ctx context.Context, height *big.Int) (u
defer span.End()
block, err := w.blockFetcher.BlockByNumber(w.ctx, height)
if err != nil {
return 0, fmt.Errorf("could not query block with given height: %v", err)
return 0, errors.Wrap(err, "could not query block with given height")
}
return block.Time(), nil
}

View File

@ -3,6 +3,7 @@ package powchain
import (
"fmt"
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-ssz"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/bls"
@ -26,16 +27,16 @@ func (w *Web3Service) processDeposit(
if !ok {
pub, err := bls.PublicKeyFromBytes(pubKey[:])
if err != nil {
return fmt.Errorf("could not deserialize validator public key: %v", err)
return errors.Wrap(err, "could not deserialize validator public key")
}
domain := bls.Domain(params.BeaconConfig().DomainDeposit, params.BeaconConfig().GenesisForkVersion)
sig, err := bls.SignatureFromBytes(deposit.Data.Signature)
if err != nil {
return fmt.Errorf("could not convert bytes to signature: %v", err)
return errors.Wrap(err, "could not convert bytes to signature")
}
root, err := ssz.SigningRoot(deposit.Data)
if err != nil {
return fmt.Errorf("could not sign root for deposit data: %v", err)
return errors.Wrap(err, "could not sign root for deposit data")
}
if !sig.Verify(root[:], pub, domain) {
return fmt.Errorf("deposit signature did not verify")
@ -64,7 +65,7 @@ func verifyDeposit(eth1Data *ethpb.Eth1Data, deposit *ethpb.Deposit) error {
receiptRoot := eth1Data.DepositRoot
leaf, err := ssz.HashTreeRoot(deposit.Data)
if err != nil {
return fmt.Errorf("could not tree hash deposit data: %v", err)
return errors.Wrap(err, "could not tree hash deposit data")
}
if ok := trieutil.VerifyMerkleProof(
receiptRoot,

View File

@ -9,6 +9,7 @@ import (
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
contracts "github.com/prysmaticlabs/prysm/contracts/deposit-contract"
@ -233,7 +234,7 @@ func (w *Web3Service) processPastLogs() error {
currentState, err := w.beaconDB.HeadState(w.ctx)
if err != nil {
return fmt.Errorf("could not get head state: %v", err)
return errors.Wrap(err, "could not get head state")
}
if currentState != nil && currentState.Eth1DepositIndex > 0 {

View File

@ -3,7 +3,6 @@ package powchain
import (
"context"
"errors"
"fmt"
"math/big"
"runtime/debug"
@ -15,6 +14,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
@ -132,7 +132,7 @@ func NewWeb3Service(ctx context.Context, config *Web3ServiceConfig) (*Web3Servic
depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth))
if err != nil {
cancel()
return nil, fmt.Errorf("could not setup deposit trie: %v", err)
return nil, errors.Wrap(err, "could not setup deposit trie")
}
return &Web3Service{
ctx: ctx,

View File

@ -41,6 +41,7 @@ go_library(
"@com_github_grpc_ecosystem_go_grpc_middleware//:go_default_library",
"@com_github_grpc_ecosystem_go_grpc_middleware//recovery:go_default_library",
"@com_github_grpc_ecosystem_go_grpc_prometheus//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@io_opencensus_go//plugin/ocgrpc:go_default_library",

View File

@ -2,9 +2,9 @@ package rpc
import (
"context"
"errors"
"fmt"
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
@ -33,7 +33,7 @@ type AttesterServer struct {
func (as *AttesterServer) SubmitAttestation(ctx context.Context, att *ethpb.Attestation) (*pb.AttestResponse, error) {
h, err := hashutil.HashProto(att)
if err != nil {
return nil, fmt.Errorf("could not hash attestation: %v", err)
return nil, errors.Wrap(err, "could not hash attestation")
}
if err := as.operationService.HandleAttestations(ctx, att); err != nil {
@ -104,17 +104,17 @@ func (as *AttesterServer) RequestAttestation(ctx context.Context, req *pb.Attest
// is the validator's view of the head block of the beacon chain during the slot.
headBlock, err := as.beaconDB.ChainHead()
if err != nil {
return nil, fmt.Errorf("failed to retrieve chain head: %v", err)
return nil, errors.Wrap(err, "failed to retrieve chain head")
}
headRoot, err := ssz.SigningRoot(headBlock)
if err != nil {
return nil, fmt.Errorf("could not tree hash beacon block: %v", err)
return nil, errors.Wrap(err, "could not tree hash beacon block")
}
// Let head state be the state of head block processed through empty slots up to assigned slot.
headState, err := as.beaconDB.HeadState(ctx)
if err != nil {
return nil, fmt.Errorf("could not fetch head state: %v", err)
return nil, errors.Wrap(err, "could not fetch head state")
}
headState, err = state.ProcessSlots(ctx, headState, req.Slot)

View File

@ -2,11 +2,11 @@ package rpc
import (
"context"
"errors"
"fmt"
"time"
ptypes "github.com/gogo/protobuf/types"
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
@ -73,7 +73,7 @@ func (bs *BeaconServer) WaitForChainStart(req *ptypes.Empty, stream pb.BeaconSer
func (bs *BeaconServer) CanonicalHead(ctx context.Context, req *ptypes.Empty) (*ethpb.BeaconBlock, error) {
block, err := bs.beaconDB.ChainHead()
if err != nil {
return nil, fmt.Errorf("could not get canonical head block: %v", err)
return nil, errors.Wrap(err, "could not get canonical head block")
}
return block, nil
}
@ -82,11 +82,11 @@ func (bs *BeaconServer) CanonicalHead(ctx context.Context, req *ptypes.Empty) (*
func (bs *BeaconServer) BlockTree(ctx context.Context, _ *ptypes.Empty) (*pb.BlockTreeResponse, error) {
justifiedState, err := bs.beaconDB.JustifiedState()
if err != nil {
return nil, fmt.Errorf("could not retrieve justified state: %v", err)
return nil, errors.Wrap(err, "could not retrieve justified state")
}
attestationTargets, err := bs.targetsFetcher.AttestationTargets(justifiedState)
if err != nil {
return nil, fmt.Errorf("could not retrieve attestation target: %v", err)
return nil, errors.Wrap(err, "could not retrieve attestation target")
}
justifiedBlock, err := bs.beaconDB.JustifiedBlock()
if err != nil {
@ -133,11 +133,11 @@ func (bs *BeaconServer) BlockTree(ctx context.Context, _ *ptypes.Empty) (*pb.Blo
func (bs *BeaconServer) BlockTreeBySlots(ctx context.Context, req *pb.TreeBlockSlotRequest) (*pb.BlockTreeResponse, error) {
justifiedState, err := bs.beaconDB.JustifiedState()
if err != nil {
return nil, fmt.Errorf("could not retrieve justified state: %v", err)
return nil, errors.Wrap(err, "could not retrieve justified state")
}
attestationTargets, err := bs.targetsFetcher.AttestationTargets(justifiedState)
if err != nil {
return nil, fmt.Errorf("could not retrieve attestation target: %v", err)
return nil, errors.Wrap(err, "could not retrieve attestation target")
}
justifiedBlock, err := bs.beaconDB.JustifiedBlock()
if err != nil {

View File

@ -2,10 +2,10 @@ package rpc
import (
"context"
"errors"
"fmt"
"math/big"
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
@ -38,31 +38,31 @@ func (ps *ProposerServer) RequestBlock(ctx context.Context, req *pb.BlockRequest
// Retrieve the parent block as the current head of the canonical chain
parent, err := ps.beaconDB.ChainHead()
if err != nil {
return nil, fmt.Errorf("could not get canonical head block: %v", err)
return nil, errors.Wrap(err, "could not get canonical head block")
}
parentRoot, err := ssz.SigningRoot(parent)
if err != nil {
return nil, fmt.Errorf("could not get parent block signing root: %v", err)
return nil, errors.Wrap(err, "could not get parent block signing root")
}
// Construct block body
// Pack ETH1 deposits which have not been included in the beacon chain
eth1Data, err := ps.eth1Data(ctx, req.Slot)
if err != nil {
return nil, fmt.Errorf("could not get ETH1 data: %v", err)
return nil, errors.Wrap(err, "could not get ETH1 data")
}
// Pack ETH1 deposits which have not been included in the beacon chain.
deposits, err := ps.deposits(ctx, eth1Data)
if err != nil {
return nil, fmt.Errorf("could not get eth1 deposits: %v", err)
return nil, errors.Wrap(err, "could not get eth1 deposits")
}
// Pack aggregated attestations which have not been included in the beacon chain.
attestations, err := ps.attestations(ctx, req.Slot)
if err != nil {
return nil, fmt.Errorf("could not get pending attestations: %v", err)
return nil, errors.Wrap(err, "could not get pending attestations")
}
// Use zero hash as stub for state root to compute later.
@ -92,7 +92,7 @@ func (ps *ProposerServer) RequestBlock(ctx context.Context, req *pb.BlockRequest
// Compute state root with the newly constructed block.
stateRoot, err = ps.computeStateRoot(ctx, blk)
if err != nil {
return nil, fmt.Errorf("could not get compute state root: %v", err)
return nil, errors.Wrap(err, "could not get compute state root")
}
blk.StateRoot = stateRoot
@ -104,18 +104,18 @@ func (ps *ProposerServer) RequestBlock(ctx context.Context, req *pb.BlockRequest
func (ps *ProposerServer) ProposeBlock(ctx context.Context, blk *ethpb.BeaconBlock) (*pb.ProposeResponse, error) {
root, err := ssz.SigningRoot(blk)
if err != nil {
return nil, fmt.Errorf("could not tree hash block: %v", err)
return nil, errors.Wrap(err, "could not tree hash block")
}
log.WithField("blockRoot", fmt.Sprintf("%#x", bytesutil.Trunc(root[:]))).Debugf(
"Block proposal received via RPC")
beaconState, err := ps.chainService.ReceiveBlock(ctx, blk)
if err != nil {
return nil, fmt.Errorf("could not process beacon block: %v", err)
return nil, errors.Wrap(err, "could not process beacon block")
}
if err := ps.beaconDB.UpdateChainHead(ctx, blk, beaconState); err != nil {
return nil, fmt.Errorf("failed to update chain: %v", err)
return nil, errors.Wrap(err, "failed to update chain")
}
ps.chainService.UpdateCanonicalRoots(blk, root)
@ -135,7 +135,7 @@ func (ps *ProposerServer) ProposeBlock(ctx context.Context, blk *ethpb.BeaconBlo
func (ps *ProposerServer) attestations(ctx context.Context, expectedSlot uint64) ([]*ethpb.Attestation, error) {
beaconState, err := ps.beaconDB.HeadState(ctx)
if err != nil {
return nil, fmt.Errorf("could not retrieve beacon state: %v", err)
return nil, errors.Wrap(err, "could not retrieve beacon state")
}
atts, err := ps.operationService.AttestationPool(ctx, expectedSlot)
if err != nil {

View File

@ -3,11 +3,11 @@ package rpc
import (
"bytes"
"context"
"errors"
"fmt"
"math/big"
"time"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state/stateutils"
@ -66,7 +66,7 @@ func (vs *ValidatorServer) WaitForActivation(req *pb.ValidatorActivationRequest,
return err
}
case <-stream.Context().Done():
return errors.New("stream context closed,exiting gorutine")
return errors.New("stream context closed, exiting gorutine")
case <-vs.ctx.Done():
return errors.New("rpc context closed, exiting goroutine")
}
@ -78,7 +78,7 @@ func (vs *ValidatorServer) WaitForActivation(req *pb.ValidatorActivationRequest,
func (vs *ValidatorServer) ValidatorIndex(ctx context.Context, req *pb.ValidatorIndexRequest) (*pb.ValidatorIndexResponse, error) {
index, err := vs.beaconDB.ValidatorIndex(req.PublicKey)
if err != nil {
return nil, fmt.Errorf("could not get validator index: %v", err)
return nil, errors.Wrap(err, "could not get validator index")
}
return &pb.ValidatorIndexResponse{Index: uint64(index)}, nil
@ -91,25 +91,25 @@ func (vs *ValidatorServer) ValidatorPerformance(
) (*pb.ValidatorPerformanceResponse, error) {
index, err := vs.beaconDB.ValidatorIndex(req.PublicKey)
if err != nil {
return nil, fmt.Errorf("could not get validator index: %v", err)
return nil, errors.Wrap(err, "could not get validator index")
}
head, err := vs.beaconDB.HeadState(ctx)
if err != nil {
return nil, fmt.Errorf("could not get head: %v", err)
return nil, errors.Wrap(err, "could not get head")
}
Validators, err := vs.beaconDB.Validators(ctx)
if err != nil {
return nil, fmt.Errorf("could not retrieve beacon state: %v", err)
return nil, errors.Wrap(err, "could not retrieve beacon state")
}
activeCount, err := helpers.ActiveValidatorCount(head, helpers.SlotToEpoch(req.Slot))
if err != nil {
return nil, fmt.Errorf("could not retrieve active validator count: %v", err)
return nil, errors.Wrap(err, "could not retrieve active validator count")
}
totalActiveBalance, err := helpers.TotalActiveBalance(head)
if err != nil {
return nil, fmt.Errorf("could not retrieve active balance: %v", err)
return nil, errors.Wrap(err, "could not retrieve active balance")
}
validatorBalances, err := vs.beaconDB.Balances(ctx)
@ -136,7 +136,7 @@ func (vs *ValidatorServer) ValidatorPerformance(
func (vs *ValidatorServer) CommitteeAssignment(ctx context.Context, req *pb.AssignmentRequest) (*pb.AssignmentResponse, error) {
s, err := vs.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")
}
// Advance state with empty transitions up to the requested slot.
@ -196,7 +196,7 @@ func (vs *ValidatorServer) assignment(
idx, err := vs.beaconDB.ValidatorIndex(pubkey)
if err != nil {
return nil, fmt.Errorf("could not get active validator index: %v", err)
return nil, errors.Wrap(err, "could not get active validator index")
}
committee, shard, slot, isProposer, err :=
@ -228,7 +228,7 @@ func (vs *ValidatorServer) ValidatorStatus(
req *pb.ValidatorIndexRequest) (*pb.ValidatorStatusResponse, error) {
beaconState, err := vs.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")
}
chainStarted := vs.powChainService.HasChainStarted()
chainStartKeys := vs.chainStartPubkeys()
@ -462,7 +462,7 @@ func (vs *ValidatorServer) chainStartPubkeys() map[[96]byte]bool {
func (vs *ValidatorServer) DomainData(ctx context.Context, request *pb.DomainRequest) (*pb.DomainResponse, error) {
state, err := vs.beaconDB.HeadState(ctx)
if err != nil {
return nil, fmt.Errorf("could not retrieve beacon state: %v", err)
return nil, errors.Wrap(err, "could not retrieve beacon state")
}
dv := helpers.Domain(state, request.Epoch, request.Domain)
return &pb.DomainResponse{

View File

@ -28,6 +28,7 @@ go_library(
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_libp2p_go_libp2p_peer//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",

View File

@ -25,6 +25,7 @@ go_library(
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_libp2p_go_libp2p_peer//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",

View File

@ -2,11 +2,11 @@ package initialsync
import (
"context"
"errors"
"fmt"
"runtime/debug"
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/p2p"
@ -21,7 +21,7 @@ func (s *InitialSync) checkBlockValidity(ctx context.Context, block *ethpb.Beaco
defer span.End()
beaconState, err := s.db.HeadState(ctx)
if err != nil {
return fmt.Errorf("failed to get beacon state: %v", err)
return errors.Wrap(err, "failed to get beacon state")
}
if block.Slot < helpers.StartSlot(beaconState.FinalizedCheckpoint.Epoch) {

View File

@ -12,8 +12,6 @@ package initialsync
import (
"context"
"errors"
"fmt"
"math/big"
"sort"
"sync"
@ -21,6 +19,7 @@ import (
"github.com/ethereum/go-ethereum/common"
peer "github.com/libp2p/go-libp2p-peer"
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
@ -172,14 +171,14 @@ func (s *InitialSync) exitInitialSync(ctx context.Context, block *ethpb.BeaconBl
}
root, err := ssz.SigningRoot(block)
if err != nil {
return fmt.Errorf("failed to tree hash block: %v", err)
return errors.Wrap(err, "failed to tree hash block")
}
if err := s.db.SaveAttestationTarget(ctx, &pb.AttestationTarget{
Slot: block.Slot,
BeaconBlockRoot: root[:],
ParentRoot: block.ParentRoot,
}); err != nil {
return fmt.Errorf("failed to save attestation target: %v", err)
return errors.Wrap(err, "failed to save attestation target")
}
state, err = s.chainService.AdvanceState(ctx, state, block)
if err != nil {
@ -188,11 +187,11 @@ func (s *InitialSync) exitInitialSync(ctx context.Context, block *ethpb.BeaconBl
case *blockchain.BlockFailedProcessingErr:
// If the block fails processing, we delete it from our DB.
if err := s.db.DeleteBlock(block); err != nil {
return fmt.Errorf("could not delete bad block from db: %v", err)
return errors.Wrap(err, "could not delete bad block from db")
}
return fmt.Errorf("could not apply block state transition: %v", err)
return errors.Wrap(err, "could not apply block state transition")
default:
return fmt.Errorf("could not apply block state transition: %v", err)
return errors.Wrap(err, "could not apply block state transition")
}
}
if err := s.chainService.CleanupBlockOperations(ctx, block); err != nil {

View File

@ -2,11 +2,11 @@ package initialsync
import (
"context"
"errors"
"fmt"
"sort"
peer "github.com/libp2p/go-libp2p-peer"
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-ssz"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
@ -141,11 +141,11 @@ func (s *InitialSync) validateAndSaveNextBlock(ctx context.Context, block *ethpb
BeaconBlockRoot: root[:],
ParentRoot: block.ParentRoot,
}); err != nil {
return fmt.Errorf("could not to save attestation target: %v", err)
return errors.Wrap(err, "could not to save attestation target")
}
state, err = s.chainService.AdvanceState(ctx, state, block)
if err != nil {
return fmt.Errorf("could not apply block state transition: %v", err)
return errors.Wrap(err, "could not apply block state transition")
}
if err := s.chainService.CleanupBlockOperations(ctx, block); err != nil {
return err

View File

@ -4,13 +4,13 @@ package sync
import (
"bytes"
"context"
"errors"
"fmt"
"runtime/debug"
"sync"
"time"
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prysmaticlabs/go-ssz"
@ -438,7 +438,7 @@ func (rs *RegularSync) receiveAttestation(msg p2p.Message) error {
}
slot, err := helpers.AttestationDataSlot(headState, attestation.Data)
if err != nil {
return fmt.Errorf("could not get attestation slot: %v", err)
return errors.Wrap(err, "could not get attestation slot")
}
span.AddAttributes(

View File

@ -19,6 +19,7 @@ go_library(
"@com_github_ethereum_go_ethereum//core/types:go_default_library",
"@com_github_ethereum_go_ethereum//crypto:go_default_library",
"@com_github_ethereum_go_ethereum//event:go_default_library",
"@com_github_pkg_errors//:go_default_library",
],
)

View File

@ -2,9 +2,9 @@ package depositcontract
import (
"bytes"
"fmt"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/pkg/errors"
)
// UnpackDepositLogData unpacks the data from a deposit log using the ABI decoder.
@ -13,7 +13,7 @@ func UnpackDepositLogData(data []byte) (pubkey []byte, withdrawalCredentials []b
reader := bytes.NewReader([]byte(DepositContractABI))
contractAbi, err := abi.JSON(reader)
if err != nil {
return nil, nil, nil, nil, nil, fmt.Errorf("unable to generate contract abi: %v", err)
return nil, nil, nil, nil, nil, errors.Wrap(err, "unable to generate contract abi")
}
unpackedLogs := []interface{}{
@ -24,7 +24,7 @@ func UnpackDepositLogData(data []byte) (pubkey []byte, withdrawalCredentials []b
&index,
}
if err := contractAbi.Unpack(&unpackedLogs, "DepositEvent", data); err != nil {
return nil, nil, nil, nil, nil, fmt.Errorf("unable to unpack logs: %v", err)
return nil, nil, nil, nil, nil, errors.Wrap(err, "unable to unpack logs")
}
return pubkey, withdrawalCredentials, amount, signature, index, nil

View File

@ -17,6 +17,7 @@ go_library(
"@com_github_ethereum_go_ethereum//crypto:go_default_library",
"@com_github_ethereum_go_ethereum//ethclient:go_default_library",
"@com_github_ethereum_go_ethereum//rpc:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_urfave_cli//:go_default_library",
"@com_github_x_cray_logrus_prefixed_formatter//:go_default_library",

View File

@ -17,6 +17,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
"github.com/pkg/errors"
contracts "github.com/prysmaticlabs/prysm/contracts/deposit-contract"
"github.com/prysmaticlabs/prysm/shared/version"
"github.com/sirupsen/logrus"
@ -195,7 +196,7 @@ func allDepositContractAddresses(client *ethclient.Client) ([]common.Address, er
logs, err := client.FilterLogs(context.Background(), query)
if err != nil {
return nil, fmt.Errorf("could not get all deposit logs: %v", err)
return nil, errors.Wrap(err, "could not get all deposit logs")
}
fmt.Printf("%d deposit logs found\n", len(logs))

View File

@ -8,6 +8,7 @@ go_library(
deps = [
"//shared/bytesutil:go_default_library",
"@com_github_phoreproject_bls//g1pubs:go_default_library",
"@com_github_pkg_errors//:go_default_library",
],
)

View File

@ -8,6 +8,7 @@ import (
"io"
g1 "github.com/phoreproject/bls/g1pubs"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
)
@ -30,7 +31,7 @@ type PublicKey struct {
func RandKey(r io.Reader) (*SecretKey, error) {
k, err := g1.RandKey(r)
if err != nil {
return nil, fmt.Errorf("could not initialize secret key: %v", err)
return nil, errors.Wrap(err, "could not initialize secret key")
}
return &SecretKey{val: k}, nil
}
@ -49,7 +50,7 @@ func PublicKeyFromBytes(pub []byte) (*PublicKey, error) {
b := bytesutil.ToBytes48(pub)
k, err := g1.DeserializePublicKey(b)
if err != nil {
return nil, fmt.Errorf("could not unmarshal bytes into public key: %v", err)
return nil, errors.Wrap(err, "could not unmarshal bytes into public key")
}
return &PublicKey{val: k}, nil
}
@ -59,7 +60,7 @@ func SignatureFromBytes(sig []byte) (*Signature, error) {
b := bytesutil.ToBytes96(sig)
s, err := g1.DeserializeSignature(b)
if err != nil {
return nil, fmt.Errorf("could not unmarshal bytes into signature: %v", err)
return nil, errors.Wrap(err, "could not unmarshal bytes into signature")
}
return &Signature{val: s}, nil
}

View File

@ -16,6 +16,7 @@ go_library(
"//shared/bls:go_default_library",
"//shared/params:go_default_library",
"@com_github_pborman_uuid//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@org_golang_x_crypto//pbkdf2:go_default_library",
"@org_golang_x_crypto//scrypt:go_default_library",

View File

@ -21,13 +21,13 @@ package keystore
import (
"encoding/hex"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"github.com/pborman/uuid"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/shared/bls"
)
@ -154,7 +154,7 @@ func newKeyFromBLS(blsKey *bls.SecretKey) (*Key, error) {
func NewKey(rand io.Reader) (*Key, error) {
secretKey, err := bls.RandKey(rand)
if err != nil {
return nil, fmt.Errorf("could not generate random key: %v", err)
return nil, errors.Wrap(err, "could not generate random key")
}
return newKeyFromBLS(secretKey)
}

View File

@ -5,7 +5,10 @@ go_library(
srcs = ["pagination.go"],
importpath = "github.com/prysmaticlabs/prysm/shared/pagination",
visibility = ["//visibility:public"],
deps = ["//shared/params:go_default_library"],
deps = [
"//shared/params:go_default_library",
"@com_github_pkg_errors//:go_default_library",
],
)
go_test(

View File

@ -4,6 +4,7 @@ import (
"fmt"
"strconv"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/shared/params"
)
@ -19,7 +20,7 @@ func StartAndEndPage(pageToken string, pageSize int, totalSize int) (int, int, s
token, err := strconv.Atoi(pageToken)
if err != nil {
return 0, 0, "", fmt.Errorf("could not convert page token: %v", err)
return 0, 0, "", errors.Wrap(err, "could not convert page token")
}
// Start page can not be greater than validator size.

View File

@ -23,6 +23,7 @@ go_library(
"@com_github_ghodss_yaml//:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_json_iterator_go//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
],

View File

@ -3,10 +3,10 @@ package testutil
import (
"crypto/rand"
"encoding/binary"
"fmt"
"sync"
"testing"
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
@ -134,7 +134,7 @@ func CreateRandaoReveal(beaconState *pb.BeaconState, epoch uint64, privKeys []*b
// We fetch the proposer's index as that is whom the RANDAO will be verified against.
proposerIdx, err := helpers.BeaconProposerIndex(beaconState)
if err != nil {
return []byte{}, fmt.Errorf("could not get beacon proposer index: %v", err)
return []byte{}, errors.Wrap(err, "could not get beacon proposer index")
}
buf := make([]byte, 32)
binary.LittleEndian.PutUint64(buf, epoch)

View File

@ -31,6 +31,7 @@ go_library(
"@com_github_ethereum_go_ethereum//ethclient:go_default_library",
"@com_github_ethereum_go_ethereum//rpc:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
@ -92,6 +93,7 @@ go_image(
"@com_github_ethereum_go_ethereum//ethclient:go_default_library",
"@com_github_ethereum_go_ethereum//rpc:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",

View File

@ -4,7 +4,6 @@ import (
"context"
"crypto/ecdsa"
"crypto/rand"
"fmt"
"math/big"
"sync"
@ -13,6 +12,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
"github.com/pkg/errors"
contracts "github.com/prysmaticlabs/prysm/contracts/deposit-contract"
pb "github.com/prysmaticlabs/prysm/proto/cluster"
"github.com/prysmaticlabs/prysm/shared/keystore"
@ -70,7 +70,7 @@ func (s *server) makeDeposit(pubkey []byte, withdrawalCredentials []byte, signat
txOps.GasLimit = gasLimit
tx, err := s.contract.Deposit(txOps, pubkey, withdrawalCredentials, signature)
if err != nil {
return fmt.Errorf("deposit failed: %v", err)
return errors.Wrap(err, "deposit failed")
}
log.WithField("tx", tx.Hash().Hex()).Info("Deposit transaction sent")

View File

@ -22,6 +22,7 @@ go_library(
"//validator/flags:go_default_library",
"//validator/node:go_default_library",
"@com_github_joonix_log//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_urfave_cli//:go_default_library",
"@com_github_x_cray_logrus_prefixed_formatter//:go_default_library",
@ -54,6 +55,7 @@ go_image(
"//validator/flags:go_default_library",
"//validator/node:go_default_library",
"@com_github_joonix_log//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_urfave_cli//:go_default_library",
"@com_github_x_cray_logrus_prefixed_formatter//:go_default_library",

View File

@ -8,6 +8,7 @@ go_library(
deps = [
"//shared/keystore:go_default_library",
"//shared/params:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
],

View File

@ -3,11 +3,11 @@ package accounts
import (
"crypto/rand"
"encoding/hex"
"errors"
"fmt"
"io"
"os"
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/shared/keystore"
"github.com/prysmaticlabs/prysm/shared/params"
@ -72,11 +72,11 @@ func NewValidatorAccount(directory string, password string) error {
data, err := keystore.DepositInput(validatorKey, shardWithdrawalKey, params.BeaconConfig().MaxEffectiveBalance)
if err != nil {
return fmt.Errorf("unable to generate deposit data: %v", err)
return errors.Wrap(err, "unable to generate deposit data")
}
serializedData, err := ssz.Marshal(data)
if err != nil {
return fmt.Errorf("could not serialize deposit data: %v", err)
return errors.Wrap(err, "could not serialize deposit data")
}
log.Info(`Account creation complete! Copy and paste the deposit data shown below when issuing a transaction into the ETH1.0 deposit contract to activate your validator client`)
fmt.Printf(`

View File

@ -22,6 +22,7 @@ go_library(
"//shared/params:go_default_library",
"//shared/slotutil:go_default_library",
"@com_github_gogo_protobuf//types:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",

View File

@ -2,9 +2,9 @@ package client
import (
"context"
"errors"
"fmt"
"github.com/pkg/errors"
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
"github.com/prysmaticlabs/prysm/shared/keystore"
"github.com/prysmaticlabs/prysm/shared/params"
@ -49,7 +49,7 @@ func NewValidatorService(ctx context.Context, cfg *Config) (*ValidatorService, e
keys, err := ks.GetKeys(validatorFolder, validatorPrefix, cfg.Password)
if err != nil {
cancel()
return nil, fmt.Errorf("could not get private key: %v", err)
return nil, errors.Wrap(err, "could not get private key")
}
var key *keystore.Key
for _, v := range keys {

View File

@ -9,6 +9,7 @@ import (
"time"
ptypes "github.com/gogo/protobuf/types"
"github.com/pkg/errors"
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/keystore"
@ -47,7 +48,7 @@ func (v *validator) WaitForChainStart(ctx context.Context) error {
// First, check if the beacon chain has started.
stream, err := v.beaconClient.WaitForChainStart(ctx, &ptypes.Empty{})
if err != nil {
return fmt.Errorf("could not setup beacon chain ChainStart streaming client: %v", err)
return errors.Wrap(err, "could not setup beacon chain ChainStart streaming client")
}
for {
log.Info("Waiting for beacon chain start log from the ETH 1.0 deposit contract...")
@ -61,7 +62,7 @@ func (v *validator) WaitForChainStart(ctx context.Context) error {
return fmt.Errorf("context has been canceled so shutting down the loop: %v", ctx.Err())
}
if err != nil {
return fmt.Errorf("could not receive ChainStart from stream: %v", err)
return errors.Wrap(err, "could not receive ChainStart from stream")
}
v.genesisTime = chainStartRes.GenesisTime
break
@ -84,7 +85,7 @@ func (v *validator) WaitForActivation(ctx context.Context) error {
}
stream, err := v.validatorClient.WaitForActivation(ctx, req)
if err != nil {
return fmt.Errorf("could not setup validator WaitForActivation streaming client: %v", err)
return errors.Wrap(err, "could not setup validator WaitForActivation streaming client")
}
var validatorActivatedRecords [][]byte
for {
@ -98,7 +99,7 @@ func (v *validator) WaitForActivation(ctx context.Context) error {
return fmt.Errorf("context has been canceled so shutting down the loop: %v", ctx.Err())
}
if err != nil {
return fmt.Errorf("could not receive validator activation from stream: %v", err)
return errors.Wrap(err, "could not receive validator activation from stream")
}
log.Info("Waiting for validator to be activated in the beacon chain")
activatedKeys := v.checkAndLogValidatorStatus(res.Statuses)

View File

@ -9,6 +9,7 @@ import (
"syscall"
joonix "github.com/joonix/log"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/shared/cmd"
"github.com/prysmaticlabs/prysm/shared/debug"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
@ -95,7 +96,7 @@ func createValidatorAccount(ctx *cli.Context) (string, string, error) {
}
if err := accounts.NewValidatorAccount(keystoreDirectory, keystorePassword); err != nil {
return "", "", fmt.Errorf("could not initialize validator account: %v", err)
return "", "", errors.Wrapf(err, "could not initialize validator account")
}
return keystoreDirectory, keystorePassword, nil
}

View File

@ -28,6 +28,7 @@ go_library(
"//shared/version:go_default_library",
"//validator/client:go_default_library",
"//validator/flags:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_urfave_cli//:go_default_library",
],

View File

@ -10,6 +10,7 @@ import (
"sync"
"syscall"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/shared"
"github.com/prysmaticlabs/prysm/shared/cmd"
"github.com/prysmaticlabs/prysm/shared/debug"
@ -140,7 +141,7 @@ func (s *ValidatorClient) registerClientService(ctx *cli.Context, password strin
CertFlag: cert,
})
if err != nil {
return fmt.Errorf("could not initialize client service: %v", err)
return errors.Wrap(err, "could not initialize client service")
}
return s.services.RegisterService(v)
}