From ced42634da9155413078de0473d8b0922076d475 Mon Sep 17 00:00:00 2001 From: Eduard S Date: Mon, 30 Nov 2020 12:58:36 +0100 Subject: [PATCH] Wrap all errors with tracerr --- api/api.go | 5 +- api/api_test.go | 34 +-- api/batch.go | 3 +- api/handlers.go | 3 +- api/parsers.go | 98 ++++---- api/slots.go | 9 +- api/state.go | 13 +- api/txspool.go | 9 +- apitypes/apitypes.go | 31 +-- apitypes/apitypes_test.go | 4 +- batchbuilder/batchbuilder.go | 9 +- cli/node/main.go | 20 +- common/account.go | 33 +-- common/account_test.go | 15 +- common/accountcreationauths.go | 3 +- common/batch.go | 3 +- common/fee.go | 4 +- common/float16.go | 4 +- common/float16_test.go | 9 +- common/l1tx.go | 59 ++--- common/l2tx.go | 20 +- common/pooll2tx.go | 41 ++-- common/token.go | 3 +- common/tx.go | 11 +- common/utils.go | 3 +- common/zk.go | 13 +- config/config.go | 13 +- coordinator/batch.go | 3 +- coordinator/coordinator.go | 49 ++-- coordinator/proofpool.go | 9 +- db/historydb/historydb.go | 161 ++++++------- db/historydb/historydb_test.go | 7 +- db/l2db/l2db.go | 29 +-- db/l2db/l2db_test.go | 11 +- db/statedb/statedb.go | 127 ++++++----- db/statedb/statedb_test.go | 15 +- db/statedb/txprocessors.go | 123 +++++----- db/statedb/utils.go | 25 +- db/statedb/utils_test.go | 3 +- db/utils.go | 13 +- eth/auction.go | 147 ++++++------ eth/client.go | 7 +- .../auction/HermezAuctionProtocol.go | 215 +++++++++--------- eth/contracts/hermez/Hermez.go | 199 ++++++++-------- eth/contracts/tokenHEZ/HEZ.go | 81 +++---- .../withdrawdelayer/WithdrawalDelayer.go | 133 +++++------ eth/ethereum.go | 35 +-- eth/rollup.go | 105 ++++----- eth/wdelayer.go | 77 +++---- node/node.go | 36 +-- priceupdater/priceupdater.go | 3 +- synchronizer/synchronizer.go | 127 ++++++----- test/debugapi/debugapi.go | 6 +- test/ethclient.go | 189 +++++++-------- test/ethclient_test.go | 11 +- test/historydb.go | 3 +- test/til/lang.go | 69 +++--- test/til/txs.go | 89 ++++---- txselector/txselector.go | 13 +- 59 files changed, 1324 insertions(+), 1268 deletions(-) diff --git a/api/api.go b/api/api.go index 0f45528..89c34ca 100644 --- a/api/api.go +++ b/api/api.go @@ -9,6 +9,7 @@ import ( "github.com/hermeznetwork/hermez-node/db/historydb" "github.com/hermeznetwork/hermez-node/db/l2db" "github.com/hermeznetwork/hermez-node/db/statedb" + "github.com/hermeznetwork/tracerr" ) // TODO: Add correct values to constants @@ -49,10 +50,10 @@ func NewAPI( // Check input // TODO: is stateDB only needed for explorer endpoints or for both? if coordinatorEndpoints && l2db == nil { - return nil, errors.New("cannot serve Coordinator endpoints without L2DB") + return nil, tracerr.Wrap(errors.New("cannot serve Coordinator endpoints without L2DB")) } if explorerEndpoints && hdb == nil { - return nil, errors.New("cannot serve Explorer endpoints without HistoryDB") + return nil, tracerr.Wrap(errors.New("cannot serve Explorer endpoints without HistoryDB")) } a := &API{ diff --git a/api/api_test.go b/api/api_test.go index e2e69e2..c80897e 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -25,6 +25,7 @@ import ( "github.com/hermeznetwork/hermez-node/log" "github.com/hermeznetwork/hermez-node/test" "github.com/hermeznetwork/hermez-node/test/til" + "github.com/hermeznetwork/tracerr" ) // Pendinger is an interface that allows getting last returned item ID and PendingItems to be used for building fromItem @@ -243,8 +244,7 @@ func TestMain(m *testing.M) { // Start server server := &http.Server{Addr: apiPort, Handler: apiGin} go func() { - if err := server.ListenAndServe(); err != nil && - err != http.ErrServerClosed { + if err := server.ListenAndServe(); err != nil && tracerr.Unwrap(err) != http.ErrServerClosed { panic(err) } }() @@ -471,7 +471,7 @@ func doGoodReqPaginated( "GET", iterPath+"&order="+order, nil, iterStruct, ); err != nil { - return err + return tracerr.Wrap(err) } appendIter(iterStruct) // Keep iterating? @@ -505,14 +505,14 @@ func doGoodReq(method, path string, reqBody io.Reader, returnStruct interface{}) client := &http.Client{} httpReq, err := http.NewRequest(method, path, reqBody) if err != nil { - return err + return tracerr.Wrap(err) } if reqBody != nil { httpReq.Header.Add("Content-Type", "application/json") } route, pathParams, err := tc.router.FindRoute(httpReq.Method, httpReq.URL) if err != nil { - return err + return tracerr.Wrap(err) } // Validate request against swagger spec requestValidationInput := &swagger.RequestValidationInput{ @@ -521,24 +521,24 @@ func doGoodReq(method, path string, reqBody io.Reader, returnStruct interface{}) Route: route, } if err := swagger.ValidateRequest(ctx, requestValidationInput); err != nil { - return err + return tracerr.Wrap(err) } // Do API call resp, err := client.Do(httpReq) if err != nil { - return err + return tracerr.Wrap(err) } if resp.Body == nil && returnStruct != nil { - return errors.New("Nil body") + return tracerr.Wrap(errors.New("Nil body")) } //nolint defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { - return err + return tracerr.Wrap(err) } if resp.StatusCode != 200 { - return fmt.Errorf("%d response. Body: %s", resp.StatusCode, string(body)) + return tracerr.Wrap(fmt.Errorf("%d response. Body: %s", resp.StatusCode, string(body))) } if returnStruct == nil { return nil @@ -547,7 +547,7 @@ func doGoodReq(method, path string, reqBody io.Reader, returnStruct interface{}) if err := json.Unmarshal(body, returnStruct); err != nil { log.Error("invalid json: " + string(body)) log.Error(err) - return err + return tracerr.Wrap(err) } // log.Info(string(body)) // Validate response against swagger spec @@ -566,7 +566,7 @@ func doBadReq(method, path string, reqBody io.Reader, expectedResponseCode int) httpReq, _ := http.NewRequest(method, path, reqBody) route, pathParams, err := tc.router.FindRoute(httpReq.Method, httpReq.URL) if err != nil { - return err + return tracerr.Wrap(err) } // Validate request against swagger spec requestValidationInput := &swagger.RequestValidationInput{ @@ -576,26 +576,26 @@ func doBadReq(method, path string, reqBody io.Reader, expectedResponseCode int) } if err := swagger.ValidateRequest(ctx, requestValidationInput); err != nil { if expectedResponseCode != 400 { - return err + return tracerr.Wrap(err) } log.Warn("The request does not match the API spec") } // Do API call resp, err := client.Do(httpReq) if err != nil { - return err + return tracerr.Wrap(err) } if resp.Body == nil { - return errors.New("Nil body") + return tracerr.Wrap(errors.New("Nil body")) } //nolint defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { - return err + return tracerr.Wrap(err) } if resp.StatusCode != expectedResponseCode { - return fmt.Errorf("Unexpected response code: %d. Body: %s", resp.StatusCode, string(body)) + return tracerr.Wrap(fmt.Errorf("Unexpected response code: %d. Body: %s", resp.StatusCode, string(body))) } // Validate response against swagger spec responseValidationInput := &swagger.ResponseValidationInput{ diff --git a/api/batch.go b/api/batch.go index 27e876e..fe09ba7 100644 --- a/api/batch.go +++ b/api/batch.go @@ -8,6 +8,7 @@ import ( "github.com/gin-gonic/gin" "github.com/hermeznetwork/hermez-node/common" "github.com/hermeznetwork/hermez-node/db/historydb" + "github.com/hermeznetwork/tracerr" ) func (a *API) getBatches(c *gin.Context) { @@ -110,7 +111,7 @@ func (a *API) getFullBatch(c *gin.Context) { txs, _, err := a.h.GetHistoryTxs( nil, nil, nil, nil, batchNum, nil, nil, &maxTxsPerBatch, historydb.OrderAsc, ) - if err != nil && err != sql.ErrNoRows { + if err != nil && tracerr.Unwrap(err) != sql.ErrNoRows { retSQLErr(err, c) return } diff --git a/api/handlers.go b/api/handlers.go index 0ddd346..4acbcf0 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -7,6 +7,7 @@ import ( "github.com/gin-gonic/gin" "github.com/hermeznetwork/hermez-node/db/historydb" + "github.com/hermeznetwork/tracerr" ) const ( @@ -32,7 +33,7 @@ var ( ) func retSQLErr(err error, c *gin.Context) { - if err == sql.ErrNoRows { + if tracerr.Unwrap(err) == sql.ErrNoRows { c.JSON(http.StatusNotFound, errorMsg{ Message: err.Error(), }) diff --git a/api/parsers.go b/api/parsers.go index 5295df6..9bf4fac 100644 --- a/api/parsers.go +++ b/api/parsers.go @@ -10,6 +10,7 @@ import ( ethCommon "github.com/ethereum/go-ethereum/common" "github.com/hermeznetwork/hermez-node/common" "github.com/hermeznetwork/hermez-node/db/historydb" + "github.com/hermeznetwork/tracerr" "github.com/iden3/go-iden3-crypto/babyjub" ) @@ -25,16 +26,16 @@ func parsePagination(c querier) (fromItem *uint, order string, limit *uint, err // FromItem fromItem, err = parseQueryUint("fromItem", nil, 0, maxUint32, c) if err != nil { - return nil, "", nil, err + return nil, "", nil, tracerr.Wrap(err) } // Order order = dfltOrder const orderName = "order" orderStr := c.Query(orderName) if orderStr != "" && !(orderStr == historydb.OrderAsc || historydb.OrderDesc == orderStr) { - return nil, "", nil, errors.New( + return nil, "", nil, tracerr.Wrap(errors.New( "order must have the value " + historydb.OrderAsc + " or " + historydb.OrderDesc, - ) + )) } if orderStr == historydb.OrderAsc { order = historydb.OrderAsc @@ -46,7 +47,7 @@ func parsePagination(c querier) (fromItem *uint, order string, limit *uint, err *limit = dfltLimit limit, err = parseQueryUint("limit", limit, 1, maxLimit, c) if err != nil { - return nil, "", nil, err + return nil, "", nil, tracerr.Wrap(err) } return fromItem, order, limit, nil } @@ -79,7 +80,7 @@ func parseQueryBool(name string, dflt *bool, c querier) (*bool, error) { //nolin *res = false return res, nil } - return nil, fmt.Errorf("Invalid %s. Must be eithe true or false", name) + return nil, tracerr.Wrap(fmt.Errorf("Invalid %s. Must be eithe true or false", name)) } func parseQueryHezEthAddr(c querier) (*ethCommon.Address, error) { @@ -135,10 +136,10 @@ func parseQueryTxType(c querier) (*common.TxType, error) { ret := common.TxTypeTransferToBJJ return &ret, nil } - return nil, fmt.Errorf( + return nil, tracerr.Wrap(fmt.Errorf( "invalid %s, %s is not a valid option. Check the valid options in the docmentation", name, typeStr, - ) + )) } func parseIdx(c querier) (*common.Idx, error) { @@ -151,7 +152,7 @@ func parseExitFilters(c querier) (*common.TokenID, *ethCommon.Address, *babyjub. // TokenID tid, err := parseQueryUint("tokenId", nil, 0, maxUint32, c) if err != nil { - return nil, nil, nil, nil, err + return nil, nil, nil, nil, tracerr.Wrap(err) } var tokenID *common.TokenID if tid != nil { @@ -161,25 +162,23 @@ func parseExitFilters(c querier) (*common.TokenID, *ethCommon.Address, *babyjub. // Hez Eth addr addr, err := parseQueryHezEthAddr(c) if err != nil { - return nil, nil, nil, nil, err + return nil, nil, nil, nil, tracerr.Wrap(err) } // BJJ bjj, err := parseQueryBJJ(c) if err != nil { - return nil, nil, nil, nil, err + return nil, nil, nil, nil, tracerr.Wrap(err) } if addr != nil && bjj != nil { - return nil, nil, nil, nil, - errors.New("bjj and hermezEthereumAddress params are incompatible") + return nil, nil, nil, nil, tracerr.Wrap(errors.New("bjj and hermezEthereumAddress params are incompatible")) } // Idx idx, err := parseIdx(c) if err != nil { - return nil, nil, nil, nil, err + return nil, nil, nil, nil, tracerr.Wrap(err) } if idx != nil && (addr != nil || bjj != nil || tokenID != nil) { - return nil, nil, nil, nil, - errors.New("accountIndex is incompatible with BJJ, hermezEthereumAddress and tokenId") + return nil, nil, nil, nil, tracerr.Wrap(errors.New("accountIndex is incompatible with BJJ, hermezEthereumAddress and tokenId")) } return tokenID, addr, bjj, idx, nil } @@ -195,7 +194,7 @@ func parseTokenFilters(c querier) ([]common.TokenID, []string, string, error) { for _, id := range ids { idUint, err := strconv.Atoi(id) if err != nil { - return nil, nil, "", err + return nil, nil, "", tracerr.Wrap(err) } tokenID := common.TokenID(idUint) tokensIDs = append(tokensIDs, tokenID) @@ -211,11 +210,11 @@ func parseTokenFilters(c querier) ([]common.TokenID, []string, string, error) { func parseBidFilters(c querier) (*int64, *ethCommon.Address, error) { slotNum, err := parseQueryInt64("slotNum", nil, 0, maxInt64, c) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } bidderAddr, err := parseQueryEthAddr("bidderAddr", c) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } return slotNum, bidderAddr, nil } @@ -223,19 +222,19 @@ func parseBidFilters(c querier) (*int64, *ethCommon.Address, error) { func parseSlotFilters(c querier) (*int64, *int64, *ethCommon.Address, *bool, error) { minSlotNum, err := parseQueryInt64("minSlotNum", nil, 0, maxInt64, c) if err != nil { - return nil, nil, nil, nil, err + return nil, nil, nil, nil, tracerr.Wrap(err) } maxSlotNum, err := parseQueryInt64("maxSlotNum", nil, 0, maxInt64, c) if err != nil { - return nil, nil, nil, nil, err + return nil, nil, nil, nil, tracerr.Wrap(err) } wonByEthereumAddress, err := parseQueryEthAddr("wonByEthereumAddress", c) if err != nil { - return nil, nil, nil, nil, err + return nil, nil, nil, nil, tracerr.Wrap(err) } finishedAuction, err := parseQueryBool("finishedAuction", nil, c) if err != nil { - return nil, nil, nil, nil, err + return nil, nil, nil, nil, tracerr.Wrap(err) } return minSlotNum, maxSlotNum, wonByEthereumAddress, finishedAuction, nil } @@ -250,7 +249,7 @@ func parseAccountFilters(c querier) ([]common.TokenID, *ethCommon.Address, *baby for _, id := range ids { idUint, err := strconv.Atoi(id) if err != nil { - return nil, nil, nil, err + return nil, nil, nil, tracerr.Wrap(err) } tokenID := common.TokenID(idUint) tokenIDs = append(tokenIDs, tokenID) @@ -259,16 +258,15 @@ func parseAccountFilters(c querier) ([]common.TokenID, *ethCommon.Address, *baby // Hez Eth addr addr, err := parseQueryHezEthAddr(c) if err != nil { - return nil, nil, nil, err + return nil, nil, nil, tracerr.Wrap(err) } // BJJ bjj, err := parseQueryBJJ(c) if err != nil { - return nil, nil, nil, err + return nil, nil, nil, tracerr.Wrap(err) } if addr != nil && bjj != nil { - return nil, nil, nil, - errors.New("bjj and hermezEthereumAddress params are incompatible") + return nil, nil, nil, tracerr.Wrap(errors.New("bjj and hermezEthereumAddress params are incompatible")) } return tokenIDs, addr, bjj, nil @@ -284,11 +282,11 @@ func parseParamTxID(c paramer) (common.TxID, error) { const name = "id" txIDStr := c.Param(name) if txIDStr == "" { - return common.TxID{}, fmt.Errorf("%s is required", name) + return common.TxID{}, tracerr.Wrap(fmt.Errorf("%s is required", name)) } txID, err := common.NewTxIDFromString(txIDStr) if err != nil { - return common.TxID{}, fmt.Errorf("invalid %s", name) + return common.TxID{}, tracerr.Wrap(fmt.Errorf("invalid %s", name)) } return txID, nil } @@ -318,22 +316,22 @@ func stringToIdx(idxStr, name string) (*common.Idx, error) { splitted := strings.Split(idxStr, ":") const expectedLen = 3 if len(splitted) != expectedLen || splitted[0] != "hez" { - return nil, fmt.Errorf( - "invalid %s, must follow this: hez::index", name) + return nil, tracerr.Wrap(fmt.Errorf( + "invalid %s, must follow this: hez::index", name)) } // TODO: check that the tokenSymbol match the token related to the account index idxInt, err := strconv.Atoi(splitted[2]) idx := common.Idx(idxInt) - return &idx, err + return &idx, tracerr.Wrap(err) } func stringToUint(uintStr, name string, dflt *uint, min, max uint) (*uint, error) { if uintStr != "" { resInt, err := strconv.Atoi(uintStr) if err != nil || resInt < 0 || resInt < int(min) || resInt > int(max) { - return nil, fmt.Errorf( + return nil, tracerr.Wrap(fmt.Errorf( "Invalid %s. Must be an integer within the range [%d, %d]", - name, min, max) + name, min, max)) } res := uint(resInt) return &res, nil @@ -345,9 +343,9 @@ func stringToInt64(uintStr, name string, dflt *int64, min, max int64) (*int64, e if uintStr != "" { resInt, err := strconv.Atoi(uintStr) if err != nil || resInt < 0 || resInt < int(min) || resInt > int(max) { - return nil, fmt.Errorf( + return nil, tracerr.Wrap(fmt.Errorf( "Invalid %s. Must be an integer within the range [%d, %d]", - name, min, max) + name, min, max)) } res := int64(resInt) return &res, nil @@ -361,32 +359,32 @@ func hezStringToEthAddr(addrStr, name string) (*ethCommon.Address, error) { } splitted := strings.Split(addrStr, "hez:") if len(splitted) != 2 || len(splitted[1]) != 42 { - return nil, fmt.Errorf( - "Invalid %s, must follow this regex: ^hez:0x[a-fA-F0-9]{40}$", name) + return nil, tracerr.Wrap(fmt.Errorf( + "Invalid %s, must follow this regex: ^hez:0x[a-fA-F0-9]{40}$", name)) } var addr ethCommon.Address err := addr.UnmarshalText([]byte(splitted[1])) - return &addr, err + return &addr, tracerr.Wrap(err) } func hezStringToBJJ(bjjStr, name string) (*babyjub.PublicKey, error) { const decodedLen = 33 splitted := strings.Split(bjjStr, "hez:") if len(splitted) != 2 || len(splitted[1]) != 44 { - return nil, fmt.Errorf( + return nil, tracerr.Wrap(fmt.Errorf( "Invalid %s, must follow this regex: ^hez:[A-Za-z0-9+/=]{44}$", - name) + name)) } decoded, err := base64.RawURLEncoding.DecodeString(splitted[1]) if err != nil { - return nil, fmt.Errorf( + return nil, tracerr.Wrap(fmt.Errorf( "Invalid %s, error decoding base64 string: %s", - name, err.Error()) + name, err.Error())) } if len(decoded) != decodedLen { - return nil, fmt.Errorf( + return nil, tracerr.Wrap(fmt.Errorf( "invalid %s, error decoding base64 string: unexpected byte array length", - name) + name)) } bjjBytes := [decodedLen - 1]byte{} copy(bjjBytes[:decodedLen-1], decoded[:decodedLen-1]) @@ -395,15 +393,15 @@ func hezStringToBJJ(bjjStr, name string) (*babyjub.PublicKey, error) { sum += bjjBytes[i] } if decoded[decodedLen-1] != sum { - return nil, fmt.Errorf("invalid %s, checksum failed", - name) + return nil, tracerr.Wrap(fmt.Errorf("invalid %s, checksum failed", + name)) } bjjComp := babyjub.PublicKeyComp(bjjBytes) bjj, err := bjjComp.Decompress() if err != nil { - return nil, fmt.Errorf( + return nil, tracerr.Wrap(fmt.Errorf( "invalid %s, error decompressing public key: %s", - name, err.Error()) + name, err.Error())) } return bjj, nil } @@ -427,7 +425,7 @@ func parseParamEthAddr(name string, c paramer) (*ethCommon.Address, error) { func parseEthAddr(ethAddrStr string) (*ethCommon.Address, error) { var addr ethCommon.Address err := addr.UnmarshalText([]byte(ethAddrStr)) - return &addr, err + return &addr, tracerr.Wrap(err) } func parseParamHezEthAddr(c paramer) (*ethCommon.Address, error) { diff --git a/api/slots.go b/api/slots.go index 6c14603..3936d94 100644 --- a/api/slots.go +++ b/api/slots.go @@ -8,6 +8,7 @@ import ( "github.com/gin-gonic/gin" "github.com/hermeznetwork/hermez-node/common" "github.com/hermeznetwork/hermez-node/db/historydb" + "github.com/hermeznetwork/tracerr" ) // SlotAPI is a repesentation of a slot information @@ -109,13 +110,13 @@ func (a *API) getSlot(c *gin.Context) { slotNum := int64(*slotNumUint) bid, err := a.h.GetBestBidAPI(&slotNum) - if err != nil && err != sql.ErrNoRows { + if err != nil && tracerr.Unwrap(err) != sql.ErrNoRows { retSQLErr(err, c) return } var slot SlotAPI - if err == sql.ErrNoRows { + if tracerr.Unwrap(err) == sql.ErrNoRows { slot = a.newSlotAPI(slotNum, currentBlock.Num, nil, auctionVars) } else { slot = a.newSlotAPI(bid.SlotNum, currentBlock.Num, &bid, auctionVars) @@ -252,14 +253,14 @@ func (a *API) getSlots(c *gin.Context) { slotMinLim, slotMaxLim, pendingItems = getLimits(*minSlotNum, *maxSlotNum, fromItem, limit, order) // Get best bids in range maxSlotNum - minSlotNum bids, _, err = a.h.GetBestBidsAPI(&slotMinLim, &slotMaxLim, wonByEthereumAddress, nil, order) - if err != nil && err != sql.ErrNoRows { + if err != nil && tracerr.Unwrap(err) != sql.ErrNoRows { retSQLErr(err, c) return } } else { slotMinLim, slotMaxLim = getLimitsWithAddr(minSlotNum, maxSlotNum, fromItem, limit, order) bids, pendingItems, err = a.h.GetBestBidsAPI(&slotMinLim, &slotMaxLim, wonByEthereumAddress, limit, order) - if err != nil && err != sql.ErrNoRows { + if err != nil && tracerr.Unwrap(err) != sql.ErrNoRows { retSQLErr(err, c) return } diff --git a/api/state.go b/api/state.go index af941ea..f9421c9 100644 --- a/api/state.go +++ b/api/state.go @@ -8,6 +8,7 @@ import ( "github.com/gin-gonic/gin" "github.com/hermeznetwork/hermez-node/common" "github.com/hermeznetwork/hermez-node/db/historydb" + "github.com/hermeznetwork/tracerr" ) // Network define status of the network @@ -89,12 +90,12 @@ func (a *API) UpdateNetworkInfo( ) error { lastBatch, err := a.h.GetBatchAPI(lastBatchNum) if err != nil { - return err + return tracerr.Wrap(err) } lastClosedSlot := currentSlot + int64(a.status.Auction.ClosedAuctionSlots) nextForgers, err := a.getNextForgers(lastSyncBlock, currentSlot, lastClosedSlot) if err != nil { - return err + return tracerr.Wrap(err) } a.status.Lock() a.status.Network.LastSyncBlock = lastSyncBlock.Num @@ -113,7 +114,7 @@ func (a *API) getNextForgers(lastBlock common.Block, currentSlot, lastClosedSlot limit := uint(lastClosedSlot - currentSlot + 1) bids, _, err := a.h.GetBestBidsAPI(¤tSlot, &lastClosedSlot, nil, &limit, "ASC") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } nextForgers := []NextForger{} // Create nextForger for each slot @@ -136,7 +137,7 @@ func (a *API) getNextForgers(lastBlock common.Block, currentSlot, lastClosedSlot foundBid = true coordinator, err := a.h.GetCoordinatorAPI(bids[j].Bidder) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } nextForger.Coordinator = *coordinator break @@ -160,7 +161,7 @@ func (a *API) UpdateMetrics() error { a.status.RUnlock() metrics, err := a.h.GetMetrics(batchNum) if err != nil { - return err + return tracerr.Wrap(err) } a.status.Lock() a.status.Metrics = *metrics @@ -174,7 +175,7 @@ func (a *API) UpdateMetrics() error { func (a *API) UpdateRecommendedFee() error { feeExistingAccount, err := a.h.GetAvgTxFee() if err != nil { - return err + return tracerr.Wrap(err) } a.status.Lock() a.status.RecommendedFee.ExistingAccount = feeExistingAccount diff --git a/api/txspool.go b/api/txspool.go index 2a89401..2120ff2 100644 --- a/api/txspool.go +++ b/api/txspool.go @@ -10,6 +10,7 @@ import ( "github.com/hermeznetwork/hermez-node/apitypes" "github.com/hermeznetwork/hermez-node/common" "github.com/hermeznetwork/hermez-node/db/l2db" + "github.com/hermeznetwork/tracerr" "github.com/iden3/go-iden3-crypto/babyjub" ) @@ -156,21 +157,21 @@ func (a *API) verifyPoolL2TxWrite(txw *l2db.PoolL2TxWrite) error { // Check type and id _, err := common.NewPoolL2Tx(&poolTx) if err != nil { - return err + return tracerr.Wrap(err) } // Get public key account, err := a.s.GetAccount(poolTx.FromIdx) if err != nil { - return err + return tracerr.Wrap(err) } // Validate feeAmount _, err = common.CalcFeeAmount(poolTx.Amount, poolTx.Fee) if err != nil { - return err + return tracerr.Wrap(err) } // Check signature if !poolTx.VerifySignature(account.PublicKey) { - return errors.New("wrong signature") + return tracerr.Wrap(errors.New("wrong signature")) } return nil } diff --git a/apitypes/apitypes.go b/apitypes/apitypes.go index b8753ef..ad257d0 100644 --- a/apitypes/apitypes.go +++ b/apitypes/apitypes.go @@ -13,6 +13,7 @@ import ( ethCommon "github.com/ethereum/go-ethereum/common" "github.com/hermeznetwork/hermez-node/common" + "github.com/hermeznetwork/tracerr" "github.com/iden3/go-iden3-crypto/babyjub" ) @@ -35,7 +36,7 @@ func NewBigIntStr(bigInt *big.Int) *BigIntStr { func (b *BigIntStr) Scan(src interface{}) error { srcBytes, ok := src.([]byte) if !ok { - return fmt.Errorf("can't scan %T into apitypes.BigIntStr", src) + return tracerr.Wrap(fmt.Errorf("can't scan %T into apitypes.BigIntStr", src)) } // bytes to *big.Int bigInt := new(big.Int).SetBytes(srcBytes) @@ -53,7 +54,7 @@ func (b BigIntStr) Value() (driver.Value, error) { // string to *big.Int bigInt, ok := new(big.Int).SetString(string(b), 10) if !ok || bigInt == nil { - return nil, errors.New("invalid representation of a *big.Int") + return nil, tracerr.Wrap(errors.New("invalid representation of a *big.Int")) } // *big.Int to bytes return bigInt.Bytes(), nil @@ -66,7 +67,7 @@ type StrBigInt big.Int func (s *StrBigInt) UnmarshalText(text []byte) error { bi, ok := (*big.Int)(s).SetString(string(text), 10) if !ok { - return fmt.Errorf("could not unmarshal %s into a StrBigInt", text) + return tracerr.Wrap(fmt.Errorf("could not unmarshal %s into a StrBigInt", text)) } *s = StrBigInt(*bi) return nil @@ -79,7 +80,7 @@ type CollectedFees map[common.TokenID]BigIntStr func (c *CollectedFees) UnmarshalJSON(text []byte) error { bigIntMap := make(map[common.TokenID]*big.Int) if err := json.Unmarshal(text, &bigIntMap); err != nil { - return err + return tracerr.Wrap(err) } *c = CollectedFees(make(map[common.TokenID]BigIntStr)) for k, v := range bigIntMap { @@ -110,7 +111,7 @@ func (a HezEthAddr) ToEthAddr() (ethCommon.Address, error) { func (a *HezEthAddr) Scan(src interface{}) error { ethAddr := ðCommon.Address{} if err := ethAddr.Scan(src); err != nil { - return err + return tracerr.Wrap(err) } if ethAddr == nil { return nil @@ -123,7 +124,7 @@ func (a *HezEthAddr) Scan(src interface{}) error { func (a HezEthAddr) Value() (driver.Value, error) { ethAddr, err := a.ToEthAddr() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return ethAddr.Value() } @@ -136,7 +137,7 @@ func (s *StrHezEthAddr) UnmarshalText(text []byte) error { withoutHez := strings.TrimPrefix(string(text), "hez:") var addr ethCommon.Address if err := addr.UnmarshalText([]byte(withoutHez)); err != nil { - return err + return tracerr.Wrap(err) } *s = StrHezEthAddr(addr) return nil @@ -180,7 +181,7 @@ func hezStrToBJJ(s string) (*babyjub.PublicKey, error) { sum += bjjBytes[i] } if decoded[decodedLen-1] != sum { - return nil, errors.New("checksum verification failed") + return nil, tracerr.Wrap(errors.New("checksum verification failed")) } bjjComp := babyjub.PublicKeyComp(bjjBytes) return bjjComp.Decompress() @@ -195,7 +196,7 @@ func (b HezBJJ) ToBJJ() (*babyjub.PublicKey, error) { func (b *HezBJJ) Scan(src interface{}) error { bjj := &babyjub.PublicKey{} if err := bjj.Scan(src); err != nil { - return err + return tracerr.Wrap(err) } if bjj == nil { return nil @@ -208,7 +209,7 @@ func (b *HezBJJ) Scan(src interface{}) error { func (b HezBJJ) Value() (driver.Value, error) { bjj, err := b.ToBJJ() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return bjj.Value() } @@ -220,7 +221,7 @@ type StrHezBJJ babyjub.PublicKey func (s *StrHezBJJ) UnmarshalText(text []byte) error { bjj, err := hezStrToBJJ(string(text)) if err != nil { - return err + return tracerr.Wrap(err) } *s = StrHezBJJ(*bjj) return nil @@ -239,11 +240,11 @@ func (s *StrHezIdx) UnmarshalText(text []byte) error { splitted := strings.Split(withoutHez, ":") const expectedLen = 2 if len(splitted) != expectedLen { - return fmt.Errorf("can not unmarshal %s into StrHezIdx", text) + return tracerr.Wrap(fmt.Errorf("can not unmarshal %s into StrHezIdx", text)) } idxInt, err := strconv.Atoi(splitted[1]) if err != nil { - return err + return tracerr.Wrap(err) } *s = StrHezIdx(common.Idx(idxInt)) return nil @@ -274,7 +275,7 @@ func (e *EthSignature) Scan(src interface{}) error { return nil } else { // unexpected src - return fmt.Errorf("can't scan %T into apitypes.EthSignature", src) + return tracerr.Wrap(fmt.Errorf("can't scan %T into apitypes.EthSignature", src)) } } @@ -289,7 +290,7 @@ func (e *EthSignature) UnmarshalText(text []byte) error { without0x := strings.TrimPrefix(string(text), "0x") signature, err := hex.DecodeString(without0x) if err != nil { - return err + return tracerr.Wrap(err) } *e = EthSignature([]byte(signature)) return nil diff --git a/apitypes/apitypes_test.go b/apitypes/apitypes_test.go index 020fc70..1e3c792 100644 --- a/apitypes/apitypes_test.go +++ b/apitypes/apitypes_test.go @@ -12,7 +12,9 @@ import ( "github.com/hermeznetwork/hermez-node/common" dbUtils "github.com/hermeznetwork/hermez-node/db" "github.com/iden3/go-iden3-crypto/babyjub" - _ "github.com/mattn/go-sqlite3" //nolint sqlite driver + + // nolint sqlite driver + _ "github.com/mattn/go-sqlite3" "github.com/russross/meddler" "github.com/stretchr/testify/assert" ) diff --git a/batchbuilder/batchbuilder.go b/batchbuilder/batchbuilder.go index cfa678d..58968c6 100644 --- a/batchbuilder/batchbuilder.go +++ b/batchbuilder/batchbuilder.go @@ -4,6 +4,7 @@ import ( ethCommon "github.com/ethereum/go-ethereum/common" "github.com/hermeznetwork/hermez-node/common" "github.com/hermeznetwork/hermez-node/db/statedb" + "github.com/hermeznetwork/tracerr" ) // ConfigCircuit contains the circuit configuration @@ -30,7 +31,7 @@ type ConfigBatch struct { func NewBatchBuilder(dbpath string, synchronizerStateDB *statedb.StateDB, configCircuits []ConfigCircuit, batchNum common.BatchNum, nLevels uint64) (*BatchBuilder, error) { localStateDB, err := statedb.NewLocalStateDB(dbpath, synchronizerStateDB, statedb.TypeBatchBuilder, int(nLevels)) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } bb := BatchBuilder{ @@ -39,7 +40,7 @@ func NewBatchBuilder(dbpath string, synchronizerStateDB *statedb.StateDB, config } err = bb.Reset(batchNum, true) - return &bb, err + return &bb, tracerr.Wrap(err) } // Reset tells the BatchBuilder to reset it's internal state to the required @@ -61,8 +62,8 @@ func (bb *BatchBuilder) BuildBatch(coordIdxs []common.Idx, configBatch *ConfigBa } ptOut, err := bb.localStateDB.ProcessTxs(ptc, coordIdxs, l1usertxs, l1coordinatortxs, pooll2txs) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } err = bb.localStateDB.MakeCheckpoint() - return ptOut.ZKInputs, err + return ptOut.ZKInputs, tracerr.Wrap(err) } diff --git a/cli/node/main.go b/cli/node/main.go index 164319e..43805b2 100644 --- a/cli/node/main.go +++ b/cli/node/main.go @@ -24,20 +24,20 @@ func cmdInit(c *cli.Context) error { log.Info("Init") cfg, err := parseCli(c) if err != nil { - return err + return tracerr.Wrap(err) } fmt.Println("TODO", cfg) - return err + return tracerr.Wrap(err) } func cmdRun(c *cli.Context) error { cfg, err := parseCli(c) if err != nil { - return fmt.Errorf("error parsing flags and config: %w", err) + return tracerr.Wrap(fmt.Errorf("error parsing flags and config: %w", err)) } node, err := node.NewNode(cfg.mode, cfg.node, cfg.coord) if err != nil { - return fmt.Errorf("error starting node: %w", err) + return tracerr.Wrap(fmt.Errorf("error starting node: %w", err)) } node.Start() @@ -72,7 +72,7 @@ func parseCli(c *cli.Context) (*Config, error) { if err := cli.ShowAppHelp(c); err != nil { panic(err) } - return nil, err + return nil, tracerr.Wrap(err) } return cfg, nil } @@ -86,27 +86,27 @@ func getConfig(c *cli.Context) (*Config, error) { case modeCoord: cfg.mode = node.ModeCoordinator default: - return nil, fmt.Errorf("invalid mode \"%v\"", mode) + return nil, tracerr.Wrap(fmt.Errorf("invalid mode \"%v\"", mode)) } if cfg.mode == node.ModeCoordinator { coordCfgPath := c.String(flagCoordCfg) if coordCfgPath == "" { - return nil, fmt.Errorf("required flag \"%v\" not set", flagCoordCfg) + return nil, tracerr.Wrap(fmt.Errorf("required flag \"%v\" not set", flagCoordCfg)) } coordCfg, err := config.LoadCoordinator(coordCfgPath) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } cfg.coord = coordCfg } nodeCfgPath := c.String(flagCfg) if nodeCfgPath == "" { - return nil, fmt.Errorf("required flag \"%v\" not set", flagCfg) + return nil, tracerr.Wrap(fmt.Errorf("required flag \"%v\" not set", flagCfg)) } nodeCfg, err := config.LoadNode(nodeCfgPath) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } // nodeCfg.Synchronizer.InitialVariables.WDelayer.HermezRollupAddress = nodeCfg.SmartContracts.Rollup cfg.node = nodeCfg diff --git a/common/account.go b/common/account.go index 4722489..3526320 100644 --- a/common/account.go +++ b/common/account.go @@ -8,6 +8,7 @@ import ( "strconv" ethCommon "github.com/ethereum/go-ethereum/common" + "github.com/hermeznetwork/tracerr" "github.com/iden3/go-iden3-crypto/babyjub" "github.com/iden3/go-iden3-crypto/poseidon" cryptoUtils "github.com/iden3/go-iden3-crypto/utils" @@ -51,7 +52,7 @@ func (idx Idx) String() string { // Bytes returns a byte array representing the Idx func (idx Idx) Bytes() ([6]byte, error) { if idx > maxIdxValue { - return [6]byte{}, ErrIdxOverflow + return [6]byte{}, tracerr.Wrap(ErrIdxOverflow) } var idxBytes [8]byte binary.BigEndian.PutUint64(idxBytes[:], uint64(idx)) @@ -68,7 +69,7 @@ func (idx Idx) BigInt() *big.Int { // IdxFromBytes returns Idx from a byte array func IdxFromBytes(b []byte) (Idx, error) { if len(b) != IdxBytesLen { - return 0, fmt.Errorf("can not parse Idx, bytes len %d, expected %d", len(b), IdxBytesLen) + return 0, tracerr.Wrap(fmt.Errorf("can not parse Idx, bytes len %d, expected %d", len(b), IdxBytesLen)) } var idxBytes [8]byte copy(idxBytes[2:], b[:]) @@ -79,7 +80,7 @@ func IdxFromBytes(b []byte) (Idx, error) { // IdxFromBigInt converts a *big.Int to Idx type func IdxFromBigInt(b *big.Int) (Idx, error) { if b.Int64() > maxIdxValue { - return 0, ErrNumOverflow + return 0, tracerr.Wrap(ErrNumOverflow) } return Idx(uint64(b.Int64())), nil } @@ -90,7 +91,7 @@ type Nonce uint64 // Bytes returns a byte array of length 5 representing the Nonce func (n Nonce) Bytes() ([5]byte, error) { if n > maxNonceValue { - return [5]byte{}, ErrNonceOverflow + return [5]byte{}, tracerr.Wrap(ErrNonceOverflow) } var nonceBytes [8]byte binary.BigEndian.PutUint64(nonceBytes[:], uint64(n)) @@ -143,22 +144,22 @@ func (a *Account) Bytes() ([32 * NLeafElems]byte, error) { var b [32 * NLeafElems]byte if a.Nonce > maxNonceValue { - return b, fmt.Errorf("%s Nonce", ErrNumOverflow) + return b, tracerr.Wrap(fmt.Errorf("%s Nonce", ErrNumOverflow)) } if len(a.Balance.Bytes()) > maxBalanceBytes { - return b, fmt.Errorf("%s Balance", ErrNumOverflow) + return b, tracerr.Wrap(fmt.Errorf("%s Balance", ErrNumOverflow)) } nonceBytes, err := a.Nonce.Bytes() if err != nil { - return b, err + return b, tracerr.Wrap(err) } copy(b[28:32], a.TokenID.Bytes()) copy(b[23:28], nonceBytes[:]) if a.PublicKey == nil { - return b, fmt.Errorf("Account.PublicKey can not be nil") + return b, tracerr.Wrap(fmt.Errorf("Account.PublicKey can not be nil")) } if babyjub.PointCoordSign(a.PublicKey.X) { b[22] = 1 @@ -178,7 +179,7 @@ func (a *Account) BigInts() ([NLeafElems]*big.Int, error) { b, err := a.Bytes() if err != nil { - return e, err + return e, tracerr.Wrap(err) } e[0] = new(big.Int).SetBytes(b[0:32]) @@ -193,7 +194,7 @@ func (a *Account) BigInts() ([NLeafElems]*big.Int, error) { func (a *Account) HashValue() (*big.Int, error) { bi, err := a.BigInts() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return poseidon.Hash(bi[:]) } @@ -201,7 +202,7 @@ func (a *Account) HashValue() (*big.Int, error) { // AccountFromBigInts returns a Account from a [5]*big.Int func AccountFromBigInts(e [NLeafElems]*big.Int) (*Account, error) { if !cryptoUtils.CheckBigIntArrayInField(e[:]) { - return nil, ErrNotInFF + return nil, tracerr.Wrap(ErrNotInFF) } e0B := e[0].Bytes() e1B := e[1].Bytes() @@ -220,7 +221,7 @@ func AccountFromBigInts(e [NLeafElems]*big.Int) (*Account, error) { func AccountFromBytes(b [32 * NLeafElems]byte) (*Account, error) { tokenID, err := TokenIDFromBytes(b[28:32]) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } var nonceBytes5 [5]byte copy(nonceBytes5[:], b[23:28]) @@ -230,21 +231,21 @@ func AccountFromBytes(b [32 * NLeafElems]byte) (*Account, error) { balance := new(big.Int).SetBytes(b[40:64]) // Balance is max of 192 bits (24 bytes) if !bytes.Equal(b[32:40], []byte{0, 0, 0, 0, 0, 0, 0, 0}) { - return nil, fmt.Errorf("%s Balance", ErrNumOverflow) + return nil, tracerr.Wrap(fmt.Errorf("%s Balance", ErrNumOverflow)) } ay := new(big.Int).SetBytes(b[64:96]) pkPoint, err := babyjub.PointFromSignAndY(sign, ay) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } publicKey := babyjub.PublicKey(*pkPoint) ethAddr := ethCommon.BytesToAddress(b[108:128]) if !cryptoUtils.CheckBigIntInField(balance) { - return nil, ErrNotInFF + return nil, tracerr.Wrap(ErrNotInFF) } if !cryptoUtils.CheckBigIntInField(ay) { - return nil, ErrNotInFF + return nil, tracerr.Wrap(ErrNotInFF) } a := Account{ diff --git a/common/account_test.go b/common/account_test.go index 5724d81..d2c8040 100644 --- a/common/account_test.go +++ b/common/account_test.go @@ -10,6 +10,7 @@ import ( ethCommon "github.com/ethereum/go-ethereum/common" ethCrypto "github.com/ethereum/go-ethereum/crypto" + "github.com/hermeznetwork/tracerr" "github.com/iden3/go-iden3-crypto/babyjub" cryptoConstants "github.com/iden3/go-iden3-crypto/constants" "github.com/iden3/go-iden3-crypto/poseidon" @@ -45,7 +46,7 @@ func TestIdxParser(t *testing.T) { i = Idx(281474976710656) iBytes, err = i.Bytes() assert.NotNil(t, err) - assert.Equal(t, ErrIdxOverflow, err) + assert.Equal(t, ErrIdxOverflow, tracerr.Unwrap(err)) } func TestNonceParser(t *testing.T) { @@ -70,7 +71,7 @@ func TestNonceParser(t *testing.T) { n = Nonce(1099511627776) nBytes, err = n.Bytes() assert.NotNil(t, err) - assert.Equal(t, ErrNonceOverflow, err) + assert.Equal(t, ErrNonceOverflow, tracerr.Unwrap(err)) } func TestAccount(t *testing.T) { @@ -296,14 +297,14 @@ func TestAccountErrNotInFF(t *testing.T) { e = [NLeafElems]*big.Int{z, z, r, r} _, err = AccountFromBigInts(e) assert.NotNil(t, err) - assert.Equal(t, ErrNotInFF, err) + assert.Equal(t, ErrNotInFF, tracerr.Unwrap(err)) // Q+1 should give error r = new(big.Int).Add(cryptoConstants.Q, big.NewInt(1)) e = [NLeafElems]*big.Int{z, z, r, r} _, err = AccountFromBigInts(e) assert.NotNil(t, err) - assert.Equal(t, ErrNotInFF, err) + assert.Equal(t, ErrNotInFF, tracerr.Unwrap(err)) } func TestAccountErrNumOverflowNonce(t *testing.T) { @@ -327,7 +328,7 @@ func TestAccountErrNumOverflowNonce(t *testing.T) { account.Nonce = Nonce(math.Pow(2, 40)) b, err := account.Bytes() assert.NotNil(t, err) - assert.Equal(t, fmt.Errorf("%s Nonce", ErrNumOverflow), err) + assert.Equal(t, fmt.Errorf("%s Nonce", ErrNumOverflow), tracerr.Unwrap(err)) _, err = AccountFromBytes(b) assert.Nil(t, err) @@ -357,7 +358,7 @@ func TestAccountErrNumOverflowBalance(t *testing.T) { assert.Equal(t, "6277101735386680763835789423207666416102355444464034512896", account.Balance.String()) b, err := account.Bytes() assert.NotNil(t, err) - assert.Equal(t, fmt.Errorf("%s Balance", ErrNumOverflow), err) + assert.Equal(t, fmt.Errorf("%s Balance", ErrNumOverflow), tracerr.Unwrap(err)) _, err = AccountFromBytes(b) assert.Nil(t, err) @@ -365,5 +366,5 @@ func TestAccountErrNumOverflowBalance(t *testing.T) { b[39] = 1 _, err = AccountFromBytes(b) assert.NotNil(t, err) - assert.Equal(t, fmt.Errorf("%s Balance", ErrNumOverflow), err) + assert.Equal(t, fmt.Errorf("%s Balance", ErrNumOverflow), tracerr.Unwrap(err)) } diff --git a/common/accountcreationauths.go b/common/accountcreationauths.go index ba3b8d4..8911edb 100644 --- a/common/accountcreationauths.go +++ b/common/accountcreationauths.go @@ -5,6 +5,7 @@ import ( ethCommon "github.com/ethereum/go-ethereum/common" ethCrypto "github.com/ethereum/go-ethereum/crypto" + "github.com/hermeznetwork/tracerr" "github.com/iden3/go-iden3-crypto/babyjub" ) @@ -22,7 +23,7 @@ func (a *AccountCreationAuth) HashToSign() ([]byte, error) { const msg = "I authorize this babyjubjub key for hermez rollup account creation" comp, err := a.BJJ.Compress().MarshalText() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } // Hash message (msg || compressed-bjj) return ethCrypto.Keccak256Hash([]byte(msg), comp).Bytes(), nil diff --git a/common/batch.go b/common/batch.go index a75ae88..eba3dea 100644 --- a/common/batch.go +++ b/common/batch.go @@ -6,6 +6,7 @@ import ( "math/big" ethCommon "github.com/ethereum/go-ethereum/common" + "github.com/hermeznetwork/tracerr" ) const batchNumBytesLen = 8 @@ -44,7 +45,7 @@ func (bn BatchNum) BigInt() *big.Int { // BatchNumFromBytes returns BatchNum from a []byte func BatchNumFromBytes(b []byte) (BatchNum, error) { if len(b) != batchNumBytesLen { - return 0, fmt.Errorf("can not parse BatchNumFromBytes, bytes len %d, expected %d", len(b), batchNumBytesLen) + return 0, tracerr.Wrap(fmt.Errorf("can not parse BatchNumFromBytes, bytes len %d, expected %d", len(b), batchNumBytesLen)) } batchNum := binary.BigEndian.Uint64(b[:batchNumBytesLen]) return BatchNum(batchNum), nil diff --git a/common/fee.go b/common/fee.go index 0d08197..9b28f08 100644 --- a/common/fee.go +++ b/common/fee.go @@ -4,6 +4,8 @@ import ( "fmt" "math" "math/big" + + "github.com/hermeznetwork/tracerr" ) // MaxFeePlan is the maximum value of the FeePlan @@ -49,7 +51,7 @@ func CalcFeeAmount(amount *big.Int, feeSel FeeSelector) (*big.Int, error) { feeAmount.Rsh(feeAmount, 60) } if feeAmount.BitLen() > 128 { //nolint:gomnd - return nil, fmt.Errorf("FeeAmount overflow (feeAmount doesn't fit in 128 bits)") + return nil, tracerr.Wrap(fmt.Errorf("FeeAmount overflow (feeAmount doesn't fit in 128 bits)")) } return feeAmount, nil } diff --git a/common/float16.go b/common/float16.go index 9cc60ec..d1bcfdb 100644 --- a/common/float16.go +++ b/common/float16.go @@ -9,6 +9,8 @@ import ( "encoding/binary" "errors" "math/big" + + "github.com/hermeznetwork/tracerr" ) var ( @@ -112,7 +114,7 @@ func NewFloat16(f *big.Int) (Float16, error) { if res.BigInt().Cmp(f) == 0 { return res, nil } - return res, ErrRoundingLoss + return res, tracerr.Wrap(ErrRoundingLoss) } // NewFloat16Floor encodes a big.Int integer as a Float16, rounding down in diff --git a/common/float16_test.go b/common/float16_test.go index 811709f..9726d0e 100644 --- a/common/float16_test.go +++ b/common/float16_test.go @@ -4,6 +4,7 @@ import ( "math/big" "testing" + "github.com/hermeznetwork/tracerr" "github.com/stretchr/testify/assert" ) @@ -65,25 +66,25 @@ func TestConversionLosses(t *testing.T) { a = big.NewInt(1024) b, err = NewFloat16(a) - assert.Equal(t, ErrRoundingLoss, err) + assert.Equal(t, ErrRoundingLoss, tracerr.Unwrap(err)) c = b.BigInt() assert.NotEqual(t, c, a) a = big.NewInt(32767) b, err = NewFloat16(a) - assert.Equal(t, ErrRoundingLoss, err) + assert.Equal(t, ErrRoundingLoss, tracerr.Unwrap(err)) c = b.BigInt() assert.NotEqual(t, c, a) a = big.NewInt(32768) b, err = NewFloat16(a) - assert.Equal(t, ErrRoundingLoss, err) + assert.Equal(t, ErrRoundingLoss, tracerr.Unwrap(err)) c = b.BigInt() assert.NotEqual(t, c, a) a = big.NewInt(65536000) b, err = NewFloat16(a) - assert.Equal(t, ErrRoundingLoss, err) + assert.Equal(t, ErrRoundingLoss, tracerr.Unwrap(err)) c = b.BigInt() assert.NotEqual(t, c, a) } diff --git a/common/l1tx.go b/common/l1tx.go index 3f9e003..7d542c8 100644 --- a/common/l1tx.go +++ b/common/l1tx.go @@ -7,6 +7,7 @@ import ( ethCommon "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" + "github.com/hermeznetwork/tracerr" "github.com/iden3/go-iden3-crypto/babyjub" ) @@ -58,7 +59,7 @@ func NewL1Tx(l1Tx *L1Tx) (*L1Tx, error) { } else if l1Tx.ToIdx >= IdxUserThreshold { txType = TxTypeCreateAccountDepositTransfer } else { - return l1Tx, fmt.Errorf("Can not determine type of L1Tx, invalid ToIdx value: %d", l1Tx.ToIdx) + return l1Tx, tracerr.Wrap(fmt.Errorf("Can not determine type of L1Tx, invalid ToIdx value: %d", l1Tx.ToIdx)) } } else if l1Tx.FromIdx >= IdxUserThreshold { if l1Tx.ToIdx == Idx(0) { @@ -72,20 +73,20 @@ func NewL1Tx(l1Tx *L1Tx) (*L1Tx, error) { txType = TxTypeDepositTransfer } } else { - return l1Tx, fmt.Errorf("Can not determine type of L1Tx, invalid ToIdx value: %d", l1Tx.ToIdx) + return l1Tx, tracerr.Wrap(fmt.Errorf("Can not determine type of L1Tx, invalid ToIdx value: %d", l1Tx.ToIdx)) } } else { - return l1Tx, fmt.Errorf("Can not determine type of L1Tx, invalid FromIdx value: %d", l1Tx.FromIdx) + return l1Tx, tracerr.Wrap(fmt.Errorf("Can not determine type of L1Tx, invalid FromIdx value: %d", l1Tx.FromIdx)) } if l1Tx.Type != "" && l1Tx.Type != txType { - return l1Tx, fmt.Errorf("L1Tx.Type: %s, should be: %s", l1Tx.Type, txType) + return l1Tx, tracerr.Wrap(fmt.Errorf("L1Tx.Type: %s, should be: %s", l1Tx.Type, txType)) } l1Tx.Type = txType txID, err := l1Tx.CalcTxID() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } l1Tx.TxID = *txID @@ -97,7 +98,7 @@ func (tx *L1Tx) CalcTxID() (*TxID, error) { var txID TxID if tx.UserOrigin { if tx.ToForgeL1TxsNum == nil { - return nil, fmt.Errorf("L1Tx.UserOrigin == true && L1Tx.ToForgeL1TxsNum == nil") + return nil, tracerr.Wrap(fmt.Errorf("L1Tx.UserOrigin == true && L1Tx.ToForgeL1TxsNum == nil")) } txID[0] = TxIDPrefixL1UserTx var toForgeL1TxsNumBytes [8]byte @@ -105,7 +106,7 @@ func (tx *L1Tx) CalcTxID() (*TxID, error) { copy(txID[1:9], toForgeL1TxsNumBytes[:]) } else { if tx.BatchNum == nil { - return nil, fmt.Errorf("L1Tx.UserOrigin == false && L1Tx.BatchNum == nil") + return nil, tracerr.Wrap(fmt.Errorf("L1Tx.UserOrigin == false && L1Tx.BatchNum == nil")) } txID[0] = TxIDPrefixL1CoordTx var batchNumBytes [8]byte @@ -164,7 +165,7 @@ func (tx L1Tx) Tx() Tx { func (tx L1Tx) TxCompressedData() (*big.Int, error) { amountFloat16, err := NewFloat16(tx.Amount) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } var b [31]byte // b[0:7] empty: no fee neither nonce @@ -172,12 +173,12 @@ func (tx L1Tx) TxCompressedData() (*big.Int, error) { copy(b[11:13], amountFloat16.Bytes()) toIdxBytes, err := tx.ToIdx.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } copy(b[13:19], toIdxBytes[:]) fromIdxBytes, err := tx.FromIdx.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } copy(b[19:25], fromIdxBytes[:]) copy(b[25:27], []byte{0, 1}) // TODO this will be generated by the ChainID config parameter @@ -195,19 +196,19 @@ func (tx *L1Tx) BytesDataAvailability(nLevels uint32) ([]byte, error) { fromIdxBytes, err := tx.FromIdx.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } copy(b[0:idxLen], fromIdxBytes[6-idxLen:]) toIdxBytes, err := tx.ToIdx.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } copy(b[idxLen:idxLen*2], toIdxBytes[6-idxLen:]) if tx.EffectiveAmount != nil { amountFloat16, err := NewFloat16(tx.EffectiveAmount) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } copy(b[idxLen*2:idxLen*2+2], amountFloat16.Bytes()) } @@ -229,23 +230,23 @@ func (tx *L1Tx) BytesGeneric() ([]byte, error) { } fromIdxBytes, err := tx.FromIdx.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } copy(b[52:58], fromIdxBytes[:]) loadAmountFloat16, err := NewFloat16(tx.LoadAmount) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } copy(b[58:60], loadAmountFloat16.Bytes()) amountFloat16, err := NewFloat16(tx.Amount) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } copy(b[60:62], amountFloat16.Bytes()) copy(b[62:66], tx.TokenID.Bytes()) toIdxBytes, err := tx.ToIdx.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } copy(b[66:72], toIdxBytes[:]) return b[:], nil @@ -254,7 +255,7 @@ func (tx *L1Tx) BytesGeneric() ([]byte, error) { // BytesUser encodes a L1UserTx into []byte func (tx *L1Tx) BytesUser() ([]byte, error) { if !tx.UserOrigin { - return nil, fmt.Errorf("Can not calculate BytesUser() for a L1CoordinatorTx") + return nil, tracerr.Wrap(fmt.Errorf("Can not calculate BytesUser() for a L1CoordinatorTx")) } return tx.BytesGeneric() } @@ -262,7 +263,7 @@ func (tx *L1Tx) BytesUser() ([]byte, error) { // BytesCoordinatorTx encodes a L1CoordinatorTx into []byte func (tx *L1Tx) BytesCoordinatorTx(compressedSignatureBytes []byte) ([]byte, error) { if tx.UserOrigin { - return nil, fmt.Errorf("Can not calculate BytesCoordinatorTx() for a L1UserTx") + return nil, tracerr.Wrap(fmt.Errorf("Can not calculate BytesCoordinatorTx() for a L1UserTx")) } var b [L1CoordinatorTxBytesLen]byte v := compressedSignatureBytes[64] @@ -281,7 +282,7 @@ func (tx *L1Tx) BytesCoordinatorTx(compressedSignatureBytes []byte) ([]byte, err // L1UserTxFromBytes decodes a L1Tx from []byte func L1UserTxFromBytes(b []byte) (*L1Tx, error) { if len(b) != L1UserTxBytesLen { - return nil, fmt.Errorf("Can not parse L1Tx bytes, expected length %d, current: %d", 68, len(b)) + return nil, tracerr.Wrap(fmt.Errorf("Can not parse L1Tx bytes, expected length %d, current: %d", 68, len(b))) } tx := &L1Tx{ @@ -296,22 +297,22 @@ func L1UserTxFromBytes(b []byte) (*L1Tx, error) { copy(pkComp[:], pkCompL) tx.FromBJJ, err = pkComp.Decompress() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } fromIdx, err := IdxFromBytes(b[52:58]) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } tx.FromIdx = fromIdx tx.LoadAmount = Float16FromBytes(b[58:60]).BigInt() tx.Amount = Float16FromBytes(b[60:62]).BigInt() tx.TokenID, err = TokenIDFromBytes(b[62:66]) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } tx.ToIdx, err = IdxFromBytes(b[66:72]) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return tx, nil @@ -325,7 +326,7 @@ func signHash(data []byte) []byte { // L1CoordinatorTxFromBytes decodes a L1Tx from []byte func L1CoordinatorTxFromBytes(b []byte, chainID *big.Int, hermezAddress ethCommon.Address) (*L1Tx, error) { if len(b) != L1CoordinatorTxBytesLen { - return nil, fmt.Errorf("Can not parse L1CoordinatorTx bytes, expected length %d, current: %d", 101, len(b)) + return nil, tracerr.Wrap(fmt.Errorf("Can not parse L1CoordinatorTx bytes, expected length %d, current: %d", 101, len(b))) } bytesMessage := []byte("I authorize this babyjubjub key for hermez rollup account creation") @@ -343,11 +344,11 @@ func L1CoordinatorTxFromBytes(b []byte, chainID *big.Int, hermezAddress ethCommo copy(pkComp[:], pkCompL) tx.FromBJJ, err = pkComp.Decompress() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } tx.TokenID, err = TokenIDFromBytes(b[97:101]) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } tx.Amount = big.NewInt(0) tx.LoadAmount = big.NewInt(0) @@ -368,11 +369,11 @@ func L1CoordinatorTxFromBytes(b []byte, chainID *big.Int, hermezAddress ethCommo hash := signHash(data) pubKeyBytes, err := crypto.Ecrecover(hash, signature) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } pubKey, err := crypto.UnmarshalPubkey(pubKeyBytes) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } tx.FromEthAddr = crypto.PubkeyToAddress(*pubKey) } else { diff --git a/common/l2tx.go b/common/l2tx.go index a34c36e..3fb239f 100644 --- a/common/l2tx.go +++ b/common/l2tx.go @@ -3,6 +3,8 @@ package common import ( "fmt" "math/big" + + "github.com/hermeznetwork/tracerr" ) // L2Tx is a struct that represents an already forged L2 tx @@ -30,12 +32,12 @@ func NewL2Tx(l2Tx *L2Tx) (*L2Tx, error) { } else if l2Tx.ToIdx >= IdxUserThreshold { txType = TxTypeTransfer } else { - return l2Tx, fmt.Errorf("Can not determine type of L2Tx, invalid ToIdx value: %d", l2Tx.ToIdx) + return l2Tx, tracerr.Wrap(fmt.Errorf("Can not determine type of L2Tx, invalid ToIdx value: %d", l2Tx.ToIdx)) } // if TxType!=l2Tx.TxType return error if l2Tx.Type != "" && l2Tx.Type != txType { - return l2Tx, fmt.Errorf("L2Tx.Type: %s, should be: %s", l2Tx.Type, txType) + return l2Tx, tracerr.Wrap(fmt.Errorf("L2Tx.Type: %s, should be: %s", l2Tx.Type, txType)) } l2Tx.Type = txType @@ -43,12 +45,12 @@ func NewL2Tx(l2Tx *L2Tx) (*L2Tx, error) { txid[0] = TxIDPrefixL2Tx fromIdxBytes, err := l2Tx.FromIdx.Bytes() if err != nil { - return l2Tx, err + return l2Tx, tracerr.Wrap(err) } copy(txid[1:7], fromIdxBytes[:]) nonceBytes, err := l2Tx.Nonce.Bytes() if err != nil { - return l2Tx, err + return l2Tx, tracerr.Wrap(err) } copy(txid[7:12], nonceBytes[:]) l2Tx.TxID = TxID(txid) @@ -111,19 +113,19 @@ func (tx L2Tx) BytesDataAvailability(nLevels uint32) ([]byte, error) { fromIdxBytes, err := tx.FromIdx.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } copy(b[0:idxLen], fromIdxBytes[6-idxLen:]) // [6-idxLen:] as is BigEndian toIdxBytes, err := tx.ToIdx.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } copy(b[idxLen:idxLen*2], toIdxBytes[6-idxLen:]) amountFloat16, err := NewFloat16(tx.Amount) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } copy(b[idxLen*2:idxLen*2+2], amountFloat16.Bytes()) @@ -142,14 +144,14 @@ func L2TxFromBytes(b []byte, nLevels int) (*L2Tx, error) { copy(paddedFromIdxBytes[6-idxLen:], b[0:idxLen]) tx.FromIdx, err = IdxFromBytes(paddedFromIdxBytes[:]) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } var paddedToIdxBytes [6]byte copy(paddedToIdxBytes[6-idxLen:6], b[idxLen:idxLen*2]) tx.ToIdx, err = IdxFromBytes(paddedToIdxBytes[:]) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } tx.Amount = Float16FromBytes(b[idxLen*2 : idxLen*2+2]).BigInt() diff --git a/common/pooll2tx.go b/common/pooll2tx.go index 4d0fb31..20de40e 100644 --- a/common/pooll2tx.go +++ b/common/pooll2tx.go @@ -7,6 +7,7 @@ import ( "time" ethCommon "github.com/ethereum/go-ethereum/common" + "github.com/hermeznetwork/tracerr" "github.com/iden3/go-iden3-crypto/babyjub" "github.com/iden3/go-iden3-crypto/poseidon" ) @@ -63,12 +64,12 @@ func NewPoolL2Tx(poolL2Tx *PoolL2Tx) (*PoolL2Tx, error) { txType = TxTypeTransferToEthAddr } } else { - return nil, errors.New("malformed transaction") + return nil, tracerr.Wrap(errors.New("malformed transaction")) } // if TxType!=poolL2Tx.TxType return error if poolL2Tx.Type != "" && poolL2Tx.Type != txType { - return poolL2Tx, fmt.Errorf("type: %s, should be: %s", poolL2Tx.Type, txType) + return poolL2Tx, tracerr.Wrap(fmt.Errorf("type: %s, should be: %s", poolL2Tx.Type, txType)) } poolL2Tx.Type = txType @@ -76,19 +77,19 @@ func NewPoolL2Tx(poolL2Tx *PoolL2Tx) (*PoolL2Tx, error) { txid[0] = TxIDPrefixL2Tx fromIdxBytes, err := poolL2Tx.FromIdx.Bytes() if err != nil { - return poolL2Tx, err + return poolL2Tx, tracerr.Wrap(err) } copy(txid[1:7], fromIdxBytes[:]) nonceBytes, err := poolL2Tx.Nonce.Bytes() if err != nil { - return poolL2Tx, err + return poolL2Tx, tracerr.Wrap(err) } copy(txid[7:12], nonceBytes[:]) txID := TxID(txid) // if TxID!=poolL2Tx.TxID return error if poolL2Tx.TxID != (TxID{}) && poolL2Tx.TxID != txID { - return poolL2Tx, fmt.Errorf("id: %s, should be: %s", poolL2Tx.TxID.String(), txID.String()) + return poolL2Tx, tracerr.Wrap(fmt.Errorf("id: %s, should be: %s", poolL2Tx.TxID.String(), txID.String())) } poolL2Tx.TxID = txID return poolL2Tx, nil @@ -109,12 +110,12 @@ func (tx *PoolL2Tx) TxCompressedData() (*big.Int, error) { // sigconstant sc, ok := new(big.Int).SetString("3322668559", 10) if !ok { - return nil, fmt.Errorf("error parsing SignatureConstant") + return nil, tracerr.Wrap(fmt.Errorf("error parsing SignatureConstant")) } amountFloat16, err := NewFloat16(tx.Amount) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } var b [31]byte toBJJSign := byte(0) @@ -125,19 +126,19 @@ func (tx *PoolL2Tx) TxCompressedData() (*big.Int, error) { b[1] = byte(tx.Fee) nonceBytes, err := tx.Nonce.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } copy(b[2:7], nonceBytes[:]) copy(b[7:11], tx.TokenID.Bytes()) copy(b[11:13], amountFloat16.Bytes()) toIdxBytes, err := tx.ToIdx.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } copy(b[13:19], toIdxBytes[:]) fromIdxBytes, err := tx.FromIdx.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } copy(b[19:25], fromIdxBytes[:]) copy(b[25:27], []byte{0, 1}) // TODO this will be generated by the ChainID config parameter @@ -162,7 +163,7 @@ func (tx *PoolL2Tx) TxCompressedDataV2() (*big.Int, error) { } amountFloat16, err := NewFloat16(tx.Amount) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } var b [25]byte toBJJSign := byte(0) @@ -173,19 +174,19 @@ func (tx *PoolL2Tx) TxCompressedDataV2() (*big.Int, error) { b[1] = byte(tx.Fee) nonceBytes, err := tx.Nonce.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } copy(b[2:7], nonceBytes[:]) copy(b[7:11], tx.TokenID.Bytes()) copy(b[11:13], amountFloat16.Bytes()) toIdxBytes, err := tx.ToIdx.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } copy(b[13:19], toIdxBytes[:]) fromIdxBytes, err := tx.FromIdx.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } copy(b[19:25], fromIdxBytes[:]) @@ -213,7 +214,7 @@ func (tx *PoolL2Tx) RqTxCompressedDataV2() (*big.Int, error) { } amountFloat16, err := NewFloat16(tx.RqAmount) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } var b [25]byte toBJJSign := byte(0) @@ -224,19 +225,19 @@ func (tx *PoolL2Tx) RqTxCompressedDataV2() (*big.Int, error) { b[1] = byte(tx.RqFee) nonceBytes, err := tx.RqNonce.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } copy(b[2:7], nonceBytes[:]) copy(b[7:11], tx.RqTokenID.Bytes()) copy(b[11:13], amountFloat16.Bytes()) toIdxBytes, err := tx.RqToIdx.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } copy(b[13:19], toIdxBytes[:]) fromIdxBytes, err := tx.RqFromIdx.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } copy(b[19:25], fromIdxBytes[:]) @@ -248,7 +249,7 @@ func (tx *PoolL2Tx) RqTxCompressedDataV2() (*big.Int, error) { func (tx *PoolL2Tx) HashToSign() (*big.Int, error) { toCompressedData, err := tx.TxCompressedData() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } toEthAddr := EthAddrToBigInt(tx.ToEthAddr) rqToEthAddr := EthAddrToBigInt(tx.RqToEthAddr) @@ -258,7 +259,7 @@ func (tx *PoolL2Tx) HashToSign() (*big.Int, error) { } rqTxCompressedDataV2, err := tx.RqTxCompressedDataV2() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } rqToBJJY := big.NewInt(0) if tx.RqToBJJ != nil { diff --git a/common/token.go b/common/token.go index fef906d..6034cb5 100644 --- a/common/token.go +++ b/common/token.go @@ -7,6 +7,7 @@ import ( "time" ethCommon "github.com/ethereum/go-ethereum/common" + "github.com/hermeznetwork/tracerr" ) // tokenIDBytesLen defines the length of the TokenID byte array representation @@ -47,7 +48,7 @@ func (t TokenID) BigInt() *big.Int { // TokenIDFromBytes returns TokenID from a byte array func TokenIDFromBytes(b []byte) (TokenID, error) { if len(b) != tokenIDBytesLen { - return 0, fmt.Errorf("can not parse TokenID, bytes len %d, expected 4", len(b)) + return 0, tracerr.Wrap(fmt.Errorf("can not parse TokenID, bytes len %d, expected 4", len(b))) } tid := binary.BigEndian.Uint32(b[:4]) return TokenID(tid), nil diff --git a/common/tx.go b/common/tx.go index e6e9d26..847f49d 100644 --- a/common/tx.go +++ b/common/tx.go @@ -10,6 +10,7 @@ import ( "strings" ethCommon "github.com/ethereum/go-ethereum/common" + "github.com/hermeznetwork/tracerr" "github.com/iden3/go-iden3-crypto/babyjub" ) @@ -40,10 +41,10 @@ type TxID [TxIDLen]byte func (txid *TxID) Scan(src interface{}) error { srcB, ok := src.([]byte) if !ok { - return fmt.Errorf("can't scan %T into TxID", src) + return tracerr.Wrap(fmt.Errorf("can't scan %T into TxID", src)) } if len(srcB) != TxIDLen { - return fmt.Errorf("can't scan []byte of len %d into TxID, need %d", len(srcB), TxIDLen) + return tracerr.Wrap(fmt.Errorf("can't scan []byte of len %d into TxID, need %d", len(srcB), TxIDLen)) } copy(txid[:], srcB) return nil @@ -65,10 +66,10 @@ func NewTxIDFromString(idStr string) (TxID, error) { idStr = strings.TrimPrefix(idStr, "0x") decoded, err := hex.DecodeString(idStr) if err != nil { - return TxID{}, err + return TxID{}, tracerr.Wrap(err) } if len(decoded) != TxIDLen { - return txid, errors.New("Invalid idStr") + return txid, tracerr.Wrap(errors.New("Invalid idStr")) } copy(txid[:], decoded) return txid, nil @@ -84,7 +85,7 @@ func (txid *TxID) UnmarshalText(data []byte) error { idStr := string(data) id, err := NewTxIDFromString(idStr) if err != nil { - return err + return tracerr.Wrap(err) } *txid = id return nil diff --git a/common/utils.go b/common/utils.go index 0fc9ab5..1345dcb 100644 --- a/common/utils.go +++ b/common/utils.go @@ -5,6 +5,7 @@ import ( "math/big" ethCommon "github.com/ethereum/go-ethereum/common" + "github.com/hermeznetwork/tracerr" "github.com/iden3/go-iden3-crypto/babyjub" ) @@ -29,7 +30,7 @@ func EthAddrToBigInt(a ethCommon.Address) *big.Int { func BJJFromStringWithChecksum(s string) (*babyjub.PublicKey, error) { b, err := hex.DecodeString(s) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } pkBytes := SwapEndianness(b) var pkComp babyjub.PublicKeyComp diff --git a/common/zk.go b/common/zk.go index a183310..3d9436a 100644 --- a/common/zk.go +++ b/common/zk.go @@ -10,6 +10,7 @@ import ( "math/big" "github.com/hermeznetwork/hermez-node/log" + "github.com/hermeznetwork/tracerr" cryptoConstants "github.com/iden3/go-iden3-crypto/constants" "github.com/iden3/go-merkletree" "github.com/mitchellh/mapstructure" @@ -258,11 +259,11 @@ func (z ZKInputs) MarshalJSON() ([]byte, error) { Result: &m, }) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } err = dec.Decode(z) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } for k, v := range m { @@ -398,13 +399,13 @@ func newSlice(n uint32) []*big.Int { func (z ZKInputs) HashGlobalData() (*big.Int, error) { b, err := z.ToHashGlobalData() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } h := sha256.New() _, err = h.Write(b) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } r := new(big.Int).SetBytes(h.Sum(nil)) @@ -427,7 +428,7 @@ func (z ZKInputs) ToHashGlobalData() ([]byte, error) { newLastIdx := make([]byte, bytesMaxLevels) newLastIdxBytes, err := z.Metadata.NewLastIdxRaw.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } copy(newLastIdx, newLastIdxBytes[len(newLastIdxBytes)-bytesMaxLevels:]) b = append(b, newLastIdx...) @@ -474,7 +475,7 @@ func (z ZKInputs) ToHashGlobalData() ([]byte, error) { l2TxsData = append(l2TxsData, z.Metadata.L2TxsData[i]...) } if len(l2TxsData) > int(expectedL2TxsDataLen) { - return nil, fmt.Errorf("len(l2TxsData): %d, expected: %d", len(l2TxsData), expectedL2TxsDataLen) + return nil, tracerr.Wrap(fmt.Errorf("len(l2TxsData): %d, expected: %d", len(l2TxsData), expectedL2TxsDataLen)) } b = append(b, l2TxsData...) diff --git a/config/config.go b/config/config.go index e0d3176..34da119 100644 --- a/config/config.go +++ b/config/config.go @@ -9,6 +9,7 @@ import ( ethCommon "github.com/ethereum/go-ethereum/common" "github.com/hermeznetwork/hermez-node/common" "github.com/hermeznetwork/hermez-node/synchronizer" + "github.com/hermeznetwork/tracerr" "gopkg.in/go-playground/validator.v9" ) @@ -21,7 +22,7 @@ type Duration struct { func (d *Duration) UnmarshalText(data []byte) error { duration, err := time.ParseDuration(string(data)) if err != nil { - return err + return tracerr.Wrap(err) } d.Duration = duration return nil @@ -104,15 +105,15 @@ type Node struct { func Load(path string, cfg interface{}) error { bs, err := ioutil.ReadFile(path) //nolint:gosec if err != nil { - return err + return tracerr.Wrap(err) } cfgToml := string(bs) if _, err := toml.Decode(cfgToml, cfg); err != nil { - return err + return tracerr.Wrap(err) } validate := validator.New() if err := validate.Struct(cfg); err != nil { - return fmt.Errorf("error validating configuration file: %w", err) + return tracerr.Wrap(fmt.Errorf("error validating configuration file: %w", err)) } return nil } @@ -121,7 +122,7 @@ func Load(path string, cfg interface{}) error { func LoadCoordinator(path string) (*Coordinator, error) { var cfg Coordinator if err := Load(path, &cfg); err != nil { - return nil, fmt.Errorf("error loading coordinator configuration file: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("error loading coordinator configuration file: %w", err)) } return &cfg, nil } @@ -130,7 +131,7 @@ func LoadCoordinator(path string) (*Coordinator, error) { func LoadNode(path string) (*Node, error) { var cfg Node if err := Load(path, &cfg); err != nil { - return nil, fmt.Errorf("error loading node configuration file: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("error loading node configuration file: %w", err)) } return &cfg, nil } diff --git a/coordinator/batch.go b/coordinator/batch.go index 372119d..5cc772d 100644 --- a/coordinator/batch.go +++ b/coordinator/batch.go @@ -9,6 +9,7 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/hermeznetwork/hermez-node/common" "github.com/hermeznetwork/hermez-node/eth" + "github.com/hermeznetwork/tracerr" ) // Proof TBD this type will be received from the proof server @@ -46,7 +47,7 @@ type BatchInfo struct { func (b *BatchInfo) DebugStore(storePath string) error { batchJSON, err := json.Marshal(b) if err != nil { - return err + return tracerr.Wrap(err) } oldStateRoot := "null" if b.ZKInputs != nil && b.ZKInputs.OldStateRoot != nil { diff --git a/coordinator/coordinator.go b/coordinator/coordinator.go index 2c74368..d619bdc 100644 --- a/coordinator/coordinator.go +++ b/coordinator/coordinator.go @@ -15,6 +15,7 @@ import ( "github.com/hermeznetwork/hermez-node/log" "github.com/hermeznetwork/hermez-node/synchronizer" "github.com/hermeznetwork/hermez-node/txselector" + "github.com/hermeznetwork/tracerr" ) var errTODO = fmt.Errorf("TODO") @@ -93,12 +94,12 @@ func NewCoordinator(cfg Config, ) (*Coordinator, error) { // nolint reason: hardcoded `1.0`, by design the percentage can't be over 100% if cfg.L1BatchTimeoutPerc >= 1.0 { //nolint:gomnd - return nil, fmt.Errorf("invalid value for Config.L1BatchTimeoutPerc (%v >= 1.0)", - cfg.L1BatchTimeoutPerc) + return nil, tracerr.Wrap(fmt.Errorf("invalid value for Config.L1BatchTimeoutPerc (%v >= 1.0)", + cfg.L1BatchTimeoutPerc)) } if cfg.EthClientAttempts < 1 { - return nil, fmt.Errorf("invalid value for Config.EthClientAttempts (%v < 1)", - cfg.EthClientAttempts) + return nil, tracerr.Wrap(fmt.Errorf("invalid value for Config.EthClientAttempts (%v < 1)", + cfg.EthClientAttempts)) } txManager := NewTxManager(&cfg, ethClient) @@ -192,7 +193,7 @@ func (c *Coordinator) handleMsgSyncStats(stats *synchronizer.Stats) error { batchNum := common.BatchNum(stats.Sync.LastBatch) c.pipeline = c.newPipeline() if err := c.pipeline.Start(batchNum, stats, &c.vars); err != nil { - return err + return tracerr.Wrap(err) } } } else { @@ -318,12 +319,12 @@ func (t *TxManager) rollupForgeBatch(ctx context.Context, batchInfo *BatchInfo) } select { case <-ctx.Done(): - return ErrDone + return tracerr.Wrap(ErrDone) case <-time.After(t.cfg.EthClientAttemptsDelay): } } if err != nil { - return fmt.Errorf("reached max attempts for ethClient.RollupForgeBatch: %w", err) + return tracerr.Wrap(fmt.Errorf("reached max attempts for ethClient.RollupForgeBatch: %w", err)) } batchInfo.EthTx = ethTx t.cfg.debugBatchStore(batchInfo) @@ -344,12 +345,12 @@ func (t *TxManager) ethTransactionReceipt(ctx context.Context, batchInfo *BatchI } select { case <-ctx.Done(): - return ErrDone + return tracerr.Wrap(ErrDone) case <-time.After(t.cfg.EthClientAttemptsDelay): } } if err != nil { - return fmt.Errorf("reached max attempts for ethClient.EthTransactionReceipt: %w", err) + return tracerr.Wrap(fmt.Errorf("reached max attempts for ethClient.EthTransactionReceipt: %w", err)) } batchInfo.Receipt = receipt t.cfg.debugBatchStore(batchInfo) @@ -361,7 +362,7 @@ func (t *TxManager) handleReceipt(batchInfo *BatchInfo) (*int64, error) { if receipt != nil { if receipt.Status == types.ReceiptStatusFailed { log.Errorw("TxManager receipt status is failed", "receipt", receipt) - return nil, fmt.Errorf("ethereum transaction receipt statis is failed") + return nil, tracerr.Wrap(fmt.Errorf("ethereum transaction receipt statis is failed")) } else if receipt.Status == types.ReceiptStatusSuccessful { confirm := t.lastBlock - receipt.BlockNumber.Int64() return &confirm, nil @@ -384,7 +385,7 @@ func (t *TxManager) Run(ctx context.Context) { case lastBlock := <-t.lastBlockCh: t.lastBlock = lastBlock case batchInfo := <-t.batchCh: - if err := t.rollupForgeBatch(ctx, batchInfo); err == ErrDone { + if err := t.rollupForgeBatch(ctx, batchInfo); tracerr.Unwrap(err) == ErrDone { continue } else if err != nil { // TODO: Reset pipeline @@ -399,7 +400,7 @@ func (t *TxManager) Run(ctx context.Context) { } batchInfo := t.queue[next] err := t.ethTransactionReceipt(ctx, batchInfo) - if err == ErrDone { + if tracerr.Unwrap(err) == ErrDone { continue } else if err != nil { //nolint:staticcheck // We can't get the receipt for the @@ -504,12 +505,12 @@ func (p *Pipeline) Start(batchNum common.BatchNum, err := p.txSelector.Reset(p.batchNum) if err != nil { log.Errorw("Pipeline: TxSelector.Reset", "error", err) - return err + return tracerr.Wrap(err) } err = p.batchBuilder.Reset(p.batchNum, true) if err != nil { log.Errorw("Pipeline: BatchBuilder.Reset", "error", err) - return err + return tracerr.Wrap(err) } queueSize := 1 @@ -528,7 +529,7 @@ func (p *Pipeline) Start(batchNum common.BatchNum, default: p.batchNum = p.batchNum + 1 batchInfo, err := p.forgeSendServerProof(p.ctx, p.batchNum) - if err == ErrDone { + if tracerr.Unwrap(err) == ErrDone { continue } if err != nil { @@ -550,7 +551,7 @@ func (p *Pipeline) Start(batchNum common.BatchNum, return case batchInfo := <-batchChSentServerProof: err := p.waitServerProof(p.ctx, batchInfo) - if err == ErrDone { + if tracerr.Unwrap(err) == ErrDone { continue } if err != nil { @@ -582,7 +583,7 @@ func (p *Pipeline) forgeSendServerProof(ctx context.Context, batchNum common.Bat // remove transactions from the pool that have been there for too long err := p.purgeRemoveByTimeout() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } batchInfo := BatchInfo{BatchNum: batchNum} // to accumulate metadata of the batch @@ -598,13 +599,13 @@ func (p *Pipeline) forgeSendServerProof(ctx context.Context, batchNum common.Bat var l1UserTxs []common.L1Tx = nil // tmp, depends on HistoryDB l1UserTxsExtra, l1OperatorTxs, poolL2Txs, err = p.txSelector.GetL1L2TxSelection([]common.Idx{}, batchNum, l1UserTxs) // TODO once feesInfo is added to method return, add the var if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } } else { // 2b: only L2 txs _, poolL2Txs, err = p.txSelector.GetL2TxSelection([]common.Idx{}, batchNum) // TODO once feesInfo is added to method return, add the var if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } l1UserTxsExtra = nil l1OperatorTxs = nil @@ -616,7 +617,7 @@ func (p *Pipeline) forgeSendServerProof(ctx context.Context, batchNum common.Bat // all the nonces smaller than the current one) err = p.purgeInvalidDueToL2TxsSelection(poolL2Txs) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } // 3. Save metadata from TxSelector output for BatchNum @@ -631,7 +632,7 @@ func (p *Pipeline) forgeSendServerProof(ctx context.Context, batchNum common.Bat } zkInputs, err := p.batchBuilder.BuildBatch([]common.Idx{}, configBatch, l1UserTxsExtra, l1OperatorTxs, poolL2Txs, nil) // TODO []common.TokenID --> feesInfo if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } // 5. Save metadata from BatchBuilder output for BatchNum @@ -641,7 +642,7 @@ func (p *Pipeline) forgeSendServerProof(ctx context.Context, batchNum common.Bat // 6. Wait for an available server proof blocking call serverProof, err := p.serverProofPool.Get(ctx) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } batchInfo.ServerProof = serverProof defer func() { @@ -657,7 +658,7 @@ func (p *Pipeline) forgeSendServerProof(ctx context.Context, batchNum common.Bat // save server proof info for batchNum err = batchInfo.ServerProof.CalculateProof(zkInputs) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &batchInfo, nil @@ -667,7 +668,7 @@ func (p *Pipeline) forgeSendServerProof(ctx context.Context, batchNum common.Bat func (p *Pipeline) waitServerProof(ctx context.Context, batchInfo *BatchInfo) error { proof, err := batchInfo.ServerProof.GetProof(ctx) // blocking call, until not resolved don't continue. Returns when the proof server has calculated the proof if err != nil { - return err + return tracerr.Wrap(err) } p.serverProofPool.Add(batchInfo.ServerProof) batchInfo.ServerProof = nil diff --git a/coordinator/proofpool.go b/coordinator/proofpool.go index cf1791c..7e7a2bc 100644 --- a/coordinator/proofpool.go +++ b/coordinator/proofpool.go @@ -6,6 +6,7 @@ import ( "github.com/hermeznetwork/hermez-node/common" "github.com/hermeznetwork/hermez-node/log" + "github.com/hermeznetwork/tracerr" ) // ServerProofInterface is the interface to a ServerProof that calculates zk proofs @@ -30,13 +31,13 @@ func NewServerProof(URL string) *ServerProof { // Proof func (p *ServerProof) CalculateProof(zkInputs *common.ZKInputs) error { log.Error("TODO") - return errTODO + return tracerr.Wrap(errTODO) } // GetProof retreives the Proof from the ServerProof func (p *ServerProof) GetProof(ctx context.Context) (*Proof, error) { log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // ServerProofMock is a mock ServerProof to be used in tests. It doesn't calculate anything @@ -56,7 +57,7 @@ func (p *ServerProofMock) GetProof(ctx context.Context) (*Proof, error) { case <-time.After(200 * time.Millisecond): //nolint:gomnd return &Proof{}, nil case <-ctx.Done(): - return nil, ErrDone + return nil, tracerr.Wrap(ErrDone) } } @@ -82,7 +83,7 @@ func (p *ServerProofPool) Get(ctx context.Context) (ServerProofInterface, error) select { case <-ctx.Done(): log.Info("ServerProofPool.Get done") - return nil, ErrDone + return nil, tracerr.Wrap(ErrDone) case serverProof := <-p.pool: return serverProof, nil } diff --git a/db/historydb/historydb.go b/db/historydb/historydb.go index 15f379e..c025d24 100644 --- a/db/historydb/historydb.go +++ b/db/historydb/historydb.go @@ -10,6 +10,7 @@ import ( ethCommon "github.com/ethereum/go-ethereum/common" "github.com/hermeznetwork/hermez-node/common" "github.com/hermeznetwork/hermez-node/db" + "github.com/hermeznetwork/tracerr" "github.com/iden3/go-iden3-crypto/babyjub" "github.com/jmoiron/sqlx" @@ -73,7 +74,7 @@ func (hdb *HistoryDB) GetBlock(blockNum int64) (*common.Block, error) { hdb.db, block, "SELECT * FROM block WHERE eth_block_num = $1;", blockNum, ) - return block, err + return block, tracerr.Wrap(err) } // GetAllBlocks retrieve all blocks from the DB @@ -83,7 +84,7 @@ func (hdb *HistoryDB) GetAllBlocks() ([]common.Block, error) { hdb.db, &blocks, "SELECT * FROM block;", ) - return db.SlicePtrsToSlice(blocks).([]common.Block), err + return db.SlicePtrsToSlice(blocks).([]common.Block), tracerr.Wrap(err) } // GetBlocks retrieve blocks from the DB, given a range of block numbers defined by from and to @@ -94,7 +95,7 @@ func (hdb *HistoryDB) GetBlocks(from, to int64) ([]common.Block, error) { "SELECT * FROM block WHERE $1 <= eth_block_num AND eth_block_num < $2;", from, to, ) - return db.SlicePtrsToSlice(blocks).([]common.Block), err + return db.SlicePtrsToSlice(blocks).([]common.Block), tracerr.Wrap(err) } // GetLastBlock retrieve the block with the highest block number from the DB @@ -103,7 +104,7 @@ func (hdb *HistoryDB) GetLastBlock() (*common.Block, error) { err := meddler.QueryRow( hdb.db, block, "SELECT * FROM block ORDER BY eth_block_num DESC LIMIT 1;", ) - return block, err + return block, tracerr.Wrap(err) } // AddBatch insert a Batch into the DB @@ -128,13 +129,13 @@ func (hdb *HistoryDB) addBatch(d meddler.DB, batch *common.Batch) error { tokenIDs, ) if err != nil { - return err + return tracerr.Wrap(err) } query = hdb.db.Rebind(query) if err := meddler.QueryAll( hdb.db, &tokenPrices, query, args..., ); err != nil { - return err + return tracerr.Wrap(err) } } // Calculate total collected @@ -159,7 +160,7 @@ func (hdb *HistoryDB) AddBatches(batches []common.Batch) error { func (hdb *HistoryDB) addBatches(d meddler.DB, batches []common.Batch) error { for i := 0; i < len(batches); i++ { if err := hdb.addBatch(d, &batches[i]); err != nil { - return err + return tracerr.Wrap(err) } } return nil @@ -258,11 +259,11 @@ func (hdb *HistoryDB) GetBatchesAPI( // log.Debug(query) batchPtrs := []*BatchAPI{} if err := meddler.QueryAll(hdb.db, &batchPtrs, query, args...); err != nil { - return nil, 0, err + return nil, 0, tracerr.Wrap(err) } batches := db.SlicePtrsToSlice(batchPtrs).([]BatchAPI) if len(batches) == 0 { - return nil, 0, sql.ErrNoRows + return nil, 0, tracerr.Wrap(sql.ErrNoRows) } return batches, batches[0].TotalItems - uint64(len(batches)), nil } @@ -276,7 +277,7 @@ func (hdb *HistoryDB) GetAllBatches() ([]common.Batch, error) { batch.fee_idxs_coordinator, batch.state_root, batch.num_accounts, batch.last_idx, batch.exit_root, batch.forge_l1_txs_num, batch.slot_num, batch.total_fees_usd FROM batch;`, ) - return db.SlicePtrsToSlice(batches).([]common.Batch), err + return db.SlicePtrsToSlice(batches).([]common.Batch), tracerr.Wrap(err) } // GetBatches retrieve batches from the DB, given a range of batch numbers defined by from and to @@ -287,7 +288,7 @@ func (hdb *HistoryDB) GetBatches(from, to common.BatchNum) ([]common.Batch, erro "SELECT * FROM batch WHERE $1 <= batch_num AND batch_num < $2;", from, to, ) - return db.SlicePtrsToSlice(batches).([]common.Batch), err + return db.SlicePtrsToSlice(batches).([]common.Batch), tracerr.Wrap(err) } // GetBatchesLen retrieve number of batches from the DB, given a slotNum @@ -331,7 +332,7 @@ func (hdb *HistoryDB) Reorg(lastValidBlock int64) error { } else { _, err = hdb.db.Exec("DELETE FROM block WHERE eth_block_num > $1;", lastValidBlock) } - return err + return tracerr.Wrap(err) } // AddBids insert Bids into the DB @@ -352,7 +353,7 @@ func (hdb *HistoryDB) GetAllBids() ([]common.Bid, error) { hdb.db, &bids, `SELECT bid.slot_num, bid.bid_value, bid.eth_block_num, bid.bidder_addr FROM bid;`, ) - return db.SlicePtrsToSlice(bids).([]common.Bid), err + return db.SlicePtrsToSlice(bids).([]common.Bid), tracerr.Wrap(err) } // GetBestBidAPI returns the best bid in specific slot by slotNum @@ -364,7 +365,7 @@ func (hdb *HistoryDB) GetBestBidAPI(slotNum *int64) (BidAPI, error) { INNER JOIN coordinator ON bid.bidder_addr = coordinator.bidder_addr WHERE slot_num = $1 ORDER BY item_id DESC LIMIT 1;`, slotNum, ) - return *bid, err + return *bid, tracerr.Wrap(err) } // GetBestBidCoordinator returns the forger address of the highest bidder in a slot by slotNum @@ -385,7 +386,7 @@ func (hdb *HistoryDB) GetBestBidCoordinator(slotNum int64) (*common.BidCoordinat WHERE bid.slot_num = $1 ORDER BY bid.item_id DESC LIMIT 1;`, slotNum) - return bidCoord, err + return bidCoord, tracerr.Wrap(err) } // GetBestBidsAPI returns the best bid in specific slot by slotNum @@ -424,12 +425,12 @@ func (hdb *HistoryDB) GetBestBidsAPI( query = hdb.db.Rebind(queryStr) bidPtrs := []*BidAPI{} if err := meddler.QueryAll(hdb.db, &bidPtrs, query, args...); err != nil { - return nil, 0, err + return nil, 0, tracerr.Wrap(err) } // log.Debug(query) bids := db.SlicePtrsToSlice(bidPtrs).([]BidAPI) if len(bids) == 0 { - return nil, 0, sql.ErrNoRows + return nil, 0, tracerr.Wrap(sql.ErrNoRows) } return bids, bids[0].TotalItems - uint64(len(bids)), nil } @@ -492,15 +493,15 @@ func (hdb *HistoryDB) GetBidsAPI( queryStr += fmt.Sprintf("LIMIT %d;", *limit) query, argsQ, err := sqlx.In(queryStr, args...) if err != nil { - return nil, 0, err + return nil, 0, tracerr.Wrap(err) } query = hdb.db.Rebind(query) bids := []*BidAPI{} if err := meddler.QueryAll(hdb.db, &bids, query, argsQ...); err != nil { - return nil, 0, err + return nil, 0, tracerr.Wrap(err) } if len(bids) == 0 { - return nil, 0, sql.ErrNoRows + return nil, 0, tracerr.Wrap(sql.ErrNoRows) } return db.SlicePtrsToSlice(bids).([]BidAPI), bids[0].TotalItems - uint64(len(bids)), nil } @@ -592,7 +593,7 @@ func (hdb *HistoryDB) updateExitTree(d sqlx.Ext, blockNum int64, ` if len(withdrawals) > 0 { if _, err := sqlx.NamedQuery(d, query, withdrawals); err != nil { - return err + return tracerr.Wrap(err) } } @@ -627,7 +628,7 @@ func (hdb *HistoryDB) UpdateTokenValue(tokenSymbol string, value float64) error "UPDATE token SET usd = $1 WHERE symbol = $2;", value, tokenSymbol, ) - return err + return tracerr.Wrap(err) } // GetToken returns a token from the DB given a TokenID @@ -636,7 +637,7 @@ func (hdb *HistoryDB) GetToken(tokenID common.TokenID) (*TokenWithUSD, error) { err := meddler.QueryRow( hdb.db, token, `SELECT * FROM token WHERE token_id = $1;`, tokenID, ) - return token, err + return token, tracerr.Wrap(err) } // GetAllTokens returns all tokens from the DB @@ -646,7 +647,7 @@ func (hdb *HistoryDB) GetAllTokens() ([]TokenWithUSD, error) { hdb.db, &tokens, "SELECT * FROM token ORDER BY token_id;", ) - return db.SlicePtrsToSlice(tokens).([]TokenWithUSD), err + return db.SlicePtrsToSlice(tokens).([]TokenWithUSD), tracerr.Wrap(err) } // GetTokens returns a list of tokens from the DB @@ -707,15 +708,15 @@ func (hdb *HistoryDB) GetTokens( queryStr += fmt.Sprintf("LIMIT %d;", *limit) query, argsQ, err := sqlx.In(queryStr, args...) if err != nil { - return nil, 0, err + return nil, 0, tracerr.Wrap(err) } query = hdb.db.Rebind(query) tokens := []*TokenWithUSD{} if err := meddler.QueryAll(hdb.db, &tokens, query, argsQ...); err != nil { - return nil, 0, err + return nil, 0, tracerr.Wrap(err) } if len(tokens) == 0 { - return nil, 0, sql.ErrNoRows + return nil, 0, tracerr.Wrap(sql.ErrNoRows) } return db.SlicePtrsToSlice(tokens).([]TokenWithUSD), uint64(len(tokens)) - tokens[0].TotalItems, nil } @@ -725,13 +726,13 @@ func (hdb *HistoryDB) GetTokenSymbols() ([]string, error) { var tokenSymbols []string rows, err := hdb.db.Query("SELECT symbol FROM token;") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } sym := new(string) for rows.Next() { err = rows.Scan(sym) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } tokenSymbols = append(tokenSymbols, *sym) } @@ -763,7 +764,7 @@ func (hdb *HistoryDB) GetAllAccounts() ([]common.Account, error) { hdb.db, &accs, "SELECT * FROM account ORDER BY idx;", ) - return db.SlicePtrsToSlice(accs).([]common.Account), err + return db.SlicePtrsToSlice(accs).([]common.Account), tracerr.Wrap(err) } // AddL1Txs inserts L1 txs to the DB. USD and LoadAmountUSD will be set automatically before storing the tx. @@ -895,7 +896,7 @@ func (hdb *HistoryDB) GetHistoryTx(txID common.TxID) (*TxAPI, error) { INNER JOIN block ON tx.eth_block_num = block.eth_block_num WHERE tx.id = $1;`, txID, ) - return tx, err + return tx, tracerr.Wrap(err) } // GetHistoryTxs returns a list of txs from the DB using the HistoryTx struct @@ -906,7 +907,7 @@ func (hdb *HistoryDB) GetHistoryTxs( fromItem, limit *uint, order string, ) ([]TxAPI, uint64, error) { if ethAddr != nil && bjj != nil { - return nil, 0, errors.New("ethAddr and bjj are incompatible") + return nil, 0, tracerr.Wrap(errors.New("ethAddr and bjj are incompatible")) } var query string var args []interface{} @@ -1010,11 +1011,11 @@ func (hdb *HistoryDB) GetHistoryTxs( // log.Debug(query) txsPtrs := []*TxAPI{} if err := meddler.QueryAll(hdb.db, &txsPtrs, query, args...); err != nil { - return nil, 0, err + return nil, 0, tracerr.Wrap(err) } txs := db.SlicePtrsToSlice(txsPtrs).([]TxAPI) if len(txs) == 0 { - return nil, 0, sql.ErrNoRows + return nil, 0, tracerr.Wrap(sql.ErrNoRows) } return txs, txs[0].TotalItems - uint64(len(txs)), nil } @@ -1028,7 +1029,7 @@ func (hdb *HistoryDB) GetAllExits() ([]common.ExitInfo, error) { exit_tree.balance, exit_tree.instant_withdrawn, exit_tree.delayed_withdraw_request, exit_tree.delayed_withdrawn FROM exit_tree;`, ) - return db.SlicePtrsToSlice(exits).([]common.ExitInfo), err + return db.SlicePtrsToSlice(exits).([]common.ExitInfo), tracerr.Wrap(err) } // GetExitAPI returns a exit from the DB @@ -1046,7 +1047,7 @@ func (hdb *HistoryDB) GetExitAPI(batchNum *uint, idx *common.Idx) (*ExitAPI, err INNER JOIN token ON account.token_id = token.token_id WHERE exit_tree.batch_num = $1 AND exit_tree.account_idx = $2;`, batchNum, idx, ) - return exit, err + return exit, tracerr.Wrap(err) } // GetExitsAPI returns a list of exits from the DB and pagination info @@ -1056,7 +1057,7 @@ func (hdb *HistoryDB) GetExitsAPI( fromItem, limit *uint, order string, ) ([]ExitAPI, uint64, error) { if ethAddr != nil && bjj != nil { - return nil, 0, errors.New("ethAddr and bjj are incompatible") + return nil, 0, tracerr.Wrap(errors.New("ethAddr and bjj are incompatible")) } var query string var args []interface{} @@ -1152,10 +1153,10 @@ func (hdb *HistoryDB) GetExitsAPI( // log.Debug(query) exits := []*ExitAPI{} if err := meddler.QueryAll(hdb.db, &exits, query, args...); err != nil { - return nil, 0, err + return nil, 0, tracerr.Wrap(err) } if len(exits) == 0 { - return nil, 0, sql.ErrNoRows + return nil, 0, tracerr.Wrap(sql.ErrNoRows) } return db.SlicePtrsToSlice(exits).([]ExitAPI), exits[0].TotalItems - uint64(len(exits)), nil } @@ -1171,7 +1172,7 @@ func (hdb *HistoryDB) GetAllL1UserTxs() ([]common.L1Tx, error) { tx.eth_block_num, tx.type, tx.batch_num FROM tx WHERE is_l1 = TRUE AND user_origin = TRUE;`, ) - return db.SlicePtrsToSlice(txs).([]common.L1Tx), err + return db.SlicePtrsToSlice(txs).([]common.L1Tx), tracerr.Wrap(err) } // GetAllL1CoordinatorTxs returns all L1CoordinatorTxs from the DB @@ -1185,7 +1186,7 @@ func (hdb *HistoryDB) GetAllL1CoordinatorTxs() ([]common.L1Tx, error) { tx.eth_block_num, tx.type, tx.batch_num FROM tx WHERE is_l1 = TRUE AND user_origin = FALSE;`, ) - return db.SlicePtrsToSlice(txs).([]common.L1Tx), err + return db.SlicePtrsToSlice(txs).([]common.L1Tx), tracerr.Wrap(err) } // GetAllL2Txs returns all L2Txs from the DB @@ -1198,7 +1199,7 @@ func (hdb *HistoryDB) GetAllL2Txs() ([]common.L2Tx, error) { tx.type, tx.eth_block_num FROM tx WHERE is_l1 = FALSE;`, ) - return db.SlicePtrsToSlice(txs).([]common.L2Tx), err + return db.SlicePtrsToSlice(txs).([]common.L2Tx), tracerr.Wrap(err) } // GetL1UserTxs gets L1 User Txs to be forged in the L1Batch with toForgeL1TxsNum. @@ -1213,7 +1214,7 @@ func (hdb *HistoryDB) GetL1UserTxs(toForgeL1TxsNum int64) ([]common.L1Tx, error) FROM tx WHERE to_forge_l1_txs_num = $1 AND is_l1 = TRUE AND user_origin = TRUE;`, toForgeL1TxsNum, ) - return db.SlicePtrsToSlice(txs).([]common.L1Tx), err + return db.SlicePtrsToSlice(txs).([]common.L1Tx), tracerr.Wrap(err) } // TODO: Think about chaning all the queries that return a last value, to queries that return the next valid value. @@ -1233,15 +1234,15 @@ func (hdb *HistoryDB) GetSCVars() (*common.RollupVariables, *common.AuctionVaria var wDelayer common.WDelayerVariables if err := meddler.QueryRow(hdb.db, &rollup, "SELECT * FROM rollup_vars ORDER BY eth_block_num DESC LIMIT 1;"); err != nil { - return nil, nil, nil, err + return nil, nil, nil, tracerr.Wrap(err) } if err := meddler.QueryRow(hdb.db, &auction, "SELECT * FROM auction_vars ORDER BY eth_block_num DESC LIMIT 1;"); err != nil { - return nil, nil, nil, err + return nil, nil, nil, tracerr.Wrap(err) } if err := meddler.QueryRow(hdb.db, &wDelayer, "SELECT * FROM wdelayer_vars ORDER BY eth_block_num DESC LIMIT 1;"); err != nil { - return nil, nil, nil, err + return nil, nil, nil, tracerr.Wrap(err) } return &rollup, &auction, &wDelayer, nil } @@ -1266,7 +1267,7 @@ func (hdb *HistoryDB) SetInitialSCVars(rollup *common.RollupVariables, auction *common.AuctionVariables, wDelayer *common.WDelayerVariables) error { txn, err := hdb.db.Beginx() if err != nil { - return err + return tracerr.Wrap(err) } defer func() { if err != nil { @@ -1280,13 +1281,13 @@ func (hdb *HistoryDB) SetInitialSCVars(rollup *common.RollupVariables, wDelayer.EthBlockNum = 0 auction.DefaultSlotSetBidSlotNum = 0 if err := hdb.setRollupVars(txn, rollup); err != nil { - return err + return tracerr.Wrap(err) } if err := hdb.setAuctionVars(txn, auction); err != nil { - return err + return tracerr.Wrap(err) } if err := hdb.setWDelayerVars(txn, wDelayer); err != nil { - return err + return tracerr.Wrap(err) } return txn.Commit() @@ -1299,7 +1300,7 @@ func (hdb *HistoryDB) SetInitialSCVars(rollup *common.RollupVariables, func (hdb *HistoryDB) AddBlockSCData(blockData *common.BlockData) (err error) { txn, err := hdb.db.Beginx() if err != nil { - return err + return tracerr.Wrap(err) } defer func() { if err != nil { @@ -1309,27 +1310,27 @@ func (hdb *HistoryDB) AddBlockSCData(blockData *common.BlockData) (err error) { // Add block if err := hdb.addBlock(txn, &blockData.Block); err != nil { - return err + return tracerr.Wrap(err) } // Add Coordinators if len(blockData.Auction.Coordinators) > 0 { if err := hdb.addCoordinators(txn, blockData.Auction.Coordinators); err != nil { - return err + return tracerr.Wrap(err) } } // Add Bids if len(blockData.Auction.Bids) > 0 { if err := hdb.addBids(txn, blockData.Auction.Bids); err != nil { - return err + return tracerr.Wrap(err) } } // Add Tokens if len(blockData.Rollup.AddedTokens) > 0 { if err := hdb.addTokens(txn, blockData.Rollup.AddedTokens); err != nil { - return err + return tracerr.Wrap(err) } } @@ -1366,69 +1367,69 @@ func (hdb *HistoryDB) AddBlockSCData(blockData *common.BlockData) (err error) { // Add Batch: this will trigger an update on the DB // that will set the batch num of forged L1 txs in this batch if err = hdb.addBatch(txn, &batch.Batch); err != nil { - return err + return tracerr.Wrap(err) } // Add accounts if len(batch.CreatedAccounts) > 0 { if err := hdb.addAccounts(txn, batch.CreatedAccounts); err != nil { - return err + return tracerr.Wrap(err) } } // Add forged l1 coordinator Txs if len(batch.L1CoordinatorTxs) > 0 { if err := hdb.addL1Txs(txn, batch.L1CoordinatorTxs); err != nil { - return err + return tracerr.Wrap(err) } } // Add l2 Txs if len(batch.L2Txs) > 0 { if err := hdb.addL2Txs(txn, batch.L2Txs); err != nil { - return err + return tracerr.Wrap(err) } } // Add user L1 txs that will be forged in next batch if userlL1s, ok := userL1s[batch.Batch.BatchNum]; ok { if err := hdb.addL1Txs(txn, userlL1s); err != nil { - return err + return tracerr.Wrap(err) } } // Add exit tree if len(batch.ExitTree) > 0 { if err := hdb.addExitTree(txn, batch.ExitTree); err != nil { - return err + return tracerr.Wrap(err) } } } // Add user L1 txs that won't be forged in this block if userL1sNotForgedInThisBlock, ok := userL1s[0]; ok { if err := hdb.addL1Txs(txn, userL1sNotForgedInThisBlock); err != nil { - return err + return tracerr.Wrap(err) } } if blockData.Rollup.Vars != nil { if err := hdb.setRollupVars(txn, blockData.Rollup.Vars); err != nil { - return err + return tracerr.Wrap(err) } } if blockData.Auction.Vars != nil { if err := hdb.setAuctionVars(txn, blockData.Auction.Vars); err != nil { - return err + return tracerr.Wrap(err) } } if blockData.WDelayer.Vars != nil { if err := hdb.setWDelayerVars(txn, blockData.WDelayer.Vars); err != nil { - return err + return tracerr.Wrap(err) } } if err := hdb.updateExitTree(txn, blockData.Block.Num, blockData.Rollup.Withdrawals, blockData.WDelayer.Withdrawals); err != nil { - return err + return tracerr.Wrap(err) } return txn.Commit() @@ -1438,7 +1439,7 @@ func (hdb *HistoryDB) AddBlockSCData(blockData *common.BlockData) (err error) { func (hdb *HistoryDB) GetCoordinatorAPI(bidderAddr ethCommon.Address) (*CoordinatorAPI, error) { coordinator := &CoordinatorAPI{} err := meddler.QueryRow(hdb.db, coordinator, "SELECT * FROM coordinator WHERE bidder_addr = $1;", bidderAddr) - return coordinator, err + return coordinator, tracerr.Wrap(err) } // GetCoordinatorsAPI returns a list of coordinators from the DB and pagination info @@ -1470,10 +1471,10 @@ func (hdb *HistoryDB) GetCoordinatorsAPI(fromItem, limit *uint, order string) ([ coordinators := []*CoordinatorAPI{} if err := meddler.QueryAll(hdb.db, &coordinators, query, args...); err != nil { - return nil, 0, err + return nil, 0, tracerr.Wrap(err) } if len(coordinators) == 0 { - return nil, 0, sql.ErrNoRows + return nil, 0, tracerr.Wrap(sql.ErrNoRows) } return db.SlicePtrsToSlice(coordinators).([]CoordinatorAPI), coordinators[0].TotalItems - uint64(len(coordinators)), nil @@ -1490,7 +1491,7 @@ func (hdb *HistoryDB) GetAuctionVars() (*common.AuctionVariables, error) { err := meddler.QueryRow( hdb.db, auctionVars, `SELECT * FROM auction_vars;`, ) - return auctionVars, err + return auctionVars, tracerr.Wrap(err) } // GetAccountAPI returns an account by its index @@ -1503,7 +1504,7 @@ func (hdb *HistoryDB) GetAccountAPI(idx common.Idx) (*AccountAPI, error) { FROM account INNER JOIN token ON account.token_id = token.token_id WHERE idx = $1;`, idx) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return account, nil @@ -1515,7 +1516,7 @@ func (hdb *HistoryDB) GetAccountsAPI( bjj *babyjub.PublicKey, fromItem, limit *uint, order string, ) ([]AccountAPI, uint64, error) { if ethAddr != nil && bjj != nil { - return nil, 0, errors.New("ethAddr and bjj are incompatible") + return nil, 0, tracerr.Wrap(errors.New("ethAddr and bjj are incompatible")) } var query string var args []interface{} @@ -1570,16 +1571,16 @@ func (hdb *HistoryDB) GetAccountsAPI( queryStr += fmt.Sprintf("LIMIT %d;", *limit) query, argsQ, err := sqlx.In(queryStr, args...) if err != nil { - return nil, 0, err + return nil, 0, tracerr.Wrap(err) } query = hdb.db.Rebind(query) accounts := []*AccountAPI{} if err := meddler.QueryAll(hdb.db, &accounts, query, argsQ...); err != nil { - return nil, 0, err + return nil, 0, tracerr.Wrap(err) } if len(accounts) == 0 { - return nil, 0, sql.ErrNoRows + return nil, 0, tracerr.Wrap(sql.ErrNoRows) } return db.SlicePtrsToSlice(accounts).([]AccountAPI), @@ -1595,7 +1596,7 @@ func (hdb *HistoryDB) GetMetrics(lastBatchNum common.BatchNum) (*Metrics, error) FROM tx INNER JOIN block ON tx.eth_block_num = block.eth_block_num WHERE block.timestamp >= NOW() - INTERVAL '24 HOURS';`) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } metrics.TransactionsPerSecond = float64(metricsTotals.TotalTransactions / (24 * 60 * 60)) @@ -1611,7 +1612,7 @@ func (hdb *HistoryDB) GetMetrics(lastBatchNum common.BatchNum) (*Metrics, error) SUM(total_fees_usd) AS total_fees FROM batch WHERE batch_num > $1;`, metricsTotals.FirstBatchNum) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } if metricsTotals.TotalBatches > 0 { metrics.BatchFrequency = float64((24 * 60 * 60) / metricsTotals.TotalBatches) @@ -1627,7 +1628,7 @@ func (hdb *HistoryDB) GetMetrics(lastBatchNum common.BatchNum) (*Metrics, error) hdb.db, metrics, `SELECT COUNT(*) AS total_bjjs, COUNT(DISTINCT(bjj)) AS total_accounts FROM account;`) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return metrics, nil @@ -1641,14 +1642,14 @@ func (hdb *HistoryDB) GetAvgTxFee() (float64, error) { FROM tx INNER JOIN block ON tx.eth_block_num = block.eth_block_num WHERE block.timestamp >= NOW() - INTERVAL '1 HOURS';`) if err != nil { - return 0, err + return 0, tracerr.Wrap(err) } err = meddler.QueryRow( hdb.db, metricsTotals, `SELECT COUNT(*) AS total_batches, SUM(total_fees_usd) AS total_fees FROM batch WHERE batch_num > $1;`, metricsTotals.FirstBatchNum) if err != nil { - return 0, err + return 0, tracerr.Wrap(err) } var avgTransactionFee float64 diff --git a/db/historydb/historydb_test.go b/db/historydb/historydb_test.go index 49f8ca4..a34bc48 100644 --- a/db/historydb/historydb_test.go +++ b/db/historydb/historydb_test.go @@ -14,6 +14,7 @@ import ( "github.com/hermeznetwork/hermez-node/log" "github.com/hermeznetwork/hermez-node/test" "github.com/hermeznetwork/hermez-node/test/til" + "github.com/hermeznetwork/tracerr" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -78,7 +79,7 @@ func TestBlocks(t *testing.T) { } // Add block 0 to the generated blocks blocks = append( - []common.BlockData{common.BlockData{Block: test.Block0}}, //nolint:gofmt + []common.BlockData{{Block: test.Block0}}, //nolint:gofmt blocks..., ) // Get all blocks from DB @@ -680,7 +681,7 @@ func exampleInitSCVars() (*common.RollupVariables, *common.AuctionVariables, *co func TestSetInitialSCVars(t *testing.T) { test.WipeDB(historyDB.DB()) _, _, _, err := historyDB.GetSCVars() - assert.Equal(t, sql.ErrNoRows, err) + assert.Equal(t, sql.ErrNoRows, tracerr.Unwrap(err)) rollup, auction, wDelayer := exampleInitSCVars() err = historyDB.SetInitialSCVars(rollup, auction, wDelayer) require.Nil(t, err) @@ -859,7 +860,7 @@ func TestGetBestBidCoordinator(t *testing.T) { require.Equal(t, coords[1].URL, forger10.URL) _, err = historyDB.GetBestBidCoordinator(11) - require.Equal(t, sql.ErrNoRows, err) + require.Equal(t, sql.ErrNoRows, tracerr.Unwrap(err)) } // setTestBlocks WARNING: this will delete the blocks and recreate them diff --git a/db/l2db/l2db.go b/db/l2db/l2db.go index a90d77e..6f0f2ae 100644 --- a/db/l2db/l2db.go +++ b/db/l2db/l2db.go @@ -7,6 +7,7 @@ import ( ethCommon "github.com/ethereum/go-ethereum/common" "github.com/hermeznetwork/hermez-node/common" "github.com/hermeznetwork/hermez-node/db" + "github.com/hermeznetwork/tracerr" "github.com/jmoiron/sqlx" //nolint:errcheck // driver for postgres DB @@ -51,7 +52,7 @@ func (l2db *L2DB) AddAccountCreationAuth(auth *common.AccountCreationAuth) error VALUES ($1, $2, $3);`, auth.EthAddr, auth.BJJ, auth.Signature, ) - return err + return tracerr.Wrap(err) } // GetAccountCreationAuth returns an account creation authorization from the DB @@ -170,7 +171,7 @@ func (l2db *L2DB) GetPendingTxs() ([]common.PoolL2Tx, error) { selectPoolTxCommon+"WHERE state = $1", common.PoolL2TxStatePending, ) - return db.SlicePtrsToSlice(txs).([]common.PoolL2Tx), err + return db.SlicePtrsToSlice(txs).([]common.PoolL2Tx), tracerr.Wrap(err) } // StartForging updates the state of the transactions that will begin the forging process. @@ -186,11 +187,11 @@ func (l2db *L2DB) StartForging(txIDs []common.TxID, batchNum common.BatchNum) er txIDs, ) if err != nil { - return err + return tracerr.Wrap(err) } query = l2db.db.Rebind(query) _, err = l2db.db.Exec(query, args...) - return err + return tracerr.Wrap(err) } // DoneForging updates the state of the transactions that have been forged @@ -206,11 +207,11 @@ func (l2db *L2DB) DoneForging(txIDs []common.TxID, batchNum common.BatchNum) err txIDs, ) if err != nil { - return err + return tracerr.Wrap(err) } query = l2db.db.Rebind(query) _, err = l2db.db.Exec(query, args...) - return err + return tracerr.Wrap(err) } // InvalidateTxs updates the state of the transactions that are invalid. @@ -225,11 +226,11 @@ func (l2db *L2DB) InvalidateTxs(txIDs []common.TxID, batchNum common.BatchNum) e txIDs, ) if err != nil { - return err + return tracerr.Wrap(err) } query = l2db.db.Rebind(query) _, err = l2db.db.Exec(query, args...) - return err + return tracerr.Wrap(err) } // CheckNonces invalidate txs with nonces that are smaller or equal than their respective accounts nonces. @@ -237,7 +238,7 @@ func (l2db *L2DB) InvalidateTxs(txIDs []common.TxID, batchNum common.BatchNum) e func (l2db *L2DB) CheckNonces(updatedAccounts []common.Account, batchNum common.BatchNum) (err error) { txn, err := l2db.db.Beginx() if err != nil { - return err + return tracerr.Wrap(err) } defer func() { // Rollback the transaction if there was an error. @@ -257,7 +258,7 @@ func (l2db *L2DB) CheckNonces(updatedAccounts []common.Account, batchNum common. updatedAccounts[i].Nonce, ) if err != nil { - return err + return tracerr.Wrap(err) } } return txn.Commit() @@ -274,7 +275,7 @@ func (l2db *L2DB) Reorg(lastValidBatch common.BatchNum) error { common.PoolL2TxStateInvalid, lastValidBatch, ) - return err + return tracerr.Wrap(err) } // Purge deletes transactions that have been forged or marked as invalid for longer than the safety period @@ -282,7 +283,7 @@ func (l2db *L2DB) Reorg(lastValidBatch common.BatchNum) error { func (l2db *L2DB) Purge(currentBatchNum common.BatchNum) (err error) { txn, err := l2db.db.Beginx() if err != nil { - return err + return tracerr.Wrap(err) } defer func() { // Rollback the transaction if there was an error. @@ -298,7 +299,7 @@ func (l2db *L2DB) Purge(currentBatchNum common.BatchNum) (err error) { time.Unix(now-int64(l2db.ttl.Seconds()), 0), ) if err != nil { - return err + return tracerr.Wrap(err) } // Delete txs that have been marked as forged / invalid after the safety period _, err = txn.Exec( @@ -309,7 +310,7 @@ func (l2db *L2DB) Purge(currentBatchNum common.BatchNum) (err error) { common.PoolL2TxStateInvalid, ) if err != nil { - return err + return tracerr.Wrap(err) } return txn.Commit() } diff --git a/db/l2db/l2db_test.go b/db/l2db/l2db_test.go index 731c9d1..69f4022 100644 --- a/db/l2db/l2db_test.go +++ b/db/l2db/l2db_test.go @@ -14,6 +14,7 @@ import ( "github.com/hermeznetwork/hermez-node/log" "github.com/hermeznetwork/hermez-node/test" "github.com/hermeznetwork/hermez-node/test/til" + "github.com/hermeznetwork/tracerr" "github.com/stretchr/testify/assert" ) @@ -69,12 +70,12 @@ func prepareHistoryDB(historyDB *historydb.HistoryDB) error { } blocks, err := tc.GenerateBlocks(setBlockchain) if err != nil { - return err + return tracerr.Wrap(err) } err = tc.FillBlocksExtra(blocks, &tilCfgExtra) if err != nil { - return err + return tracerr.Wrap(err) } tokens = make(map[common.TokenID]historydb.TokenWithUSD) tokensValue = make(map[common.TokenID]float64) @@ -85,7 +86,7 @@ func prepareHistoryDB(historyDB *historydb.HistoryDB) error { for i := range blocks[:len(blocks)-1] { err = historyDB.AddBlockSCData(&blocks[i]) if err != nil { - return err + return tracerr.Wrap(err) } for _, batch := range blocks[i].Rollup.Batches { for _, account := range batch.CreatedAccounts { @@ -110,7 +111,7 @@ func prepareHistoryDB(historyDB *historydb.HistoryDB) error { tokenSymbol := "" err := historyDB.UpdateTokenValue(tokenSymbol, value) if err != nil { - return err + return tracerr.Wrap(err) } } return nil @@ -135,7 +136,7 @@ func generatePoolL2Txs() ([]common.PoolL2Tx, error) { ` poolL2Txs, err := tc.GeneratePoolL2Txs(setPool) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return poolL2Txs, nil } diff --git a/db/statedb/statedb.go b/db/statedb/statedb.go index a90add1..b621d16 100644 --- a/db/statedb/statedb.go +++ b/db/statedb/statedb.go @@ -9,6 +9,7 @@ import ( "github.com/hermeznetwork/hermez-node/common" "github.com/hermeznetwork/hermez-node/log" + "github.com/hermeznetwork/tracerr" "github.com/iden3/go-merkletree" "github.com/iden3/go-merkletree/db" "github.com/iden3/go-merkletree/db/pebble" @@ -92,18 +93,18 @@ func NewStateDB(path string, typ TypeStateDB, nLevels int) (*StateDB, error) { var err error sto, err = pebble.NewPebbleStorage(path+PathCurrent, false) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } var mt *merkletree.MerkleTree = nil if typ == TypeSynchronizer || typ == TypeBatchBuilder { mt, err = merkletree.NewMerkleTree(sto.WithPrefix(PrefixKeyMT), nLevels) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } } if typ == TypeTxSelector && nLevels != 0 { - return nil, fmt.Errorf("invalid StateDB parameters: StateDB type==TypeStateDB can not have nLevels!=0") + return nil, tracerr.Wrap(fmt.Errorf("invalid StateDB parameters: StateDB type==TypeStateDB can not have nLevels!=0")) } sdb := &StateDB{ @@ -116,13 +117,13 @@ func NewStateDB(path string, typ TypeStateDB, nLevels int) (*StateDB, error) { // load currentBatch sdb.currentBatch, err = sdb.GetCurrentBatch() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } // make reset (get checkpoint) at currentBatch err = sdb.reset(sdb.currentBatch, false) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return sdb, nil @@ -136,11 +137,11 @@ func (s *StateDB) DB() *pebble.PebbleStorage { // GetCurrentBatch returns the current BatchNum stored in the StateDB func (s *StateDB) GetCurrentBatch() (common.BatchNum, error) { cbBytes, err := s.db.Get(KeyCurrentBatch) - if err == db.ErrNotFound { + if tracerr.Unwrap(err) == db.ErrNotFound { return 0, nil } if err != nil { - return 0, err + return 0, tracerr.Wrap(err) } return common.BatchNumFromBytes(cbBytes) } @@ -149,14 +150,14 @@ func (s *StateDB) GetCurrentBatch() (common.BatchNum, error) { func (s *StateDB) setCurrentBatch() error { tx, err := s.db.NewTx() if err != nil { - return err + return tracerr.Wrap(err) } err = tx.Put(KeyCurrentBatch, s.currentBatch.Bytes()) if err != nil { - return err + return tracerr.Wrap(err) } if err := tx.Commit(); err != nil { - return err + return tracerr.Wrap(err) } return nil } @@ -171,23 +172,23 @@ func (s *StateDB) MakeCheckpoint() error { err := s.setCurrentBatch() if err != nil { - return err + return tracerr.Wrap(err) } // if checkpoint BatchNum already exist in disk, delete it if _, err := os.Stat(checkpointPath); !os.IsNotExist(err) { err := os.RemoveAll(checkpointPath) if err != nil { - return err + return tracerr.Wrap(err) } } else if err != nil && !os.IsNotExist(err) { - return err + return tracerr.Wrap(err) } // execute Checkpoint err = s.db.Pebble().Checkpoint(checkpointPath) if err != nil { - return err + return tracerr.Wrap(err) } return nil @@ -198,7 +199,7 @@ func (s *StateDB) DeleteCheckpoint(batchNum common.BatchNum) error { checkpointPath := s.path + PathBatchNum + strconv.Itoa(int(batchNum)) if _, err := os.Stat(checkpointPath); os.IsNotExist(err) { - return fmt.Errorf("Checkpoint with batchNum %d does not exist in DB", batchNum) + return tracerr.Wrap(fmt.Errorf("Checkpoint with batchNum %d does not exist in DB", batchNum)) } return os.RemoveAll(checkpointPath) @@ -209,15 +210,15 @@ func pebbleMakeCheckpoint(source, dest string) error { if _, err := os.Stat(dest); !os.IsNotExist(err) { err := os.RemoveAll(dest) if err != nil { - return err + return tracerr.Wrap(err) } } else if err != nil && !os.IsNotExist(err) { - return err + return tracerr.Wrap(err) } sto, err := pebble.NewPebbleStorage(source, false) if err != nil { - return err + return tracerr.Wrap(err) } defer func() { errClose := sto.Pebble().Close() @@ -229,7 +230,7 @@ func pebbleMakeCheckpoint(source, dest string) error { // execute Checkpoint err = sto.Pebble().Checkpoint(dest) if err != nil { - return err + return tracerr.Wrap(err) } return nil @@ -253,19 +254,19 @@ func (s *StateDB) reset(batchNum common.BatchNum, closeCurrent bool) error { if closeCurrent { if err := s.db.Pebble().Close(); err != nil { - return err + return tracerr.Wrap(err) } } // remove 'current' err := os.RemoveAll(currentPath) if err != nil { - return err + return tracerr.Wrap(err) } if batchNum == 0 { // if batchNum == 0, open the new fresh 'current' sto, err := pebble.NewPebbleStorage(currentPath, false) if err != nil { - return err + return tracerr.Wrap(err) } s.db = sto s.idx = 255 @@ -275,7 +276,7 @@ func (s *StateDB) reset(batchNum common.BatchNum, closeCurrent bool) error { // open the MT for the current s.db mt, err := merkletree.NewMerkleTree(s.db.WithPrefix(PrefixKeyMT), s.mt.MaxLevels()) if err != nil { - return err + return tracerr.Wrap(err) } s.mt = mt } @@ -286,32 +287,32 @@ func (s *StateDB) reset(batchNum common.BatchNum, closeCurrent bool) error { // copy 'BatchNumX' to 'current' err = pebbleMakeCheckpoint(checkpointPath, currentPath) if err != nil { - return err + return tracerr.Wrap(err) } // open the new 'current' sto, err := pebble.NewPebbleStorage(currentPath, false) if err != nil { - return err + return tracerr.Wrap(err) } s.db = sto // get currentBatch num s.currentBatch, err = s.GetCurrentBatch() if err != nil { - return err + return tracerr.Wrap(err) } // idx is obtained from the statedb reset s.idx, err = s.getIdx() if err != nil { - return err + return tracerr.Wrap(err) } if s.mt != nil { // open the MT for the current s.db mt, err := merkletree.NewMerkleTree(s.db.WithPrefix(PrefixKeyMT), s.mt.MaxLevels()) if err != nil { - return err + return tracerr.Wrap(err) } s.mt = mt } @@ -335,18 +336,18 @@ func (s *StateDB) GetAccounts() ([]common.Account, error) { if err := idxDB.Iterate(func(k []byte, v []byte) (bool, error) { idx, err := common.IdxFromBytes(k) if err != nil { - return false, err + return false, tracerr.Wrap(err) } idxs = append(idxs, idx) return true, nil }); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } accs := []common.Account{} for i := range idxs { acc, err := s.GetAccount(idxs[i]) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } accs = append(accs, *acc) } @@ -358,21 +359,21 @@ func (s *StateDB) GetAccounts() ([]common.Account, error) { func getAccountInTreeDB(sto db.Storage, idx common.Idx) (*common.Account, error) { idxBytes, err := idx.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } vBytes, err := sto.Get(append(PrefixKeyIdx, idxBytes[:]...)) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } accBytes, err := sto.Get(append(PrefixKeyAccHash, vBytes...)) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } var b [32 * common.NLeafElems]byte copy(b[:], accBytes) account, err := common.AccountFromBytes(b) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } account.Idx = idx return account, nil @@ -384,11 +385,11 @@ func getAccountInTreeDB(sto db.Storage, idx common.Idx) (*common.Account, error) func (s *StateDB) CreateAccount(idx common.Idx, account *common.Account) (*merkletree.CircomProcessorProof, error) { cpp, err := createAccountInTreeDB(s.db, s.mt, idx, account) if err != nil { - return cpp, err + return cpp, tracerr.Wrap(err) } // store idx by EthAddr & BJJ err = s.setIdxByEthAddrBJJ(idx, account.EthAddr, account.PublicKey, account.TokenID) - return cpp, err + return cpp, tracerr.Wrap(err) } // createAccountInTreeDB is abstracted from StateDB to be used from StateDB and @@ -399,39 +400,39 @@ func createAccountInTreeDB(sto db.Storage, mt *merkletree.MerkleTree, idx common // store at the DB the key: v, and value: leaf.Bytes() v, err := account.HashValue() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } accountBytes, err := account.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } // store the Leaf value tx, err := sto.NewTx() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } idxBytes, err := idx.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } _, err = tx.Get(append(PrefixKeyIdx, idxBytes[:]...)) - if err != db.ErrNotFound { - return nil, ErrAccountAlreadyExists + if tracerr.Unwrap(err) != db.ErrNotFound { + return nil, tracerr.Wrap(ErrAccountAlreadyExists) } err = tx.Put(append(PrefixKeyAccHash, v.Bytes()...), accountBytes[:]) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } err = tx.Put(append(PrefixKeyIdx, idxBytes[:]...), v.Bytes()) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } if err := tx.Commit(); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } if mt != nil { @@ -456,32 +457,32 @@ func updateAccountInTreeDB(sto db.Storage, mt *merkletree.MerkleTree, idx common // store at the DB the key: v, and value: account.Bytes() v, err := account.HashValue() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } accountBytes, err := account.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } tx, err := sto.NewTx() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } err = tx.Put(append(PrefixKeyAccHash, v.Bytes()...), accountBytes[:]) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } idxBytes, err := idx.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } err = tx.Put(append(PrefixKeyIdx, idxBytes[:]...), v.Bytes()) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } if err := tx.Commit(); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } if mt != nil { @@ -493,7 +494,7 @@ func updateAccountInTreeDB(sto db.Storage, mt *merkletree.MerkleTree, idx common // MTGetProof returns the CircomVerifierProof for a given Idx func (s *StateDB) MTGetProof(idx common.Idx) (*merkletree.CircomVerifierProof, error) { if s.mt == nil { - return nil, ErrStateDBWithoutMT + return nil, tracerr.Wrap(ErrStateDBWithoutMT) } return s.mt.GenerateCircomVerifierProof(idx.BigInt(), s.mt.Root()) } @@ -516,7 +517,7 @@ type LocalStateDB struct { func NewLocalStateDB(path string, synchronizerDB *StateDB, typ TypeStateDB, nLevels int) (*LocalStateDB, error) { s, err := NewStateDB(path, typ, nLevels) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &LocalStateDB{ s, @@ -540,44 +541,44 @@ func (l *LocalStateDB) Reset(batchNum common.BatchNum, fromSynchronizer bool) er // use checkpoint from SynchronizerStateDB if _, err := os.Stat(synchronizerCheckpointPath); os.IsNotExist(err) { // if synchronizerStateDB does not have checkpoint at batchNum, return err - return fmt.Errorf("Checkpoint not exist in Synchronizer") + return tracerr.Wrap(fmt.Errorf("Checkpoint not exist in Synchronizer")) } if err := l.db.Pebble().Close(); err != nil { - return err + return tracerr.Wrap(err) } // remove 'current' err := os.RemoveAll(currentPath) if err != nil { - return err + return tracerr.Wrap(err) } // copy synchronizer'BatchNumX' to 'current' err = pebbleMakeCheckpoint(synchronizerCheckpointPath, currentPath) if err != nil { - return err + return tracerr.Wrap(err) } // copy synchronizer'BatchNumX' to 'BatchNumX' err = pebbleMakeCheckpoint(synchronizerCheckpointPath, checkpointPath) if err != nil { - return err + return tracerr.Wrap(err) } // open the new 'current' sto, err := pebble.NewPebbleStorage(currentPath, false) if err != nil { - return err + return tracerr.Wrap(err) } l.db = sto // get currentBatch num l.currentBatch, err = l.GetCurrentBatch() if err != nil { - return err + return tracerr.Wrap(err) } // open the MT for the current s.db mt, err := merkletree.NewMerkleTree(l.db.WithPrefix(PrefixKeyMT), l.mt.MaxLevels()) if err != nil { - return err + return tracerr.Wrap(err) } l.mt = mt diff --git a/db/statedb/statedb_test.go b/db/statedb/statedb_test.go index be29a02..6e28dc9 100644 --- a/db/statedb/statedb_test.go +++ b/db/statedb/statedb_test.go @@ -12,6 +12,7 @@ import ( ethCommon "github.com/ethereum/go-ethereum/common" ethCrypto "github.com/ethereum/go-ethereum/crypto" "github.com/hermeznetwork/hermez-node/common" + "github.com/hermeznetwork/tracerr" "github.com/iden3/go-iden3-crypto/babyjub" "github.com/iden3/go-merkletree/db" "github.com/stretchr/testify/assert" @@ -69,7 +70,7 @@ func TestNewStateDBIntermediateState(t *testing.T) { assert.Nil(t, err) v, err = sdb.db.Get(k0) assert.NotNil(t, err) - assert.Equal(t, db.ErrNotFound, err) + assert.Equal(t, db.ErrNotFound, tracerr.Unwrap(err)) assert.Nil(t, v) // store the same data from the beginning that has ben lost since last NewStateDB @@ -116,7 +117,7 @@ func TestNewStateDBIntermediateState(t *testing.T) { v, err = sdb.db.Get(k1) assert.NotNil(t, err) - assert.Equal(t, db.ErrNotFound, err) + assert.Equal(t, db.ErrNotFound, tracerr.Unwrap(err)) assert.Nil(t, v) } @@ -138,7 +139,7 @@ func TestStateDBWithoutMT(t *testing.T) { unexistingAccount := common.Idx(1) _, err = sdb.GetAccount(unexistingAccount) assert.NotNil(t, err) - assert.Equal(t, db.ErrNotFound, err) + assert.Equal(t, db.ErrNotFound, tracerr.Unwrap(err)) // add test accounts for i := 0; i < len(accounts); i++ { @@ -159,7 +160,7 @@ func TestStateDBWithoutMT(t *testing.T) { assert.Nil(t, err) _, err = sdb.CreateAccount(common.Idx(256), accounts[1]) // check that can not be created twice assert.NotNil(t, err) - assert.Equal(t, ErrAccountAlreadyExists, err) + assert.Equal(t, ErrAccountAlreadyExists, tracerr.Unwrap(err)) // update accounts for i := 0; i < len(accounts); i++ { @@ -171,7 +172,7 @@ func TestStateDBWithoutMT(t *testing.T) { _, err = sdb.MTGetProof(common.Idx(1)) assert.NotNil(t, err) - assert.Equal(t, ErrStateDBWithoutMT, err) + assert.Equal(t, ErrStateDBWithoutMT, tracerr.Unwrap(err)) } func TestStateDBWithMT(t *testing.T) { @@ -191,7 +192,7 @@ func TestStateDBWithMT(t *testing.T) { // get non-existing account, expecting an error _, err = sdb.GetAccount(common.Idx(1)) assert.NotNil(t, err) - assert.Equal(t, db.ErrNotFound, err) + assert.Equal(t, db.ErrNotFound, tracerr.Unwrap(err)) // add test accounts for i := 0; i < len(accounts); i++ { @@ -210,7 +211,7 @@ func TestStateDBWithMT(t *testing.T) { assert.Nil(t, err) _, err = sdb.CreateAccount(common.Idx(256), accounts[1]) // check that can not be created twice assert.NotNil(t, err) - assert.Equal(t, ErrAccountAlreadyExists, err) + assert.Equal(t, ErrAccountAlreadyExists, tracerr.Unwrap(err)) _, err = sdb.MTGetProof(common.Idx(256)) assert.Nil(t, err) diff --git a/db/statedb/txprocessors.go b/db/statedb/txprocessors.go index e75f698..f4aae4e 100644 --- a/db/statedb/txprocessors.go +++ b/db/statedb/txprocessors.go @@ -10,6 +10,7 @@ import ( "github.com/hermeznetwork/hermez-node/common" "github.com/hermeznetwork/hermez-node/log" + "github.com/hermeznetwork/tracerr" "github.com/iden3/go-iden3-crypto/babyjub" "github.com/iden3/go-merkletree" "github.com/iden3/go-merkletree/db" @@ -70,12 +71,12 @@ func (s *StateDB) ProcessTxs(ptc ProcessTxsConfig, coordIdxs []common.Idx, l1use var createdAccounts []common.Account if s.zki != nil { - return nil, errors.New("Expected StateDB.zki==nil, something went wrong and it's not empty") + return nil, tracerr.Wrap(errors.New("Expected StateDB.zki==nil, something went wrong and it's not empty")) } defer s.resetZKInputs() if len(coordIdxs) >= int(ptc.MaxFeeTx) { - return nil, fmt.Errorf("CoordIdxs (%d) length must be smaller than MaxFeeTx (%d)", len(coordIdxs), ptc.MaxFeeTx) + return nil, tracerr.Wrap(fmt.Errorf("CoordIdxs (%d) length must be smaller than MaxFeeTx (%d)", len(coordIdxs), ptc.MaxFeeTx)) } s.accumulatedFees = make(map[common.Idx]*big.Int) @@ -104,7 +105,7 @@ func (s *StateDB) ProcessTxs(ptc ProcessTxsConfig, coordIdxs []common.Idx, l1use if s.typ == TypeSynchronizer || s.typ == TypeBatchBuilder { tmpDir, err := ioutil.TempDir("", "hermez-statedb-exittree") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } defer func() { if err := os.RemoveAll(tmpDir); err != nil { @@ -113,11 +114,11 @@ func (s *StateDB) ProcessTxs(ptc ProcessTxsConfig, coordIdxs []common.Idx, l1use }() sto, err := pebble.NewPebbleStorage(tmpDir, false) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } exitTree, err = merkletree.NewMerkleTree(sto, s.mt.MaxLevels()) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } } @@ -126,7 +127,7 @@ func (s *StateDB) ProcessTxs(ptc ProcessTxsConfig, coordIdxs []common.Idx, l1use // assumption: l1usertx are sorted by L1Tx.Position exitIdx, exitAccount, newExit, createdAccount, err := s.processL1Tx(exitTree, &l1usertxs[i]) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } if s.typ == TypeSynchronizer && createdAccount != nil { createdAccounts = append(createdAccounts, *createdAccount) @@ -135,13 +136,13 @@ func (s *StateDB) ProcessTxs(ptc ProcessTxsConfig, coordIdxs []common.Idx, l1use if s.zki != nil { l1TxData, err := l1usertxs[i].BytesGeneric() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } s.zki.Metadata.L1TxsData = append(s.zki.Metadata.L1TxsData, l1TxData) l1TxDataAvailability, err := l1usertxs[i].BytesDataAvailability(s.zki.Metadata.NLevels) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } s.zki.Metadata.L1TxsDataAvailability = append(s.zki.Metadata.L1TxsDataAvailability, l1TxDataAvailability) @@ -167,7 +168,7 @@ func (s *StateDB) ProcessTxs(ptc ProcessTxsConfig, coordIdxs []common.Idx, l1use for i := 0; i < len(l1coordinatortxs); i++ { exitIdx, _, _, createdAccount, err := s.processL1Tx(exitTree, &l1coordinatortxs[i]) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } if exitIdx != nil { log.Error("Unexpected Exit in L1CoordinatorTx") @@ -178,7 +179,7 @@ func (s *StateDB) ProcessTxs(ptc ProcessTxsConfig, coordIdxs []common.Idx, l1use if s.zki != nil { l1TxData, err := l1coordinatortxs[i].BytesGeneric() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } s.zki.Metadata.L1TxsData = append(s.zki.Metadata.L1TxsData, l1TxData) @@ -200,7 +201,7 @@ func (s *StateDB) ProcessTxs(ptc ProcessTxsConfig, coordIdxs []common.Idx, l1use // created in the current batch, at this point the Idx will be created coordIdxsMap, err := s.getTokenIDsFromIdxs(coordIdxs) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } // collectedFees will contain the amount of fee collected for each // TokenID @@ -217,7 +218,7 @@ func (s *StateDB) ProcessTxs(ptc ProcessTxsConfig, coordIdxs []common.Idx, l1use feePlanTokens, err := s.getFeePlanTokens(coordIdxs, l2txs) if err != nil { log.Error(err) - return nil, err + return nil, tracerr.Wrap(err) } copy(s.zki.FeePlanTokens, feePlanTokens) } @@ -226,12 +227,12 @@ func (s *StateDB) ProcessTxs(ptc ProcessTxsConfig, coordIdxs []common.Idx, l1use for i := 0; i < len(l2txs); i++ { exitIdx, exitAccount, newExit, err := s.processL2Tx(coordIdxsMap, collectedFees, exitTree, &l2txs[i]) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } if s.zki != nil { l2TxData, err := l2txs[i].L2Tx().BytesDataAvailability(s.zki.Metadata.NLevels) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } s.zki.Metadata.L2TxsData = append(s.zki.Metadata.L2TxsData, l2TxData) @@ -271,13 +272,13 @@ func (s *StateDB) ProcessTxs(ptc ProcessTxsConfig, coordIdxs []common.Idx, l1use accCoord, err := s.GetAccount(idx) if err != nil { log.Errorw("Can not distribute accumulated fees to coordinator account: No coord Idx to receive fee", "idx", idx) - return nil, err + return nil, tracerr.Wrap(err) } accCoord.Balance = new(big.Int).Add(accCoord.Balance, accumulatedFee) pFee, err := s.UpdateAccount(idx, accCoord) if err != nil { log.Error(err) - return nil, err + return nil, tracerr.Wrap(err) } if s.zki != nil { s.zki.TokenID3[iFee] = accCoord.TokenID.BigInt() @@ -315,7 +316,7 @@ func (s *StateDB) ProcessTxs(ptc ProcessTxsConfig, coordIdxs []common.Idx, l1use // 0. generate MerkleProof p, err := exitTree.GenerateCircomVerifierProof(exitIdx.BigInt(), nil) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } // 1. generate common.ExitInfo ei := common.ExitInfo{ @@ -389,7 +390,7 @@ func (s *StateDB) getFeePlanTokens(coordIdxs []common.Idx, l2txs []common.PoolL2 acc, err := s.GetAccount(coordIdxs[i]) if err != nil { log.Errorf("could not get account to determine TokenID of CoordIdx %d not found: %s", coordIdxs[i], err.Error()) - return nil, err + return nil, tracerr.Wrap(err) } coordTokenIDs[acc.TokenID] = true } @@ -401,7 +402,7 @@ func (s *StateDB) getFeePlanTokens(coordIdxs []common.Idx, l2txs []common.PoolL2 acc, err := s.GetAccount(l2txs[i].FromIdx) if err != nil { log.Errorf("could not get account to determine TokenID of L2Tx: FromIdx %d not found: %s", l2txs[i].FromIdx, err.Error()) - return nil, err + return nil, tracerr.Wrap(err) } if _, ok := coordTokenIDs[acc.TokenID]; ok { tokenIDs[acc.TokenID] = true @@ -429,7 +430,7 @@ func (s *StateDB) processL1Tx(exitTree *merkletree.MerkleTree, tx *common.L1Tx) s.zki.TxCompressedData[s.i], err = tx.TxCompressedData() if err != nil { log.Error(err) - return nil, nil, false, nil, err + return nil, nil, false, nil, tracerr.Wrap(err) } s.zki.FromIdx[s.i] = tx.FromIdx.BigInt() s.zki.ToIdx[s.i] = tx.ToIdx.BigInt() @@ -460,7 +461,7 @@ func (s *StateDB) processL1Tx(exitTree *merkletree.MerkleTree, tx *common.L1Tx) err := s.applyTransfer(nil, nil, tx.Tx(), 0) if err != nil { log.Error(err) - return nil, nil, false, nil, err + return nil, nil, false, nil, tracerr.Wrap(err) } case common.TxTypeCreateAccountDeposit: s.computeEffectiveAmounts(tx) @@ -469,7 +470,7 @@ func (s *StateDB) processL1Tx(exitTree *merkletree.MerkleTree, tx *common.L1Tx) err := s.applyCreateAccount(tx) if err != nil { log.Error(err) - return nil, nil, false, nil, err + return nil, nil, false, nil, tracerr.Wrap(err) } // TODO applyCreateAccount will return the created account, // which in the case type==TypeSynchronizer will be added to an @@ -481,7 +482,7 @@ func (s *StateDB) processL1Tx(exitTree *merkletree.MerkleTree, tx *common.L1Tx) err := s.applyDeposit(tx, false) if err != nil { log.Error(err) - return nil, nil, false, nil, err + return nil, nil, false, nil, tracerr.Wrap(err) } case common.TxTypeDepositTransfer: s.computeEffectiveAmounts(tx) @@ -491,7 +492,7 @@ func (s *StateDB) processL1Tx(exitTree *merkletree.MerkleTree, tx *common.L1Tx) err := s.applyDeposit(tx, true) if err != nil { log.Error(err) - return nil, nil, false, nil, err + return nil, nil, false, nil, tracerr.Wrap(err) } case common.TxTypeCreateAccountDepositTransfer: s.computeEffectiveAmounts(tx) @@ -501,7 +502,7 @@ func (s *StateDB) processL1Tx(exitTree *merkletree.MerkleTree, tx *common.L1Tx) err := s.applyCreateAccountDepositTransfer(tx) if err != nil { log.Error(err) - return nil, nil, false, nil, err + return nil, nil, false, nil, tracerr.Wrap(err) } case common.TxTypeForceExit: s.computeEffectiveAmounts(tx) @@ -511,7 +512,7 @@ func (s *StateDB) processL1Tx(exitTree *merkletree.MerkleTree, tx *common.L1Tx) exitAccount, newExit, err := s.applyExit(nil, nil, exitTree, tx.Tx()) if err != nil { log.Error(err) - return nil, nil, false, nil, err + return nil, nil, false, nil, tracerr.Wrap(err) } return &tx.FromIdx, exitAccount, newExit, nil, nil default: @@ -523,7 +524,7 @@ func (s *StateDB) processL1Tx(exitTree *merkletree.MerkleTree, tx *common.L1Tx) createdAccount, err = s.GetAccount(s.idx) if err != nil { log.Error(err) - return nil, nil, false, nil, err + return nil, nil, false, nil, tracerr.Wrap(err) } } @@ -542,12 +543,12 @@ func (s *StateDB) processL2Tx(coordIdxsMap map[common.TokenID]common.Idx, collec if s.typ == TypeSynchronizer { // this should never be reached log.Error("WARNING: In StateDB with Synchronizer mode L2.ToIdx can't be 0") - return nil, nil, false, fmt.Errorf("In StateDB with Synchronizer mode L2.ToIdx can't be 0") + return nil, nil, false, tracerr.Wrap(fmt.Errorf("In StateDB with Synchronizer mode L2.ToIdx can't be 0")) } // case when tx.Type== common.TxTypeTransferToEthAddr or common.TxTypeTransferToBJJ tx.AuxToIdx, err = s.GetIdxByEthAddrBJJ(tx.ToEthAddr, tx.ToBJJ, tx.TokenID) if err != nil { - return nil, nil, false, err + return nil, nil, false, tracerr.Wrap(err) } } @@ -556,11 +557,11 @@ func (s *StateDB) processL2Tx(coordIdxsMap map[common.TokenID]common.Idx, collec // Txs s.zki.TxCompressedData[s.i], err = tx.TxCompressedData() if err != nil { - return nil, nil, false, err + return nil, nil, false, tracerr.Wrap(err) } s.zki.TxCompressedDataV2[s.i], err = tx.TxCompressedDataV2() if err != nil { - return nil, nil, false, err + return nil, nil, false, tracerr.Wrap(err) } s.zki.FromIdx[s.i] = tx.FromIdx.BigInt() s.zki.ToIdx[s.i] = tx.ToIdx.BigInt() @@ -589,7 +590,7 @@ func (s *StateDB) processL2Tx(coordIdxsMap map[common.TokenID]common.Idx, collec signature, err := tx.Signature.Decompress() if err != nil { log.Error(err) - return nil, nil, false, err + return nil, nil, false, tracerr.Wrap(err) } s.zki.S[s.i] = signature.S s.zki.R8x[s.i] = signature.R8.X @@ -602,7 +603,7 @@ func (s *StateDB) processL2Tx(coordIdxsMap map[common.TokenID]common.Idx, collec acc, err := s.GetAccount(tx.FromIdx) if err != nil { log.Errorw("GetAccount", "fromIdx", tx.FromIdx, "err", err) - return nil, nil, false, err + return nil, nil, false, tracerr.Wrap(err) } tx.Nonce = acc.Nonce + 1 tx.TokenID = acc.TokenID @@ -615,14 +616,14 @@ func (s *StateDB) processL2Tx(coordIdxsMap map[common.TokenID]common.Idx, collec err = s.applyTransfer(coordIdxsMap, collectedFees, tx.Tx(), tx.AuxToIdx) if err != nil { log.Error(err) - return nil, nil, false, err + return nil, nil, false, tracerr.Wrap(err) } case common.TxTypeExit: // execute exit flow exitAccount, newExit, err := s.applyExit(coordIdxsMap, collectedFees, exitTree, tx.Tx()) if err != nil { log.Error(err) - return nil, nil, false, err + return nil, nil, false, tracerr.Wrap(err) } return &tx.FromIdx, exitAccount, newExit, nil default: @@ -643,7 +644,7 @@ func (s *StateDB) applyCreateAccount(tx *common.L1Tx) error { p, err := s.CreateAccount(common.Idx(s.idx+1), account) if err != nil { - return err + return tracerr.Wrap(err) } if s.zki != nil { s.zki.TokenID1[s.i] = tx.TokenID.BigInt() @@ -683,7 +684,7 @@ func (s *StateDB) applyDeposit(tx *common.L1Tx, transfer bool) error { // deposit the tx.EffectiveLoadAmount into the sender account accSender, err := s.GetAccount(tx.FromIdx) if err != nil { - return err + return tracerr.Wrap(err) } accSender.Balance = new(big.Int).Add(accSender.Balance, tx.EffectiveLoadAmount) @@ -692,7 +693,7 @@ func (s *StateDB) applyDeposit(tx *common.L1Tx, transfer bool) error { if transfer { accReceiver, err = s.GetAccount(tx.ToIdx) if err != nil { - return err + return tracerr.Wrap(err) } // subtract amount to the sender accSender.Balance = new(big.Int).Sub(accSender.Balance, tx.EffectiveAmount) @@ -702,7 +703,7 @@ func (s *StateDB) applyDeposit(tx *common.L1Tx, transfer bool) error { // update sender account in localStateDB p, err := s.UpdateAccount(tx.FromIdx, accSender) if err != nil { - return err + return tracerr.Wrap(err) } if s.zki != nil { s.zki.TokenID1[s.i] = accSender.TokenID.BigInt() @@ -722,7 +723,7 @@ func (s *StateDB) applyDeposit(tx *common.L1Tx, transfer bool) error { // update receiver account in localStateDB p, err := s.UpdateAccount(tx.ToIdx, accReceiver) if err != nil { - return err + return tracerr.Wrap(err) } if s.zki != nil { s.zki.TokenID2[s.i] = accReceiver.TokenID.BigInt() @@ -757,7 +758,7 @@ func (s *StateDB) applyTransfer(coordIdxsMap map[common.TokenID]common.Idx, accSender, err := s.GetAccount(tx.FromIdx) if err != nil { log.Error(err) - return err + return tracerr.Wrap(err) } if !tx.IsL1 { // increment nonce @@ -766,7 +767,7 @@ func (s *StateDB) applyTransfer(coordIdxsMap map[common.TokenID]common.Idx, // compute fee and subtract it from the accSender fee, err := common.CalcFeeAmount(tx.Amount, *tx.Fee) if err != nil { - return err + return tracerr.Wrap(err) } feeAndAmount := new(big.Int).Add(tx.Amount, fee) accSender.Balance = new(big.Int).Sub(accSender.Balance, feeAndAmount) @@ -798,7 +799,7 @@ func (s *StateDB) applyTransfer(coordIdxsMap map[common.TokenID]common.Idx, accReceiver, err = s.GetAccount(auxToIdx) if err != nil { log.Error(err) - return err + return tracerr.Wrap(err) } } @@ -809,7 +810,7 @@ func (s *StateDB) applyTransfer(coordIdxsMap map[common.TokenID]common.Idx, pSender, err := s.UpdateAccount(tx.FromIdx, accSender) if err != nil { log.Error(err) - return err + return tracerr.Wrap(err) } if s.zki != nil { s.zki.TokenID1[s.i] = accSender.TokenID.BigInt() @@ -826,7 +827,7 @@ func (s *StateDB) applyTransfer(coordIdxsMap map[common.TokenID]common.Idx, // update receiver account in localStateDB pReceiver, err := s.UpdateAccount(auxToIdx, accReceiver) if err != nil { - return err + return tracerr.Wrap(err) } if s.zki != nil { s.zki.TokenID2[s.i] = accReceiver.TokenID.BigInt() @@ -855,7 +856,7 @@ func (s *StateDB) applyCreateAccountDepositTransfer(tx *common.L1Tx) error { } accReceiver, err := s.GetAccount(tx.ToIdx) if err != nil { - return err + return tracerr.Wrap(err) } // subtract amount to the sender accSender.Balance = new(big.Int).Sub(accSender.Balance, tx.EffectiveAmount) @@ -865,7 +866,7 @@ func (s *StateDB) applyCreateAccountDepositTransfer(tx *common.L1Tx) error { // create Account of the Sender p, err := s.CreateAccount(common.Idx(s.idx+1), accSender) if err != nil { - return err + return tracerr.Wrap(err) } if s.zki != nil { s.zki.TokenID1[s.i] = tx.TokenID.BigInt() @@ -895,7 +896,7 @@ func (s *StateDB) applyCreateAccountDepositTransfer(tx *common.L1Tx) error { // update receiver account in localStateDB p, err = s.UpdateAccount(tx.ToIdx, accReceiver) if err != nil { - return err + return tracerr.Wrap(err) } if s.zki != nil { s.zki.TokenID2[s.i] = accReceiver.TokenID.BigInt() @@ -922,7 +923,7 @@ func (s *StateDB) applyExit(coordIdxsMap map[common.TokenID]common.Idx, // add the tx.Amount into the Account (tx.FromIdx) in the ExitMT acc, err := s.GetAccount(tx.FromIdx) if err != nil { - return nil, false, err + return nil, false, tracerr.Wrap(err) } if !tx.IsL1 { @@ -932,7 +933,7 @@ func (s *StateDB) applyExit(coordIdxsMap map[common.TokenID]common.Idx, // compute fee and subtract it from the accSender fee, err := common.CalcFeeAmount(tx.Amount, *tx.Fee) if err != nil { - return nil, false, err + return nil, false, tracerr.Wrap(err) } feeAndAmount := new(big.Int).Add(tx.Amount, fee) acc.Balance = new(big.Int).Sub(acc.Balance, feeAndAmount) @@ -956,7 +957,7 @@ func (s *StateDB) applyExit(coordIdxsMap map[common.TokenID]common.Idx, p, err := s.UpdateAccount(tx.FromIdx, acc) if err != nil { - return nil, false, err + return nil, false, tracerr.Wrap(err) } if s.zki != nil { s.zki.TokenID1[s.i] = acc.TokenID.BigInt() @@ -974,7 +975,7 @@ func (s *StateDB) applyExit(coordIdxsMap map[common.TokenID]common.Idx, return nil, false, nil } exitAccount, err := getAccountInTreeDB(exitTree.DB(), tx.FromIdx) - if err == db.ErrNotFound { + if tracerr.Unwrap(err) == db.ErrNotFound { // 1a. if idx does not exist in exitTree: // add new leaf 'ExitTreeLeaf', where ExitTreeLeaf.Balance = exitAmount (exitAmount=tx.Amount) exitAccount := &common.Account{ @@ -985,16 +986,16 @@ func (s *StateDB) applyExit(coordIdxsMap map[common.TokenID]common.Idx, EthAddr: acc.EthAddr, } _, err = createAccountInTreeDB(exitTree.DB(), exitTree, tx.FromIdx, exitAccount) - return exitAccount, true, err + return exitAccount, true, tracerr.Wrap(err) } else if err != nil { - return exitAccount, false, err + return exitAccount, false, tracerr.Wrap(err) } // 1b. if idx already exist in exitTree: // update account, where account.Balance += exitAmount exitAccount.Balance = new(big.Int).Add(exitAccount.Balance, tx.Amount) _, err = updateAccountInTreeDB(exitTree.DB(), exitTree, tx.FromIdx, exitAccount) - return exitAccount, false, err + return exitAccount, false, tracerr.Wrap(err) } // computeEffectiveAmounts checks that the L1Tx data is correct @@ -1084,11 +1085,11 @@ func (s *StateDB) computeEffectiveAmounts(tx *common.L1Tx) { // used for an Account in the localStateDB. func (s *StateDB) getIdx() (common.Idx, error) { idxBytes, err := s.DB().Get(keyidx) - if err == db.ErrNotFound { + if tracerr.Unwrap(err) == db.ErrNotFound { return 0, nil } if err != nil { - return 0, err + return 0, tracerr.Wrap(err) } return common.IdxFromBytes(idxBytes[:]) } @@ -1097,18 +1098,18 @@ func (s *StateDB) getIdx() (common.Idx, error) { func (s *StateDB) setIdx(idx common.Idx) error { tx, err := s.DB().NewTx() if err != nil { - return err + return tracerr.Wrap(err) } idxBytes, err := idx.Bytes() if err != nil { - return err + return tracerr.Wrap(err) } err = tx.Put(keyidx, idxBytes[:]) if err != nil { - return err + return tracerr.Wrap(err) } if err := tx.Commit(); err != nil { - return err + return tracerr.Wrap(err) } return nil } diff --git a/db/statedb/utils.go b/db/statedb/utils.go index fc09095..6c88ce1 100644 --- a/db/statedb/utils.go +++ b/db/statedb/utils.go @@ -8,6 +8,7 @@ import ( ethCommon "github.com/ethereum/go-ethereum/common" "github.com/hermeznetwork/hermez-node/common" "github.com/hermeznetwork/hermez-node/log" + "github.com/hermeznetwork/tracerr" "github.com/iden3/go-iden3-crypto/babyjub" "github.com/iden3/go-merkletree" ) @@ -46,7 +47,7 @@ func (s *StateDB) setIdxByEthAddrBJJ(idx common.Idx, addr ethCommon.Address, pk } if pk == nil { - return fmt.Errorf("BabyJubJub pk not defined") + return tracerr.Wrap(fmt.Errorf("BabyJubJub pk not defined")) } // store idx for EthAddr & BJJ assuming that EthAddr & BJJ still don't @@ -55,28 +56,28 @@ func (s *StateDB) setIdxByEthAddrBJJ(idx common.Idx, addr ethCommon.Address, pk // (smaller) tx, err := s.db.NewTx() if err != nil { - return err + return tracerr.Wrap(err) } idxBytes, err := idx.Bytes() if err != nil { - return err + return tracerr.Wrap(err) } // store Addr&BJJ-idx k := concatEthAddrBJJTokenID(addr, pk, tokenID) err = tx.Put(append(PrefixKeyAddrBJJ, k...), idxBytes[:]) if err != nil { - return err + return tracerr.Wrap(err) } // store Addr-idx k = concatEthAddrTokenID(addr, tokenID) err = tx.Put(append(PrefixKeyAddr, k...), idxBytes[:]) if err != nil { - return err + return tracerr.Wrap(err) } err = tx.Commit() if err != nil { - return err + return tracerr.Wrap(err) } return nil } @@ -88,11 +89,11 @@ func (s *StateDB) GetIdxByEthAddr(addr ethCommon.Address, tokenID common.TokenID k := concatEthAddrTokenID(addr, tokenID) b, err := s.db.Get(append(PrefixKeyAddr, k...)) if err != nil { - return common.Idx(0), fmt.Errorf("GetIdxByEthAddr: %s: ToEthAddr: %s, TokenID: %d", ErrToIdxNotFound, addr.Hex(), tokenID) + return common.Idx(0), tracerr.Wrap(fmt.Errorf("GetIdxByEthAddr: %s: ToEthAddr: %s, TokenID: %d", ErrToIdxNotFound, addr.Hex(), tokenID)) } idx, err := common.IdxFromBytes(b) if err != nil { - return common.Idx(0), fmt.Errorf("GetIdxByEthAddr: %s: ToEthAddr: %s, TokenID: %d", err, addr.Hex(), tokenID) + return common.Idx(0), tracerr.Wrap(fmt.Errorf("GetIdxByEthAddr: %s: ToEthAddr: %s, TokenID: %d", err, addr.Hex(), tokenID)) } return idx, nil } @@ -112,16 +113,16 @@ func (s *StateDB) GetIdxByEthAddrBJJ(addr ethCommon.Address, pk *babyjub.PublicK k := concatEthAddrBJJTokenID(addr, pk, tokenID) b, err := s.db.Get(append(PrefixKeyAddrBJJ, k...)) if err != nil { - return common.Idx(0), fmt.Errorf("GetIdxByEthAddrBJJ: %s: ToEthAddr: %s, ToBJJ: %s, TokenID: %d", ErrToIdxNotFound, addr.Hex(), pk, tokenID) + return common.Idx(0), tracerr.Wrap(fmt.Errorf("GetIdxByEthAddrBJJ: %s: ToEthAddr: %s, ToBJJ: %s, TokenID: %d", ErrToIdxNotFound, addr.Hex(), pk, tokenID)) } idx, err := common.IdxFromBytes(b) if err != nil { - return common.Idx(0), fmt.Errorf("GetIdxByEthAddrBJJ: %s: ToEthAddr: %s, ToBJJ: %s, TokenID: %d", err, addr.Hex(), pk, tokenID) + return common.Idx(0), tracerr.Wrap(fmt.Errorf("GetIdxByEthAddrBJJ: %s: ToEthAddr: %s, ToBJJ: %s, TokenID: %d", err, addr.Hex(), pk, tokenID)) } return idx, nil } // rest of cases (included case ToEthAddr==0) are not possible - return common.Idx(0), fmt.Errorf("GetIdxByEthAddrBJJ: Not found, %s: ToEthAddr: %s, ToBJJ: %s, TokenID: %d", ErrGetIdxNoCase, addr.Hex(), pk, tokenID) + return common.Idx(0), tracerr.Wrap(fmt.Errorf("GetIdxByEthAddrBJJ: Not found, %s: ToEthAddr: %s, ToBJJ: %s, TokenID: %d", ErrGetIdxNoCase, addr.Hex(), pk, tokenID)) } func (s *StateDB) getTokenIDsFromIdxs(idxs []common.Idx) (map[common.TokenID]common.Idx, error) { @@ -129,7 +130,7 @@ func (s *StateDB) getTokenIDsFromIdxs(idxs []common.Idx) (map[common.TokenID]com for i := 0; i < len(idxs); i++ { a, err := s.GetAccount(idxs[i]) if err != nil { - return nil, fmt.Errorf("getTokenIDsFromIdxs error on GetAccount with Idx==%d: %s", idxs[i], err.Error()) + return nil, tracerr.Wrap(fmt.Errorf("getTokenIDsFromIdxs error on GetAccount with Idx==%d: %s", idxs[i], err.Error())) } m[a.TokenID] = idxs[i] } diff --git a/db/statedb/utils_test.go b/db/statedb/utils_test.go index 9fd3e5d..90d9566 100644 --- a/db/statedb/utils_test.go +++ b/db/statedb/utils_test.go @@ -9,6 +9,7 @@ import ( ethCommon "github.com/ethereum/go-ethereum/common" "github.com/hermeznetwork/hermez-node/common" + "github.com/hermeznetwork/tracerr" "github.com/iden3/go-iden3-crypto/babyjub" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -84,7 +85,7 @@ func TestGetIdx(t *testing.T) { idxR, err = sdb.GetIdxByEthAddrBJJ(addr2, pk2, tokenID0) assert.NotNil(t, err) expectedErr := fmt.Errorf("GetIdxByEthAddrBJJ: %s: ToEthAddr: %s, ToBJJ: %s, TokenID: %d", ErrToIdxNotFound, addr2.Hex(), pk2, tokenID0) - assert.Equal(t, expectedErr, err) + assert.Equal(t, expectedErr, tracerr.Unwrap(err)) assert.Equal(t, common.Idx(0), idxR) // expect error when trying to get Idx by addr with not used TokenID _, err = sdb.GetIdxByEthAddr(addr, tokenID1) diff --git a/db/utils.go b/db/utils.go index 0e3a594..d3f64b4 100644 --- a/db/utils.go +++ b/db/utils.go @@ -8,6 +8,7 @@ import ( "github.com/gobuffalo/packr/v2" "github.com/hermeznetwork/hermez-node/log" + "github.com/hermeznetwork/tracerr" "github.com/jmoiron/sqlx" migrate "github.com/rubenv/sql-migrate" "github.com/russross/meddler" @@ -29,7 +30,7 @@ func InitSQLDB(port int, host, user, password, name string) (*sqlx.DB, error) { ) db, err := sqlx.Connect("postgres", psqlconn) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } // Run DB migrations migrations := &migrate.PackrMigrationSource{ @@ -37,7 +38,7 @@ func InitSQLDB(port int, host, user, password, name string) (*sqlx.DB, error) { } nMigrations, err := migrate.Exec(db.DB, "postgres", migrations, migrate.Up) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } log.Info("successfully ran ", nMigrations, " migrations") return db, nil @@ -64,7 +65,7 @@ func BulkInsert(db meddler.DB, q string, args interface{}) error { arg := arrayValue.Index(i).Addr().Interface() elemArglist, err := meddler.Default.Values(arg, true) if err != nil { - return err + return tracerr.Wrap(err) } arglist = append(arglist, elemArglist...) value := "(" @@ -76,7 +77,7 @@ func BulkInsert(db meddler.DB, q string, args interface{}) error { } stmt := fmt.Sprintf(q, strings.Join(valueStrings, ",")) _, err := db.Exec(stmt, arglist...) - return err + return tracerr.Wrap(err) } // BigIntMeddler encodes or decodes the field value to or from JSON @@ -92,7 +93,7 @@ func (b BigIntMeddler) PreRead(fieldAddr interface{}) (scanTarget interface{}, e func (b BigIntMeddler) PostRead(fieldPtr, scanTarget interface{}) error { ptr := scanTarget.(*string) if ptr == nil { - return fmt.Errorf("BigIntMeddler.PostRead: nil pointer") + return tracerr.Wrap(fmt.Errorf("BigIntMeddler.PostRead: nil pointer")) } field := fieldPtr.(**big.Int) *field = new(big.Int).SetBytes([]byte(*ptr)) @@ -126,7 +127,7 @@ func (b BigIntNullMeddler) PostRead(fieldPtr, scanTarget interface{}) error { // not null ptr := (*ptrPtr).([]byte) if ptr == nil { - return fmt.Errorf("BigIntMeddler.PostRead: nil pointer") + return tracerr.Wrap(fmt.Errorf("BigIntMeddler.PostRead: nil pointer")) } *field = new(big.Int).SetBytes(ptr) return nil diff --git a/eth/auction.go b/eth/auction.go index e022ee8..cf23bcf 100644 --- a/eth/auction.go +++ b/eth/auction.go @@ -17,6 +17,7 @@ import ( HermezAuctionProtocol "github.com/hermeznetwork/hermez-node/eth/contracts/auction" HEZ "github.com/hermeznetwork/hermez-node/eth/contracts/tokenHEZ" "github.com/hermeznetwork/hermez-node/log" + "github.com/hermeznetwork/tracerr" ) // SlotState is the state of a slot @@ -238,15 +239,15 @@ type AuctionClient struct { func NewAuctionClient(client *EthereumClient, address ethCommon.Address, tokenHEZCfg TokenConfig) (*AuctionClient, error) { contractAbi, err := abi.JSON(strings.NewReader(string(HermezAuctionProtocol.HermezAuctionProtocolABI))) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(address, client.Client()) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } tokenHEZ, err := HEZ.NewHEZ(tokenHEZCfg.Address, client.Client()) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &AuctionClient{ client: client, @@ -268,7 +269,7 @@ func (c *AuctionClient) AuctionSetSlotDeadline(newDeadline uint8) (*types.Transa return c.auction.SetSlotDeadline(auth, newDeadline) }, ); err != nil { - return nil, fmt.Errorf("Failed setting slotDeadline: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed setting slotDeadline: %w", err)) } return tx, nil } @@ -277,9 +278,9 @@ func (c *AuctionClient) AuctionSetSlotDeadline(newDeadline uint8) (*types.Transa func (c *AuctionClient) AuctionGetSlotDeadline() (slotDeadline uint8, err error) { if err := c.client.Call(func(ec *ethclient.Client) error { slotDeadline, err = c.auction.GetSlotDeadline(nil) - return err + return tracerr.Wrap(err) }); err != nil { - return 0, err + return 0, tracerr.Wrap(err) } return slotDeadline, nil } @@ -292,7 +293,7 @@ func (c *AuctionClient) AuctionSetOpenAuctionSlots(newOpenAuctionSlots uint16) ( return c.auction.SetOpenAuctionSlots(auth, newOpenAuctionSlots) }, ); err != nil { - return nil, fmt.Errorf("Failed setting openAuctionSlots: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed setting openAuctionSlots: %w", err)) } return tx, nil } @@ -301,9 +302,9 @@ func (c *AuctionClient) AuctionSetOpenAuctionSlots(newOpenAuctionSlots uint16) ( func (c *AuctionClient) AuctionGetOpenAuctionSlots() (openAuctionSlots uint16, err error) { if err := c.client.Call(func(ec *ethclient.Client) error { openAuctionSlots, err = c.auction.GetOpenAuctionSlots(nil) - return err + return tracerr.Wrap(err) }); err != nil { - return 0, err + return 0, tracerr.Wrap(err) } return openAuctionSlots, nil } @@ -316,7 +317,7 @@ func (c *AuctionClient) AuctionSetClosedAuctionSlots(newClosedAuctionSlots uint1 return c.auction.SetClosedAuctionSlots(auth, newClosedAuctionSlots) }, ); err != nil { - return nil, fmt.Errorf("Failed setting closedAuctionSlots: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed setting closedAuctionSlots: %w", err)) } return tx, nil } @@ -325,9 +326,9 @@ func (c *AuctionClient) AuctionSetClosedAuctionSlots(newClosedAuctionSlots uint1 func (c *AuctionClient) AuctionGetClosedAuctionSlots() (closedAuctionSlots uint16, err error) { if err := c.client.Call(func(ec *ethclient.Client) error { closedAuctionSlots, err = c.auction.GetClosedAuctionSlots(nil) - return err + return tracerr.Wrap(err) }); err != nil { - return 0, err + return 0, tracerr.Wrap(err) } return closedAuctionSlots, nil } @@ -340,7 +341,7 @@ func (c *AuctionClient) AuctionSetOutbidding(newOutbidding uint16) (tx *types.Tr return c.auction.SetOutbidding(auth, newOutbidding) }, ); err != nil { - return nil, fmt.Errorf("Failed setting setOutbidding: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed setting setOutbidding: %w", err)) } return tx, nil } @@ -349,9 +350,9 @@ func (c *AuctionClient) AuctionSetOutbidding(newOutbidding uint16) (tx *types.Tr func (c *AuctionClient) AuctionGetOutbidding() (outbidding uint16, err error) { if err := c.client.Call(func(ec *ethclient.Client) error { outbidding, err = c.auction.GetOutbidding(nil) - return err + return tracerr.Wrap(err) }); err != nil { - return 0, err + return 0, tracerr.Wrap(err) } return outbidding, nil } @@ -364,7 +365,7 @@ func (c *AuctionClient) AuctionSetAllocationRatio(newAllocationRatio [3]uint16) return c.auction.SetAllocationRatio(auth, newAllocationRatio) }, ); err != nil { - return nil, fmt.Errorf("Failed setting allocationRatio: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed setting allocationRatio: %w", err)) } return tx, nil } @@ -373,9 +374,9 @@ func (c *AuctionClient) AuctionSetAllocationRatio(newAllocationRatio [3]uint16) func (c *AuctionClient) AuctionGetAllocationRatio() (allocationRation [3]uint16, err error) { if err := c.client.Call(func(ec *ethclient.Client) error { allocationRation, err = c.auction.GetAllocationRatio(nil) - return err + return tracerr.Wrap(err) }); err != nil { - return [3]uint16{}, err + return [3]uint16{}, tracerr.Wrap(err) } return allocationRation, nil } @@ -388,7 +389,7 @@ func (c *AuctionClient) AuctionSetDonationAddress(newDonationAddress ethCommon.A return c.auction.SetDonationAddress(auth, newDonationAddress) }, ); err != nil { - return nil, fmt.Errorf("Failed setting donationAddress: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed setting donationAddress: %w", err)) } return tx, nil } @@ -398,9 +399,9 @@ func (c *AuctionClient) AuctionGetDonationAddress() (donationAddress *ethCommon. var _donationAddress ethCommon.Address if err := c.client.Call(func(ec *ethclient.Client) error { _donationAddress, err = c.auction.GetDonationAddress(nil) - return err + return tracerr.Wrap(err) }); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &_donationAddress, nil } @@ -413,7 +414,7 @@ func (c *AuctionClient) AuctionSetBootCoordinator(newBootCoordinator ethCommon.A return c.auction.SetBootCoordinator(auth, newBootCoordinator) }, ); err != nil { - return nil, fmt.Errorf("Failed setting bootCoordinator: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed setting bootCoordinator: %w", err)) } return tx, nil } @@ -423,9 +424,9 @@ func (c *AuctionClient) AuctionGetBootCoordinator() (bootCoordinator *ethCommon. var _bootCoordinator ethCommon.Address if err := c.client.Call(func(ec *ethclient.Client) error { _bootCoordinator, err = c.auction.GetBootCoordinator(nil) - return err + return tracerr.Wrap(err) }); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &_bootCoordinator, nil } @@ -439,7 +440,7 @@ func (c *AuctionClient) AuctionChangeDefaultSlotSetBid(slotSet int64, newInitial return c.auction.ChangeDefaultSlotSetBid(auth, slotSetToSend, newInitialMinBid) }, ); err != nil { - return nil, fmt.Errorf("Failed changing slotSet Bid: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed changing slotSet Bid: %w", err)) } return tx, nil } @@ -448,9 +449,9 @@ func (c *AuctionClient) AuctionChangeDefaultSlotSetBid(slotSet int64, newInitial func (c *AuctionClient) AuctionGetClaimableHEZ(claimAddress ethCommon.Address) (claimableHEZ *big.Int, err error) { if err := c.client.Call(func(ec *ethclient.Client) error { claimableHEZ, err = c.auction.GetClaimableHEZ(nil, claimAddress) - return err + return tracerr.Wrap(err) }); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return claimableHEZ, nil } @@ -463,7 +464,7 @@ func (c *AuctionClient) AuctionSetCoordinator(forger ethCommon.Address, coordina return c.auction.SetCoordinator(auth, forger, coordinatorURL) }, ); err != nil { - return nil, fmt.Errorf("Failed set coordinator: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed set coordinator: %w", err)) } return tx, nil } @@ -473,9 +474,9 @@ func (c *AuctionClient) AuctionGetCurrentSlotNumber() (currentSlotNumber int64, var _currentSlotNumber *big.Int if err := c.client.Call(func(ec *ethclient.Client) error { _currentSlotNumber, err = c.auction.GetCurrentSlotNumber(nil) - return err + return tracerr.Wrap(err) }); err != nil { - return 0, err + return 0, tracerr.Wrap(err) } return _currentSlotNumber.Int64(), nil } @@ -485,9 +486,9 @@ func (c *AuctionClient) AuctionGetMinBidBySlot(slot int64) (minBid *big.Int, err if err := c.client.Call(func(ec *ethclient.Client) error { slotToSend := big.NewInt(slot) minBid, err = c.auction.GetMinBidBySlot(nil, slotToSend) - return err + return tracerr.Wrap(err) }); err != nil { - return big.NewInt(0), err + return big.NewInt(0), tracerr.Wrap(err) } return minBid, nil } @@ -497,9 +498,9 @@ func (c *AuctionClient) AuctionGetSlotSet(slot int64) (slotSet *big.Int, err err if err := c.client.Call(func(ec *ethclient.Client) error { slotToSend := big.NewInt(slot) slotSet, err = c.auction.GetSlotSet(nil, slotToSend) - return err + return tracerr.Wrap(err) }); err != nil { - return big.NewInt(0), err + return big.NewInt(0), tracerr.Wrap(err) } return slotSet, nil } @@ -508,9 +509,9 @@ func (c *AuctionClient) AuctionGetSlotSet(slot int64) (slotSet *big.Int, err err func (c *AuctionClient) AuctionGetDefaultSlotSetBid(slotSet uint8) (minBidSlotSet *big.Int, err error) { if err := c.client.Call(func(ec *ethclient.Client) error { minBidSlotSet, err = c.auction.GetDefaultSlotSetBid(nil, slotSet) - return err + return tracerr.Wrap(err) }); err != nil { - return big.NewInt(0), err + return big.NewInt(0), tracerr.Wrap(err) } return minBidSlotSet, nil } @@ -520,9 +521,9 @@ func (c *AuctionClient) AuctionGetSlotNumber(blockNum int64) (slot int64, err er var _slot *big.Int if err := c.client.Call(func(ec *ethclient.Client) error { _slot, err = c.auction.GetSlotNumber(nil, big.NewInt(blockNum)) - return err + return tracerr.Wrap(err) }); err != nil { - return 0, err + return 0, tracerr.Wrap(err) } return _slot.Int64(), nil } @@ -536,7 +537,7 @@ func (c *AuctionClient) AuctionBid(amount *big.Int, slot int64, bidAmount *big.I spender := c.address nonce, err := c.tokenHEZ.Nonces(nil, owner) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } tokenName := c.tokenHEZCfg.Name tokenAddr := c.tokenHEZCfg.Address @@ -548,7 +549,7 @@ func (c *AuctionClient) AuctionBid(amount *big.Int, slot int64, bidAmount *big.I return c.auction.ProcessBid(auth, amount, _slot, bidAmount, permit) }, ); err != nil { - return nil, fmt.Errorf("Failed bid: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed bid: %w", err)) } return tx, nil } @@ -563,7 +564,7 @@ func (c *AuctionClient) AuctionMultiBid(amount *big.Int, startingSlot, endingSlo spender := c.address nonce, err := c.tokenHEZ.Nonces(nil, owner) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } tokenName := c.tokenHEZCfg.Name tokenAddr := c.tokenHEZCfg.Address @@ -577,7 +578,7 @@ func (c *AuctionClient) AuctionMultiBid(amount *big.Int, startingSlot, endingSlo return c.auction.ProcessMultiBid(auth, amount, _startingSlot, _endingSlot, slotSets, maxBid, minBid, permit) }, ); err != nil { - return nil, fmt.Errorf("Failed multibid: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed multibid: %w", err)) } return tx, nil } @@ -586,9 +587,9 @@ func (c *AuctionClient) AuctionMultiBid(amount *big.Int, startingSlot, endingSlo func (c *AuctionClient) AuctionCanForge(forger ethCommon.Address, blockNum int64) (canForge bool, err error) { if err := c.client.Call(func(ec *ethclient.Client) error { canForge, err = c.auction.CanForge(nil, forger, big.NewInt(blockNum)) - return err + return tracerr.Wrap(err) }); err != nil { - return false, err + return false, tracerr.Wrap(err) } return canForge, nil } @@ -601,7 +602,7 @@ func (c *AuctionClient) AuctionClaimHEZ() (tx *types.Transaction, err error) { return c.auction.ClaimHEZ(auth) }, ); err != nil { - return nil, fmt.Errorf("Failed claim HEZ: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed claim HEZ: %w", err)) } return tx, nil } @@ -614,7 +615,7 @@ func (c *AuctionClient) AuctionForge(forger ethCommon.Address) (tx *types.Transa return c.auction.Forge(auth, forger) }, ); err != nil { - return nil, fmt.Errorf("Failed forge: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed forge: %w", err)) } return tx, nil } @@ -625,25 +626,25 @@ func (c *AuctionClient) AuctionConstants() (auctionConstants *common.AuctionCons if err := c.client.Call(func(ec *ethclient.Client) error { auctionConstants.BlocksPerSlot, err = c.auction.BLOCKSPERSLOT(nil) if err != nil { - return err + return tracerr.Wrap(err) } genesisBlock, err := c.auction.GenesisBlock(nil) if err != nil { - return err + return tracerr.Wrap(err) } auctionConstants.GenesisBlockNum = genesisBlock.Int64() auctionConstants.HermezRollup, err = c.auction.HermezRollup(nil) if err != nil { - return err + return tracerr.Wrap(err) } auctionConstants.InitialMinimalBidding, err = c.auction.INITIALMINIMALBIDDING(nil) if err != nil { - return err + return tracerr.Wrap(err) } auctionConstants.TokenHEZ, err = c.auction.TokenHEZ(nil) - return err + return tracerr.Wrap(err) }); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return auctionConstants, nil } @@ -654,43 +655,43 @@ func (c *AuctionClient) AuctionVariables() (auctionVariables *common.AuctionVari if err := c.client.Call(func(ec *ethclient.Client) error { auctionVariables.AllocationRatio, err = c.AuctionGetAllocationRatio() if err != nil { - return err + return tracerr.Wrap(err) } bootCoordinator, err := c.AuctionGetBootCoordinator() if err != nil { - return err + return tracerr.Wrap(err) } auctionVariables.BootCoordinator = *bootCoordinator auctionVariables.ClosedAuctionSlots, err = c.AuctionGetClosedAuctionSlots() if err != nil { - return err + return tracerr.Wrap(err) } var defaultSlotSetBid [6]*big.Int for i := uint8(0); i < 6; i++ { bid, err := c.AuctionGetDefaultSlotSetBid(i) if err != nil { - return err + return tracerr.Wrap(err) } defaultSlotSetBid[i] = bid } auctionVariables.DefaultSlotSetBid = defaultSlotSetBid donationAddress, err := c.AuctionGetDonationAddress() if err != nil { - return err + return tracerr.Wrap(err) } auctionVariables.DonationAddress = *donationAddress auctionVariables.OpenAuctionSlots, err = c.AuctionGetOpenAuctionSlots() if err != nil { - return err + return tracerr.Wrap(err) } auctionVariables.Outbidding, err = c.AuctionGetOutbidding() if err != nil { - return err + return tracerr.Wrap(err) } auctionVariables.SlotDeadline, err = c.AuctionGetSlotDeadline() - return err + return tracerr.Wrap(err) }); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return auctionVariables, nil } @@ -729,7 +730,7 @@ func (c *AuctionClient) AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *e logs, err := c.client.client.FilterLogs(context.TODO(), query) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } if len(logs) > 0 { blockHash = &logs[0].BlockHash @@ -737,7 +738,7 @@ func (c *AuctionClient) AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *e for _, vLog := range logs { if vLog.BlockHash != *blockHash { log.Errorw("Block hash mismatch", "expected", blockHash.String(), "got", vLog.BlockHash.String()) - return nil, nil, ErrBlockHashMismatchEvent + return nil, nil, tracerr.Wrap(ErrBlockHashMismatchEvent) } switch vLog.Topics[0] { case logAuctionNewBid: @@ -748,7 +749,7 @@ func (c *AuctionClient) AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *e } var newBid AuctionEventNewBid if err := c.contractAbi.Unpack(&auxNewBid, "NewBid", vLog.Data); err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } newBid.BidAmount = auxNewBid.BidAmount newBid.Slot = new(big.Int).SetBytes(vLog.Topics[1][:]).Int64() @@ -757,19 +758,19 @@ func (c *AuctionClient) AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *e case logAuctionNewSlotDeadline: var newSlotDeadline AuctionEventNewSlotDeadline if err := c.contractAbi.Unpack(&newSlotDeadline, "NewSlotDeadline", vLog.Data); err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } auctionEvents.NewSlotDeadline = append(auctionEvents.NewSlotDeadline, newSlotDeadline) case logAuctionNewClosedAuctionSlots: var newClosedAuctionSlots AuctionEventNewClosedAuctionSlots if err := c.contractAbi.Unpack(&newClosedAuctionSlots, "NewClosedAuctionSlots", vLog.Data); err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } auctionEvents.NewClosedAuctionSlots = append(auctionEvents.NewClosedAuctionSlots, newClosedAuctionSlots) case logAuctionNewOutbidding: var newOutbidding AuctionEventNewOutbidding if err := c.contractAbi.Unpack(&newOutbidding, "NewOutbidding", vLog.Data); err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } auctionEvents.NewOutbidding = append(auctionEvents.NewOutbidding, newOutbidding) case logAuctionNewDonationAddress: @@ -783,19 +784,19 @@ func (c *AuctionClient) AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *e case logAuctionNewOpenAuctionSlots: var newOpenAuctionSlots AuctionEventNewOpenAuctionSlots if err := c.contractAbi.Unpack(&newOpenAuctionSlots, "NewOpenAuctionSlots", vLog.Data); err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } auctionEvents.NewOpenAuctionSlots = append(auctionEvents.NewOpenAuctionSlots, newOpenAuctionSlots) case logAuctionNewAllocationRatio: var newAllocationRatio AuctionEventNewAllocationRatio if err := c.contractAbi.Unpack(&newAllocationRatio, "NewAllocationRatio", vLog.Data); err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } auctionEvents.NewAllocationRatio = append(auctionEvents.NewAllocationRatio, newAllocationRatio) case logAuctionSetCoordinator: var setCoordinator AuctionEventSetCoordinator if err := c.contractAbi.Unpack(&setCoordinator, "SetCoordinator", vLog.Data); err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } setCoordinator.BidderAddress = ethCommon.BytesToAddress(vLog.Topics[1].Bytes()) setCoordinator.ForgerAddress = ethCommon.BytesToAddress(vLog.Topics[2].Bytes()) @@ -803,7 +804,7 @@ func (c *AuctionClient) AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *e case logAuctionNewForgeAllocated: var newForgeAllocated AuctionEventNewForgeAllocated if err := c.contractAbi.Unpack(&newForgeAllocated, "NewForgeAllocated", vLog.Data); err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } newForgeAllocated.Bidder = ethCommon.BytesToAddress(vLog.Topics[1].Bytes()) newForgeAllocated.Forger = ethCommon.BytesToAddress(vLog.Topics[2].Bytes()) @@ -816,7 +817,7 @@ func (c *AuctionClient) AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *e } var newDefaultSlotSetBid AuctionEventNewDefaultSlotSetBid if err := c.contractAbi.Unpack(&auxNewDefaultSlotSetBid, "NewDefaultSlotSetBid", vLog.Data); err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } newDefaultSlotSetBid.NewInitialMinBid = auxNewDefaultSlotSetBid.NewInitialMinBid newDefaultSlotSetBid.SlotSet = auxNewDefaultSlotSetBid.SlotSet.Int64() @@ -829,7 +830,7 @@ func (c *AuctionClient) AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *e case logAuctionHEZClaimed: var HEZClaimed AuctionEventHEZClaimed if err := c.contractAbi.Unpack(&HEZClaimed, "HEZClaimed", vLog.Data); err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } HEZClaimed.Owner = ethCommon.BytesToAddress(vLog.Topics[1].Bytes()) auctionEvents.HEZClaimed = append(auctionEvents.HEZClaimed, HEZClaimed) diff --git a/eth/client.go b/eth/client.go index 3d9feb8..4401b0d 100644 --- a/eth/client.go +++ b/eth/client.go @@ -7,6 +7,7 @@ import ( ethKeystore "github.com/ethereum/go-ethereum/accounts/keystore" ethCommon "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethclient" + "github.com/hermeznetwork/tracerr" ) var errTODO = fmt.Errorf("TODO: Not implemented yet") @@ -67,15 +68,15 @@ func NewClient(client *ethclient.Client, account *accounts.Account, ks *ethKeyst ethereumClient := NewEthereumClient(client, account, ks, &cfg.Ethereum) auctionClient, err := NewAuctionClient(ethereumClient, cfg.Auction.Address, cfg.Auction.TokenHEZ) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } rollupClient, err := NewRollupClient(ethereumClient, cfg.Rollup.Address, cfg.Auction.TokenHEZ) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } wDelayerClient, err := NewWDelayerClient(ethereumClient, cfg.WDelayer.Address) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &Client{ EthereumClient: *ethereumClient, diff --git a/eth/contracts/auction/HermezAuctionProtocol.go b/eth/contracts/auction/HermezAuctionProtocol.go index 1be1037..8dc9c08 100644 --- a/eth/contracts/auction/HermezAuctionProtocol.go +++ b/eth/contracts/auction/HermezAuctionProtocol.go @@ -13,6 +13,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/event" + "github.com/hermeznetwork/tracerr" ) // Reference imports to suppress errors if they are not otherwise used. @@ -36,12 +37,12 @@ var HermezAuctionProtocolBin = "0x608060405234801561001057600080fd5b50613d678061 func DeployHermezAuctionProtocol(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *HermezAuctionProtocol, error) { parsed, err := abi.JSON(strings.NewReader(HermezAuctionProtocolABI)) if err != nil { - return common.Address{}, nil, nil, err + return common.Address{}, nil, nil, tracerr.Wrap(err) } address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(HermezAuctionProtocolBin), backend) if err != nil { - return common.Address{}, nil, nil, err + return common.Address{}, nil, nil, tracerr.Wrap(err) } return address, tx, &HermezAuctionProtocol{HermezAuctionProtocolCaller: HermezAuctionProtocolCaller{contract: contract}, HermezAuctionProtocolTransactor: HermezAuctionProtocolTransactor{contract: contract}, HermezAuctionProtocolFilterer: HermezAuctionProtocolFilterer{contract: contract}}, nil } @@ -109,7 +110,7 @@ type HermezAuctionProtocolTransactorRaw struct { func NewHermezAuctionProtocol(address common.Address, backend bind.ContractBackend) (*HermezAuctionProtocol, error) { contract, err := bindHermezAuctionProtocol(address, backend, backend, backend) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezAuctionProtocol{HermezAuctionProtocolCaller: HermezAuctionProtocolCaller{contract: contract}, HermezAuctionProtocolTransactor: HermezAuctionProtocolTransactor{contract: contract}, HermezAuctionProtocolFilterer: HermezAuctionProtocolFilterer{contract: contract}}, nil } @@ -118,7 +119,7 @@ func NewHermezAuctionProtocol(address common.Address, backend bind.ContractBacke func NewHermezAuctionProtocolCaller(address common.Address, caller bind.ContractCaller) (*HermezAuctionProtocolCaller, error) { contract, err := bindHermezAuctionProtocol(address, caller, nil, nil) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezAuctionProtocolCaller{contract: contract}, nil } @@ -127,7 +128,7 @@ func NewHermezAuctionProtocolCaller(address common.Address, caller bind.Contract func NewHermezAuctionProtocolTransactor(address common.Address, transactor bind.ContractTransactor) (*HermezAuctionProtocolTransactor, error) { contract, err := bindHermezAuctionProtocol(address, nil, transactor, nil) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezAuctionProtocolTransactor{contract: contract}, nil } @@ -136,7 +137,7 @@ func NewHermezAuctionProtocolTransactor(address common.Address, transactor bind. func NewHermezAuctionProtocolFilterer(address common.Address, filterer bind.ContractFilterer) (*HermezAuctionProtocolFilterer, error) { contract, err := bindHermezAuctionProtocol(address, nil, nil, filterer) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezAuctionProtocolFilterer{contract: contract}, nil } @@ -145,7 +146,7 @@ func NewHermezAuctionProtocolFilterer(address common.Address, filterer bind.Cont func bindHermezAuctionProtocol(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { parsed, err := abi.JSON(strings.NewReader(HermezAuctionProtocolABI)) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil } @@ -197,7 +198,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) BLOCKSPERSLOT(opts *b ) out := ret0 err := _HermezAuctionProtocol.contract.Call(opts, out, "BLOCKS_PER_SLOT") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // BLOCKSPERSLOT is a free data retrieval call binding the contract method 0x2243de47. @@ -223,7 +224,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) INITIALMINIMALBIDDING ) out := ret0 err := _HermezAuctionProtocol.contract.Call(opts, out, "INITIAL_MINIMAL_BIDDING") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // INITIALMINIMALBIDDING is a free data retrieval call binding the contract method 0xe6065914. @@ -249,7 +250,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) CanForge(opts *bind.C ) out := ret0 err := _HermezAuctionProtocol.contract.Call(opts, out, "canForge", forger, blockNumber) - return *ret0, err + return *ret0, tracerr.Wrap(err) } // CanForge is a free data retrieval call binding the contract method 0x83b1f6a0. @@ -279,7 +280,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) Coordinators(opts *bi }) out := ret err := _HermezAuctionProtocol.contract.Call(opts, out, "coordinators", arg0) - return *ret, err + return *ret, tracerr.Wrap(err) } // Coordinators is a free data retrieval call binding the contract method 0xa48af096. @@ -311,7 +312,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) GenesisBlock(opts *bi ) out := ret0 err := _HermezAuctionProtocol.contract.Call(opts, out, "genesisBlock") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // GenesisBlock is a free data retrieval call binding the contract method 0x4cdc9c63. @@ -337,7 +338,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) GetAllocationRatio(op ) out := ret0 err := _HermezAuctionProtocol.contract.Call(opts, out, "getAllocationRatio") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // GetAllocationRatio is a free data retrieval call binding the contract method 0xec29159b. @@ -363,7 +364,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) GetBootCoordinator(op ) out := ret0 err := _HermezAuctionProtocol.contract.Call(opts, out, "getBootCoordinator") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // GetBootCoordinator is a free data retrieval call binding the contract method 0xb5f7f2f0. @@ -389,7 +390,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) GetClaimableHEZ(opts ) out := ret0 err := _HermezAuctionProtocol.contract.Call(opts, out, "getClaimableHEZ", bidder) - return *ret0, err + return *ret0, tracerr.Wrap(err) } // GetClaimableHEZ is a free data retrieval call binding the contract method 0x5cca4903. @@ -415,7 +416,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) GetClosedAuctionSlots ) out := ret0 err := _HermezAuctionProtocol.contract.Call(opts, out, "getClosedAuctionSlots") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // GetClosedAuctionSlots is a free data retrieval call binding the contract method 0x4da9639d. @@ -441,7 +442,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) GetCurrentSlotNumber( ) out := ret0 err := _HermezAuctionProtocol.contract.Call(opts, out, "getCurrentSlotNumber") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // GetCurrentSlotNumber is a free data retrieval call binding the contract method 0x0c4da4f6. @@ -467,7 +468,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) GetDefaultSlotSetBid( ) out := ret0 err := _HermezAuctionProtocol.contract.Call(opts, out, "getDefaultSlotSetBid", slotSet) - return *ret0, err + return *ret0, tracerr.Wrap(err) } // GetDefaultSlotSetBid is a free data retrieval call binding the contract method 0x564e6a71. @@ -493,7 +494,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) GetDonationAddress(op ) out := ret0 err := _HermezAuctionProtocol.contract.Call(opts, out, "getDonationAddress") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // GetDonationAddress is a free data retrieval call binding the contract method 0x54c03ab7. @@ -519,7 +520,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) GetMinBidBySlot(opts ) out := ret0 err := _HermezAuctionProtocol.contract.Call(opts, out, "getMinBidBySlot", slot) - return *ret0, err + return *ret0, tracerr.Wrap(err) } // GetMinBidBySlot is a free data retrieval call binding the contract method 0x37d1bd0b. @@ -545,7 +546,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) GetOpenAuctionSlots(o ) out := ret0 err := _HermezAuctionProtocol.contract.Call(opts, out, "getOpenAuctionSlots") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // GetOpenAuctionSlots is a free data retrieval call binding the contract method 0xac4b9012. @@ -571,7 +572,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) GetOutbidding(opts *b ) out := ret0 err := _HermezAuctionProtocol.contract.Call(opts, out, "getOutbidding") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // GetOutbidding is a free data retrieval call binding the contract method 0x55b442e6. @@ -597,7 +598,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) GetSlotDeadline(opts ) out := ret0 err := _HermezAuctionProtocol.contract.Call(opts, out, "getSlotDeadline") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // GetSlotDeadline is a free data retrieval call binding the contract method 0x13de9af2. @@ -623,7 +624,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) GetSlotNumber(opts *b ) out := ret0 err := _HermezAuctionProtocol.contract.Call(opts, out, "getSlotNumber", blockNumber) - return *ret0, err + return *ret0, tracerr.Wrap(err) } // GetSlotNumber is a free data retrieval call binding the contract method 0xb3dc7bb1. @@ -649,7 +650,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) GetSlotSet(opts *bind ) out := ret0 err := _HermezAuctionProtocol.contract.Call(opts, out, "getSlotSet", slot) - return *ret0, err + return *ret0, tracerr.Wrap(err) } // GetSlotSet is a free data retrieval call binding the contract method 0xac5f658b. @@ -675,7 +676,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) HermezRollup(opts *bi ) out := ret0 err := _HermezAuctionProtocol.contract.Call(opts, out, "hermezRollup") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // HermezRollup is a free data retrieval call binding the contract method 0xaebd6d98. @@ -701,7 +702,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) PendingBalances(opts ) out := ret0 err := _HermezAuctionProtocol.contract.Call(opts, out, "pendingBalances", arg0) - return *ret0, err + return *ret0, tracerr.Wrap(err) } // PendingBalances is a free data retrieval call binding the contract method 0xecdae41b. @@ -735,7 +736,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) Slots(opts *bind.Call }) out := ret err := _HermezAuctionProtocol.contract.Call(opts, out, "slots", arg0) - return *ret, err + return *ret, tracerr.Wrap(err) } // Slots is a free data retrieval call binding the contract method 0xbc415567. @@ -771,7 +772,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) TokenHEZ(opts *bind.C ) out := ret0 err := _HermezAuctionProtocol.contract.Call(opts, out, "tokenHEZ") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // TokenHEZ is a free data retrieval call binding the contract method 0x79a135e3. @@ -1168,7 +1169,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) FilterHEZClaimed(op logs, sub, err := _HermezAuctionProtocol.contract.FilterLogs(opts, "HEZClaimed", ownerRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezAuctionProtocolHEZClaimedIterator{contract: _HermezAuctionProtocol.contract, event: "HEZClaimed", logs: logs, sub: sub}, nil } @@ -1185,7 +1186,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchHEZClaimed(opt logs, sub, err := _HermezAuctionProtocol.contract.WatchLogs(opts, "HEZClaimed", ownerRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -1195,19 +1196,19 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchHEZClaimed(opt // New log arrived, parse the event and forward to the user event := new(HermezAuctionProtocolHEZClaimed) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "HEZClaimed", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -1221,7 +1222,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchHEZClaimed(opt func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) ParseHEZClaimed(log types.Log) (*HermezAuctionProtocolHEZClaimed, error) { event := new(HermezAuctionProtocolHEZClaimed) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "HEZClaimed", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -1306,7 +1307,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) FilterNewAllocation logs, sub, err := _HermezAuctionProtocol.contract.FilterLogs(opts, "NewAllocationRatio") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezAuctionProtocolNewAllocationRatioIterator{contract: _HermezAuctionProtocol.contract, event: "NewAllocationRatio", logs: logs, sub: sub}, nil } @@ -1318,7 +1319,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewAllocationR logs, sub, err := _HermezAuctionProtocol.contract.WatchLogs(opts, "NewAllocationRatio") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -1328,19 +1329,19 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewAllocationR // New log arrived, parse the event and forward to the user event := new(HermezAuctionProtocolNewAllocationRatio) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "NewAllocationRatio", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -1354,7 +1355,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewAllocationR func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) ParseNewAllocationRatio(log types.Log) (*HermezAuctionProtocolNewAllocationRatio, error) { event := new(HermezAuctionProtocolNewAllocationRatio) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "NewAllocationRatio", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -1451,7 +1452,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) FilterNewBid(opts * logs, sub, err := _HermezAuctionProtocol.contract.FilterLogs(opts, "NewBid", slotRule, bidderRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezAuctionProtocolNewBidIterator{contract: _HermezAuctionProtocol.contract, event: "NewBid", logs: logs, sub: sub}, nil } @@ -1473,7 +1474,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewBid(opts *b logs, sub, err := _HermezAuctionProtocol.contract.WatchLogs(opts, "NewBid", slotRule, bidderRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -1483,19 +1484,19 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewBid(opts *b // New log arrived, parse the event and forward to the user event := new(HermezAuctionProtocolNewBid) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "NewBid", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -1509,7 +1510,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewBid(opts *b func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) ParseNewBid(log types.Log) (*HermezAuctionProtocolNewBid, error) { event := new(HermezAuctionProtocolNewBid) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "NewBid", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -1599,7 +1600,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) FilterNewBootCoordi logs, sub, err := _HermezAuctionProtocol.contract.FilterLogs(opts, "NewBootCoordinator", newBootCoordinatorRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezAuctionProtocolNewBootCoordinatorIterator{contract: _HermezAuctionProtocol.contract, event: "NewBootCoordinator", logs: logs, sub: sub}, nil } @@ -1616,7 +1617,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewBootCoordin logs, sub, err := _HermezAuctionProtocol.contract.WatchLogs(opts, "NewBootCoordinator", newBootCoordinatorRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -1626,19 +1627,19 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewBootCoordin // New log arrived, parse the event and forward to the user event := new(HermezAuctionProtocolNewBootCoordinator) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "NewBootCoordinator", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -1652,7 +1653,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewBootCoordin func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) ParseNewBootCoordinator(log types.Log) (*HermezAuctionProtocolNewBootCoordinator, error) { event := new(HermezAuctionProtocolNewBootCoordinator) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "NewBootCoordinator", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -1737,7 +1738,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) FilterNewClosedAuct logs, sub, err := _HermezAuctionProtocol.contract.FilterLogs(opts, "NewClosedAuctionSlots") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezAuctionProtocolNewClosedAuctionSlotsIterator{contract: _HermezAuctionProtocol.contract, event: "NewClosedAuctionSlots", logs: logs, sub: sub}, nil } @@ -1749,7 +1750,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewClosedAucti logs, sub, err := _HermezAuctionProtocol.contract.WatchLogs(opts, "NewClosedAuctionSlots") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -1759,19 +1760,19 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewClosedAucti // New log arrived, parse the event and forward to the user event := new(HermezAuctionProtocolNewClosedAuctionSlots) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "NewClosedAuctionSlots", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -1785,7 +1786,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewClosedAucti func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) ParseNewClosedAuctionSlots(log types.Log) (*HermezAuctionProtocolNewClosedAuctionSlots, error) { event := new(HermezAuctionProtocolNewClosedAuctionSlots) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "NewClosedAuctionSlots", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -1871,7 +1872,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) FilterNewDefaultSlo logs, sub, err := _HermezAuctionProtocol.contract.FilterLogs(opts, "NewDefaultSlotSetBid") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezAuctionProtocolNewDefaultSlotSetBidIterator{contract: _HermezAuctionProtocol.contract, event: "NewDefaultSlotSetBid", logs: logs, sub: sub}, nil } @@ -1883,7 +1884,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewDefaultSlot logs, sub, err := _HermezAuctionProtocol.contract.WatchLogs(opts, "NewDefaultSlotSetBid") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -1893,19 +1894,19 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewDefaultSlot // New log arrived, parse the event and forward to the user event := new(HermezAuctionProtocolNewDefaultSlotSetBid) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "NewDefaultSlotSetBid", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -1919,7 +1920,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewDefaultSlot func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) ParseNewDefaultSlotSetBid(log types.Log) (*HermezAuctionProtocolNewDefaultSlotSetBid, error) { event := new(HermezAuctionProtocolNewDefaultSlotSetBid) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "NewDefaultSlotSetBid", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -2009,7 +2010,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) FilterNewDonationAd logs, sub, err := _HermezAuctionProtocol.contract.FilterLogs(opts, "NewDonationAddress", newDonationAddressRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezAuctionProtocolNewDonationAddressIterator{contract: _HermezAuctionProtocol.contract, event: "NewDonationAddress", logs: logs, sub: sub}, nil } @@ -2026,7 +2027,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewDonationAdd logs, sub, err := _HermezAuctionProtocol.contract.WatchLogs(opts, "NewDonationAddress", newDonationAddressRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -2036,19 +2037,19 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewDonationAdd // New log arrived, parse the event and forward to the user event := new(HermezAuctionProtocolNewDonationAddress) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "NewDonationAddress", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -2062,7 +2063,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewDonationAdd func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) ParseNewDonationAddress(log types.Log) (*HermezAuctionProtocolNewDonationAddress, error) { event := new(HermezAuctionProtocolNewDonationAddress) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "NewDonationAddress", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -2157,7 +2158,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) FilterNewForge(opts logs, sub, err := _HermezAuctionProtocol.contract.FilterLogs(opts, "NewForge", forgerRule, slotToForgeRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezAuctionProtocolNewForgeIterator{contract: _HermezAuctionProtocol.contract, event: "NewForge", logs: logs, sub: sub}, nil } @@ -2178,7 +2179,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewForge(opts logs, sub, err := _HermezAuctionProtocol.contract.WatchLogs(opts, "NewForge", forgerRule, slotToForgeRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -2188,19 +2189,19 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewForge(opts // New log arrived, parse the event and forward to the user event := new(HermezAuctionProtocolNewForge) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "NewForge", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -2214,7 +2215,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewForge(opts func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) ParseNewForge(log types.Log) (*HermezAuctionProtocolNewForge, error) { event := new(HermezAuctionProtocolNewForge) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "NewForge", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -2317,7 +2318,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) FilterNewForgeAlloc logs, sub, err := _HermezAuctionProtocol.contract.FilterLogs(opts, "NewForgeAllocated", bidderRule, forgerRule, slotToForgeRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezAuctionProtocolNewForgeAllocatedIterator{contract: _HermezAuctionProtocol.contract, event: "NewForgeAllocated", logs: logs, sub: sub}, nil } @@ -2342,7 +2343,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewForgeAlloca logs, sub, err := _HermezAuctionProtocol.contract.WatchLogs(opts, "NewForgeAllocated", bidderRule, forgerRule, slotToForgeRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -2352,19 +2353,19 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewForgeAlloca // New log arrived, parse the event and forward to the user event := new(HermezAuctionProtocolNewForgeAllocated) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "NewForgeAllocated", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -2378,7 +2379,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewForgeAlloca func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) ParseNewForgeAllocated(log types.Log) (*HermezAuctionProtocolNewForgeAllocated, error) { event := new(HermezAuctionProtocolNewForgeAllocated) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "NewForgeAllocated", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -2463,7 +2464,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) FilterNewOpenAuctio logs, sub, err := _HermezAuctionProtocol.contract.FilterLogs(opts, "NewOpenAuctionSlots") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezAuctionProtocolNewOpenAuctionSlotsIterator{contract: _HermezAuctionProtocol.contract, event: "NewOpenAuctionSlots", logs: logs, sub: sub}, nil } @@ -2475,7 +2476,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewOpenAuction logs, sub, err := _HermezAuctionProtocol.contract.WatchLogs(opts, "NewOpenAuctionSlots") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -2485,19 +2486,19 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewOpenAuction // New log arrived, parse the event and forward to the user event := new(HermezAuctionProtocolNewOpenAuctionSlots) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "NewOpenAuctionSlots", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -2511,7 +2512,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewOpenAuction func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) ParseNewOpenAuctionSlots(log types.Log) (*HermezAuctionProtocolNewOpenAuctionSlots, error) { event := new(HermezAuctionProtocolNewOpenAuctionSlots) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "NewOpenAuctionSlots", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -2596,7 +2597,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) FilterNewOutbidding logs, sub, err := _HermezAuctionProtocol.contract.FilterLogs(opts, "NewOutbidding") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezAuctionProtocolNewOutbiddingIterator{contract: _HermezAuctionProtocol.contract, event: "NewOutbidding", logs: logs, sub: sub}, nil } @@ -2608,7 +2609,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewOutbidding( logs, sub, err := _HermezAuctionProtocol.contract.WatchLogs(opts, "NewOutbidding") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -2618,19 +2619,19 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewOutbidding( // New log arrived, parse the event and forward to the user event := new(HermezAuctionProtocolNewOutbidding) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "NewOutbidding", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -2644,7 +2645,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewOutbidding( func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) ParseNewOutbidding(log types.Log) (*HermezAuctionProtocolNewOutbidding, error) { event := new(HermezAuctionProtocolNewOutbidding) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "NewOutbidding", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -2729,7 +2730,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) FilterNewSlotDeadli logs, sub, err := _HermezAuctionProtocol.contract.FilterLogs(opts, "NewSlotDeadline") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezAuctionProtocolNewSlotDeadlineIterator{contract: _HermezAuctionProtocol.contract, event: "NewSlotDeadline", logs: logs, sub: sub}, nil } @@ -2741,7 +2742,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewSlotDeadlin logs, sub, err := _HermezAuctionProtocol.contract.WatchLogs(opts, "NewSlotDeadline") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -2751,19 +2752,19 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewSlotDeadlin // New log arrived, parse the event and forward to the user event := new(HermezAuctionProtocolNewSlotDeadline) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "NewSlotDeadline", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -2777,7 +2778,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchNewSlotDeadlin func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) ParseNewSlotDeadline(log types.Log) (*HermezAuctionProtocolNewSlotDeadline, error) { event := new(HermezAuctionProtocolNewSlotDeadline) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "NewSlotDeadline", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -2873,7 +2874,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) FilterSetCoordinato logs, sub, err := _HermezAuctionProtocol.contract.FilterLogs(opts, "SetCoordinator", bidderRule, forgerRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezAuctionProtocolSetCoordinatorIterator{contract: _HermezAuctionProtocol.contract, event: "SetCoordinator", logs: logs, sub: sub}, nil } @@ -2894,7 +2895,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchSetCoordinator logs, sub, err := _HermezAuctionProtocol.contract.WatchLogs(opts, "SetCoordinator", bidderRule, forgerRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -2904,19 +2905,19 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchSetCoordinator // New log arrived, parse the event and forward to the user event := new(HermezAuctionProtocolSetCoordinator) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "SetCoordinator", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -2930,7 +2931,7 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) WatchSetCoordinator func (_HermezAuctionProtocol *HermezAuctionProtocolFilterer) ParseSetCoordinator(log types.Log) (*HermezAuctionProtocolSetCoordinator, error) { event := new(HermezAuctionProtocolSetCoordinator) if err := _HermezAuctionProtocol.contract.UnpackLog(event, "SetCoordinator", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } diff --git a/eth/contracts/hermez/Hermez.go b/eth/contracts/hermez/Hermez.go index 5af7762..8a233f7 100644 --- a/eth/contracts/hermez/Hermez.go +++ b/eth/contracts/hermez/Hermez.go @@ -13,6 +13,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/event" + "github.com/hermeznetwork/tracerr" ) // Reference imports to suppress errors if they are not otherwise used. @@ -36,12 +37,12 @@ var HermezBin = "0x608060405234801561001057600080fd5b506158f6806100206000396000f func DeployHermez(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *Hermez, error) { parsed, err := abi.JSON(strings.NewReader(HermezABI)) if err != nil { - return common.Address{}, nil, nil, err + return common.Address{}, nil, nil, tracerr.Wrap(err) } address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(HermezBin), backend) if err != nil { - return common.Address{}, nil, nil, err + return common.Address{}, nil, nil, tracerr.Wrap(err) } return address, tx, &Hermez{HermezCaller: HermezCaller{contract: contract}, HermezTransactor: HermezTransactor{contract: contract}, HermezFilterer: HermezFilterer{contract: contract}}, nil } @@ -109,7 +110,7 @@ type HermezTransactorRaw struct { func NewHermez(address common.Address, backend bind.ContractBackend) (*Hermez, error) { contract, err := bindHermez(address, backend, backend, backend) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &Hermez{HermezCaller: HermezCaller{contract: contract}, HermezTransactor: HermezTransactor{contract: contract}, HermezFilterer: HermezFilterer{contract: contract}}, nil } @@ -118,7 +119,7 @@ func NewHermez(address common.Address, backend bind.ContractBackend) (*Hermez, e func NewHermezCaller(address common.Address, caller bind.ContractCaller) (*HermezCaller, error) { contract, err := bindHermez(address, caller, nil, nil) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezCaller{contract: contract}, nil } @@ -127,7 +128,7 @@ func NewHermezCaller(address common.Address, caller bind.ContractCaller) (*Herme func NewHermezTransactor(address common.Address, transactor bind.ContractTransactor) (*HermezTransactor, error) { contract, err := bindHermez(address, nil, transactor, nil) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezTransactor{contract: contract}, nil } @@ -136,7 +137,7 @@ func NewHermezTransactor(address common.Address, transactor bind.ContractTransac func NewHermezFilterer(address common.Address, filterer bind.ContractFilterer) (*HermezFilterer, error) { contract, err := bindHermez(address, nil, nil, filterer) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezFilterer{contract: contract}, nil } @@ -145,7 +146,7 @@ func NewHermezFilterer(address common.Address, filterer bind.ContractFilterer) ( func bindHermez(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { parsed, err := abi.JSON(strings.NewReader(HermezABI)) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil } @@ -197,7 +198,7 @@ func (_Hermez *HermezCaller) ABSOLUTEMAXL1L2BATCHTIMEOUT(opts *bind.CallOpts) (u ) out := ret0 err := _Hermez.contract.Call(opts, out, "ABSOLUTE_MAX_L1L2BATCHTIMEOUT") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // ABSOLUTEMAXL1L2BATCHTIMEOUT is a free data retrieval call binding the contract method 0x95a09f2a. @@ -233,7 +234,7 @@ func (_Hermez *HermezCaller) Buckets(opts *bind.CallOpts, arg0 *big.Int) (struct }) out := ret err := _Hermez.contract.Call(opts, out, "buckets", arg0) - return *ret, err + return *ret, tracerr.Wrap(err) } // Buckets is a free data retrieval call binding the contract method 0x9b51fb0d. @@ -271,7 +272,7 @@ func (_Hermez *HermezCaller) ExitNullifierMap(opts *bind.CallOpts, arg0 uint64, ) out := ret0 err := _Hermez.contract.Call(opts, out, "exitNullifierMap", arg0, arg1) - return *ret0, err + return *ret0, tracerr.Wrap(err) } // ExitNullifierMap is a free data retrieval call binding the contract method 0xe9b5269c. @@ -297,7 +298,7 @@ func (_Hermez *HermezCaller) ExitRootsMap(opts *bind.CallOpts, arg0 uint64) (*bi ) out := ret0 err := _Hermez.contract.Call(opts, out, "exitRootsMap", arg0) - return *ret0, err + return *ret0, tracerr.Wrap(err) } // ExitRootsMap is a free data retrieval call binding the contract method 0x506d5463. @@ -323,7 +324,7 @@ func (_Hermez *HermezCaller) FeeAddToken(opts *bind.CallOpts) (*big.Int, error) ) out := ret0 err := _Hermez.contract.Call(opts, out, "feeAddToken") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // FeeAddToken is a free data retrieval call binding the contract method 0xbded9bb8. @@ -349,7 +350,7 @@ func (_Hermez *HermezCaller) ForgeL1L2BatchTimeout(opts *bind.CallOpts) (uint8, ) out := ret0 err := _Hermez.contract.Call(opts, out, "forgeL1L2BatchTimeout") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // ForgeL1L2BatchTimeout is a free data retrieval call binding the contract method 0xa3275838. @@ -375,7 +376,7 @@ func (_Hermez *HermezCaller) HermezAuctionContract(opts *bind.CallOpts) (common. ) out := ret0 err := _Hermez.contract.Call(opts, out, "hermezAuctionContract") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // HermezAuctionContract is a free data retrieval call binding the contract method 0x2bd83626. @@ -401,7 +402,7 @@ func (_Hermez *HermezCaller) HermezGovernanceDAOAddress(opts *bind.CallOpts) (co ) out := ret0 err := _Hermez.contract.Call(opts, out, "hermezGovernanceDAOAddress") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // HermezGovernanceDAOAddress is a free data retrieval call binding the contract method 0xdd46bf84. @@ -427,7 +428,7 @@ func (_Hermez *HermezCaller) InstantWithdrawalViewer(opts *bind.CallOpts, tokenA ) out := ret0 err := _Hermez.contract.Call(opts, out, "instantWithdrawalViewer", tokenAddress, amount) - return *ret0, err + return *ret0, tracerr.Wrap(err) } // InstantWithdrawalViewer is a free data retrieval call binding the contract method 0x375110aa. @@ -453,7 +454,7 @@ func (_Hermez *HermezCaller) LastForgedBatch(opts *bind.CallOpts) (uint64, error ) out := ret0 err := _Hermez.contract.Call(opts, out, "lastForgedBatch") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // LastForgedBatch is a free data retrieval call binding the contract method 0x44e0b2ce. @@ -479,7 +480,7 @@ func (_Hermez *HermezCaller) LastIdx(opts *bind.CallOpts) (*big.Int, error) { ) out := ret0 err := _Hermez.contract.Call(opts, out, "lastIdx") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // LastIdx is a free data retrieval call binding the contract method 0xd486645c. @@ -505,7 +506,7 @@ func (_Hermez *HermezCaller) LastL1L2Batch(opts *bind.CallOpts) (uint64, error) ) out := ret0 err := _Hermez.contract.Call(opts, out, "lastL1L2Batch") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // LastL1L2Batch is a free data retrieval call binding the contract method 0x84ef9ed4. @@ -531,7 +532,7 @@ func (_Hermez *HermezCaller) MapL1TxQueue(opts *bind.CallOpts, arg0 uint64) ([]b ) out := ret0 err := _Hermez.contract.Call(opts, out, "mapL1TxQueue", arg0) - return *ret0, err + return *ret0, tracerr.Wrap(err) } // MapL1TxQueue is a free data retrieval call binding the contract method 0xe796fcf3. @@ -557,7 +558,7 @@ func (_Hermez *HermezCaller) NextL1FillingQueue(opts *bind.CallOpts) (uint64, er ) out := ret0 err := _Hermez.contract.Call(opts, out, "nextL1FillingQueue") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // NextL1FillingQueue is a free data retrieval call binding the contract method 0x0ee8e52b. @@ -583,7 +584,7 @@ func (_Hermez *HermezCaller) NextL1ToForgeQueue(opts *bind.CallOpts) (uint64, er ) out := ret0 err := _Hermez.contract.Call(opts, out, "nextL1ToForgeQueue") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // NextL1ToForgeQueue is a free data retrieval call binding the contract method 0xd0f32e67. @@ -609,7 +610,7 @@ func (_Hermez *HermezCaller) RegisterTokensCount(opts *bind.CallOpts) (*big.Int, ) out := ret0 err := _Hermez.contract.Call(opts, out, "registerTokensCount") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // RegisterTokensCount is a free data retrieval call binding the contract method 0x9f34e9a3. @@ -641,7 +642,7 @@ func (_Hermez *HermezCaller) RollupVerifiers(opts *bind.CallOpts, arg0 *big.Int) }) out := ret err := _Hermez.contract.Call(opts, out, "rollupVerifiers", arg0) - return *ret, err + return *ret, tracerr.Wrap(err) } // RollupVerifiers is a free data retrieval call binding the contract method 0x38330200. @@ -675,7 +676,7 @@ func (_Hermez *HermezCaller) SafetyAddress(opts *bind.CallOpts) (common.Address, ) out := ret0 err := _Hermez.contract.Call(opts, out, "safetyAddress") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // SafetyAddress is a free data retrieval call binding the contract method 0xe56e27ae. @@ -701,7 +702,7 @@ func (_Hermez *HermezCaller) StateRootMap(opts *bind.CallOpts, arg0 uint64) (*bi ) out := ret0 err := _Hermez.contract.Call(opts, out, "stateRootMap", arg0) - return *ret0, err + return *ret0, tracerr.Wrap(err) } // StateRootMap is a free data retrieval call binding the contract method 0x86c6acc1. @@ -727,7 +728,7 @@ func (_Hermez *HermezCaller) TokenExchange(opts *bind.CallOpts, arg0 common.Addr ) out := ret0 err := _Hermez.contract.Call(opts, out, "tokenExchange", arg0) - return *ret0, err + return *ret0, tracerr.Wrap(err) } // TokenExchange is a free data retrieval call binding the contract method 0x0dd94b96. @@ -753,7 +754,7 @@ func (_Hermez *HermezCaller) TokenHEZ(opts *bind.CallOpts) (common.Address, erro ) out := ret0 err := _Hermez.contract.Call(opts, out, "tokenHEZ") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // TokenHEZ is a free data retrieval call binding the contract method 0x79a135e3. @@ -779,7 +780,7 @@ func (_Hermez *HermezCaller) TokenList(opts *bind.CallOpts, arg0 *big.Int) (comm ) out := ret0 err := _Hermez.contract.Call(opts, out, "tokenList", arg0) - return *ret0, err + return *ret0, tracerr.Wrap(err) } // TokenList is a free data retrieval call binding the contract method 0x9ead7222. @@ -805,7 +806,7 @@ func (_Hermez *HermezCaller) TokenMap(opts *bind.CallOpts, arg0 common.Address) ) out := ret0 err := _Hermez.contract.Call(opts, out, "tokenMap", arg0) - return *ret0, err + return *ret0, tracerr.Wrap(err) } // TokenMap is a free data retrieval call binding the contract method 0x004aca6e. @@ -831,7 +832,7 @@ func (_Hermez *HermezCaller) WithdrawDelayerContract(opts *bind.CallOpts) (commo ) out := ret0 err := _Hermez.contract.Call(opts, out, "withdrawDelayerContract") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // WithdrawDelayerContract is a free data retrieval call binding the contract method 0x1b0a8223. @@ -857,7 +858,7 @@ func (_Hermez *HermezCaller) WithdrawVerifier(opts *bind.CallOpts) (common.Addre ) out := ret0 err := _Hermez.contract.Call(opts, out, "withdrawVerifier") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // WithdrawVerifier is a free data retrieval call binding the contract method 0x864eb164. @@ -883,7 +884,7 @@ func (_Hermez *HermezCaller) WithdrawalDelay(opts *bind.CallOpts) (uint64, error ) out := ret0 err := _Hermez.contract.Call(opts, out, "withdrawalDelay") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // WithdrawalDelay is a free data retrieval call binding the contract method 0xa7ab6961. @@ -1238,7 +1239,7 @@ func (_Hermez *HermezFilterer) FilterAddToken(opts *bind.FilterOpts, tokenAddres logs, sub, err := _Hermez.contract.FilterLogs(opts, "AddToken", tokenAddressRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezAddTokenIterator{contract: _Hermez.contract, event: "AddToken", logs: logs, sub: sub}, nil } @@ -1255,7 +1256,7 @@ func (_Hermez *HermezFilterer) WatchAddToken(opts *bind.WatchOpts, sink chan<- * logs, sub, err := _Hermez.contract.WatchLogs(opts, "AddToken", tokenAddressRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -1265,19 +1266,19 @@ func (_Hermez *HermezFilterer) WatchAddToken(opts *bind.WatchOpts, sink chan<- * // New log arrived, parse the event and forward to the user event := new(HermezAddToken) if err := _Hermez.contract.UnpackLog(event, "AddToken", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -1291,7 +1292,7 @@ func (_Hermez *HermezFilterer) WatchAddToken(opts *bind.WatchOpts, sink chan<- * func (_Hermez *HermezFilterer) ParseAddToken(log types.Log) (*HermezAddToken, error) { event := new(HermezAddToken) if err := _Hermez.contract.UnpackLog(event, "AddToken", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -1381,7 +1382,7 @@ func (_Hermez *HermezFilterer) FilterForgeBatch(opts *bind.FilterOpts, batchNum logs, sub, err := _Hermez.contract.FilterLogs(opts, "ForgeBatch", batchNumRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezForgeBatchIterator{contract: _Hermez.contract, event: "ForgeBatch", logs: logs, sub: sub}, nil } @@ -1398,7 +1399,7 @@ func (_Hermez *HermezFilterer) WatchForgeBatch(opts *bind.WatchOpts, sink chan<- logs, sub, err := _Hermez.contract.WatchLogs(opts, "ForgeBatch", batchNumRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -1408,19 +1409,19 @@ func (_Hermez *HermezFilterer) WatchForgeBatch(opts *bind.WatchOpts, sink chan<- // New log arrived, parse the event and forward to the user event := new(HermezForgeBatch) if err := _Hermez.contract.UnpackLog(event, "ForgeBatch", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -1434,7 +1435,7 @@ func (_Hermez *HermezFilterer) WatchForgeBatch(opts *bind.WatchOpts, sink chan<- func (_Hermez *HermezFilterer) ParseForgeBatch(log types.Log) (*HermezForgeBatch, error) { event := new(HermezForgeBatch) if err := _Hermez.contract.UnpackLog(event, "ForgeBatch", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -1530,7 +1531,7 @@ func (_Hermez *HermezFilterer) FilterL1UserTxEvent(opts *bind.FilterOpts, queueI logs, sub, err := _Hermez.contract.FilterLogs(opts, "L1UserTxEvent", queueIndexRule, positionRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezL1UserTxEventIterator{contract: _Hermez.contract, event: "L1UserTxEvent", logs: logs, sub: sub}, nil } @@ -1551,7 +1552,7 @@ func (_Hermez *HermezFilterer) WatchL1UserTxEvent(opts *bind.WatchOpts, sink cha logs, sub, err := _Hermez.contract.WatchLogs(opts, "L1UserTxEvent", queueIndexRule, positionRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -1561,19 +1562,19 @@ func (_Hermez *HermezFilterer) WatchL1UserTxEvent(opts *bind.WatchOpts, sink cha // New log arrived, parse the event and forward to the user event := new(HermezL1UserTxEvent) if err := _Hermez.contract.UnpackLog(event, "L1UserTxEvent", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -1587,7 +1588,7 @@ func (_Hermez *HermezFilterer) WatchL1UserTxEvent(opts *bind.WatchOpts, sink cha func (_Hermez *HermezFilterer) ParseL1UserTxEvent(log types.Log) (*HermezL1UserTxEvent, error) { event := new(HermezL1UserTxEvent) if err := _Hermez.contract.UnpackLog(event, "L1UserTxEvent", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -1671,7 +1672,7 @@ func (_Hermez *HermezFilterer) FilterSafeMode(opts *bind.FilterOpts) (*HermezSaf logs, sub, err := _Hermez.contract.FilterLogs(opts, "SafeMode") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezSafeModeIterator{contract: _Hermez.contract, event: "SafeMode", logs: logs, sub: sub}, nil } @@ -1683,7 +1684,7 @@ func (_Hermez *HermezFilterer) WatchSafeMode(opts *bind.WatchOpts, sink chan<- * logs, sub, err := _Hermez.contract.WatchLogs(opts, "SafeMode") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -1693,19 +1694,19 @@ func (_Hermez *HermezFilterer) WatchSafeMode(opts *bind.WatchOpts, sink chan<- * // New log arrived, parse the event and forward to the user event := new(HermezSafeMode) if err := _Hermez.contract.UnpackLog(event, "SafeMode", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -1719,7 +1720,7 @@ func (_Hermez *HermezFilterer) WatchSafeMode(opts *bind.WatchOpts, sink chan<- * func (_Hermez *HermezFilterer) ParseSafeMode(log types.Log) (*HermezSafeMode, error) { event := new(HermezSafeMode) if err := _Hermez.contract.UnpackLog(event, "SafeMode", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -1815,7 +1816,7 @@ func (_Hermez *HermezFilterer) FilterUpdateBucketWithdraw(opts *bind.FilterOpts, logs, sub, err := _Hermez.contract.FilterLogs(opts, "UpdateBucketWithdraw", numBucketRule, blockStampRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezUpdateBucketWithdrawIterator{contract: _Hermez.contract, event: "UpdateBucketWithdraw", logs: logs, sub: sub}, nil } @@ -1836,7 +1837,7 @@ func (_Hermez *HermezFilterer) WatchUpdateBucketWithdraw(opts *bind.WatchOpts, s logs, sub, err := _Hermez.contract.WatchLogs(opts, "UpdateBucketWithdraw", numBucketRule, blockStampRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -1846,19 +1847,19 @@ func (_Hermez *HermezFilterer) WatchUpdateBucketWithdraw(opts *bind.WatchOpts, s // New log arrived, parse the event and forward to the user event := new(HermezUpdateBucketWithdraw) if err := _Hermez.contract.UnpackLog(event, "UpdateBucketWithdraw", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -1872,7 +1873,7 @@ func (_Hermez *HermezFilterer) WatchUpdateBucketWithdraw(opts *bind.WatchOpts, s func (_Hermez *HermezFilterer) ParseUpdateBucketWithdraw(log types.Log) (*HermezUpdateBucketWithdraw, error) { event := new(HermezUpdateBucketWithdraw) if err := _Hermez.contract.UnpackLog(event, "UpdateBucketWithdraw", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -1957,7 +1958,7 @@ func (_Hermez *HermezFilterer) FilterUpdateBucketsParameters(opts *bind.FilterOp logs, sub, err := _Hermez.contract.FilterLogs(opts, "UpdateBucketsParameters") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezUpdateBucketsParametersIterator{contract: _Hermez.contract, event: "UpdateBucketsParameters", logs: logs, sub: sub}, nil } @@ -1969,7 +1970,7 @@ func (_Hermez *HermezFilterer) WatchUpdateBucketsParameters(opts *bind.WatchOpts logs, sub, err := _Hermez.contract.WatchLogs(opts, "UpdateBucketsParameters") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -1979,19 +1980,19 @@ func (_Hermez *HermezFilterer) WatchUpdateBucketsParameters(opts *bind.WatchOpts // New log arrived, parse the event and forward to the user event := new(HermezUpdateBucketsParameters) if err := _Hermez.contract.UnpackLog(event, "UpdateBucketsParameters", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -2005,7 +2006,7 @@ func (_Hermez *HermezFilterer) WatchUpdateBucketsParameters(opts *bind.WatchOpts func (_Hermez *HermezFilterer) ParseUpdateBucketsParameters(log types.Log) (*HermezUpdateBucketsParameters, error) { event := new(HermezUpdateBucketsParameters) if err := _Hermez.contract.UnpackLog(event, "UpdateBucketsParameters", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -2090,7 +2091,7 @@ func (_Hermez *HermezFilterer) FilterUpdateFeeAddToken(opts *bind.FilterOpts) (* logs, sub, err := _Hermez.contract.FilterLogs(opts, "UpdateFeeAddToken") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezUpdateFeeAddTokenIterator{contract: _Hermez.contract, event: "UpdateFeeAddToken", logs: logs, sub: sub}, nil } @@ -2102,7 +2103,7 @@ func (_Hermez *HermezFilterer) WatchUpdateFeeAddToken(opts *bind.WatchOpts, sink logs, sub, err := _Hermez.contract.WatchLogs(opts, "UpdateFeeAddToken") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -2112,19 +2113,19 @@ func (_Hermez *HermezFilterer) WatchUpdateFeeAddToken(opts *bind.WatchOpts, sink // New log arrived, parse the event and forward to the user event := new(HermezUpdateFeeAddToken) if err := _Hermez.contract.UnpackLog(event, "UpdateFeeAddToken", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -2138,7 +2139,7 @@ func (_Hermez *HermezFilterer) WatchUpdateFeeAddToken(opts *bind.WatchOpts, sink func (_Hermez *HermezFilterer) ParseUpdateFeeAddToken(log types.Log) (*HermezUpdateFeeAddToken, error) { event := new(HermezUpdateFeeAddToken) if err := _Hermez.contract.UnpackLog(event, "UpdateFeeAddToken", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -2223,7 +2224,7 @@ func (_Hermez *HermezFilterer) FilterUpdateForgeL1L2BatchTimeout(opts *bind.Filt logs, sub, err := _Hermez.contract.FilterLogs(opts, "UpdateForgeL1L2BatchTimeout") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezUpdateForgeL1L2BatchTimeoutIterator{contract: _Hermez.contract, event: "UpdateForgeL1L2BatchTimeout", logs: logs, sub: sub}, nil } @@ -2235,7 +2236,7 @@ func (_Hermez *HermezFilterer) WatchUpdateForgeL1L2BatchTimeout(opts *bind.Watch logs, sub, err := _Hermez.contract.WatchLogs(opts, "UpdateForgeL1L2BatchTimeout") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -2245,19 +2246,19 @@ func (_Hermez *HermezFilterer) WatchUpdateForgeL1L2BatchTimeout(opts *bind.Watch // New log arrived, parse the event and forward to the user event := new(HermezUpdateForgeL1L2BatchTimeout) if err := _Hermez.contract.UnpackLog(event, "UpdateForgeL1L2BatchTimeout", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -2271,7 +2272,7 @@ func (_Hermez *HermezFilterer) WatchUpdateForgeL1L2BatchTimeout(opts *bind.Watch func (_Hermez *HermezFilterer) ParseUpdateForgeL1L2BatchTimeout(log types.Log) (*HermezUpdateForgeL1L2BatchTimeout, error) { event := new(HermezUpdateForgeL1L2BatchTimeout) if err := _Hermez.contract.UnpackLog(event, "UpdateForgeL1L2BatchTimeout", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -2357,7 +2358,7 @@ func (_Hermez *HermezFilterer) FilterUpdateTokenExchange(opts *bind.FilterOpts) logs, sub, err := _Hermez.contract.FilterLogs(opts, "UpdateTokenExchange") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezUpdateTokenExchangeIterator{contract: _Hermez.contract, event: "UpdateTokenExchange", logs: logs, sub: sub}, nil } @@ -2369,7 +2370,7 @@ func (_Hermez *HermezFilterer) WatchUpdateTokenExchange(opts *bind.WatchOpts, si logs, sub, err := _Hermez.contract.WatchLogs(opts, "UpdateTokenExchange") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -2379,19 +2380,19 @@ func (_Hermez *HermezFilterer) WatchUpdateTokenExchange(opts *bind.WatchOpts, si // New log arrived, parse the event and forward to the user event := new(HermezUpdateTokenExchange) if err := _Hermez.contract.UnpackLog(event, "UpdateTokenExchange", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -2405,7 +2406,7 @@ func (_Hermez *HermezFilterer) WatchUpdateTokenExchange(opts *bind.WatchOpts, si func (_Hermez *HermezFilterer) ParseUpdateTokenExchange(log types.Log) (*HermezUpdateTokenExchange, error) { event := new(HermezUpdateTokenExchange) if err := _Hermez.contract.UnpackLog(event, "UpdateTokenExchange", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -2490,7 +2491,7 @@ func (_Hermez *HermezFilterer) FilterUpdateWithdrawalDelay(opts *bind.FilterOpts logs, sub, err := _Hermez.contract.FilterLogs(opts, "UpdateWithdrawalDelay") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezUpdateWithdrawalDelayIterator{contract: _Hermez.contract, event: "UpdateWithdrawalDelay", logs: logs, sub: sub}, nil } @@ -2502,7 +2503,7 @@ func (_Hermez *HermezFilterer) WatchUpdateWithdrawalDelay(opts *bind.WatchOpts, logs, sub, err := _Hermez.contract.WatchLogs(opts, "UpdateWithdrawalDelay") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -2512,19 +2513,19 @@ func (_Hermez *HermezFilterer) WatchUpdateWithdrawalDelay(opts *bind.WatchOpts, // New log arrived, parse the event and forward to the user event := new(HermezUpdateWithdrawalDelay) if err := _Hermez.contract.UnpackLog(event, "UpdateWithdrawalDelay", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -2538,7 +2539,7 @@ func (_Hermez *HermezFilterer) WatchUpdateWithdrawalDelay(opts *bind.WatchOpts, func (_Hermez *HermezFilterer) ParseUpdateWithdrawalDelay(log types.Log) (*HermezUpdateWithdrawalDelay, error) { event := new(HermezUpdateWithdrawalDelay) if err := _Hermez.contract.UnpackLog(event, "UpdateWithdrawalDelay", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -2638,7 +2639,7 @@ func (_Hermez *HermezFilterer) FilterWithdrawEvent(opts *bind.FilterOpts, idx [] logs, sub, err := _Hermez.contract.FilterLogs(opts, "WithdrawEvent", idxRule, numExitRootRule, instantWithdrawRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HermezWithdrawEventIterator{contract: _Hermez.contract, event: "WithdrawEvent", logs: logs, sub: sub}, nil } @@ -2663,7 +2664,7 @@ func (_Hermez *HermezFilterer) WatchWithdrawEvent(opts *bind.WatchOpts, sink cha logs, sub, err := _Hermez.contract.WatchLogs(opts, "WithdrawEvent", idxRule, numExitRootRule, instantWithdrawRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -2673,19 +2674,19 @@ func (_Hermez *HermezFilterer) WatchWithdrawEvent(opts *bind.WatchOpts, sink cha // New log arrived, parse the event and forward to the user event := new(HermezWithdrawEvent) if err := _Hermez.contract.UnpackLog(event, "WithdrawEvent", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -2699,7 +2700,7 @@ func (_Hermez *HermezFilterer) WatchWithdrawEvent(opts *bind.WatchOpts, sink cha func (_Hermez *HermezFilterer) ParseWithdrawEvent(log types.Log) (*HermezWithdrawEvent, error) { event := new(HermezWithdrawEvent) if err := _Hermez.contract.UnpackLog(event, "WithdrawEvent", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } diff --git a/eth/contracts/tokenHEZ/HEZ.go b/eth/contracts/tokenHEZ/HEZ.go index cd170da..f2aa758 100644 --- a/eth/contracts/tokenHEZ/HEZ.go +++ b/eth/contracts/tokenHEZ/HEZ.go @@ -13,6 +13,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/event" + "github.com/hermeznetwork/tracerr" ) // Reference imports to suppress errors if they are not otherwise used. @@ -36,12 +37,12 @@ var HEZBin = "0x608060405234801561001057600080fd5b506040516111153803806111158339 func DeployHEZ(auth *bind.TransactOpts, backend bind.ContractBackend, initialHolder common.Address) (common.Address, *types.Transaction, *HEZ, error) { parsed, err := abi.JSON(strings.NewReader(HEZABI)) if err != nil { - return common.Address{}, nil, nil, err + return common.Address{}, nil, nil, tracerr.Wrap(err) } address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(HEZBin), backend, initialHolder) if err != nil { - return common.Address{}, nil, nil, err + return common.Address{}, nil, nil, tracerr.Wrap(err) } return address, tx, &HEZ{HEZCaller: HEZCaller{contract: contract}, HEZTransactor: HEZTransactor{contract: contract}, HEZFilterer: HEZFilterer{contract: contract}}, nil } @@ -109,7 +110,7 @@ type HEZTransactorRaw struct { func NewHEZ(address common.Address, backend bind.ContractBackend) (*HEZ, error) { contract, err := bindHEZ(address, backend, backend, backend) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HEZ{HEZCaller: HEZCaller{contract: contract}, HEZTransactor: HEZTransactor{contract: contract}, HEZFilterer: HEZFilterer{contract: contract}}, nil } @@ -118,7 +119,7 @@ func NewHEZ(address common.Address, backend bind.ContractBackend) (*HEZ, error) func NewHEZCaller(address common.Address, caller bind.ContractCaller) (*HEZCaller, error) { contract, err := bindHEZ(address, caller, nil, nil) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HEZCaller{contract: contract}, nil } @@ -127,7 +128,7 @@ func NewHEZCaller(address common.Address, caller bind.ContractCaller) (*HEZCalle func NewHEZTransactor(address common.Address, transactor bind.ContractTransactor) (*HEZTransactor, error) { contract, err := bindHEZ(address, nil, transactor, nil) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HEZTransactor{contract: contract}, nil } @@ -136,7 +137,7 @@ func NewHEZTransactor(address common.Address, transactor bind.ContractTransactor func NewHEZFilterer(address common.Address, filterer bind.ContractFilterer) (*HEZFilterer, error) { contract, err := bindHEZ(address, nil, nil, filterer) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HEZFilterer{contract: contract}, nil } @@ -145,7 +146,7 @@ func NewHEZFilterer(address common.Address, filterer bind.ContractFilterer) (*HE func bindHEZ(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { parsed, err := abi.JSON(strings.NewReader(HEZABI)) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil } @@ -197,7 +198,7 @@ func (_HEZ *HEZCaller) EIP712DOMAINHASH(opts *bind.CallOpts) ([32]byte, error) { ) out := ret0 err := _HEZ.contract.Call(opts, out, "EIP712DOMAIN_HASH") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // EIP712DOMAINHASH is a free data retrieval call binding the contract method 0xc473af33. @@ -223,7 +224,7 @@ func (_HEZ *HEZCaller) NAMEHASH(opts *bind.CallOpts) ([32]byte, error) { ) out := ret0 err := _HEZ.contract.Call(opts, out, "NAME_HASH") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // NAMEHASH is a free data retrieval call binding the contract method 0x04622c2e. @@ -249,7 +250,7 @@ func (_HEZ *HEZCaller) PERMITTYPEHASH(opts *bind.CallOpts) ([32]byte, error) { ) out := ret0 err := _HEZ.contract.Call(opts, out, "PERMIT_TYPEHASH") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // PERMITTYPEHASH is a free data retrieval call binding the contract method 0x30adf81f. @@ -275,7 +276,7 @@ func (_HEZ *HEZCaller) TRANSFERWITHAUTHORIZATIONTYPEHASH(opts *bind.CallOpts) ([ ) out := ret0 err := _HEZ.contract.Call(opts, out, "TRANSFER_WITH_AUTHORIZATION_TYPEHASH") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // TRANSFERWITHAUTHORIZATIONTYPEHASH is a free data retrieval call binding the contract method 0xa0cc6a68. @@ -301,7 +302,7 @@ func (_HEZ *HEZCaller) VERSIONHASH(opts *bind.CallOpts) ([32]byte, error) { ) out := ret0 err := _HEZ.contract.Call(opts, out, "VERSION_HASH") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // VERSIONHASH is a free data retrieval call binding the contract method 0x9e4e7318. @@ -327,7 +328,7 @@ func (_HEZ *HEZCaller) Allowance(opts *bind.CallOpts, arg0 common.Address, arg1 ) out := ret0 err := _HEZ.contract.Call(opts, out, "allowance", arg0, arg1) - return *ret0, err + return *ret0, tracerr.Wrap(err) } // Allowance is a free data retrieval call binding the contract method 0xdd62ed3e. @@ -353,7 +354,7 @@ func (_HEZ *HEZCaller) AuthorizationState(opts *bind.CallOpts, arg0 common.Addre ) out := ret0 err := _HEZ.contract.Call(opts, out, "authorizationState", arg0, arg1) - return *ret0, err + return *ret0, tracerr.Wrap(err) } // AuthorizationState is a free data retrieval call binding the contract method 0xe94a0102. @@ -379,7 +380,7 @@ func (_HEZ *HEZCaller) BalanceOf(opts *bind.CallOpts, arg0 common.Address) (*big ) out := ret0 err := _HEZ.contract.Call(opts, out, "balanceOf", arg0) - return *ret0, err + return *ret0, tracerr.Wrap(err) } // BalanceOf is a free data retrieval call binding the contract method 0x70a08231. @@ -405,7 +406,7 @@ func (_HEZ *HEZCaller) Decimals(opts *bind.CallOpts) (uint8, error) { ) out := ret0 err := _HEZ.contract.Call(opts, out, "decimals") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // Decimals is a free data retrieval call binding the contract method 0x313ce567. @@ -431,7 +432,7 @@ func (_HEZ *HEZCaller) GetChainId(opts *bind.CallOpts) (*big.Int, error) { ) out := ret0 err := _HEZ.contract.Call(opts, out, "getChainId") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // GetChainId is a free data retrieval call binding the contract method 0x3408e470. @@ -457,7 +458,7 @@ func (_HEZ *HEZCaller) InitialBalance(opts *bind.CallOpts) (*big.Int, error) { ) out := ret0 err := _HEZ.contract.Call(opts, out, "initialBalance") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // InitialBalance is a free data retrieval call binding the contract method 0x18369a2a. @@ -483,7 +484,7 @@ func (_HEZ *HEZCaller) Name(opts *bind.CallOpts) (string, error) { ) out := ret0 err := _HEZ.contract.Call(opts, out, "name") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // Name is a free data retrieval call binding the contract method 0x06fdde03. @@ -509,7 +510,7 @@ func (_HEZ *HEZCaller) Nonces(opts *bind.CallOpts, arg0 common.Address) (*big.In ) out := ret0 err := _HEZ.contract.Call(opts, out, "nonces", arg0) - return *ret0, err + return *ret0, tracerr.Wrap(err) } // Nonces is a free data retrieval call binding the contract method 0x7ecebe00. @@ -535,7 +536,7 @@ func (_HEZ *HEZCaller) Symbol(opts *bind.CallOpts) (string, error) { ) out := ret0 err := _HEZ.contract.Call(opts, out, "symbol") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // Symbol is a free data retrieval call binding the contract method 0x95d89b41. @@ -561,7 +562,7 @@ func (_HEZ *HEZCaller) TotalSupply(opts *bind.CallOpts) (*big.Int, error) { ) out := ret0 err := _HEZ.contract.Call(opts, out, "totalSupply") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // TotalSupply is a free data retrieval call binding the contract method 0x18160ddd. @@ -795,7 +796,7 @@ func (_HEZ *HEZFilterer) FilterApproval(opts *bind.FilterOpts, owner []common.Ad logs, sub, err := _HEZ.contract.FilterLogs(opts, "Approval", ownerRule, spenderRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HEZApprovalIterator{contract: _HEZ.contract, event: "Approval", logs: logs, sub: sub}, nil } @@ -816,7 +817,7 @@ func (_HEZ *HEZFilterer) WatchApproval(opts *bind.WatchOpts, sink chan<- *HEZApp logs, sub, err := _HEZ.contract.WatchLogs(opts, "Approval", ownerRule, spenderRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -826,19 +827,19 @@ func (_HEZ *HEZFilterer) WatchApproval(opts *bind.WatchOpts, sink chan<- *HEZApp // New log arrived, parse the event and forward to the user event := new(HEZApproval) if err := _HEZ.contract.UnpackLog(event, "Approval", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -852,7 +853,7 @@ func (_HEZ *HEZFilterer) WatchApproval(opts *bind.WatchOpts, sink chan<- *HEZApp func (_HEZ *HEZFilterer) ParseApproval(log types.Log) (*HEZApproval, error) { event := new(HEZApproval) if err := _HEZ.contract.UnpackLog(event, "Approval", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -947,7 +948,7 @@ func (_HEZ *HEZFilterer) FilterAuthorizationUsed(opts *bind.FilterOpts, authoriz logs, sub, err := _HEZ.contract.FilterLogs(opts, "AuthorizationUsed", authorizerRule, nonceRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HEZAuthorizationUsedIterator{contract: _HEZ.contract, event: "AuthorizationUsed", logs: logs, sub: sub}, nil } @@ -968,7 +969,7 @@ func (_HEZ *HEZFilterer) WatchAuthorizationUsed(opts *bind.WatchOpts, sink chan< logs, sub, err := _HEZ.contract.WatchLogs(opts, "AuthorizationUsed", authorizerRule, nonceRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -978,19 +979,19 @@ func (_HEZ *HEZFilterer) WatchAuthorizationUsed(opts *bind.WatchOpts, sink chan< // New log arrived, parse the event and forward to the user event := new(HEZAuthorizationUsed) if err := _HEZ.contract.UnpackLog(event, "AuthorizationUsed", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -1004,7 +1005,7 @@ func (_HEZ *HEZFilterer) WatchAuthorizationUsed(opts *bind.WatchOpts, sink chan< func (_HEZ *HEZFilterer) ParseAuthorizationUsed(log types.Log) (*HEZAuthorizationUsed, error) { event := new(HEZAuthorizationUsed) if err := _HEZ.contract.UnpackLog(event, "AuthorizationUsed", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -1100,7 +1101,7 @@ func (_HEZ *HEZFilterer) FilterTransfer(opts *bind.FilterOpts, from []common.Add logs, sub, err := _HEZ.contract.FilterLogs(opts, "Transfer", fromRule, toRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &HEZTransferIterator{contract: _HEZ.contract, event: "Transfer", logs: logs, sub: sub}, nil } @@ -1121,7 +1122,7 @@ func (_HEZ *HEZFilterer) WatchTransfer(opts *bind.WatchOpts, sink chan<- *HEZTra logs, sub, err := _HEZ.contract.WatchLogs(opts, "Transfer", fromRule, toRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -1131,19 +1132,19 @@ func (_HEZ *HEZFilterer) WatchTransfer(opts *bind.WatchOpts, sink chan<- *HEZTra // New log arrived, parse the event and forward to the user event := new(HEZTransfer) if err := _HEZ.contract.UnpackLog(event, "Transfer", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -1157,7 +1158,7 @@ func (_HEZ *HEZFilterer) WatchTransfer(opts *bind.WatchOpts, sink chan<- *HEZTra func (_HEZ *HEZFilterer) ParseTransfer(log types.Log) (*HEZTransfer, error) { event := new(HEZTransfer) if err := _HEZ.contract.UnpackLog(event, "Transfer", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } diff --git a/eth/contracts/withdrawdelayer/WithdrawalDelayer.go b/eth/contracts/withdrawdelayer/WithdrawalDelayer.go index 7bf050f..29eca9e 100644 --- a/eth/contracts/withdrawdelayer/WithdrawalDelayer.go +++ b/eth/contracts/withdrawdelayer/WithdrawalDelayer.go @@ -13,6 +13,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/event" + "github.com/hermeznetwork/tracerr" ) // Reference imports to suppress errors if they are not otherwise used. @@ -36,12 +37,12 @@ var WithdrawalDelayerBin = "0x608060405234801561001057600080fd5b50611be680610020 func DeployWithdrawalDelayer(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *WithdrawalDelayer, error) { parsed, err := abi.JSON(strings.NewReader(WithdrawalDelayerABI)) if err != nil { - return common.Address{}, nil, nil, err + return common.Address{}, nil, nil, tracerr.Wrap(err) } address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(WithdrawalDelayerBin), backend) if err != nil { - return common.Address{}, nil, nil, err + return common.Address{}, nil, nil, tracerr.Wrap(err) } return address, tx, &WithdrawalDelayer{WithdrawalDelayerCaller: WithdrawalDelayerCaller{contract: contract}, WithdrawalDelayerTransactor: WithdrawalDelayerTransactor{contract: contract}, WithdrawalDelayerFilterer: WithdrawalDelayerFilterer{contract: contract}}, nil } @@ -109,7 +110,7 @@ type WithdrawalDelayerTransactorRaw struct { func NewWithdrawalDelayer(address common.Address, backend bind.ContractBackend) (*WithdrawalDelayer, error) { contract, err := bindWithdrawalDelayer(address, backend, backend, backend) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &WithdrawalDelayer{WithdrawalDelayerCaller: WithdrawalDelayerCaller{contract: contract}, WithdrawalDelayerTransactor: WithdrawalDelayerTransactor{contract: contract}, WithdrawalDelayerFilterer: WithdrawalDelayerFilterer{contract: contract}}, nil } @@ -118,7 +119,7 @@ func NewWithdrawalDelayer(address common.Address, backend bind.ContractBackend) func NewWithdrawalDelayerCaller(address common.Address, caller bind.ContractCaller) (*WithdrawalDelayerCaller, error) { contract, err := bindWithdrawalDelayer(address, caller, nil, nil) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &WithdrawalDelayerCaller{contract: contract}, nil } @@ -127,7 +128,7 @@ func NewWithdrawalDelayerCaller(address common.Address, caller bind.ContractCall func NewWithdrawalDelayerTransactor(address common.Address, transactor bind.ContractTransactor) (*WithdrawalDelayerTransactor, error) { contract, err := bindWithdrawalDelayer(address, nil, transactor, nil) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &WithdrawalDelayerTransactor{contract: contract}, nil } @@ -136,7 +137,7 @@ func NewWithdrawalDelayerTransactor(address common.Address, transactor bind.Cont func NewWithdrawalDelayerFilterer(address common.Address, filterer bind.ContractFilterer) (*WithdrawalDelayerFilterer, error) { contract, err := bindWithdrawalDelayer(address, nil, nil, filterer) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &WithdrawalDelayerFilterer{contract: contract}, nil } @@ -145,7 +146,7 @@ func NewWithdrawalDelayerFilterer(address common.Address, filterer bind.Contract func bindWithdrawalDelayer(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { parsed, err := abi.JSON(strings.NewReader(WithdrawalDelayerABI)) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil } @@ -197,7 +198,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerCaller) MAXEMERGENCYMODETIME(opts *bi ) out := ret0 err := _WithdrawalDelayer.contract.Call(opts, out, "MAX_EMERGENCY_MODE_TIME") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // MAXEMERGENCYMODETIME is a free data retrieval call binding the contract method 0xb4b8e39d. @@ -223,7 +224,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerCaller) MAXWITHDRAWALDELAY(opts *bind ) out := ret0 err := _WithdrawalDelayer.contract.Call(opts, out, "MAX_WITHDRAWAL_DELAY") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // MAXWITHDRAWALDELAY is a free data retrieval call binding the contract method 0xa238f9df. @@ -253,7 +254,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerCaller) DepositInfo(opts *bind.CallOp ret1, } err := _WithdrawalDelayer.contract.Call(opts, out, "depositInfo", _owner, _token) - return *ret0, *ret1, err + return *ret0, *ret1, tracerr.Wrap(err) } // DepositInfo is a free data retrieval call binding the contract method 0x493b0170. @@ -283,7 +284,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerCaller) Deposits(opts *bind.CallOpts, }) out := ret err := _WithdrawalDelayer.contract.Call(opts, out, "deposits", arg0) - return *ret, err + return *ret, tracerr.Wrap(err) } // Deposits is a free data retrieval call binding the contract method 0x3d4dff7b. @@ -315,7 +316,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerCaller) GetEmergencyModeStartingTime( ) out := ret0 err := _WithdrawalDelayer.contract.Call(opts, out, "getEmergencyModeStartingTime") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // GetEmergencyModeStartingTime is a free data retrieval call binding the contract method 0x668cdd67. @@ -341,7 +342,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerCaller) GetHermezGovernanceDAOAddress ) out := ret0 err := _WithdrawalDelayer.contract.Call(opts, out, "getHermezGovernanceDAOAddress") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // GetHermezGovernanceDAOAddress is a free data retrieval call binding the contract method 0x580fc611. @@ -367,7 +368,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerCaller) GetHermezKeeperAddress(opts * ) out := ret0 err := _WithdrawalDelayer.contract.Call(opts, out, "getHermezKeeperAddress") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // GetHermezKeeperAddress is a free data retrieval call binding the contract method 0x305887f9. @@ -393,7 +394,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerCaller) GetWhiteHackGroupAddress(opts ) out := ret0 err := _WithdrawalDelayer.contract.Call(opts, out, "getWhiteHackGroupAddress") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // GetWhiteHackGroupAddress is a free data retrieval call binding the contract method 0xae7efbbd. @@ -419,7 +420,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerCaller) GetWithdrawalDelay(opts *bind ) out := ret0 err := _WithdrawalDelayer.contract.Call(opts, out, "getWithdrawalDelay") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // GetWithdrawalDelay is a free data retrieval call binding the contract method 0x03160940. @@ -445,7 +446,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerCaller) HermezRollupAddress(opts *bin ) out := ret0 err := _WithdrawalDelayer.contract.Call(opts, out, "hermezRollupAddress") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // HermezRollupAddress is a free data retrieval call binding the contract method 0x0fd266d7. @@ -471,7 +472,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerCaller) IsEmergencyMode(opts *bind.Ca ) out := ret0 err := _WithdrawalDelayer.contract.Call(opts, out, "isEmergencyMode") - return *ret0, err + return *ret0, tracerr.Wrap(err) } // IsEmergencyMode is a free data retrieval call binding the contract method 0x20a194b8. @@ -769,7 +770,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) FilterDeposit(opts *bind.Fi logs, sub, err := _WithdrawalDelayer.contract.FilterLogs(opts, "Deposit", ownerRule, tokenRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &WithdrawalDelayerDepositIterator{contract: _WithdrawalDelayer.contract, event: "Deposit", logs: logs, sub: sub}, nil } @@ -790,7 +791,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchDeposit(opts *bind.Wat logs, sub, err := _WithdrawalDelayer.contract.WatchLogs(opts, "Deposit", ownerRule, tokenRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -800,19 +801,19 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchDeposit(opts *bind.Wat // New log arrived, parse the event and forward to the user event := new(WithdrawalDelayerDeposit) if err := _WithdrawalDelayer.contract.UnpackLog(event, "Deposit", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -826,7 +827,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchDeposit(opts *bind.Wat func (_WithdrawalDelayer *WithdrawalDelayerFilterer) ParseDeposit(log types.Log) (*WithdrawalDelayerDeposit, error) { event := new(WithdrawalDelayerDeposit) if err := _WithdrawalDelayer.contract.UnpackLog(event, "Deposit", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -910,7 +911,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) FilterEmergencyModeEnabled( logs, sub, err := _WithdrawalDelayer.contract.FilterLogs(opts, "EmergencyModeEnabled") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &WithdrawalDelayerEmergencyModeEnabledIterator{contract: _WithdrawalDelayer.contract, event: "EmergencyModeEnabled", logs: logs, sub: sub}, nil } @@ -922,7 +923,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchEmergencyModeEnabled(o logs, sub, err := _WithdrawalDelayer.contract.WatchLogs(opts, "EmergencyModeEnabled") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -932,19 +933,19 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchEmergencyModeEnabled(o // New log arrived, parse the event and forward to the user event := new(WithdrawalDelayerEmergencyModeEnabled) if err := _WithdrawalDelayer.contract.UnpackLog(event, "EmergencyModeEnabled", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -958,7 +959,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchEmergencyModeEnabled(o func (_WithdrawalDelayer *WithdrawalDelayerFilterer) ParseEmergencyModeEnabled(log types.Log) (*WithdrawalDelayerEmergencyModeEnabled, error) { event := new(WithdrawalDelayerEmergencyModeEnabled) if err := _WithdrawalDelayer.contract.UnpackLog(event, "EmergencyModeEnabled", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -1059,7 +1060,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) FilterEscapeHatchWithdrawal logs, sub, err := _WithdrawalDelayer.contract.FilterLogs(opts, "EscapeHatchWithdrawal", whoRule, toRule, tokenRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &WithdrawalDelayerEscapeHatchWithdrawalIterator{contract: _WithdrawalDelayer.contract, event: "EscapeHatchWithdrawal", logs: logs, sub: sub}, nil } @@ -1084,7 +1085,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchEscapeHatchWithdrawal( logs, sub, err := _WithdrawalDelayer.contract.WatchLogs(opts, "EscapeHatchWithdrawal", whoRule, toRule, tokenRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -1094,19 +1095,19 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchEscapeHatchWithdrawal( // New log arrived, parse the event and forward to the user event := new(WithdrawalDelayerEscapeHatchWithdrawal) if err := _WithdrawalDelayer.contract.UnpackLog(event, "EscapeHatchWithdrawal", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -1120,7 +1121,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchEscapeHatchWithdrawal( func (_WithdrawalDelayer *WithdrawalDelayerFilterer) ParseEscapeHatchWithdrawal(log types.Log) (*WithdrawalDelayerEscapeHatchWithdrawal, error) { event := new(WithdrawalDelayerEscapeHatchWithdrawal) if err := _WithdrawalDelayer.contract.UnpackLog(event, "EscapeHatchWithdrawal", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -1205,7 +1206,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) FilterNewHermezGovernanceDA logs, sub, err := _WithdrawalDelayer.contract.FilterLogs(opts, "NewHermezGovernanceDAOAddress") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &WithdrawalDelayerNewHermezGovernanceDAOAddressIterator{contract: _WithdrawalDelayer.contract, event: "NewHermezGovernanceDAOAddress", logs: logs, sub: sub}, nil } @@ -1217,7 +1218,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchNewHermezGovernanceDAO logs, sub, err := _WithdrawalDelayer.contract.WatchLogs(opts, "NewHermezGovernanceDAOAddress") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -1227,19 +1228,19 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchNewHermezGovernanceDAO // New log arrived, parse the event and forward to the user event := new(WithdrawalDelayerNewHermezGovernanceDAOAddress) if err := _WithdrawalDelayer.contract.UnpackLog(event, "NewHermezGovernanceDAOAddress", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -1253,7 +1254,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchNewHermezGovernanceDAO func (_WithdrawalDelayer *WithdrawalDelayerFilterer) ParseNewHermezGovernanceDAOAddress(log types.Log) (*WithdrawalDelayerNewHermezGovernanceDAOAddress, error) { event := new(WithdrawalDelayerNewHermezGovernanceDAOAddress) if err := _WithdrawalDelayer.contract.UnpackLog(event, "NewHermezGovernanceDAOAddress", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -1338,7 +1339,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) FilterNewHermezKeeperAddres logs, sub, err := _WithdrawalDelayer.contract.FilterLogs(opts, "NewHermezKeeperAddress") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &WithdrawalDelayerNewHermezKeeperAddressIterator{contract: _WithdrawalDelayer.contract, event: "NewHermezKeeperAddress", logs: logs, sub: sub}, nil } @@ -1350,7 +1351,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchNewHermezKeeperAddress logs, sub, err := _WithdrawalDelayer.contract.WatchLogs(opts, "NewHermezKeeperAddress") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -1360,19 +1361,19 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchNewHermezKeeperAddress // New log arrived, parse the event and forward to the user event := new(WithdrawalDelayerNewHermezKeeperAddress) if err := _WithdrawalDelayer.contract.UnpackLog(event, "NewHermezKeeperAddress", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -1386,7 +1387,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchNewHermezKeeperAddress func (_WithdrawalDelayer *WithdrawalDelayerFilterer) ParseNewHermezKeeperAddress(log types.Log) (*WithdrawalDelayerNewHermezKeeperAddress, error) { event := new(WithdrawalDelayerNewHermezKeeperAddress) if err := _WithdrawalDelayer.contract.UnpackLog(event, "NewHermezKeeperAddress", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -1471,7 +1472,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) FilterNewWhiteHackGroupAddr logs, sub, err := _WithdrawalDelayer.contract.FilterLogs(opts, "NewWhiteHackGroupAddress") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &WithdrawalDelayerNewWhiteHackGroupAddressIterator{contract: _WithdrawalDelayer.contract, event: "NewWhiteHackGroupAddress", logs: logs, sub: sub}, nil } @@ -1483,7 +1484,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchNewWhiteHackGroupAddre logs, sub, err := _WithdrawalDelayer.contract.WatchLogs(opts, "NewWhiteHackGroupAddress") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -1493,19 +1494,19 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchNewWhiteHackGroupAddre // New log arrived, parse the event and forward to the user event := new(WithdrawalDelayerNewWhiteHackGroupAddress) if err := _WithdrawalDelayer.contract.UnpackLog(event, "NewWhiteHackGroupAddress", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -1519,7 +1520,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchNewWhiteHackGroupAddre func (_WithdrawalDelayer *WithdrawalDelayerFilterer) ParseNewWhiteHackGroupAddress(log types.Log) (*WithdrawalDelayerNewWhiteHackGroupAddress, error) { event := new(WithdrawalDelayerNewWhiteHackGroupAddress) if err := _WithdrawalDelayer.contract.UnpackLog(event, "NewWhiteHackGroupAddress", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -1604,7 +1605,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) FilterNewWithdrawalDelay(op logs, sub, err := _WithdrawalDelayer.contract.FilterLogs(opts, "NewWithdrawalDelay") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &WithdrawalDelayerNewWithdrawalDelayIterator{contract: _WithdrawalDelayer.contract, event: "NewWithdrawalDelay", logs: logs, sub: sub}, nil } @@ -1616,7 +1617,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchNewWithdrawalDelay(opt logs, sub, err := _WithdrawalDelayer.contract.WatchLogs(opts, "NewWithdrawalDelay") if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -1626,19 +1627,19 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchNewWithdrawalDelay(opt // New log arrived, parse the event and forward to the user event := new(WithdrawalDelayerNewWithdrawalDelay) if err := _WithdrawalDelayer.contract.UnpackLog(event, "NewWithdrawalDelay", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -1652,7 +1653,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchNewWithdrawalDelay(opt func (_WithdrawalDelayer *WithdrawalDelayerFilterer) ParseNewWithdrawalDelay(log types.Log) (*WithdrawalDelayerNewWithdrawalDelay, error) { event := new(WithdrawalDelayerNewWithdrawalDelay) if err := _WithdrawalDelayer.contract.UnpackLog(event, "NewWithdrawalDelay", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } @@ -1748,7 +1749,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) FilterWithdraw(opts *bind.F logs, sub, err := _WithdrawalDelayer.contract.FilterLogs(opts, "Withdraw", tokenRule, ownerRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &WithdrawalDelayerWithdrawIterator{contract: _WithdrawalDelayer.contract, event: "Withdraw", logs: logs, sub: sub}, nil } @@ -1769,7 +1770,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchWithdraw(opts *bind.Wa logs, sub, err := _WithdrawalDelayer.contract.WatchLogs(opts, "Withdraw", tokenRule, ownerRule) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event.NewSubscription(func(quit <-chan struct{}) error { defer sub.Unsubscribe() @@ -1779,19 +1780,19 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchWithdraw(opts *bind.Wa // New log arrived, parse the event and forward to the user event := new(WithdrawalDelayerWithdraw) if err := _WithdrawalDelayer.contract.UnpackLog(event, "Withdraw", log); err != nil { - return err + return tracerr.Wrap(err) } event.Raw = log select { case sink <- event: case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } case err := <-sub.Err(): - return err + return tracerr.Wrap(err) case <-quit: return nil } @@ -1805,7 +1806,7 @@ func (_WithdrawalDelayer *WithdrawalDelayerFilterer) WatchWithdraw(opts *bind.Wa func (_WithdrawalDelayer *WithdrawalDelayerFilterer) ParseWithdraw(log types.Log) (*WithdrawalDelayerWithdraw, error) { event := new(WithdrawalDelayerWithdraw) if err := _WithdrawalDelayer.contract.UnpackLog(event, "Withdraw", log); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return event, nil } diff --git a/eth/ethereum.go b/eth/ethereum.go index 4a01f5e..76891fa 100644 --- a/eth/ethereum.go +++ b/eth/ethereum.go @@ -15,6 +15,7 @@ import ( "github.com/hermeznetwork/hermez-node/common" HEZ "github.com/hermeznetwork/hermez-node/eth/contracts/tokenHEZ" "github.com/hermeznetwork/hermez-node/log" + "github.com/hermeznetwork/tracerr" ) // ERC20Consts are the constants defined in a particular ERC20 Token instance @@ -105,7 +106,7 @@ func (c *EthereumClient) Account() *accounts.Account { // EthAddress returns the ethereum address of the account loaded into the EthereumClient func (c *EthereumClient) EthAddress() (*ethCommon.Address, error) { if c.account == nil { - return nil, ErrAccountNil + return nil, tracerr.Wrap(ErrAccountNil) } return &c.account.Address, nil } @@ -116,12 +117,12 @@ func (c *EthereumClient) EthAddress() (*ethCommon.Address, error) { func (c *EthereumClient) CallAuth(gasLimit uint64, fn func(*ethclient.Client, *bind.TransactOpts) (*types.Transaction, error)) (*types.Transaction, error) { if c.account == nil { - return nil, ErrAccountNil + return nil, tracerr.Wrap(ErrAccountNil) } gasPrice, err := c.client.SuggestGasPrice(context.Background()) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } inc := new(big.Int).Set(gasPrice) inc.Div(inc, new(big.Int).SetUint64(c.config.GasPriceDiv)) @@ -130,7 +131,7 @@ func (c *EthereumClient) CallAuth(gasLimit uint64, auth, err := bind.NewKeyStoreTransactor(c.ks, *c.account) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } auth.Value = big.NewInt(0) // in wei if gasLimit == 0 { @@ -144,7 +145,7 @@ func (c *EthereumClient) CallAuth(gasLimit uint64, if tx != nil { log.Debugw("Transaction", "tx", tx.Hash().Hex(), "nonce", tx.Nonce()) } - return tx, err + return tx, tracerr.Wrap(err) } // ContractData contains the contract data @@ -167,20 +168,20 @@ func (c *EthereumClient) Deploy(name string, func(client *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) { addr, tx, _, err := fn(client, auth) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } contractData.Address = addr return tx, nil }, ) if err != nil { - return contractData, fmt.Errorf(errStrDeploy, name, err) + return contractData, tracerr.Wrap(fmt.Errorf(errStrDeploy, name, err)) } log.Infow("Waiting receipt", "tx", tx.Hash().Hex(), "contract", name) contractData.Tx = tx receipt, err := c.WaitReceipt(tx) if err != nil { - return contractData, fmt.Errorf(errStrWaitReceipt, name, err) + return contractData, tracerr.Wrap(fmt.Errorf(errStrWaitReceipt, name, err)) } contractData.Receipt = receipt return contractData, nil @@ -229,16 +230,16 @@ func (c *EthereumClient) waitReceipt(ctx context.Context, tx *types.Transaction, if receipt != nil && receipt.Status == types.ReceiptStatusFailed { log.Errorw("Failed transaction", "tx", txHash.Hex()) - return receipt, ErrReceiptStatusFailed + return receipt, tracerr.Wrap(ErrReceiptStatusFailed) } if receipt == nil { log.Debugw("Pendingtransaction / Wait receipt timeout", "tx", txHash.Hex(), "lasterr", err) - return receipt, ErrReceiptNotReceived + return receipt, tracerr.Wrap(ErrReceiptNotReceived) } log.Debugw("Successful transaction", "tx", txHash.Hex()) - return receipt, err + return receipt, tracerr.Wrap(err) } // EthLastBlock returns the last block number in the blockchain @@ -247,7 +248,7 @@ func (c *EthereumClient) EthLastBlock() (int64, error) { defer cancel() header, err := c.client.HeaderByNumber(ctx, nil) if err != nil { - return 0, err + return 0, tracerr.Wrap(err) } return header.Number.Int64(), nil } @@ -266,7 +267,7 @@ func (c *EthereumClient) EthBlockByNumber(ctx context.Context, number int64) (*c } block, err := c.client.BlockByNumber(ctx, blockNum) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } b := &common.Block{ Num: block.Number().Int64(), @@ -283,21 +284,21 @@ func (c *EthereumClient) EthERC20Consts(tokenAddress ethCommon.Address) (*ERC20C // ERC20, which allows us to access the standard ERC20 constants. instance, err := HEZ.NewHEZ(tokenAddress, c.client) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } name, err := instance.Name(nil) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } symbol, err := instance.Symbol(nil) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } decimals, err := instance.Decimals(nil) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &ERC20Consts{ Name: name, diff --git a/eth/rollup.go b/eth/rollup.go index 99a8110..51f72ee 100644 --- a/eth/rollup.go +++ b/eth/rollup.go @@ -17,6 +17,7 @@ import ( Hermez "github.com/hermeznetwork/hermez-node/eth/contracts/hermez" HEZ "github.com/hermeznetwork/hermez-node/eth/contracts/tokenHEZ" "github.com/hermeznetwork/hermez-node/log" + "github.com/hermeznetwork/tracerr" "github.com/iden3/go-iden3-crypto/babyjub" ) @@ -202,19 +203,19 @@ type RollupClient struct { func NewRollupClient(client *EthereumClient, address ethCommon.Address, tokenHEZCfg TokenConfig) (*RollupClient, error) { contractAbi, err := abi.JSON(strings.NewReader(string(Hermez.HermezABI))) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } hermez, err := Hermez.NewHermez(address, client.Client()) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } tokenHEZ, err := HEZ.NewHEZ(tokenHEZCfg.Address, client.Client()) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } chainID, err := client.client.ChainID(context.Background()) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &RollupClient{ client: client, @@ -234,7 +235,7 @@ func (c *RollupClient) RollupForgeBatch(args *RollupForgeBatchArgs) (tx *types.T func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) { rollupConst, err := c.RollupConstants() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } nLevels := rollupConst.Verifiers[args.VerifierIdx].NLevels lenBytes := nLevels / 8 //nolint:gomnd @@ -244,7 +245,7 @@ func (c *RollupClient) RollupForgeBatch(args *RollupForgeBatchArgs) (tx *types.T l1 := args.L1CoordinatorTxs[i] bytesl1, err := l1.BytesCoordinatorTx(args.L1CoordinatorTxsAuths[i]) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } l1CoordinatorBytes = append(l1CoordinatorBytes, bytesl1[:]...) } @@ -253,14 +254,14 @@ func (c *RollupClient) RollupForgeBatch(args *RollupForgeBatchArgs) (tx *types.T l2 := args.L2TxsData[i] bytesl2, err := l2.BytesDataAvailability(uint32(nLevels)) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } l2DataBytes = append(l2DataBytes, bytesl2[:]...) } var feeIdxCoordinator []byte if len(args.FeeIdxCoordinator) > common.RollupConstMaxFeeIdxCoordinator { - return nil, fmt.Errorf("len(args.FeeIdxCoordinator) > %v", - common.RollupConstMaxFeeIdxCoordinator) + return nil, tracerr.Wrap(fmt.Errorf("len(args.FeeIdxCoordinator) > %v", + common.RollupConstMaxFeeIdxCoordinator)) } for i := 0; i < common.RollupConstMaxFeeIdxCoordinator; i++ { feeIdx := common.Idx(0) @@ -269,14 +270,14 @@ func (c *RollupClient) RollupForgeBatch(args *RollupForgeBatchArgs) (tx *types.T } bytesFeeIdx, err := feeIdx.Bytes() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } feeIdxCoordinator = append(feeIdxCoordinator, bytesFeeIdx[len(bytesFeeIdx)-int(lenBytes):]...) } return c.hermez.ForgeBatch(auth, newLastIdx, args.NewStRoot, args.NewExitRoot, l1CoordinatorBytes, l2DataBytes, feeIdxCoordinator, args.VerifierIdx, args.L1Batch, args.ProofA, args.ProofB, args.ProofC) }, ); err != nil { - return nil, fmt.Errorf("Failed forge batch: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed forge batch: %w", err)) } return tx, nil } @@ -292,7 +293,7 @@ func (c *RollupClient) RollupAddToken(tokenAddress ethCommon.Address, feeAddToke spender := c.address nonce, err := c.tokenHEZ.Nonces(nil, owner) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } tokenName := c.tokenHEZCfg.Name tokenAddr := c.tokenHEZCfg.Address @@ -303,7 +304,7 @@ func (c *RollupClient) RollupAddToken(tokenAddress ethCommon.Address, feeAddToke return c.hermez.AddToken(auth, tokenAddress, permit) }, ); err != nil { - return nil, fmt.Errorf("Failed add Token %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed add Token %w", err)) } return tx, nil } @@ -321,7 +322,7 @@ func (c *RollupClient) RollupWithdrawMerkleProof(fromBJJ *babyjub.PublicKey, tok return c.hermez.WithdrawMerkleProof(auth, tokenID, amount, babyPubKey, numExitRootB, siblings, idxBig, instantWithdraw) }, ); err != nil { - return nil, fmt.Errorf("Failed update WithdrawMerkleProof: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed update WithdrawMerkleProof: %w", err)) } return tx, nil } @@ -329,7 +330,7 @@ func (c *RollupClient) RollupWithdrawMerkleProof(fromBJJ *babyjub.PublicKey, tok // RollupWithdrawCircuit is the interface to call the smart contract function func (c *RollupClient) RollupWithdrawCircuit(proofA, proofC [2]*big.Int, proofB [2][2]*big.Int, tokenID uint32, numExitRoot, idx int64, amount *big.Int, instantWithdraw bool) (*types.Transaction, error) { log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // RollupL1UserTxERC20ETH is the interface to call the smart contract function @@ -344,11 +345,11 @@ func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromId toIdxBig := big.NewInt(toIdx) loadAmountF, err := common.NewFloat16(loadAmount) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } amountF, err := common.NewFloat16(amount) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } if tokenID == 0 { auth.Value = loadAmount @@ -358,7 +359,7 @@ func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromId uint16(amountF), tokenID, toIdxBig, permit) }, ); err != nil { - return nil, fmt.Errorf("Failed add L1 Tx ERC20/ETH: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed add L1 Tx ERC20/ETH: %w", err)) } return tx, nil } @@ -375,11 +376,11 @@ func (c *RollupClient) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fro toIdxBig := big.NewInt(toIdx) loadAmountF, err := common.NewFloat16(loadAmount) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } amountF, err := common.NewFloat16(amount) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } if tokenID == 0 { auth.Value = loadAmount @@ -388,7 +389,7 @@ func (c *RollupClient) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fro spender := c.address nonce, err := c.tokenHEZ.Nonces(nil, owner) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } tokenName := c.tokenHEZCfg.Name tokenAddr := c.tokenHEZCfg.Address @@ -399,7 +400,7 @@ func (c *RollupClient) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fro uint16(amountF), tokenID, toIdxBig, permit) }, ); err != nil { - return nil, fmt.Errorf("Failed add L1 Tx ERC20Permit: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed add L1 Tx ERC20Permit: %w", err)) } return tx, nil } @@ -408,9 +409,9 @@ func (c *RollupClient) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fro func (c *RollupClient) RollupRegisterTokensCount() (registerTokensCount *big.Int, err error) { if err := c.client.Call(func(ec *ethclient.Client) error { registerTokensCount, err = c.hermez.RegisterTokensCount(nil) - return err + return tracerr.Wrap(err) }); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return registerTokensCount, nil } @@ -420,9 +421,9 @@ func (c *RollupClient) RollupLastForgedBatch() (lastForgedBatch int64, err error if err := c.client.Call(func(ec *ethclient.Client) error { _lastForgedBatch, err := c.hermez.LastForgedBatch(nil) lastForgedBatch = int64(_lastForgedBatch) - return err + return tracerr.Wrap(err) }); err != nil { - return 0, err + return 0, tracerr.Wrap(err) } return lastForgedBatch, nil } @@ -435,7 +436,7 @@ func (c *RollupClient) RollupUpdateForgeL1L2BatchTimeout(newForgeL1L2BatchTimeou return c.hermez.UpdateForgeL1L2BatchTimeout(auth, uint8(newForgeL1L2BatchTimeout)) }, ); err != nil { - return nil, fmt.Errorf("Failed update ForgeL1L2BatchTimeout: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed update ForgeL1L2BatchTimeout: %w", err)) } return tx, nil } @@ -448,7 +449,7 @@ func (c *RollupClient) RollupUpdateFeeAddToken(newFeeAddToken *big.Int) (tx *typ return c.hermez.UpdateFeeAddToken(auth, newFeeAddToken) }, ); err != nil { - return nil, fmt.Errorf("Failed update FeeAddToken: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed update FeeAddToken: %w", err)) } return tx, nil } @@ -459,18 +460,18 @@ func (c *RollupClient) RollupConstants() (rollupConstants *common.RollupConstant if err := c.client.Call(func(ec *ethclient.Client) error { absoluteMaxL1L2BatchTimeout, err := c.hermez.ABSOLUTEMAXL1L2BATCHTIMEOUT(nil) if err != nil { - return err + return tracerr.Wrap(err) } rollupConstants.AbsoluteMaxL1L2BatchTimeout = int64(absoluteMaxL1L2BatchTimeout) rollupConstants.TokenHEZ, err = c.hermez.TokenHEZ(nil) if err != nil { - return err + return tracerr.Wrap(err) } for i := int64(0); i < int64(common.LenVerifiers); i++ { var newRollupVerifier common.RollupVerifierStruct rollupVerifier, err := c.hermez.RollupVerifiers(nil, big.NewInt(i)) if err != nil { - return err + return tracerr.Wrap(err) } newRollupVerifier.MaxTx = rollupVerifier.MaxTx.Int64() newRollupVerifier.NLevels = rollupVerifier.NLevels.Int64() @@ -478,20 +479,20 @@ func (c *RollupClient) RollupConstants() (rollupConstants *common.RollupConstant } rollupConstants.HermezAuctionContract, err = c.hermez.HermezAuctionContract(nil) if err != nil { - return err + return tracerr.Wrap(err) } rollupConstants.HermezGovernanceDAOAddress, err = c.hermez.HermezGovernanceDAOAddress(nil) if err != nil { - return err + return tracerr.Wrap(err) } rollupConstants.SafetyAddress, err = c.hermez.SafetyAddress(nil) if err != nil { - return err + return tracerr.Wrap(err) } rollupConstants.WithdrawDelayerContract, err = c.hermez.WithdrawDelayerContract(nil) - return err + return tracerr.Wrap(err) }); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return rollupConstants, nil } @@ -521,7 +522,7 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC } logs, err := c.client.client.FilterLogs(context.Background(), query) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } if len(logs) > 0 { blockHash = &logs[0].BlockHash @@ -529,7 +530,7 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC for _, vLog := range logs { if vLog.BlockHash != *blockHash { log.Errorw("Block hash mismatch", "expected", blockHash.String(), "got", vLog.BlockHash.String()) - return nil, nil, ErrBlockHashMismatchEvent + return nil, nil, tracerr.Wrap(ErrBlockHashMismatchEvent) } switch vLog.Topics[0] { case logHermezL1UserTxEvent: @@ -537,11 +538,11 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC var L1UserTx RollupEventL1UserTx err := c.contractAbi.Unpack(&L1UserTxAux, "L1UserTxEvent", vLog.Data) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } L1Tx, err := common.L1UserTxFromBytes(L1UserTxAux.L1UserTx) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } toForgeL1TxsNum := new(big.Int).SetBytes(vLog.Topics[1][:]).Int64() L1Tx.ToForgeL1TxsNum = &toForgeL1TxsNum @@ -553,7 +554,7 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC var addToken RollupEventAddToken err := c.contractAbi.Unpack(&addToken, "AddToken", vLog.Data) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } addToken.TokenAddress = ethCommon.BytesToAddress(vLog.Topics[1].Bytes()) rollupEvents.AddToken = append(rollupEvents.AddToken, addToken) @@ -569,7 +570,7 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC } err := c.contractAbi.Unpack(&updateForgeL1L2BatchTimeout, "UpdateForgeL1L2BatchTimeout", vLog.Data) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } rollupEvents.UpdateForgeL1L2BatchTimeout = append(rollupEvents.UpdateForgeL1L2BatchTimeout, RollupEventUpdateForgeL1L2BatchTimeout{ @@ -579,7 +580,7 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC var updateFeeAddToken RollupEventUpdateFeeAddToken err := c.contractAbi.Unpack(&updateFeeAddToken, "UpdateFeeAddToken", vLog.Data) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } rollupEvents.UpdateFeeAddToken = append(rollupEvents.UpdateFeeAddToken, updateFeeAddToken) case logHermezWithdrawEvent: @@ -602,25 +603,25 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupForgeBatchArgs, *ethCommon.Address, error) { tx, _, err := c.client.client.TransactionByHash(context.Background(), ethTxHash) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } txData := tx.Data() method, err := c.contractAbi.MethodById(txData[:4]) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } receipt, err := c.client.client.TransactionReceipt(context.Background(), ethTxHash) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } sender, err := c.client.client.TransactionSender(context.Background(), tx, receipt.Logs[0].BlockHash, receipt.Logs[0].Index) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } var aux RollupForgeBatchArgsAux if err := method.Inputs.Unpack(&aux, txData[4:]); err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } rollupForgeBatchArgs := RollupForgeBatchArgs{ L1Batch: aux.L1Batch, @@ -648,14 +649,14 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupFo signature = append(signature, v) l1Tx, err := common.L1CoordinatorTxFromBytes(bytesL1Coordinator, c.chainID, c.address) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } rollupForgeBatchArgs.L1CoordinatorTxs = append(rollupForgeBatchArgs.L1CoordinatorTxs, *l1Tx) rollupForgeBatchArgs.L1CoordinatorTxsAuths = append(rollupForgeBatchArgs.L1CoordinatorTxsAuths, signature) } rollupConsts, err := c.RollupConstants() if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } nLevels := rollupConsts.Verifiers[rollupForgeBatchArgs.VerifierIdx].NLevels lenL2TxsBytes := int((nLevels/8)*2 + 2 + 1) @@ -663,7 +664,7 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupFo for i := 0; i < numTxsL2; i++ { l2Tx, err := common.L2TxFromBytes(aux.L2TxsData[i*lenL2TxsBytes:(i+1)*lenL2TxsBytes], int(nLevels)) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } rollupForgeBatchArgs.L2TxsData = append(rollupForgeBatchArgs.L2TxsData, *l2Tx) } @@ -679,7 +680,7 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupFo } feeIdxCoordinator, err := common.IdxFromBytes(paddedFeeIdx[:]) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } if feeIdxCoordinator != common.Idx(0) { rollupForgeBatchArgs.FeeIdxCoordinator = append(rollupForgeBatchArgs.FeeIdxCoordinator, feeIdxCoordinator) diff --git a/eth/wdelayer.go b/eth/wdelayer.go index 05dcad7..b599c6e 100644 --- a/eth/wdelayer.go +++ b/eth/wdelayer.go @@ -16,6 +16,7 @@ import ( "github.com/hermeznetwork/hermez-node/common" WithdrawalDelayer "github.com/hermeznetwork/hermez-node/eth/contracts/withdrawdelayer" "github.com/hermeznetwork/hermez-node/log" + "github.com/hermeznetwork/tracerr" ) // DepositState is the state of Deposit @@ -140,11 +141,11 @@ type WDelayerClient struct { func NewWDelayerClient(client *EthereumClient, address ethCommon.Address) (*WDelayerClient, error) { contractAbi, err := abi.JSON(strings.NewReader(string(WithdrawalDelayer.WithdrawalDelayerABI))) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } wdelayer, err := WithdrawalDelayer.NewWithdrawalDelayer(address, client.Client()) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &WDelayerClient{ client: client, @@ -159,9 +160,9 @@ func (c *WDelayerClient) WDelayerGetHermezGovernanceDAOAddress() (hermezGovernan var _hermezGovernanceDAOAddress ethCommon.Address if err := c.client.Call(func(ec *ethclient.Client) error { _hermezGovernanceDAOAddress, err = c.wdelayer.GetHermezGovernanceDAOAddress(nil) - return err + return tracerr.Wrap(err) }); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &_hermezGovernanceDAOAddress, nil } @@ -174,7 +175,7 @@ func (c *WDelayerClient) WDelayerSetHermezGovernanceDAOAddress(newAddress ethCom return c.wdelayer.SetHermezGovernanceDAOAddress(auth, newAddress) }, ); err != nil { - return nil, fmt.Errorf("Failed setting hermezGovernanceDAOAddress: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed setting hermezGovernanceDAOAddress: %w", err)) } return tx, nil } @@ -184,9 +185,9 @@ func (c *WDelayerClient) WDelayerGetHermezKeeperAddress() (hermezKeeperAddress * var _hermezKeeperAddress ethCommon.Address if err := c.client.Call(func(ec *ethclient.Client) error { _hermezKeeperAddress, err = c.wdelayer.GetHermezKeeperAddress(nil) - return err + return tracerr.Wrap(err) }); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &_hermezKeeperAddress, nil } @@ -199,7 +200,7 @@ func (c *WDelayerClient) WDelayerSetHermezKeeperAddress(newAddress ethCommon.Add return c.wdelayer.SetHermezKeeperAddress(auth, newAddress) }, ); err != nil { - return nil, fmt.Errorf("Failed setting hermezKeeperAddress: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed setting hermezKeeperAddress: %w", err)) } return tx, nil } @@ -209,9 +210,9 @@ func (c *WDelayerClient) WDelayerGetWhiteHackGroupAddress() (whiteHackGroupAddre var _whiteHackGroupAddress ethCommon.Address if err := c.client.Call(func(ec *ethclient.Client) error { _whiteHackGroupAddress, err = c.wdelayer.GetWhiteHackGroupAddress(nil) - return err + return tracerr.Wrap(err) }); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &_whiteHackGroupAddress, nil } @@ -224,7 +225,7 @@ func (c *WDelayerClient) WDelayerSetWhiteHackGroupAddress(newAddress ethCommon.A return c.wdelayer.SetWhiteHackGroupAddress(auth, newAddress) }, ); err != nil { - return nil, fmt.Errorf("Failed setting whiteHackGroupAddress: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed setting whiteHackGroupAddress: %w", err)) } return tx, nil } @@ -233,9 +234,9 @@ func (c *WDelayerClient) WDelayerSetWhiteHackGroupAddress(newAddress ethCommon.A func (c *WDelayerClient) WDelayerIsEmergencyMode() (ermergencyMode bool, err error) { if err := c.client.Call(func(ec *ethclient.Client) error { ermergencyMode, err = c.wdelayer.IsEmergencyMode(nil) - return err + return tracerr.Wrap(err) }); err != nil { - return false, err + return false, tracerr.Wrap(err) } return ermergencyMode, nil } @@ -244,9 +245,9 @@ func (c *WDelayerClient) WDelayerIsEmergencyMode() (ermergencyMode bool, err err func (c *WDelayerClient) WDelayerGetWithdrawalDelay() (withdrawalDelay *big.Int, err error) { if err := c.client.Call(func(ec *ethclient.Client) error { withdrawalDelay, err = c.wdelayer.GetWithdrawalDelay(nil) - return err + return tracerr.Wrap(err) }); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return withdrawalDelay, nil } @@ -255,9 +256,9 @@ func (c *WDelayerClient) WDelayerGetWithdrawalDelay() (withdrawalDelay *big.Int, func (c *WDelayerClient) WDelayerGetEmergencyModeStartingTime() (emergencyModeStartingTime *big.Int, err error) { if err := c.client.Call(func(ec *ethclient.Client) error { emergencyModeStartingTime, err = c.wdelayer.GetEmergencyModeStartingTime(nil) - return err + return tracerr.Wrap(err) }); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return emergencyModeStartingTime, nil } @@ -270,7 +271,7 @@ func (c *WDelayerClient) WDelayerEnableEmergencyMode() (tx *types.Transaction, e return c.wdelayer.EnableEmergencyMode(auth) }, ); err != nil { - return nil, fmt.Errorf("Failed setting enable emergency mode: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed setting enable emergency mode: %w", err)) } return tx, nil } @@ -283,7 +284,7 @@ func (c *WDelayerClient) WDelayerChangeWithdrawalDelay(newWithdrawalDelay uint64 return c.wdelayer.ChangeWithdrawalDelay(auth, newWithdrawalDelay) }, ); err != nil { - return nil, fmt.Errorf("Failed setting withdrawal delay: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed setting withdrawal delay: %w", err)) } return tx, nil } @@ -294,9 +295,9 @@ func (c *WDelayerClient) WDelayerDepositInfo(owner, token ethCommon.Address) (de amount, depositTimestamp, err := c.wdelayer.DepositInfo(nil, owner, token) depositInfo.Amount = amount depositInfo.DepositTimestamp = depositTimestamp - return err + return tracerr.Wrap(err) }); err != nil { - return depositInfo, err + return depositInfo, tracerr.Wrap(err) } return depositInfo, nil } @@ -309,7 +310,7 @@ func (c *WDelayerClient) WDelayerDeposit(owner, token ethCommon.Address, amount return c.wdelayer.Deposit(auth, owner, token, amount) }, ); err != nil { - return nil, fmt.Errorf("Failed deposit: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed deposit: %w", err)) } return tx, nil } @@ -322,7 +323,7 @@ func (c *WDelayerClient) WDelayerWithdrawal(owner, token ethCommon.Address) (tx return c.wdelayer.Withdrawal(auth, owner, token) }, ); err != nil { - return nil, fmt.Errorf("Failed withdrawal: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed withdrawal: %w", err)) } return tx, nil } @@ -335,7 +336,7 @@ func (c *WDelayerClient) WDelayerEscapeHatchWithdrawal(to, token ethCommon.Addre return c.wdelayer.EscapeHatchWithdrawal(auth, to, token, amount) }, ); err != nil { - return nil, fmt.Errorf("Failed escapeHatchWithdrawal: %w", err) + return nil, tracerr.Wrap(fmt.Errorf("Failed escapeHatchWithdrawal: %w", err)) } return tx, nil } @@ -346,19 +347,19 @@ func (c *WDelayerClient) WDelayerConstants() (constants *common.WDelayerConstant if err := c.client.Call(func(ec *ethclient.Client) error { constants.MaxWithdrawalDelay, err = c.wdelayer.MAXWITHDRAWALDELAY(nil) if err != nil { - return err + return tracerr.Wrap(err) } constants.MaxEmergencyModeTime, err = c.wdelayer.MAXEMERGENCYMODETIME(nil) if err != nil { - return err + return tracerr.Wrap(err) } constants.HermezRollup, err = c.wdelayer.HermezRollupAddress(nil) if err != nil { - return err + return tracerr.Wrap(err) } - return err + return tracerr.Wrap(err) }); err != nil { - return constants, err + return constants, tracerr.Wrap(err) } return constants, nil } @@ -393,7 +394,7 @@ func (c *WDelayerClient) WDelayerEventsByBlock(blockNum int64) (*WDelayerEvents, logs, err := c.client.client.FilterLogs(context.Background(), query) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } if len(logs) > 0 { blockHash = &logs[0].BlockHash @@ -401,14 +402,14 @@ func (c *WDelayerClient) WDelayerEventsByBlock(blockNum int64) (*WDelayerEvents, for _, vLog := range logs { if vLog.BlockHash != *blockHash { log.Errorw("Block hash mismatch", "expected", blockHash.String(), "got", vLog.BlockHash.String()) - return nil, nil, ErrBlockHashMismatchEvent + return nil, nil, tracerr.Wrap(ErrBlockHashMismatchEvent) } switch vLog.Topics[0] { case logWDelayerDeposit: var deposit WDelayerEventDeposit err := c.contractAbi.Unpack(&deposit, "Deposit", vLog.Data) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } deposit.Owner = ethCommon.BytesToAddress(vLog.Topics[1].Bytes()) deposit.Token = ethCommon.BytesToAddress(vLog.Topics[2].Bytes()) @@ -419,7 +420,7 @@ func (c *WDelayerClient) WDelayerEventsByBlock(blockNum int64) (*WDelayerEvents, var withdraw WDelayerEventWithdraw err := c.contractAbi.Unpack(&withdraw, "Withdraw", vLog.Data) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } withdraw.Token = ethCommon.BytesToAddress(vLog.Topics[1].Bytes()) withdraw.Owner = ethCommon.BytesToAddress(vLog.Topics[2].Bytes()) @@ -433,7 +434,7 @@ func (c *WDelayerClient) WDelayerEventsByBlock(blockNum int64) (*WDelayerEvents, var withdrawalDelay WDelayerEventNewWithdrawalDelay err := c.contractAbi.Unpack(&withdrawalDelay, "NewWithdrawalDelay", vLog.Data) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } wdelayerEvents.NewWithdrawalDelay = append(wdelayerEvents.NewWithdrawalDelay, withdrawalDelay) @@ -441,7 +442,7 @@ func (c *WDelayerClient) WDelayerEventsByBlock(blockNum int64) (*WDelayerEvents, var escapeHatchWithdrawal WDelayerEventEscapeHatchWithdrawal err := c.contractAbi.Unpack(&escapeHatchWithdrawal, "EscapeHatchWithdrawal", vLog.Data) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } escapeHatchWithdrawal.Who = ethCommon.BytesToAddress(vLog.Topics[1].Bytes()) escapeHatchWithdrawal.To = ethCommon.BytesToAddress(vLog.Topics[2].Bytes()) @@ -452,7 +453,7 @@ func (c *WDelayerClient) WDelayerEventsByBlock(blockNum int64) (*WDelayerEvents, var keeperAddress WDelayerEventNewHermezKeeperAddress err := c.contractAbi.Unpack(&keeperAddress, "NewHermezKeeperAddress", vLog.Data) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } wdelayerEvents.NewHermezKeeperAddress = append(wdelayerEvents.NewHermezKeeperAddress, keeperAddress) @@ -460,7 +461,7 @@ func (c *WDelayerClient) WDelayerEventsByBlock(blockNum int64) (*WDelayerEvents, var whiteHackGroupAddress WDelayerEventNewWhiteHackGroupAddress err := c.contractAbi.Unpack(&whiteHackGroupAddress, "NewWhiteHackGroupAddress", vLog.Data) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } wdelayerEvents.NewWhiteHackGroupAddress = append(wdelayerEvents.NewWhiteHackGroupAddress, whiteHackGroupAddress) @@ -468,7 +469,7 @@ func (c *WDelayerClient) WDelayerEventsByBlock(blockNum int64) (*WDelayerEvents, var governanceDAOAddress WDelayerEventNewHermezGovernanceDAOAddress err := c.contractAbi.Unpack(&governanceDAOAddress, "NewHermezGovernanceDAOAddress", vLog.Data) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } wdelayerEvents.NewHermezGovernanceDAOAddress = append(wdelayerEvents.NewHermezGovernanceDAOAddress, governanceDAOAddress) } diff --git a/node/node.go b/node/node.go index 329b6e4..c3e317f 100644 --- a/node/node.go +++ b/node/node.go @@ -24,6 +24,7 @@ import ( "github.com/hermeznetwork/hermez-node/synchronizer" "github.com/hermeznetwork/hermez-node/test/debugapi" "github.com/hermeznetwork/hermez-node/txselector" + "github.com/hermeznetwork/tracerr" "github.com/jmoiron/sqlx" ) @@ -73,19 +74,19 @@ func NewNode(mode Mode, cfg *config.Node, coordCfg *config.Coordinator) (*Node, cfg.PostgreSQL.Name, ) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } historyDB := historydb.NewHistoryDB(db) stateDB, err := statedb.NewStateDB(cfg.StateDB.Path, statedb.TypeSynchronizer, 32) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } ethClient, err := ethclient.Dial(cfg.Web3.URL) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } var ethCfg eth.EthereumConfig if mode == ModeCoordinator { @@ -114,7 +115,7 @@ func NewNode(mode Mode, cfg *config.Node, coordCfg *config.Coordinator) (*Node, }, }) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } sync, err := synchronizer.NewSynchronizer(client, historyDB, stateDB, synchronizer.Config{ @@ -123,7 +124,7 @@ func NewNode(mode Mode, cfg *config.Node, coordCfg *config.Coordinator) (*Node, StatsRefreshPeriod: cfg.Synchronizer.StatsRefreshPeriod.Duration, }) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } varsRollup, varsAuction, varsWDelayer := sync.SCVars() initSCVars := synchronizer.SCVariables{ @@ -150,16 +151,16 @@ func NewNode(mode Mode, cfg *config.Node, coordCfg *config.Coordinator) (*Node, // TODO: Get (maxL1UserTxs, maxL1OperatorTxs, maxTxs) from the smart contract txSelector, err := txselector.NewTxSelector(coordCfg.TxSelector.Path, stateDB, l2DB, 10, 10, 10) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } // TODO: Get (configCircuits []ConfigCircuit, batchNum common.BatchNum, nLevels uint64) from smart contract nLevels := uint64(32) //nolint:gomnd batchBuilder, err := batchbuilder.NewBatchBuilder(coordCfg.BatchBuilder.Path, stateDB, nil, 0, nLevels) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } serverProofs := make([]coordinator.ServerProofInterface, len(coordCfg.ServerProofs)) for i, serverProofCfg := range coordCfg.ServerProofs { @@ -180,18 +181,18 @@ func NewNode(mode Mode, cfg *config.Node, coordCfg *config.Coordinator) (*Node, &initSCVars, ) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } } var nodeAPI *NodeAPI if cfg.API.Address != "" { if cfg.API.UpdateMetricsInterval.Duration == 0 { - return nil, fmt.Errorf("invalid cfg.API.UpdateMetricsInterval: %v", - cfg.API.UpdateMetricsInterval.Duration) + return nil, tracerr.Wrap(fmt.Errorf("invalid cfg.API.UpdateMetricsInterval: %v", + cfg.API.UpdateMetricsInterval.Duration)) } if cfg.API.UpdateRecommendedFeeInterval.Duration == 0 { - return nil, fmt.Errorf("invalid cfg.API.UpdateRecommendedFeeInterval: %v", - cfg.API.UpdateRecommendedFeeInterval.Duration) + return nil, tracerr.Wrap(fmt.Errorf("invalid cfg.API.UpdateRecommendedFeeInterval: %v", + cfg.API.UpdateRecommendedFeeInterval.Duration)) } server := gin.Default() coord := false @@ -213,7 +214,7 @@ func NewNode(mode Mode, cfg *config.Node, coordCfg *config.Coordinator) (*Node, }, ) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } nodeAPI.api.SetRollupVariables(initSCVars.Rollup) nodeAPI.api.SetAuctionVariables(initSCVars.Auction) @@ -273,7 +274,7 @@ func NewNodeAPI( config, ) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &NodeAPI{ addr: addr, @@ -295,8 +296,7 @@ func (a *NodeAPI) Run(ctx context.Context) error { } go func() { log.Infof("NodeAPI is ready at %v", a.addr) - if err := server.ListenAndServe(); err != nil && - err != http.ErrServerClosed { + if err := server.ListenAndServe(); err != nil && tracerr.Unwrap(err) != http.ErrServerClosed { log.Fatalf("Listen: %s\n", err) } }() @@ -306,7 +306,7 @@ func (a *NodeAPI) Run(ctx context.Context) error { ctxTimeout, cancel := context.WithTimeout(context.Background(), 10*time.Second) //nolint:gomnd defer cancel() if err := server.Shutdown(ctxTimeout); err != nil { - return err + return tracerr.Wrap(err) } log.Info("NodeAPI done") return nil diff --git a/priceupdater/priceupdater.go b/priceupdater/priceupdater.go index 1b1f41a..69da16a 100644 --- a/priceupdater/priceupdater.go +++ b/priceupdater/priceupdater.go @@ -8,6 +8,7 @@ import ( "github.com/dghubble/sling" "github.com/hermeznetwork/hermez-node/db/historydb" "github.com/hermeznetwork/hermez-node/log" + "github.com/hermeznetwork/tracerr" ) const ( @@ -66,7 +67,7 @@ func (p *PriceUpdater) UpdatePrices() { func (p *PriceUpdater) UpdateTokenList() error { tokenSymbols, err := p.db.GetTokenSymbols() if err != nil { - return err + return tracerr.Wrap(err) } p.tokenSymbols = tokenSymbols return nil diff --git a/synchronizer/synchronizer.go b/synchronizer/synchronizer.go index 60bd5e6..109f6af 100644 --- a/synchronizer/synchronizer.go +++ b/synchronizer/synchronizer.go @@ -14,6 +14,7 @@ import ( "github.com/hermeznetwork/hermez-node/db/statedb" "github.com/hermeznetwork/hermez-node/eth" "github.com/hermeznetwork/hermez-node/log" + "github.com/hermeznetwork/tracerr" ) var ( @@ -122,11 +123,11 @@ func (s *StatsHolder) UpdateEth(ethClient eth.ClientInterface) error { lastBlock, err := ethClient.EthBlockByNumber(context.TODO(), -1) if err != nil { - return err + return tracerr.Wrap(err) } lastBatch, err := ethClient.RollupLastForgedBatch() if err != nil { - return err + return tracerr.Wrap(err) } s.rw.Lock() s.Eth.Updated = now @@ -218,17 +219,17 @@ func NewSynchronizer(ethClient eth.ClientInterface, historyDB *historydb.History auctionConstants, err := ethClient.AuctionConstants() if err != nil { log.Errorw("NewSynchronizer ethClient.AuctionConstants()", "err", err) - return nil, err + return nil, tracerr.Wrap(err) } rollupConstants, err := ethClient.RollupConstants() if err != nil { log.Errorw("NewSynchronizer ethClient.RollupConstants()", "err", err) - return nil, err + return nil, tracerr.Wrap(err) } wDelayerConstants, err := ethClient.WDelayerConstants() if err != nil { log.Errorw("NewSynchronizer ethClient.WDelayerConstants()", "err", err) - return nil, err + return nil, tracerr.Wrap(err) } // Set startBlockNum to the minimum between Auction, Rollup and @@ -296,7 +297,7 @@ func (s *Synchronizer) updateCurrentSlotIfSync(batchesLen int) error { // fmt.Printf("DBG -1 from: %v, to: %v, len: %v\n", from, to, dbBatchesLen) if err != nil { log.Errorw("historyDB.GetBatchesLen", "err", err) - return err + return tracerr.Wrap(err) } slot.BatchesLen = dbBatchesLen } else if slotNum > slot.SlotNum { @@ -311,10 +312,10 @@ func (s *Synchronizer) updateCurrentSlotIfSync(batchesLen int) error { // If Synced, update the current coordinator if s.stats.Synced() { bidCoord, err := s.historyDB.GetBestBidCoordinator(slot.SlotNum) - if err != nil && err != sql.ErrNoRows { - return err + if err != nil && tracerr.Unwrap(err) != sql.ErrNoRows { + return tracerr.Wrap(err) } - if err == sql.ErrNoRows { + if tracerr.Unwrap(err) == sql.ErrNoRows { slot.BootCoord = true slot.Forger = s.vars.Auction.BootCoordinator slot.URL = "???" @@ -339,11 +340,11 @@ func (s *Synchronizer) updateCurrentSlotIfSync(batchesLen int) error { // BEGIN SANITY CHECK canForge, err := s.ethClient.AuctionCanForge(slot.Forger, blockNum) if err != nil { - return err + return tracerr.Wrap(err) } if !canForge { - return fmt.Errorf("Synchronized value of forger address for closed slot "+ - "differs from smart contract: %+v", slot) + return tracerr.Wrap(fmt.Errorf("Synchronized value of forger address for closed slot "+ + "differs from smart contract: %+v", slot)) } // END SANITY CHECK } @@ -355,24 +356,24 @@ func (s *Synchronizer) init() error { // Update stats parameters so that they have valid values before the // first Sync call if err := s.stats.UpdateEth(s.ethClient); err != nil { - return err + return tracerr.Wrap(err) } lastBlock := &common.Block{} lastSavedBlock, err := s.historyDB.GetLastBlock() - if err != nil && err != sql.ErrNoRows { - return err + if err != nil && tracerr.Unwrap(err) != sql.ErrNoRows { + return tracerr.Wrap(err) } // If there's no block in the DB (or we only have the default block 0), // make sure that the stateDB is clean - if err == sql.ErrNoRows || lastSavedBlock.Num == 0 { + if tracerr.Unwrap(err) == sql.ErrNoRows || lastSavedBlock.Num == 0 { if err := s.stateDB.Reset(0); err != nil { - return err + return tracerr.Wrap(err) } } else { lastBlock = lastSavedBlock } if err := s.resetState(lastBlock); err != nil { - return err + return tracerr.Wrap(err) } log.Infow("Sync init block", @@ -401,12 +402,12 @@ func (s *Synchronizer) Sync2(ctx context.Context, lastSavedBlock *common.Block) var err error // Get lastSavedBlock from History DB lastSavedBlock, err = s.historyDB.GetLastBlock() - if err != nil && err != sql.ErrNoRows { - return nil, nil, err + if err != nil && tracerr.Unwrap(err) != sql.ErrNoRows { + return nil, nil, tracerr.Wrap(err) } // If we don't have any stored block, we must do a full sync // starting from the startBlockNum - if err == sql.ErrNoRows || lastSavedBlock.Num == 0 { + if tracerr.Unwrap(err) == sql.ErrNoRows || lastSavedBlock.Num == 0 { nextBlockNum = s.startBlockNum lastSavedBlock = nil } @@ -416,16 +417,16 @@ func (s *Synchronizer) Sync2(ctx context.Context, lastSavedBlock *common.Block) } ethBlock, err := s.ethClient.EthBlockByNumber(ctx, nextBlockNum) - if err == ethereum.NotFound { + if tracerr.Unwrap(err) == ethereum.NotFound { return nil, nil, nil } else if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } log.Debugf("ethBlock: num: %v, parent: %v, hash: %v", ethBlock.Num, ethBlock.ParentHash.String(), ethBlock.Hash.String()) if err := s.stats.UpdateEth(s.ethClient); err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } log.Debugw("Syncing...", @@ -442,7 +443,7 @@ func (s *Synchronizer) Sync2(ctx context.Context, lastSavedBlock *common.Block) "block.parent(got)", ethBlock.ParentHash, "parent.hash(exp)", lastSavedBlock.Hash) lastDBBlockNum, err := s.reorg(lastSavedBlock) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } discarded := lastSavedBlock.Num - lastDBBlockNum return nil, &discarded, nil @@ -452,19 +453,19 @@ func (s *Synchronizer) Sync2(ctx context.Context, lastSavedBlock *common.Block) // Get data from the rollup contract rollupData, err := s.rollupSync(ethBlock) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } // Get data from the auction contract auctionData, err := s.auctionSync(ethBlock) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } // Get data from the WithdrawalDelayer contract wDelayerData, err := s.wdelayerSync(ethBlock) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } for i := range rollupData.Withdrawals { @@ -472,8 +473,8 @@ func (s *Synchronizer) Sync2(ctx context.Context, lastSavedBlock *common.Block) if !withdrawal.InstantWithdraw { wDelayerTransfers := wDelayerData.DepositsByTxHash[withdrawal.TxHash] if len(wDelayerTransfers) == 0 { - return nil, nil, fmt.Errorf("WDelayer deposit corresponding to " + - "non-instant rollup withdrawal not found") + return nil, nil, tracerr.Wrap(fmt.Errorf("WDelayer deposit corresponding to " + + "non-instant rollup withdrawal not found")) } // Pop the first wDelayerTransfer to consume them in chronological order wDelayerTransfer := wDelayerTransfers[0] @@ -500,7 +501,7 @@ func (s *Synchronizer) Sync2(ctx context.Context, lastSavedBlock *common.Block) // } err = s.historyDB.AddBlockSCData(&blockData) if err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } batchesLen := len(rollupData.Batches) @@ -517,7 +518,7 @@ func (s *Synchronizer) Sync2(ctx context.Context, lastSavedBlock *common.Block) &rollupData.Batches[batchesLen-1].Batch.BatchNum, lastL1BatchBlock) } if err := s.updateCurrentSlotIfSync(len(rollupData.Batches)); err != nil { - return nil, nil, err + return nil, nil, tracerr.Wrap(err) } log.Debugw("Synced block", @@ -549,13 +550,13 @@ func (s *Synchronizer) reorg(uncleBlock *common.Block) (int64, error) { ethBlock, err := s.ethClient.EthBlockByNumber(context.Background(), blockNum) if err != nil { log.Errorw("ethClient.EthBlockByNumber", "err", err) - return 0, err + return 0, tracerr.Wrap(err) } block, err = s.historyDB.GetBlock(blockNum) if err != nil { log.Errorw("historyDB.GetBlock", "err", err) - return 0, err + return 0, tracerr.Wrap(err) } if block.Hash == ethBlock.Hash { log.Debugf("Found valid block: %v", blockNum) @@ -569,11 +570,11 @@ func (s *Synchronizer) reorg(uncleBlock *common.Block) (int64, error) { // Set History DB and State DB to the correct state err := s.historyDB.Reorg(block.Num) if err != nil { - return 0, err + return 0, tracerr.Wrap(err) } if err := s.resetState(block); err != nil { - return 0, err + return 0, tracerr.Wrap(err) } return block.Num, nil @@ -583,14 +584,14 @@ func (s *Synchronizer) resetState(block *common.Block) error { rollup, auction, wDelayer, err := s.historyDB.GetSCVars() // If SCVars are not in the HistoryDB, this is probably the first run // of the Synchronizer: store the initial vars taken from config - if err == sql.ErrNoRows { + if tracerr.Unwrap(err) == sql.ErrNoRows { rollup = &s.cfg.InitialVariables.Rollup auction = &s.cfg.InitialVariables.Auction wDelayer = &s.cfg.InitialVariables.WDelayer log.Info("Setting initial SCVars in HistoryDB") if err = s.historyDB.SetInitialSCVars(rollup, auction, wDelayer); err != nil { log.Errorw("historyDB.SetInitialSCVars", "err", err) - return err + return tracerr.Wrap(err) } } s.vars.Rollup = *rollup @@ -598,33 +599,33 @@ func (s *Synchronizer) resetState(block *common.Block) error { s.vars.WDelayer = *wDelayer batchNum, err := s.historyDB.GetLastBatchNum() - if err != nil && err != sql.ErrNoRows { + if err != nil && tracerr.Unwrap(err) != sql.ErrNoRows { log.Errorw("historyDB.GetLastBatchNum", "err", err) - return err + return tracerr.Wrap(err) } - if err == sql.ErrNoRows { + if tracerr.Unwrap(err) == sql.ErrNoRows { batchNum = 0 } lastL1BatchBlockNum, err := s.historyDB.GetLastL1BatchBlockNum() - if err != nil && err != sql.ErrNoRows { + if err != nil && tracerr.Unwrap(err) != sql.ErrNoRows { log.Errorw("historyDB.GetLastL1BatchBlockNum", "err", err) - return err + return tracerr.Wrap(err) } - if err == sql.ErrNoRows { + if tracerr.Unwrap(err) == sql.ErrNoRows { lastL1BatchBlockNum = 0 } err = s.stateDB.Reset(batchNum) if err != nil { log.Errorw("stateDB.Reset", "err", err) - return err + return tracerr.Wrap(err) } s.stats.UpdateSync(block, &batchNum, &lastL1BatchBlockNum) // TODO if err := s.updateCurrentSlotIfSync(-1); err != nil { - return err + return tracerr.Wrap(err) } return nil } @@ -685,7 +686,7 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e // the expected one. rollupEvents, blockHash, err := s.ethClient.RollupEventsByBlock(blockNum) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } // No events in this block if blockHash == nil { @@ -694,13 +695,13 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e if *blockHash != ethBlock.Hash { log.Errorw("Block hash mismatch in Rollup events", "expected", ethBlock.Hash.String(), "got", blockHash.String()) - return nil, eth.ErrBlockHashMismatchEvent + return nil, tracerr.Wrap(eth.ErrBlockHashMismatchEvent) } var nextForgeL1TxsNum int64 // forgeL1TxsNum for the next L1Batch nextForgeL1TxsNumPtr, err := s.historyDB.GetLastL1TxsNum() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } if nextForgeL1TxsNumPtr != nil { nextForgeL1TxsNum = *nextForgeL1TxsNumPtr + 1 @@ -711,7 +712,7 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e // Get L1UserTX rollupData.L1UserTxs, err = getL1UserTx(rollupEvents.L1UserTx, blockNum) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } // Get ForgeBatch events to get the L1CoordinatorTxs @@ -722,7 +723,7 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e // Get the input for each Tx forgeBatchArgs, sender, err := s.ethClient.RollupForgeBatchArgs(evtForgeBatch.EthTxHash) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } batchNum := common.BatchNum(evtForgeBatch.BatchNum) @@ -736,7 +737,7 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e // First try to find them in HistoryDB. l1UserTxs, err = s.historyDB.GetL1UserTxs(nextForgeL1TxsNum) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } // Apart from the DB, try to find them in this block. // This could happen because in a block there could be @@ -763,7 +764,7 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e l1CoordinatorTx.BatchNum = &batchNum l1Tx, err := common.NewL1Tx(&l1CoordinatorTx) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } batchData.L1CoordinatorTxs = append(batchData.L1CoordinatorTxs, *l1Tx) @@ -787,7 +788,7 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e processTxsOut, err := s.stateDB.ProcessTxs(ptc, forgeBatchArgs.FeeIdxCoordinator, l1UserTxs, batchData.L1CoordinatorTxs, poolL2Txs) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } // Set batchNum in exits @@ -799,7 +800,7 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e l2Txs, err := common.PoolL2TxsToL2Txs(poolL2Txs) // NOTE: This is a big uggly, find a better way if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } for i := range l2Txs { @@ -809,7 +810,7 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e tx.BatchNum = batchNum nTx, err := common.NewL2Tx(tx) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } batchData.L2Txs = append(batchData.L2Txs, *nTx) @@ -923,7 +924,7 @@ func (s *Synchronizer) auctionSync(ethBlock *common.Block) (*common.AuctionData, // Get auction events in the block auctionEvents, blockHash, err := s.ethClient.AuctionEventsByBlock(blockNum) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } // No events in this block if blockHash == nil { @@ -932,7 +933,7 @@ func (s *Synchronizer) auctionSync(ethBlock *common.Block) (*common.AuctionData, if *blockHash != ethBlock.Hash { log.Errorw("Block hash mismatch in Auction events", "expected", ethBlock.Hash.String(), "got", blockHash.String()) - return nil, eth.ErrBlockHashMismatchEvent + return nil, tracerr.Wrap(eth.ErrBlockHashMismatchEvent) } // Get bids @@ -988,8 +989,8 @@ func (s *Synchronizer) auctionSync(ethBlock *common.Block) (*common.AuctionData, } for _, evt := range auctionEvents.NewDefaultSlotSetBid { if evt.SlotSet > 6 { //nolint:gomnd - return nil, fmt.Errorf("unexpected SlotSet in "+ - "auctionEvents.NewDefaultSlotSetBid: %v", evt.SlotSet) + return nil, tracerr.Wrap(fmt.Errorf("unexpected SlotSet in "+ + "auctionEvents.NewDefaultSlotSetBid: %v", evt.SlotSet)) } s.vars.Auction.DefaultSlotSetBid[evt.SlotSet] = evt.NewInitialMinBid s.vars.Auction.DefaultSlotSetBidSlotNum = s.consts.Auction.SlotNum(blockNum) + @@ -1017,7 +1018,7 @@ func (s *Synchronizer) wdelayerSync(ethBlock *common.Block) (*common.WDelayerDat // Get wDelayer events in the block wDelayerEvents, blockHash, err := s.ethClient.WDelayerEventsByBlock(blockNum) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } // No events in this block if blockHash == nil { @@ -1026,7 +1027,7 @@ func (s *Synchronizer) wdelayerSync(ethBlock *common.Block) (*common.WDelayerDat if *blockHash != ethBlock.Hash { log.Errorw("Block hash mismatch in WDelayer events", "expected", ethBlock.Hash.String(), "got", blockHash.String()) - return nil, eth.ErrBlockHashMismatchEvent + return nil, tracerr.Wrap(eth.ErrBlockHashMismatchEvent) } for _, evt := range wDelayerEvents.Deposit { @@ -1086,7 +1087,7 @@ func getL1UserTx(eventsL1UserTx []eth.RollupEventL1UserTx, blockNum int64) ([]co // Check validity of L1UserTx l1Tx, err := common.NewL1Tx(&eventsL1UserTx[i].L1UserTx) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } l1Txs[i] = *l1Tx } diff --git a/test/debugapi/debugapi.go b/test/debugapi/debugapi.go index c2638bc..2d56c56 100644 --- a/test/debugapi/debugapi.go +++ b/test/debugapi/debugapi.go @@ -11,6 +11,7 @@ import ( "github.com/hermeznetwork/hermez-node/db/statedb" "github.com/hermeznetwork/hermez-node/log" "github.com/hermeznetwork/hermez-node/synchronizer" + "github.com/hermeznetwork/tracerr" ) func handleNoRoute(c *gin.Context) { @@ -118,8 +119,7 @@ func (a *DebugAPI) Run(ctx context.Context) error { } go func() { log.Infof("DebugAPI is ready at %v", a.addr) - if err := debugAPIServer.ListenAndServe(); err != nil && - err != http.ErrServerClosed { + if err := debugAPIServer.ListenAndServe(); err != nil && tracerr.Unwrap(err) != http.ErrServerClosed { log.Fatalf("Listen: %s\n", err) } }() @@ -129,7 +129,7 @@ func (a *DebugAPI) Run(ctx context.Context) error { ctxTimeout, cancel := context.WithTimeout(context.Background(), 10*time.Second) //nolint:gomnd defer cancel() if err := debugAPIServer.Shutdown(ctxTimeout); err != nil { - return err + return tracerr.Wrap(err) } log.Info("DebugAPI done") return nil diff --git a/test/ethclient.go b/test/ethclient.go index 74f2b24..65e8956 100644 --- a/test/ethclient.go +++ b/test/ethclient.go @@ -16,6 +16,7 @@ import ( "github.com/hermeznetwork/hermez-node/common" "github.com/hermeznetwork/hermez-node/eth" "github.com/hermeznetwork/hermez-node/log" + "github.com/hermeznetwork/tracerr" "github.com/iden3/go-iden3-crypto/babyjub" "github.com/mitchellh/copystructure" ) @@ -111,7 +112,7 @@ func (a *AuctionBlock) getSlotSet(slot int64) int64 { func (a *AuctionBlock) getMinBidBySlot(slot int64) (*big.Int, error) { if slot < a.getCurrentSlotNumber()+int64(a.Vars.ClosedAuctionSlots) { - return nil, errBidClosed + return nil, tracerr.Wrap(errBidClosed) } slotSet := a.getSlotSet(slot) @@ -140,9 +141,9 @@ func (a *AuctionBlock) getMinBidBySlot(slot int64) (*big.Int, error) { func (a *AuctionBlock) forge(forger ethCommon.Address) error { if ok, err := a.canForge(forger, a.Eth.BlockNum); err != nil { - return err + return tracerr.Wrap(err) } else if !ok { - return fmt.Errorf("Can't forge") + return tracerr.Wrap(fmt.Errorf("Can't forge")) } slotToForge := a.getSlotNumber(a.Eth.BlockNum) @@ -162,7 +163,7 @@ func (a *AuctionBlock) forge(forger ethCommon.Address) error { func (a *AuctionBlock) canForge(forger ethCommon.Address, blockNum int64) (bool, error) { if blockNum < a.Constants.GenesisBlockNum { - return false, fmt.Errorf("Auction has not started yet") + return false, tracerr.Wrap(fmt.Errorf("Auction has not started yet")) } slotToForge := a.getSlotNumber(blockNum) @@ -616,7 +617,7 @@ func (c *Client) EthERC20Consts(tokenAddr ethCommon.Address) (*eth.ERC20Consts, if constants, ok := e.Tokens[tokenAddr]; ok { return &constants, nil } - return nil, fmt.Errorf("tokenAddr not found") + return nil, tracerr.Wrap(fmt.Errorf("tokenAddr not found")) } // func newHeader(number *big.Int) *types.Header { @@ -656,7 +657,7 @@ func (c *Client) EthBlockByNumber(ctx context.Context, blockNum int64) (*common. // EthAddress returns the ethereum address of the account loaded into the Client func (c *Client) EthAddress() (*ethCommon.Address, error) { if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } return c.addr, nil } @@ -697,7 +698,7 @@ var errTODO = fmt.Errorf("TODO: Not implemented yet") // RollupL1UserTxERC20Permit is the interface to call the smart contract function func (c *Client) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64, deadline *big.Int) (tx *types.Transaction, err error) { log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // RollupL1UserTxERC20ETH sends an L1UserTx to the Rollup. @@ -716,11 +717,11 @@ func (c *Client) RollupL1UserTxERC20ETH( _, err = common.NewFloat16(amount) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } _, err = common.NewFloat16(loadAmount) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } nextBlock := c.nextBlock() @@ -751,7 +752,7 @@ func (c *Client) RollupL1UserTxERC20ETH( UserOrigin: true, }) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } queue.L1TxQueue = append(queue.L1TxQueue, *l1Tx) @@ -770,7 +771,7 @@ func (c *Client) RollupL1UserTxERC20ETH( // RollupRegisterTokensCount is the interface to call the smart contract function func (c *Client) RollupRegisterTokensCount() (*big.Int, error) { log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // RollupLastForgedBatch is the interface to call the smart contract function @@ -786,7 +787,7 @@ func (c *Client) RollupLastForgedBatch() (int64, error) { // RollupWithdrawCircuit is the interface to call the smart contract function func (c *Client) RollupWithdrawCircuit(proofA, proofC [2]*big.Int, proofB [2][2]*big.Int, tokenID uint32, numExitRoot, idx int64, amount *big.Int, instantWithdraw bool) (*types.Transaction, error) { log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // RollupWithdrawMerkleProof is the interface to call the smart contract function @@ -800,10 +801,10 @@ func (c *Client) RollupWithdrawMerkleProof(babyPubKey *babyjub.PublicKey, tokenI r := nextBlock.Rollup if int(numExitRoot) >= len(r.State.ExitRoots) { - return nil, fmt.Errorf("numExitRoot >= len(r.State.ExitRoots)") + return nil, tracerr.Wrap(fmt.Errorf("numExitRoot >= len(r.State.ExitRoots)")) } if _, ok := r.State.ExitNullifierMap[numExitRoot][idx]; ok { - return nil, fmt.Errorf("exit already withdrawn") + return nil, tracerr.Wrap(fmt.Errorf("exit already withdrawn")) } r.State.ExitNullifierMap[numExitRoot][idx] = true @@ -860,16 +861,16 @@ func (c *Client) RollupForgeBatch(args *eth.RollupForgeBatchArgs) (tx *types.Tra cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } a := c.nextBlock().Auction ok, err := a.canForge(*c.addr, a.Eth.BlockNum) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } if !ok { - return nil, fmt.Errorf("incorrect slot") + return nil, tracerr.Wrap(fmt.Errorf("incorrect slot")) } // TODO: Verify proof @@ -877,7 +878,7 @@ func (c *Client) RollupForgeBatch(args *eth.RollupForgeBatchArgs) (tx *types.Tra // Auction err = a.forge(*c.addr) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } // TODO: If successful, store the tx in a successful array. @@ -902,7 +903,7 @@ func (c *Client) addBatch(args *eth.RollupForgeBatchArgs) (*types.Transaction, e r := nextBlock.Rollup r.State.StateRoot = args.NewStRoot if args.NewLastIdx < r.State.CurrentIdx { - return nil, fmt.Errorf("args.NewLastIdx < r.State.CurrentIdx") + return nil, tracerr.Wrap(fmt.Errorf("args.NewLastIdx < r.State.CurrentIdx")) } r.State.CurrentIdx = args.NewLastIdx r.State.ExitNullifierMap[int64(len(r.State.ExitRoots))] = make(map[int64]bool) @@ -938,16 +939,16 @@ func (c *Client) RollupAddToken(tokenAddress ethCommon.Address, feeAddToken *big cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } nextBlock := c.nextBlock() r := nextBlock.Rollup if _, ok := r.State.TokenMap[tokenAddress]; ok { - return nil, fmt.Errorf("Token %v already registered", tokenAddress) + return nil, tracerr.Wrap(fmt.Errorf("Token %v already registered", tokenAddress)) } if feeAddToken.Cmp(r.Vars.FeeAddToken) != 0 { - return nil, fmt.Errorf("Expected fee: %v but got: %v", r.Vars.FeeAddToken, feeAddToken) + return nil, tracerr.Wrap(fmt.Errorf("Expected fee: %v but got: %v", r.Vars.FeeAddToken, feeAddToken)) } r.State.TokenMap[tokenAddress] = true @@ -963,7 +964,7 @@ func (c *Client) RollupGetCurrentTokens() (*big.Int, error) { defer c.rw.RUnlock() log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // RollupUpdateForgeL1L2BatchTimeout is the interface to call the smart contract function @@ -973,7 +974,7 @@ func (c *Client) RollupUpdateForgeL1L2BatchTimeout(newForgeL1Timeout int64) (tx cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } nextBlock := c.nextBlock() @@ -992,11 +993,11 @@ func (c *Client) RollupUpdateFeeAddToken(newFeeAddToken *big.Int) (tx *types.Tra cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // RollupUpdateTokensHEZ is the interface to call the smart contract function @@ -1030,7 +1031,7 @@ func (c *Client) RollupEventsByBlock(blockNum int64) (*eth.RollupEvents, *ethCom block, ok := c.blocks[blockNum] if !ok { - return nil, nil, fmt.Errorf("Block %v doesn't exist", blockNum) + return nil, nil, tracerr.Wrap(fmt.Errorf("Block %v doesn't exist", blockNum)) } return &block.Rollup.Events, &block.Eth.Hash, nil } @@ -1042,7 +1043,7 @@ func (c *Client) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*eth.RollupForg batch, ok := c.forgeBatchArgs[ethTxHash] if !ok { - return nil, nil, fmt.Errorf("transaction not found") + return nil, nil, tracerr.Wrap(fmt.Errorf("transaction not found")) } return &batch.ForgeBatchArgs, &batch.Sender, nil } @@ -1058,11 +1059,11 @@ func (c *Client) AuctionSetSlotDeadline(newDeadline uint8) (tx *types.Transactio cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // AuctionGetSlotDeadline is the interface to call the smart contract function @@ -1071,7 +1072,7 @@ func (c *Client) AuctionGetSlotDeadline() (uint8, error) { defer c.rw.RUnlock() log.Error("TODO") - return 0, errTODO + return 0, tracerr.Wrap(errTODO) } // AuctionSetOpenAuctionSlots is the interface to call the smart contract function @@ -1081,7 +1082,7 @@ func (c *Client) AuctionSetOpenAuctionSlots(newOpenAuctionSlots uint16) (tx *typ cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } nextBlock := c.nextBlock() @@ -1099,7 +1100,7 @@ func (c *Client) AuctionGetOpenAuctionSlots() (uint16, error) { defer c.rw.RUnlock() log.Error("TODO") - return 0, errTODO + return 0, tracerr.Wrap(errTODO) } // AuctionSetClosedAuctionSlots is the interface to call the smart contract function @@ -1109,11 +1110,11 @@ func (c *Client) AuctionSetClosedAuctionSlots(newClosedAuctionSlots uint16) (tx cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // AuctionGetClosedAuctionSlots is the interface to call the smart contract function @@ -1122,7 +1123,7 @@ func (c *Client) AuctionGetClosedAuctionSlots() (uint16, error) { defer c.rw.RUnlock() log.Error("TODO") - return 0, errTODO + return 0, tracerr.Wrap(errTODO) } // AuctionSetOutbidding is the interface to call the smart contract function @@ -1132,11 +1133,11 @@ func (c *Client) AuctionSetOutbidding(newOutbidding uint16) (tx *types.Transacti cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // AuctionGetOutbidding is the interface to call the smart contract function @@ -1145,7 +1146,7 @@ func (c *Client) AuctionGetOutbidding() (uint16, error) { defer c.rw.RUnlock() log.Error("TODO") - return 0, errTODO + return 0, tracerr.Wrap(errTODO) } // AuctionSetAllocationRatio is the interface to call the smart contract function @@ -1155,11 +1156,11 @@ func (c *Client) AuctionSetAllocationRatio(newAllocationRatio [3]uint16) (tx *ty cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // AuctionGetAllocationRatio is the interface to call the smart contract function @@ -1168,7 +1169,7 @@ func (c *Client) AuctionGetAllocationRatio() ([3]uint16, error) { defer c.rw.RUnlock() log.Error("TODO") - return [3]uint16{}, errTODO + return [3]uint16{}, tracerr.Wrap(errTODO) } // AuctionSetDonationAddress is the interface to call the smart contract function @@ -1178,11 +1179,11 @@ func (c *Client) AuctionSetDonationAddress(newDonationAddress ethCommon.Address) cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // AuctionGetDonationAddress is the interface to call the smart contract function @@ -1191,7 +1192,7 @@ func (c *Client) AuctionGetDonationAddress() (*ethCommon.Address, error) { defer c.rw.RUnlock() log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // AuctionSetBootCoordinator is the interface to call the smart contract function @@ -1201,11 +1202,11 @@ func (c *Client) AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address) cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // AuctionGetBootCoordinator is the interface to call the smart contract function @@ -1226,11 +1227,11 @@ func (c *Client) AuctionChangeDefaultSlotSetBid(slotSet int64, newInitialMinBid cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // AuctionSetCoordinator is the interface to call the smart contract function @@ -1240,7 +1241,7 @@ func (c *Client) AuctionSetCoordinator(forger ethCommon.Address, URL string) (tx cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } nextBlock := c.nextBlock() @@ -1272,7 +1273,7 @@ func (c *Client) AuctionIsRegisteredCoordinator(forgerAddress ethCommon.Address) defer c.rw.RUnlock() log.Error("TODO") - return false, errTODO + return false, tracerr.Wrap(errTODO) } // AuctionUpdateCoordinatorInfo is the interface to call the smart contract function @@ -1282,11 +1283,11 @@ func (c *Client) AuctionUpdateCoordinatorInfo(forgerAddress ethCommon.Address, n cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // AuctionGetSlotNumber is the interface to call the smart contract function @@ -1305,7 +1306,7 @@ func (c *Client) AuctionGetCurrentSlotNumber() (int64, error) { defer c.rw.RUnlock() log.Error("TODO") - return 0, errTODO + return 0, tracerr.Wrap(errTODO) } // AuctionGetMinBidBySlot is the interface to call the smart contract function @@ -1314,7 +1315,7 @@ func (c *Client) AuctionGetMinBidBySlot(slot int64) (*big.Int, error) { defer c.rw.RUnlock() log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // AuctionGetDefaultSlotSetBid is the interface to call the smart contract function @@ -1323,7 +1324,7 @@ func (c *Client) AuctionGetDefaultSlotSetBid(slotSet uint8) (*big.Int, error) { defer c.rw.RUnlock() log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // AuctionGetSlotSet is the interface to call the smart contract function @@ -1332,7 +1333,7 @@ func (c *Client) AuctionGetSlotSet(slot int64) (*big.Int, error) { defer c.rw.RUnlock() log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // AuctionTokensReceived is the interface to call the smart contract function @@ -1354,30 +1355,30 @@ func (c *Client) AuctionBid(amount *big.Int, slot int64, bidAmount *big.Int, cpy := c.nextBlock().copy() defer func() { func() { c.revertIfErr(err, cpy) }() }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } nextBlock := c.nextBlock() a := nextBlock.Auction if slot < a.getCurrentSlotNumber()+int64(a.Vars.ClosedAuctionSlots) { - return nil, errBidClosed + return nil, tracerr.Wrap(errBidClosed) } if slot >= a.getCurrentSlotNumber()+int64(a.Vars.ClosedAuctionSlots)+int64(a.Vars.OpenAuctionSlots) { - return nil, errBidNotOpen + return nil, tracerr.Wrap(errBidNotOpen) } minBid, err := a.getMinBidBySlot(slot) if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } if bidAmount.Cmp(minBid) == -1 { - return nil, errBidBelowMin + return nil, tracerr.Wrap(errBidBelowMin) } if _, ok := a.State.Coordinators[*c.addr]; !ok { - return nil, errCoordNotReg + return nil, tracerr.Wrap(errCoordNotReg) } slotState, ok := a.State.Slots[slot] @@ -1408,11 +1409,11 @@ func (c *Client) AuctionMultiBid(amount *big.Int, startingSlot int64, endingSlot cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // AuctionCanForge is the interface to call the smart contract function @@ -1432,11 +1433,11 @@ func (c *Client) AuctionForge(forger ethCommon.Address) (tx *types.Transaction, cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // AuctionClaimHEZ is the interface to call the smart contract function @@ -1446,11 +1447,11 @@ func (c *Client) AuctionClaimHEZ() (tx *types.Transaction, err error) { cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // AuctionGetClaimableHEZ is the interface to call the smart contract function @@ -1459,7 +1460,7 @@ func (c *Client) AuctionGetClaimableHEZ(bidder ethCommon.Address) (*big.Int, err defer c.rw.RUnlock() log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // AuctionConstants returns the Constants of the Auction Smart Contract @@ -1477,7 +1478,7 @@ func (c *Client) AuctionEventsByBlock(blockNum int64) (*eth.AuctionEvents, *ethC block, ok := c.blocks[blockNum] if !ok { - return nil, nil, fmt.Errorf("Block %v doesn't exist", blockNum) + return nil, nil, tracerr.Wrap(fmt.Errorf("Block %v doesn't exist", blockNum)) } return &block.Auction.Events, &block.Eth.Hash, nil } @@ -1492,7 +1493,7 @@ func (c *Client) WDelayerGetHermezGovernanceDAOAddress() (*ethCommon.Address, er defer c.rw.RUnlock() log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // WDelayerSetHermezGovernanceDAOAddress is the interface to call the smart contract function @@ -1502,11 +1503,11 @@ func (c *Client) WDelayerSetHermezGovernanceDAOAddress(newAddress ethCommon.Addr cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // WDelayerGetHermezKeeperAddress is the interface to call the smart contract function @@ -1515,7 +1516,7 @@ func (c *Client) WDelayerGetHermezKeeperAddress() (*ethCommon.Address, error) { defer c.rw.RUnlock() log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // WDelayerSetHermezKeeperAddress is the interface to call the smart contract function @@ -1525,11 +1526,11 @@ func (c *Client) WDelayerSetHermezKeeperAddress(newAddress ethCommon.Address) (t cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // WDelayerGetWhiteHackGroupAddress is the interface to call the smart contract function @@ -1538,7 +1539,7 @@ func (c *Client) WDelayerGetWhiteHackGroupAddress() (*ethCommon.Address, error) defer c.rw.RUnlock() log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // WDelayerSetWhiteHackGroupAddress is the interface to call the smart contract function @@ -1548,11 +1549,11 @@ func (c *Client) WDelayerSetWhiteHackGroupAddress(newAddress ethCommon.Address) cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // WDelayerIsEmergencyMode is the interface to call the smart contract function @@ -1561,7 +1562,7 @@ func (c *Client) WDelayerIsEmergencyMode() (bool, error) { defer c.rw.RUnlock() log.Error("TODO") - return false, errTODO + return false, tracerr.Wrap(errTODO) } // WDelayerGetWithdrawalDelay is the interface to call the smart contract function @@ -1570,7 +1571,7 @@ func (c *Client) WDelayerGetWithdrawalDelay() (*big.Int, error) { defer c.rw.RUnlock() log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // WDelayerGetEmergencyModeStartingTime is the interface to call the smart contract function @@ -1579,7 +1580,7 @@ func (c *Client) WDelayerGetEmergencyModeStartingTime() (*big.Int, error) { defer c.rw.RUnlock() log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // WDelayerEnableEmergencyMode is the interface to call the smart contract function @@ -1589,11 +1590,11 @@ func (c *Client) WDelayerEnableEmergencyMode() (tx *types.Transaction, err error cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // WDelayerChangeWithdrawalDelay is the interface to call the smart contract function @@ -1603,7 +1604,7 @@ func (c *Client) WDelayerChangeWithdrawalDelay(newWithdrawalDelay uint64) (tx *t cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } nextBlock := c.nextBlock() @@ -1621,7 +1622,7 @@ func (c *Client) WDelayerDepositInfo(owner, token ethCommon.Address) (eth.Deposi defer c.rw.RUnlock() log.Error("TODO") - return eth.DepositState{}, errTODO + return eth.DepositState{}, tracerr.Wrap(errTODO) } // WDelayerDeposit is the interface to call the smart contract function @@ -1631,11 +1632,11 @@ func (c *Client) WDelayerDeposit(onwer, token ethCommon.Address, amount *big.Int cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // WDelayerWithdrawal is the interface to call the smart contract function @@ -1645,11 +1646,11 @@ func (c *Client) WDelayerWithdrawal(owner, token ethCommon.Address) (tx *types.T cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // WDelayerEscapeHatchWithdrawal is the interface to call the smart contract function @@ -1659,11 +1660,11 @@ func (c *Client) WDelayerEscapeHatchWithdrawal(to, token ethCommon.Address, amou cpy := c.nextBlock().copy() defer func() { c.revertIfErr(err, cpy) }() if c.addr == nil { - return nil, eth.ErrAccountNil + return nil, tracerr.Wrap(eth.ErrAccountNil) } log.Error("TODO") - return nil, errTODO + return nil, tracerr.Wrap(errTODO) } // WDelayerEventsByBlock returns the events in a block that happened in the WDelayer Contract @@ -1673,7 +1674,7 @@ func (c *Client) WDelayerEventsByBlock(blockNum int64) (*eth.WDelayerEvents, *et block, ok := c.blocks[blockNum] if !ok { - return nil, nil, fmt.Errorf("Block %v doesn't exist", blockNum) + return nil, nil, tracerr.Wrap(fmt.Errorf("Block %v doesn't exist", blockNum)) } return &block.WDelayer.Events, &block.Eth.Hash, nil } diff --git a/test/ethclient_test.go b/test/ethclient_test.go index 47c3b33..a165a5f 100644 --- a/test/ethclient_test.go +++ b/test/ethclient_test.go @@ -12,6 +12,7 @@ import ( ethCrypto "github.com/ethereum/go-ethereum/crypto" "github.com/hermeznetwork/hermez-node/common" "github.com/hermeznetwork/hermez-node/eth" + "github.com/hermeznetwork/tracerr" "github.com/iden3/go-iden3-crypto/babyjub" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -95,20 +96,20 @@ func TestClientAuction(t *testing.T) { // Check several cases in which bid doesn't succed, and also do 2 successful bids. _, err := c.AuctionBidSimple(0, big.NewInt(1)) - assert.Equal(t, errBidClosed, err) + assert.Equal(t, errBidClosed, tracerr.Unwrap(err)) _, err = c.AuctionBidSimple(4322, big.NewInt(1)) - assert.Equal(t, errBidNotOpen, err) + assert.Equal(t, errBidNotOpen, tracerr.Unwrap(err)) // 101 % 6 = 5; defaultSlotSetBid[5] = 1500; 1500 + 10% = 1650 _, err = c.AuctionBidSimple(101, big.NewInt(1650)) - assert.Equal(t, errCoordNotReg, err) + assert.Equal(t, errCoordNotReg, tracerr.Unwrap(err)) _, err = c.AuctionSetCoordinator(addrForge, "https://foo.bar") assert.Nil(t, err) _, err = c.AuctionBidSimple(3, big.NewInt(1)) - assert.Equal(t, errBidBelowMin, err) + assert.Equal(t, errBidBelowMin, tracerr.Unwrap(err)) _, err = c.AuctionBidSimple(3, big.NewInt(1650)) assert.Nil(t, err) @@ -118,7 +119,7 @@ func TestClientAuction(t *testing.T) { assert.Nil(t, err) _, err = c.AuctionBidSimple(3, big.NewInt(16)) - assert.Equal(t, errBidBelowMin, err) + assert.Equal(t, errBidBelowMin, tracerr.Unwrap(err)) // 1650 + 10% = 1815 _, err = c.AuctionBidSimple(3, big.NewInt(1815)) diff --git a/test/historydb.go b/test/historydb.go index 2a35516..9c318e2 100644 --- a/test/historydb.go +++ b/test/historydb.go @@ -8,6 +8,7 @@ import ( ethCommon "github.com/ethereum/go-ethereum/common" "github.com/hermeznetwork/hermez-node/common" + "github.com/hermeznetwork/tracerr" "github.com/iden3/go-iden3-crypto/babyjub" "github.com/iden3/go-merkletree" ) @@ -425,7 +426,7 @@ func randomAccount(seed int, userAccount bool, userAddr *ethCommon.Address, accs i++ i = i % len(accs) if i == firstI { - return &acc, errors.New("Didnt found any account matchinng the criteria") + return &acc, tracerr.Wrap(errors.New("Didnt found any account matchinng the criteria")) } } } diff --git a/test/til/lang.go b/test/til/lang.go index 7802568..7104ef8 100644 --- a/test/til/lang.go +++ b/test/til/lang.go @@ -11,6 +11,7 @@ import ( "github.com/hermeznetwork/hermez-node/common" "github.com/hermeznetwork/hermez-node/log" + "github.com/hermeznetwork/tracerr" ) var eof = rune(0) @@ -272,7 +273,7 @@ func (p *parser) parseLine(setType setType) (*instruction, error) { c := &instruction{} tok, lit := p.scanIgnoreWhitespace() if tok == EOF { - return nil, errof + return nil, tracerr.Wrap(errof) } c.literal += lit if lit == "/" { @@ -280,7 +281,7 @@ func (p *parser) parseLine(setType setType) (*instruction, error) { return nil, commentLine } else if lit == ">" { if setType == setTypePoolL2 { - return c, fmt.Errorf("Unexpected '>' at PoolL2Txs set") + return c, tracerr.Wrap(fmt.Errorf("Unexpected '>' at PoolL2Txs set")) } _, lit = p.scanIgnoreWhitespace() if lit == "batch" { @@ -293,11 +294,11 @@ func (p *parser) parseLine(setType setType) (*instruction, error) { _, _ = p.s.r.ReadString('\n') return &instruction{typ: typeNewBlock}, newEventLine } else { - return c, fmt.Errorf("Unexpected '> %s', expected '> batch' or '> block'", lit) + return c, tracerr.Wrap(fmt.Errorf("Unexpected '> %s', expected '> batch' or '> block'", lit)) } } else if lit == "Type" { if err := p.expectChar(c, ":"); err != nil { - return c, err + return c, tracerr.Wrap(err) } _, lit = p.scanIgnoreWhitespace() if lit == "Blockchain" { @@ -305,11 +306,11 @@ func (p *parser) parseLine(setType setType) (*instruction, error) { } else if lit == "PoolL2" { return &instruction{typ: "PoolL2"}, setTypeLine } else { - return c, fmt.Errorf("Invalid set type: '%s'. Valid set types: 'Blockchain', 'PoolL2'", lit) + return c, tracerr.Wrap(fmt.Errorf("Invalid set type: '%s'. Valid set types: 'Blockchain', 'PoolL2'", lit)) } } else if lit == "AddToken" { if err := p.expectChar(c, "("); err != nil { - return c, err + return c, tracerr.Wrap(err) } _, lit = p.scanIgnoreWhitespace() c.literal += lit @@ -317,11 +318,11 @@ func (p *parser) parseLine(setType setType) (*instruction, error) { if err != nil { line, _ := p.s.r.ReadString('\n') c.literal += line - return c, err + return c, tracerr.Wrap(err) } c.tokenID = common.TokenID(tidI) if err := p.expectChar(c, ")"); err != nil { - return c, err + return c, tracerr.Wrap(err) } c.typ = typeAddToken line, _ := p.s.r.ReadString('\n') @@ -330,7 +331,7 @@ func (p *parser) parseLine(setType setType) (*instruction, error) { } if setType == "" { - return c, fmt.Errorf("Set type not defined") + return c, tracerr.Wrap(fmt.Errorf("Set type not defined")) } transferring := false fee := false @@ -363,7 +364,7 @@ func (p *parser) parseLine(setType setType) (*instruction, error) { case "ForceExit": c.typ = common.TxTypeForceExit default: - return c, fmt.Errorf("Unexpected Blockchain tx type: %s", lit) + return c, tracerr.Wrap(fmt.Errorf("Unexpected Blockchain tx type: %s", lit)) } } else if setType == setTypePoolL2 { switch lit { @@ -383,14 +384,14 @@ func (p *parser) parseLine(setType setType) (*instruction, error) { c.typ = common.TxTypeExit fee = true default: - return c, fmt.Errorf("Unexpected PoolL2 tx type: %s", lit) + return c, tracerr.Wrap(fmt.Errorf("Unexpected PoolL2 tx type: %s", lit)) } } else { - return c, fmt.Errorf("Invalid set type: '%s'. Valid set types: 'Blockchain', 'PoolL2'", setType) + return c, tracerr.Wrap(fmt.Errorf("Invalid set type: '%s'. Valid set types: 'Blockchain', 'PoolL2'", setType)) } if err := p.expectChar(c, "("); err != nil { - return c, err + return c, tracerr.Wrap(err) } _, lit = p.scanIgnoreWhitespace() c.literal += lit @@ -398,11 +399,11 @@ func (p *parser) parseLine(setType setType) (*instruction, error) { if err != nil { line, _ := p.s.r.ReadString('\n') c.literal += line - return c, err + return c, tracerr.Wrap(err) } c.tokenID = common.TokenID(tidI) if err := p.expectChar(c, ")"); err != nil { - return c, err + return c, tracerr.Wrap(err) } _, lit = p.scanIgnoreWhitespace() c.literal += lit @@ -416,7 +417,7 @@ func (p *parser) parseLine(setType setType) (*instruction, error) { c.literal += lit if transferring { if lit != "-" { - return c, fmt.Errorf("Expected '-', found '%s'", lit) + return c, tracerr.Wrap(fmt.Errorf("Expected '-', found '%s'", lit)) } _, lit = p.scanIgnoreWhitespace() c.literal += lit @@ -427,7 +428,7 @@ func (p *parser) parseLine(setType setType) (*instruction, error) { if lit != ":" { line, _ := p.s.r.ReadString('\n') c.literal += line - return c, fmt.Errorf("Expected ':', found '%s'", lit) + return c, tracerr.Wrap(fmt.Errorf("Expected ':', found '%s'", lit)) } if c.typ == common.TxTypeDepositTransfer || c.typ == common.TxTypeCreateAccountDepositTransfer { @@ -438,11 +439,11 @@ func (p *parser) parseLine(setType setType) (*instruction, error) { if !ok { line, _ := p.s.r.ReadString('\n') c.literal += line - return c, fmt.Errorf("Can not parse number for LoadAmount") + return c, tracerr.Wrap(fmt.Errorf("Can not parse number for LoadAmount")) } c.loadAmount = loadAmount if err := p.expectChar(c, ","); err != nil { - return c, err + return c, tracerr.Wrap(err) } } _, lit = p.scanIgnoreWhitespace() @@ -451,7 +452,7 @@ func (p *parser) parseLine(setType setType) (*instruction, error) { if !ok { line, _ := p.s.r.ReadString('\n') c.literal += line - return c, fmt.Errorf("Can not parse number for Amount: %s", lit) + return c, tracerr.Wrap(fmt.Errorf("Can not parse number for Amount: %s", lit)) } if c.typ == common.TxTypeDeposit || c.typ == common.TxTypeCreateAccountDeposit { @@ -461,7 +462,7 @@ func (p *parser) parseLine(setType setType) (*instruction, error) { } if fee { if err := p.expectChar(c, "("); err != nil { - return c, err + return c, tracerr.Wrap(err) } _, lit = p.scanIgnoreWhitespace() c.literal += lit @@ -469,22 +470,22 @@ func (p *parser) parseLine(setType setType) (*instruction, error) { if err != nil { line, _ := p.s.r.ReadString('\n') c.literal += line - return c, err + return c, tracerr.Wrap(err) } if fee > common.MaxFeePlan-1 { line, _ := p.s.r.ReadString('\n') c.literal += line - return c, fmt.Errorf("Fee %d can not be bigger than 255", fee) + return c, tracerr.Wrap(fmt.Errorf("Fee %d can not be bigger than 255", fee)) } c.fee = uint8(fee) if err := p.expectChar(c, ")"); err != nil { - return c, err + return c, tracerr.Wrap(err) } } if tok == EOF { - return nil, errof + return nil, tracerr.Wrap(errof) } return c, nil } @@ -495,7 +496,7 @@ func (p *parser) expectChar(c *instruction, ch string) error { if lit != ch { line, _ := p.s.r.ReadString('\n') c.literal += line - return fmt.Errorf("Expected '%s', found '%s'", ch, lit) + return tracerr.Wrap(fmt.Errorf("Expected '%s', found '%s'", ch, lit)) } return nil } @@ -512,12 +513,12 @@ func (p *parser) parse() (*parsedSet, error) { for { i++ instruction, err := p.parseLine(ps.typ) - if err == errof { + if tracerr.Unwrap(err) == errof { break } - if err == setTypeLine { + if tracerr.Unwrap(err) == setTypeLine { if ps.typ != "" { - return ps, fmt.Errorf("Line %d: Instruction of 'Type: %s' when there is already a previous instruction 'Type: %s' defined", i, instruction.typ, ps.typ) + return ps, tracerr.Wrap(fmt.Errorf("Line %d: Instruction of 'Type: %s' when there is already a previous instruction 'Type: %s' defined", i, instruction.typ, ps.typ)) } if instruction.typ == "PoolL2" { ps.typ = setTypePoolL2 @@ -528,22 +529,22 @@ func (p *parser) parse() (*parsedSet, error) { } continue } - if err == commentLine { + if tracerr.Unwrap(err) == commentLine { continue } instruction.lineNum = i - if err == newEventLine { + if tracerr.Unwrap(err) == newEventLine { if instruction.typ == typeAddToken && instruction.tokenID == common.TokenID(0) { - return ps, fmt.Errorf("Line %d: AddToken can not register TokenID 0", i) + return ps, tracerr.Wrap(fmt.Errorf("Line %d: AddToken can not register TokenID 0", i)) } ps.instructions = append(ps.instructions, *instruction) continue } if err != nil { - return ps, fmt.Errorf("Line %d: %s, err: %s", i, instruction.literal, err.Error()) + return ps, tracerr.Wrap(fmt.Errorf("Line %d: %s, err: %s", i, instruction.literal, err.Error())) } if ps.typ == "" { - return ps, fmt.Errorf("Line %d: Set type not defined", i) + return ps, tracerr.Wrap(fmt.Errorf("Line %d: Set type not defined", i)) } ps.instructions = append(ps.instructions, *instruction) users[instruction.from] = true diff --git a/test/til/txs.go b/test/til/txs.go index 9369859..0db9dfc 100644 --- a/test/til/txs.go +++ b/test/til/txs.go @@ -12,6 +12,7 @@ import ( ethCrypto "github.com/ethereum/go-ethereum/crypto" "github.com/hermeznetwork/hermez-node/common" "github.com/hermeznetwork/hermez-node/log" + "github.com/hermeznetwork/tracerr" "github.com/iden3/go-iden3-crypto/babyjub" ) @@ -151,10 +152,10 @@ func (tc *Context) GenerateBlocks(set string) ([]common.BlockData, error) { parser := newParser(strings.NewReader(set)) parsedSet, err := parser.parse() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } if parsedSet.typ != setTypeBlockchain { - return nil, fmt.Errorf("Expected set type: %s, found: %s", setTypeBlockchain, parsedSet.typ) + return nil, tracerr.Wrap(fmt.Errorf("Expected set type: %s, found: %s", setTypeBlockchain, parsedSet.typ)) } tc.Instructions = parsedSet.instructions @@ -168,7 +169,7 @@ func (tc *Context) GenerateBlocks(set string) ([]common.BlockData, error) { case txTypeCreateAccountDepositCoordinator: // tx source: L1CoordinatorTx if err := tc.checkIfTokenIsRegistered(inst); err != nil { log.Error(err) - return nil, fmt.Errorf("Line %d: %s", inst.lineNum, err.Error()) + return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.lineNum, err.Error())) } tx := common.L1Tx{ FromEthAddr: tc.Users[inst.from].Addr, @@ -188,7 +189,7 @@ func (tc *Context) GenerateBlocks(set string) ([]common.BlockData, error) { case common.TxTypeCreateAccountDeposit, common.TxTypeCreateAccountDepositTransfer: // tx source: L1UserTx if err := tc.checkIfTokenIsRegistered(inst); err != nil { log.Error(err) - return nil, fmt.Errorf("Line %d: %s", inst.lineNum, err.Error()) + return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.lineNum, err.Error())) } tx := common.L1Tx{ FromEthAddr: tc.Users[inst.from].Addr, @@ -208,16 +209,16 @@ func (tc *Context) GenerateBlocks(set string) ([]common.BlockData, error) { L1Tx: tx, } if err := tc.addToL1UserQueue(testTx); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } case common.TxTypeDeposit, common.TxTypeDepositTransfer: // tx source: L1UserTx if err := tc.checkIfTokenIsRegistered(inst); err != nil { log.Error(err) - return nil, fmt.Errorf("Line %d: %s", inst.lineNum, err.Error()) + return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.lineNum, err.Error())) } if err := tc.checkIfAccountExists(inst.from, inst); err != nil { log.Error(err) - return nil, fmt.Errorf("Line %d: %s", inst.lineNum, err.Error()) + return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.lineNum, err.Error())) } tx := common.L1Tx{ TokenID: inst.tokenID, @@ -235,12 +236,12 @@ func (tc *Context) GenerateBlocks(set string) ([]common.BlockData, error) { L1Tx: tx, } if err := tc.addToL1UserQueue(testTx); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } case common.TxTypeTransfer: // L2Tx if err := tc.checkIfTokenIsRegistered(inst); err != nil { log.Error(err) - return nil, fmt.Errorf("Line %d: %s", inst.lineNum, err.Error()) + return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.lineNum, err.Error())) } tx := common.L2Tx{ Amount: inst.amount, @@ -260,7 +261,7 @@ func (tc *Context) GenerateBlocks(set string) ([]common.BlockData, error) { case common.TxTypeForceTransfer: // tx source: L1UserTx if err := tc.checkIfTokenIsRegistered(inst); err != nil { log.Error(err) - return nil, fmt.Errorf("Line %d: %s", inst.lineNum, err.Error()) + return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.lineNum, err.Error())) } tx := common.L1Tx{ TokenID: inst.tokenID, @@ -275,12 +276,12 @@ func (tc *Context) GenerateBlocks(set string) ([]common.BlockData, error) { L1Tx: tx, } if err := tc.addToL1UserQueue(testTx); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } case common.TxTypeExit: // tx source: L2Tx if err := tc.checkIfTokenIsRegistered(inst); err != nil { log.Error(err) - return nil, fmt.Errorf("Line %d: %s", inst.lineNum, err.Error()) + return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.lineNum, err.Error())) } tx := common.L2Tx{ ToIdx: common.Idx(1), // as is an Exit @@ -301,7 +302,7 @@ func (tc *Context) GenerateBlocks(set string) ([]common.BlockData, error) { case common.TxTypeForceExit: // tx source: L1UserTx if err := tc.checkIfTokenIsRegistered(inst); err != nil { log.Error(err) - return nil, fmt.Errorf("Line %d: %s", inst.lineNum, err.Error()) + return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.lineNum, err.Error())) } tx := common.L1Tx{ ToIdx: common.Idx(1), // as is an Exit @@ -317,28 +318,28 @@ func (tc *Context) GenerateBlocks(set string) ([]common.BlockData, error) { L1Tx: tx, } if err := tc.addToL1UserQueue(testTx); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } case typeNewBatch: if err = tc.calculateIdxForL1Txs(true, tc.currBatchTest.l1CoordinatorTxs); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } if err = tc.setIdxs(); err != nil { log.Error(err) - return nil, err + return nil, tracerr.Wrap(err) } case typeNewBatchL1: // for each L1UserTx of the Queues[ToForgeNum], calculate the Idx if err = tc.calculateIdxForL1Txs(false, tc.Queues[tc.ToForgeNum]); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } if err = tc.calculateIdxForL1Txs(true, tc.currBatchTest.l1CoordinatorTxs); err != nil { - return nil, err + return nil, tracerr.Wrap(err) } tc.currBatch.L1Batch = true if err = tc.setIdxs(); err != nil { log.Error(err) - return nil, err + return nil, tracerr.Wrap(err) } toForgeL1TxsNum := int64(tc.openToForge) tc.currBatch.Batch.ForgeL1TxsNum = &toForgeL1TxsNum @@ -363,12 +364,12 @@ func (tc *Context) GenerateBlocks(set string) ([]common.BlockData, error) { EthBlockNum: tc.blockNum, } if inst.tokenID != tc.LastRegisteredTokenID+1 { - return nil, fmt.Errorf("Line %d: AddToken TokenID should be sequential, expected TokenID: %d, defined TokenID: %d", inst.lineNum, tc.LastRegisteredTokenID+1, inst.tokenID) + return nil, tracerr.Wrap(fmt.Errorf("Line %d: AddToken TokenID should be sequential, expected TokenID: %d, defined TokenID: %d", inst.lineNum, tc.LastRegisteredTokenID+1, inst.tokenID)) } tc.LastRegisteredTokenID++ tc.currBlock.Rollup.AddedTokens = append(tc.currBlock.Rollup.AddedTokens, newToken) default: - return nil, fmt.Errorf("Line %d: Unexpected type: %s", inst.lineNum, inst.typ) + return nil, tracerr.Wrap(fmt.Errorf("Line %d: Unexpected type: %s", inst.lineNum, inst.typ)) } } @@ -383,7 +384,7 @@ func (tc *Context) calculateIdxForL1Txs(isCoordinatorTxs bool, txs []L1Tx) error tx := txs[i] if tx.L1Tx.Type == common.TxTypeCreateAccountDeposit || tx.L1Tx.Type == common.TxTypeCreateAccountDepositTransfer { if tc.Users[tx.fromIdxName].Accounts[tx.L1Tx.TokenID] != nil { // if account already exists, return error - return fmt.Errorf("Can not create same account twice (same User (%s) & same TokenID (%d)) (this is a design property of Til)", tx.fromIdxName, tx.L1Tx.TokenID) + return tracerr.Wrap(fmt.Errorf("Can not create same account twice (same User (%s) & same TokenID (%d)) (this is a design property of Til)", tx.fromIdxName, tx.L1Tx.TokenID)) } tc.Users[tx.fromIdxName].Accounts[tx.L1Tx.TokenID] = &Account{ Idx: common.Idx(tc.idx), @@ -410,11 +411,11 @@ func (tc *Context) setIdxs() error { testTx := &tc.currBatchTest.l2Txs[i] if tc.Users[testTx.fromIdxName].Accounts[testTx.tokenID] == nil { - return fmt.Errorf("Line %d: %s from User %s for TokenID %d while account not created yet", testTx.lineNum, testTx.L2Tx.Type, testTx.fromIdxName, testTx.tokenID) + return tracerr.Wrap(fmt.Errorf("Line %d: %s from User %s for TokenID %d while account not created yet", testTx.lineNum, testTx.L2Tx.Type, testTx.fromIdxName, testTx.tokenID)) } if testTx.L2Tx.Type == common.TxTypeTransfer { if _, ok := tc.l1CreatedAccounts[idxTokenIDToString(testTx.toIdxName, testTx.tokenID)]; !ok { - return fmt.Errorf("Line %d: Can not create Transfer for a non existing account. Batch %d, ToIdx name: %s, TokenID: %d", testTx.lineNum, tc.currBatchNum, testTx.toIdxName, testTx.tokenID) + return tracerr.Wrap(fmt.Errorf("Line %d: Can not create Transfer for a non existing account. Batch %d, ToIdx name: %s, TokenID: %d", testTx.lineNum, tc.currBatchNum, testTx.toIdxName, testTx.tokenID)) } } tc.Users[testTx.fromIdxName].Accounts[testTx.tokenID].Nonce++ @@ -433,7 +434,7 @@ func (tc *Context) setIdxs() error { nTx, err := common.NewL2Tx(&testTx.L2Tx) if err != nil { - return fmt.Errorf("Line %d: %s", testTx.lineNum, err.Error()) + return tracerr.Wrap(fmt.Errorf("Line %d: %s", testTx.lineNum, err.Error())) } testTx.L2Tx = *nTx @@ -476,8 +477,8 @@ func (tc *Context) addToL1UserQueue(tx L1Tx) error { } else { account, ok := tc.Users[tx.toIdxName].Accounts[tx.L1Tx.TokenID] if !ok { - return fmt.Errorf("Line %d: Transfer to User: %s, for TokenID: %d, "+ - "while account not created yet", tx.lineNum, tx.toIdxName, tx.L1Tx.TokenID) + return tracerr.Wrap(fmt.Errorf("Line %d: Transfer to User: %s, for TokenID: %d, "+ + "while account not created yet", tx.lineNum, tx.toIdxName, tx.L1Tx.TokenID)) } tx.L1Tx.ToIdx = account.Idx } @@ -486,7 +487,7 @@ func (tc *Context) addToL1UserQueue(tx L1Tx) error { } nTx, err := common.NewL1Tx(&tx.L1Tx) if err != nil { - return fmt.Errorf("Line %d: %s", tx.lineNum, err.Error()) + return tracerr.Wrap(fmt.Errorf("Line %d: %s", tx.lineNum, err.Error())) } tx.L1Tx = *nTx @@ -498,13 +499,13 @@ func (tc *Context) addToL1UserQueue(tx L1Tx) error { func (tc *Context) checkIfAccountExists(tf string, inst instruction) error { if tc.Users[tf].Accounts[inst.tokenID] == nil { - return fmt.Errorf("%s at User: %s, for TokenID: %d, while account not created yet", inst.typ, tf, inst.tokenID) + return tracerr.Wrap(fmt.Errorf("%s at User: %s, for TokenID: %d, while account not created yet", inst.typ, tf, inst.tokenID)) } return nil } func (tc *Context) checkIfTokenIsRegistered(inst instruction) error { if inst.tokenID > tc.LastRegisteredTokenID { - return fmt.Errorf("Can not process %s: TokenID %d not registered, last registered TokenID: %d", inst.typ, inst.tokenID, tc.LastRegisteredTokenID) + return tracerr.Wrap(fmt.Errorf("Can not process %s: TokenID %d not registered, last registered TokenID: %d", inst.typ, inst.tokenID, tc.LastRegisteredTokenID)) } return nil } @@ -515,10 +516,10 @@ func (tc *Context) GeneratePoolL2Txs(set string) ([]common.PoolL2Tx, error) { parser := newParser(strings.NewReader(set)) parsedSet, err := parser.parse() if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } if parsedSet.typ != setTypePoolL2 { - return nil, fmt.Errorf("Expected set type: %s, found: %s", setTypePoolL2, parsedSet.typ) + return nil, tracerr.Wrap(fmt.Errorf("Expected set type: %s, found: %s", setTypePoolL2, parsedSet.typ)) } tc.Instructions = parsedSet.instructions @@ -532,13 +533,13 @@ func (tc *Context) GeneratePoolL2Txs(set string) ([]common.PoolL2Tx, error) { case common.TxTypeTransfer, common.TxTypeTransferToEthAddr, common.TxTypeTransferToBJJ: if err := tc.checkIfAccountExists(inst.from, inst); err != nil { log.Error(err) - return nil, fmt.Errorf("Line %d: %s", inst.lineNum, err.Error()) + return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.lineNum, err.Error())) } if inst.typ == common.TxTypeTransfer { // if TxTypeTransfer, need to exist the ToIdx account if err := tc.checkIfAccountExists(inst.to, inst); err != nil { log.Error(err) - return nil, fmt.Errorf("Line %d: %s", inst.lineNum, err.Error()) + return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.lineNum, err.Error())) } } tc.Users[inst.from].Accounts[inst.tokenID].Nonce++ @@ -570,13 +571,13 @@ func (tc *Context) GeneratePoolL2Txs(set string) ([]common.PoolL2Tx, error) { } nTx, err := common.NewPoolL2Tx(&tx) if err != nil { - return nil, fmt.Errorf("Line %d: %s", inst.lineNum, err.Error()) + return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.lineNum, err.Error())) } tx = *nTx // perform signature and set it to tx.Signature toSign, err := tx.HashToSign() if err != nil { - return nil, fmt.Errorf("Line %d: %s", inst.lineNum, err.Error()) + return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.lineNum, err.Error())) } sig := tc.Users[inst.from].BJJ.SignPoseidon(toSign) tx.Signature = sig.Compress() @@ -596,19 +597,19 @@ func (tc *Context) GeneratePoolL2Txs(set string) ([]common.PoolL2Tx, error) { } nTx, err := common.NewPoolL2Tx(&tx) if err != nil { - return nil, fmt.Errorf("Line %d: %s", inst.lineNum, err.Error()) + return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.lineNum, err.Error())) } tx = *nTx // perform signature and set it to tx.Signature toSign, err := tx.HashToSign() if err != nil { - return nil, fmt.Errorf("Line %d: %s", inst.lineNum, err.Error()) + return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.lineNum, err.Error())) } sig := tc.Users[inst.from].BJJ.SignPoseidon(toSign) tx.Signature = sig.Compress() txs = append(txs, tx) default: - return nil, fmt.Errorf("Line %d: instruction type unrecognized: %s", inst.lineNum, inst.typ) + return nil, tracerr.Wrap(fmt.Errorf("Line %d: instruction type unrecognized: %s", inst.lineNum, inst.typ)) } } @@ -750,7 +751,7 @@ func (tc *Context) FillBlocksExtra(blocks []common.BlockData, cfg *ConfigExtra) tx.Type == common.TxTypeCreateAccountDepositTransfer { user, ok := tc.UsersByIdx[tc.extra.idx] if !ok { - return fmt.Errorf("Created account with idx: %v not found", tc.extra.idx) + return tracerr.Wrap(fmt.Errorf("Created account with idx: %v not found", tc.extra.idx)) } batch.CreatedAccounts = append(batch.CreatedAccounts, common.Account{ @@ -785,7 +786,7 @@ func (tc *Context) FillBlocksExtra(blocks []common.BlockData, cfg *ConfigExtra) tx.EffectiveLoadAmount = big.NewInt(0) nTx, err := common.NewL1Tx(tx) if err != nil { - return err + return tracerr.Wrap(err) } *tx = *nTx } @@ -797,7 +798,7 @@ func (tc *Context) FillBlocksExtra(blocks []common.BlockData, cfg *ConfigExtra) tx.Nonce = tc.extra.nonces[tx.FromIdx] nTx, err := common.NewL2Tx(tx) if err != nil { - return err + return tracerr.Wrap(err) } *tx = *nTx } @@ -834,13 +835,13 @@ func (tc *Context) FillBlocksExtra(blocks []common.BlockData, cfg *ConfigExtra) } fee, err := common.CalcFeeAmount(tx.Amount, tx.Fee) if err != nil { - return err + return tracerr.Wrap(err) } // Find the TokenID of the tx fromAcc, ok := tc.accountsByIdx[int(tx.FromIdx)] if !ok { - return fmt.Errorf("L2tx.FromIdx idx: %v not found", tx.FromIdx) + return tracerr.Wrap(fmt.Errorf("L2tx.FromIdx idx: %v not found", tx.FromIdx)) } // Find the idx of the CoordUser for the diff --git a/txselector/txselector.go b/txselector/txselector.go index 6422c7b..aa0f0ce 100644 --- a/txselector/txselector.go +++ b/txselector/txselector.go @@ -12,6 +12,7 @@ import ( "github.com/hermeznetwork/hermez-node/db/l2db" "github.com/hermeznetwork/hermez-node/db/statedb" "github.com/hermeznetwork/hermez-node/log" + "github.com/hermeznetwork/tracerr" "github.com/iden3/go-iden3-crypto/babyjub" ) @@ -45,7 +46,7 @@ type TxSelector struct { func NewTxSelector(dbpath string, synchronizerStateDB *statedb.StateDB, l2 *l2db.L2DB, maxL1UserTxs, maxL1OperatorTxs, maxTxs uint64) (*TxSelector, error) { localAccountsDB, err := statedb.NewLocalStateDB(dbpath, synchronizerStateDB, statedb.TypeTxSelector, 0) // without merkletree if err != nil { - return nil, err + return nil, tracerr.Wrap(err) } return &TxSelector{ @@ -62,7 +63,7 @@ func NewTxSelector(dbpath string, synchronizerStateDB *statedb.StateDB, l2 *l2db func (txsel *TxSelector) Reset(batchNum common.BatchNum) error { err := txsel.localAccountsDB.Reset(batchNum, true) if err != nil { - return err + return tracerr.Wrap(err) } return nil } @@ -71,7 +72,7 @@ func (txsel *TxSelector) Reset(batchNum common.BatchNum) error { // for the next batch, from the L2DB pool func (txsel *TxSelector) GetL2TxSelection(coordIdxs []common.Idx, batchNum common.BatchNum) ([]common.L1Tx, []common.PoolL2Tx, error) { _, l1CoordinatorTxs, l2Txs, err := txsel.GetL1L2TxSelection(coordIdxs, batchNum, []common.L1Tx{}) - return l1CoordinatorTxs, l2Txs, err + return l1CoordinatorTxs, l2Txs, tracerr.Wrap(err) } // GetL1L2TxSelection returns the selection of L1 + L2 txs @@ -84,7 +85,7 @@ func (txsel *TxSelector) GetL1L2TxSelection(coordIdxs []common.Idx, batchNum com // get pending l2-tx from tx-pool l2TxsRaw, err := txsel.l2db.GetPendingTxs() // (batchID) if err != nil { - return nil, nil, nil, err + return nil, nil, nil, tracerr.Wrap(err) } var validTxs txs @@ -224,11 +225,11 @@ func (txsel *TxSelector) GetL1L2TxSelection(coordIdxs []common.Idx, batchNum com // process the txs in the local AccountsDB _, err = txsel.localAccountsDB.ProcessTxs(ptc, coordIdxs, l1Txs, l1CoordinatorTxs, l2Txs) if err != nil { - return nil, nil, nil, err + return nil, nil, nil, tracerr.Wrap(err) } err = txsel.localAccountsDB.MakeCheckpoint() if err != nil { - return nil, nil, nil, err + return nil, nil, nil, tracerr.Wrap(err) } return l1Txs, l1CoordinatorTxs, l2Txs, nil