mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Wrap all errors with tracerr
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user