From b1a8384f2759c6b2a9f976e9fe8f7c3d6156acd8 Mon Sep 17 00:00:00 2001 From: Eduard S Date: Fri, 18 Dec 2020 13:39:42 +0100 Subject: [PATCH] Run go-instrument-errors to wrap errors --- common/l1tx.go | 4 ++-- common/l2tx.go | 4 ++-- common/pooll2tx.go | 4 ++-- eth/auction.go | 6 +++--- eth/rollup.go | 6 +++--- eth/wdelayer.go | 6 +++--- prover/prover.go | 10 +++++----- synchronizer/synchronizer.go | 12 ++++++------ test/ethclient.go | 6 +++--- test/til/txs.go | 2 +- 10 files changed, 30 insertions(+), 30 deletions(-) diff --git a/common/l1tx.go b/common/l1tx.go index e4018cf..152622d 100644 --- a/common/l1tx.go +++ b/common/l1tx.go @@ -53,7 +53,7 @@ type L1Tx struct { func NewL1Tx(tx *L1Tx) (*L1Tx, error) { txTypeOld := tx.Type if err := tx.SetType(); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } // If original Type doesn't match the correct one, return error if txTypeOld != "" && txTypeOld != tx.Type { @@ -63,7 +63,7 @@ func NewL1Tx(tx *L1Tx) (*L1Tx, error) { txIDOld := tx.TxID if err := tx.SetID(); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } // If original TxID doesn't match the correct one, return error if txIDOld != (TxID{}) && txIDOld != tx.TxID { diff --git a/common/l2tx.go b/common/l2tx.go index 8a197ad..b228640 100644 --- a/common/l2tx.go +++ b/common/l2tx.go @@ -27,7 +27,7 @@ type L2Tx struct { func NewL2Tx(tx *L2Tx) (*L2Tx, error) { txTypeOld := tx.Type if err := tx.SetType(); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } // If original Type doesn't match the correct one, return error if txTypeOld != "" && txTypeOld != tx.Type { @@ -37,7 +37,7 @@ func NewL2Tx(tx *L2Tx) (*L2Tx, error) { txIDOld := tx.TxID if err := tx.SetID(); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } // If original TxID doesn't match the correct one, return error if txIDOld != (TxID{}) && txIDOld != tx.TxID { diff --git a/common/pooll2tx.go b/common/pooll2tx.go index b256768..1d80e66 100644 --- a/common/pooll2tx.go +++ b/common/pooll2tx.go @@ -53,7 +53,7 @@ type PoolL2Tx struct { func NewPoolL2Tx(tx *PoolL2Tx) (*PoolL2Tx, error) { txTypeOld := tx.Type if err := tx.SetType(); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } // If original Type doesn't match the correct one, return error if txTypeOld != "" && txTypeOld != tx.Type { @@ -63,7 +63,7 @@ func NewPoolL2Tx(tx *PoolL2Tx) (*PoolL2Tx, error) { txIDOld := tx.TxID if err := tx.SetID(); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } // If original TxID doesn't match the correct one, return error if txIDOld != (TxID{}) && txIDOld != tx.TxID { diff --git a/eth/auction.go b/eth/auction.go index 453eae7..d502904 100644 --- a/eth/auction.go +++ b/eth/auction.go @@ -777,11 +777,11 @@ func (c *AuctionClient) AuctionEventInit() (*AuctionEventInitialize, int64, erro return nil, 0, tracerr.Wrap(err) } if len(logs) != 1 { - return nil, 0, fmt.Errorf("no event of type InitializeHermezAuctionProtocolEvent found") + return nil, 0, tracerr.Wrap(fmt.Errorf("no event of type InitializeHermezAuctionProtocolEvent found")) } vLog := logs[0] if vLog.Topics[0] != logAuctionInitialize { - return nil, 0, fmt.Errorf("event is not InitializeHermezAuctionProtocolEvent") + return nil, 0, tracerr.Wrap(fmt.Errorf("event is not InitializeHermezAuctionProtocolEvent")) } var auctionInit AuctionEventInitialize @@ -789,7 +789,7 @@ func (c *AuctionClient) AuctionEventInit() (*AuctionEventInitialize, int64, erro "InitializeHermezAuctionProtocolEvent", vLog.Data); err != nil { return nil, 0, tracerr.Wrap(err) } - return &auctionInit, int64(vLog.BlockNumber), err + return &auctionInit, int64(vLog.BlockNumber), tracerr.Wrap(err) } // AuctionEventsByBlock returns the events in a block that happened in the diff --git a/eth/rollup.go b/eth/rollup.go index 80b13e3..f6ccc6b 100644 --- a/eth/rollup.go +++ b/eth/rollup.go @@ -710,18 +710,18 @@ func (c *RollupClient) RollupEventInit() (*RollupEventInitialize, int64, error) return nil, 0, tracerr.Wrap(err) } if len(logs) != 1 { - return nil, 0, fmt.Errorf("no event of type InitializeHermezEvent found") + return nil, 0, tracerr.Wrap(fmt.Errorf("no event of type InitializeHermezEvent found")) } vLog := logs[0] if vLog.Topics[0] != logHermezInitialize { - return nil, 0, fmt.Errorf("event is not InitializeHermezEvent") + return nil, 0, tracerr.Wrap(fmt.Errorf("event is not InitializeHermezEvent")) } var rollupInit RollupEventInitialize if err := c.contractAbi.UnpackIntoInterface(&rollupInit, "InitializeHermezEvent", vLog.Data); err != nil { return nil, 0, tracerr.Wrap(err) } - return &rollupInit, int64(vLog.BlockNumber), err + return &rollupInit, int64(vLog.BlockNumber), tracerr.Wrap(err) } // RollupEventsByBlock returns the events in a block that happened in the Rollup Smart Contract diff --git a/eth/wdelayer.go b/eth/wdelayer.go index f883832..32e6e22 100644 --- a/eth/wdelayer.go +++ b/eth/wdelayer.go @@ -408,11 +408,11 @@ func (c *WDelayerClient) WDelayerEventInit() (*WDelayerEventInitialize, int64, e return nil, 0, tracerr.Wrap(err) } if len(logs) != 1 { - return nil, 0, fmt.Errorf("no event of type InitializeWithdrawalDelayerEvent found") + return nil, 0, tracerr.Wrap(fmt.Errorf("no event of type InitializeWithdrawalDelayerEvent found")) } vLog := logs[0] if vLog.Topics[0] != logWDelayerInitialize { - return nil, 0, fmt.Errorf("event is not InitializeWithdrawalDelayerEvent") + return nil, 0, tracerr.Wrap(fmt.Errorf("event is not InitializeWithdrawalDelayerEvent")) } var wDelayerInit WDelayerEventInitialize @@ -420,7 +420,7 @@ func (c *WDelayerClient) WDelayerEventInit() (*WDelayerEventInitialize, int64, e vLog.Data); err != nil { return nil, 0, tracerr.Wrap(err) } - return &wDelayerInit, int64(vLog.BlockNumber), err + return &wDelayerInit, int64(vLog.BlockNumber), tracerr.Wrap(err) } // WDelayerEventsByBlock returns the events in a block that happened in the diff --git a/prover/prover.go b/prover/prover.go index 09d6324..a20f0af 100644 --- a/prover/prover.go +++ b/prover/prover.go @@ -27,7 +27,7 @@ type bigInt big.Int func (b *bigInt) UnmarshalText(text []byte) error { _, ok := (*big.Int)(b).SetString(string(text), 10) if !ok { - return fmt.Errorf("invalid big int: \"%v\"", string(text)) + return tracerr.Wrap(fmt.Errorf("invalid big int: \"%v\"", string(text))) } return nil } @@ -42,7 +42,7 @@ func (p *Proof) UnmarshalJSON(data []byte) error { Protocol string `json:"protocol"` }{} if err := json.Unmarshal(data, &proof); err != nil { - return err + return tracerr.Wrap(err) } p.PiA[0] = (*big.Int)(proof.PiA[0]) p.PiA[1] = (*big.Int)(proof.PiA[1]) @@ -66,7 +66,7 @@ type PublicInputs []*big.Int func (p *PublicInputs) UnmarshalJSON(data []byte) error { pubInputs := []*bigInt{} if err := json.Unmarshal(data, &pubInputs); err != nil { - return err + return tracerr.Wrap(err) } *p = make([]*big.Int, len(pubInputs)) for i, v := range pubInputs { @@ -245,7 +245,7 @@ func (p *ProofServerClient) GetProof(ctx context.Context) (*Proof, []*big.Int, e } return &proof, pubInputs, nil } - return nil, nil, fmt.Errorf("status != StatusCodeSuccess, status = %v", status.Status) + return nil, nil, tracerr.Wrap(fmt.Errorf("status != StatusCodeSuccess, status = %v", status.Status)) } // Cancel cancels any current proof computation @@ -261,7 +261,7 @@ func (p *ProofServerClient) WaitReady(ctx context.Context) error { return tracerr.Wrap(err) } if !status.Status.IsInitialized() { - return fmt.Errorf("Proof Server is not initialized") + return tracerr.Wrap(fmt.Errorf("Proof Server is not initialized")) } if status.Status.IsReady() { return nil diff --git a/synchronizer/synchronizer.go b/synchronizer/synchronizer.go index a413f3e..7a030e4 100644 --- a/synchronizer/synchronizer.go +++ b/synchronizer/synchronizer.go @@ -226,7 +226,7 @@ func NewSynchronizer(ethClient eth.ClientInterface, historyDB *historydb.History initVars, startBlockNums, err := getInitialVariables(ethClient, &consts) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } log.Infow("Synchronizer syncing from smart contract blocks", "rollup", startBlockNums.Rollup, @@ -587,15 +587,15 @@ func getInitialVariables(ethClient eth.ClientInterface, consts *SCConsts) (*SCVariables, *StartBlockNums, error) { rollupInit, rollupInitBlock, err := ethClient.RollupEventInit() if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } auctionInit, auctionInitBlock, err := ethClient.AuctionEventInit() if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } wDelayerInit, wDelayerInitBlock, err := ethClient.WDelayerEventInit() if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } rollupVars := rollupInit.RollupVariables() auctionVars := auctionInit.AuctionVariables(consts.Auction.InitialMinimalBidding) @@ -625,7 +625,7 @@ func (s *Synchronizer) resetState(block *common.Block) error { s.vars.Auction = *vars.Auction.Copy() s.vars.WDelayer = *vars.WDelayer.Copy() } else if err != nil { - return err + return tracerr.Wrap(err) } else { s.vars.Rollup = *rollup s.vars.Auction = *auction @@ -805,7 +805,7 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e // Set TxID, BlockNum, BatchNum and Position to the forged L2Txs for i := range l2Txs { if err := l2Txs[i].SetID(); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } l2Txs[i].EthBlockNum = blockNum l2Txs[i].BatchNum = batchNum diff --git a/test/ethclient.go b/test/ethclient.go index 9a999ef..ffd0cb5 100644 --- a/test/ethclient.go +++ b/test/ethclient.go @@ -1777,14 +1777,14 @@ func (c *Client) CtlAddBlocks(blocks []common.BlockData) (err error) { auction := nextBlock.Auction for _, token := range block.Rollup.AddedTokens { if _, err := c.RollupAddTokenSimple(token.EthAddr, rollup.Vars.FeeAddToken); err != nil { - return err + return tracerr.Wrap(err) } } for _, tx := range block.Rollup.L1UserTxs { c.CtlSetAddr(tx.FromEthAddr) if _, err := c.RollupL1UserTxERC20ETH(tx.FromBJJ, int64(tx.FromIdx), tx.DepositAmount, tx.Amount, uint32(tx.TokenID), int64(tx.ToIdx)); err != nil { - return err + return tracerr.Wrap(err) } } c.CtlSetAddr(auction.Vars.BootCoordinator) @@ -1804,7 +1804,7 @@ func (c *Client) CtlAddBlocks(blocks []common.BlockData) (err error) { ProofB: [2][2]*big.Int{}, // Intentionally empty ProofC: [2]*big.Int{}, // Intentionally empty }); err != nil { - return err + return tracerr.Wrap(err) } } // Mine block and sync diff --git a/test/til/txs.go b/test/til/txs.go index 889e5f6..88d4b35 100644 --- a/test/til/txs.go +++ b/test/til/txs.go @@ -883,7 +883,7 @@ func (tc *Context) FillBlocksExtra(blocks []common.BlockData, cfg *ConfigExtra) tc.extra.nonces[tx.FromIdx]++ tx.Nonce = tc.extra.nonces[tx.FromIdx] if err := tx.SetID(); err != nil { - return err + return tracerr.Wrap(err) } nTx, err := common.NewL2Tx(tx) if err != nil {