Wrap all errors with tracerr

This commit is contained in:
Eduard S
2020-11-30 12:58:36 +01:00
parent 879af66a2a
commit ced42634da
59 changed files with 1324 additions and 1268 deletions

View File

@@ -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

View File

@@ -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
}

View File

@@ -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))

View File

@@ -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"))
}
}
}

View File

@@ -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

View File

@@ -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