diff --git a/.gitignore b/.gitignore index ef249c7..f9f71f5 100644 --- a/.gitignore +++ b/.gitignore @@ -19,7 +19,7 @@ public.json *.wtns #.env -.env +sequencer/.env # etc .DS_Store \ No newline at end of file diff --git a/sequencer/common/account.go b/sequencer/common/account.go index 1b32afe..fae6852 100644 --- a/sequencer/common/account.go +++ b/sequencer/common/account.go @@ -26,7 +26,7 @@ type Account struct { } // AccountIdx represents the account Index in the MerkleTree -type AccountIdx uint64 +type AccountIdx uint32 const ( // NAccountLeafElems is the number of elements for a leaf in account tree @@ -62,10 +62,10 @@ func (idx AccountIdx) Bytes() ([NLevelsAsBytes]byte, error) { if idx > maxAccountIdxValue { return [NLevelsAsBytes]byte{}, Wrap(ErrIdxOverflow) } - var idxBytes [8]byte - binary.BigEndian.PutUint64(idxBytes[:], uint64(idx)) + var idxBytes [4]byte + binary.BigEndian.PutUint32(idxBytes[:], uint32(idx)) var b [NLevelsAsBytes]byte - copy(b[:], idxBytes[8-NLevelsAsBytes:]) + copy(b[:], idxBytes[4-NLevelsAsBytes:]) return b, nil } @@ -75,9 +75,9 @@ func AccountIdxFromBytes(b []byte) (AccountIdx, error) { return 0, Wrap(fmt.Errorf("can not parse Idx, bytes len %d, expected %d", len(b), AccountIdxBytesLen)) } - var idxBytes [8]byte - copy(idxBytes[8-NLevelsAsBytes:], b[:]) - idx := binary.BigEndian.Uint64(idxBytes[:]) + var idxBytes [4]byte + copy(idxBytes[4-NLevelsAsBytes:], b[:]) + idx := binary.BigEndian.Uint32(idxBytes[:]) return AccountIdx(idx), nil } @@ -86,17 +86,17 @@ func (idx AccountIdx) BigInt() *big.Int { return big.NewInt(int64(idx)) } -// IdxFromBytes returns Idx from a byte array -func IdxFromBytes(b []byte) (AccountIdx, error) { - if len(b) != AccountIdxBytesLen { - return 0, Wrap(fmt.Errorf("can not parse Idx, bytes len %d, expected %d", - len(b), AccountIdxBytesLen)) - } - var idxBytes [8]byte - copy(idxBytes[2:], b[:]) - idx := binary.BigEndian.Uint64(idxBytes[:]) - return AccountIdx(idx), nil -} +// // IdxFromBytes returns Idx from a byte array +// func IdxFromBytes(b []byte) (AccountIdx, error) { +// if len(b) != AccountIdxBytesLen { +// return 0, Wrap(fmt.Errorf("can not parse Idx, bytes len %d, expected %d", +// len(b), AccountIdxBytesLen)) +// } +// var idxBytes [8]byte +// copy(idxBytes[2:], b[:]) +// idx := binary.BigEndian.Uint32(idxBytes[:]) +// return AccountIdx(idx), nil +// } // Bytes returns the bytes representing the Account, in a way that each BigInt // is represented by 32 bytes, in spite of the BigInt could be represented in diff --git a/sequencer/common/errors.go b/sequencer/common/errors.go index fc0552e..6fb5317 100644 --- a/sequencer/common/errors.go +++ b/sequencer/common/errors.go @@ -11,7 +11,7 @@ var ErrNotInFF = errors.New("BigInt not inside the Finite Field") var ErrNumOverflow = errors.New("Value overflows the type") // ErrIdxOverflow is used when a given nonce overflows the maximum capacity of the Idx (2**48-1) -var ErrIdxOverflow = errors.New("idx overflow, max value: 2**48 -1") +var ErrIdxOverflow = errors.New("idx overflow, max value: 2**24 -1") // ErrScoreOverflow is used when a given score overflows the maximum capacity of the Score (2**32-1) var ErrScoreOverflow = errors.New("Score overflow, max value: 2**32-1") diff --git a/sequencer/common/l1tx.go b/sequencer/common/l1tx.go index b55a26a..f374e79 100644 --- a/sequencer/common/l1tx.go +++ b/sequencer/common/l1tx.go @@ -171,8 +171,8 @@ func (tx L1Tx) Tx() Tx { // [ 1 bits ] empty (toBJJSign) // 1 byte // [ 8 bits ] empty (userFee) // 1 byte // [ 40 bits ] empty (nonce) // 5 bytes -// [ 48 bits ] toIdx // 6 bytes -// [ 48 bits ] fromIdx // 6 bytes +// [ 48 bits ] toIdx // 3 bytes +// [ 48 bits ] fromIdx // 3 bytes // [ 16 bits ] chainId // 2 bytes // [ 32 bits ] empty (signatureConstant) // 4 bytes // Total bits compressed data: 225 bits // 29 bytes in *big.Int representation @@ -213,7 +213,7 @@ func L1UserTxFromBytes(b []byte) (*L1Tx, error) { pkCompB := b[20:52] pkCompL := SwapEndianness(pkCompB) copy(tx.FromBJJ[:], pkCompL) - fromIdx, err := IdxFromBytes(b[52:58]) + fromIdx, err := AccountIdxFromBytes(b[52:55]) if err != nil { return nil, Wrap(err) } @@ -226,7 +226,7 @@ func L1UserTxFromBytes(b []byte) (*L1Tx, error) { if err != nil { return nil, Wrap(err) } - tx.ToIdx, err = IdxFromBytes(b[72:78]) + tx.ToIdx, err = AccountIdxFromBytes(b[72:75]) if err != nil { return nil, Wrap(err) } @@ -243,12 +243,12 @@ func L1TxFromDataAvailability(b []byte, nLevels uint32) (*L1Tx, error) { amountBytes := b[idxLen*2 : idxLen*2+Float40BytesLength] l1tx := L1Tx{} - fromIdx, err := IdxFromBytes(ethCommon.LeftPadBytes(fromIdxBytes, 6)) + fromIdx, err := AccountIdxFromBytes(ethCommon.LeftPadBytes(fromIdxBytes, 3)) if err != nil { return nil, Wrap(err) } l1tx.FromIdx = fromIdx - toIdx, err := IdxFromBytes(ethCommon.LeftPadBytes(toIdxBytes, 6)) + toIdx, err := AccountIdxFromBytes(ethCommon.LeftPadBytes(toIdxBytes, 3)) if err != nil { return nil, Wrap(err) } diff --git a/sequencer/common/l2tx.go b/sequencer/common/l2tx.go index e9809e2..6ccc5d6 100644 --- a/sequencer/common/l2tx.go +++ b/sequencer/common/l2tx.go @@ -123,16 +123,16 @@ func L2TxFromBytesDataAvailability(b []byte, nLevels int) (*L2Tx, error) { tx := &L2Tx{} var err error - var paddedFromIdxBytes [6]byte - copy(paddedFromIdxBytes[6-idxLen:], b[0:idxLen]) - tx.FromIdx, err = IdxFromBytes(paddedFromIdxBytes[:]) + var paddedFromIdxBytes [3]byte + copy(paddedFromIdxBytes[3-idxLen:], b[0:idxLen]) + tx.FromIdx, err = AccountIdxFromBytes(paddedFromIdxBytes[:]) if err != nil { return nil, Wrap(err) } - var paddedToIdxBytes [6]byte - copy(paddedToIdxBytes[6-idxLen:6], b[idxLen:idxLen*2]) - tx.ToIdx, err = IdxFromBytes(paddedToIdxBytes[:]) + var paddedToIdxBytes [3]byte + copy(paddedToIdxBytes[3-idxLen:3], b[idxLen:idxLen*2]) + tx.ToIdx, err = AccountIdxFromBytes(paddedToIdxBytes[:]) if err != nil { return nil, Wrap(err) } diff --git a/sequencer/common/token.go b/sequencer/common/token.go index 829e875..5498470 100644 --- a/sequencer/common/token.go +++ b/sequencer/common/token.go @@ -25,4 +25,4 @@ func (t TokenID) Bytes() []byte { var tokenIDBytes [4]byte binary.BigEndian.PutUint32(tokenIDBytes[:], uint32(t)) return tokenIDBytes[:] -} \ No newline at end of file +} diff --git a/sequencer/common/vouch.go b/sequencer/common/vouch.go index 473887f..4c27ba9 100644 --- a/sequencer/common/vouch.go +++ b/sequencer/common/vouch.go @@ -38,16 +38,12 @@ func (idx VouchIdx) Bytes() ([2 * NLevelsAsBytes]byte, error) { } // GenerateVouchIdx -func GenerateVouchIdx(fromIdx AccountIdx, toIdx AccountIdx) *big.Int { - // Create a new big.Int to hold the result - result := new(big.Int) +func GenerateVouchIdx(fromIdx AccountIdx, toIdx AccountIdx) VouchIdx { - // Shift fromIdx left by 64 bits and add toIdx - result.SetUint64(uint64(fromIdx)) - result.Lsh(result, 24) - result.Or(result, new(big.Int).SetUint64(uint64(toIdx))) + // Shift fromIdx left by 32 bits then concat with toIdx + vouchIdx := (uint64(fromIdx) << 32) | uint64(toIdx) - return result + return VouchIdx(vouchIdx) } func VouchIdxFromBytes(b []byte) (VouchIdx, error) { diff --git a/sequencer/database/historydb/historydb.go b/sequencer/database/historydb/historydb.go index 0134c2e..808bc28 100644 --- a/sequencer/database/historydb/historydb.go +++ b/sequencer/database/historydb/historydb.go @@ -387,6 +387,9 @@ func (hdb *HistoryDB) AddL2Txs(l2txs []common.L2Tx) error { // addL2Txs inserts L2 txs to the DB. TokenID, USD and FeeUSD will be set automatically before storing the tx. func (hdb *HistoryDB) addL2Txs(d meddler.DB, l2txs []common.L2Tx) error { + if len(l2txs) == 0 { + return nil + } txs := []txWrite{} for i := 0; i < len(l2txs); i++ { f := new(big.Float).SetInt(l2txs[i].Amount) @@ -427,7 +430,6 @@ func (hdb *HistoryDB) addTxs(d meddler.DB, txs []txWrite) error { to_idx, amount, amount_f, - token_id, batch_num, eth_block_num, to_forge_l1_txs_num, @@ -463,7 +465,7 @@ func (hdb *HistoryDB) GetAllL1UserTxs() ([]common.L1Tx, error) { err := meddler.QueryAll( hdb.dbRead, &txs, `SELECT tx.id, tx.to_forge_l1_txs_num, tx.position, tx.user_origin, - tx.from_idx, tx.effective_from_idx, tx.from_eth_addr, tx.from_bjj, tx.to_idx, tx.token_id, + tx.from_idx, tx.effective_from_idx, tx.from_eth_addr, tx.from_bjj, tx.to_idx, tx.amount, (CASE WHEN tx.batch_num IS NULL THEN NULL WHEN tx.amount_success THEN tx.amount ELSE 0 END) AS effective_amount, tx.deposit_amount, (CASE WHEN tx.batch_num IS NULL THEN NULL WHEN tx.deposit_amount_success THEN tx.deposit_amount ELSE 0 END) AS effective_deposit_amount, tx.eth_block_num, tx.type, tx.batch_num @@ -480,7 +482,7 @@ func (hdb *HistoryDB) GetAllL1CoordinatorTxs() ([]common.L1Tx, error) { err := meddler.QueryAll( hdb.dbRead, &txs, `SELECT tx.id, tx.to_forge_l1_txs_num, tx.position, tx.user_origin, - tx.from_idx, tx.effective_from_idx, tx.from_eth_addr, tx.from_bjj, tx.to_idx, tx.token_id, + tx.from_idx, tx.effective_from_idx, tx.from_eth_addr, tx.from_bjj, tx.to_idx, tx.amount, tx.amount AS effective_amount, tx.deposit_amount, tx.deposit_amount AS effective_deposit_amount, tx.eth_block_num, tx.type, tx.batch_num @@ -495,8 +497,8 @@ func (hdb *HistoryDB) GetAllL2Txs() ([]common.L2Tx, error) { err := meddler.QueryAll( hdb.dbRead, &txs, `SELECT tx.id, tx.batch_num, tx.position, - tx.from_idx, tx.to_idx, tx.amount, tx.token_id, - tx.fee, tx.nonce, tx.type, tx.eth_block_num + tx.from_idx, tx.to_idx, tx.amount, + tx.nonce, tx.type, tx.eth_block_num FROM tx WHERE is_l1 = FALSE ORDER BY item_id;`, ) return database.SlicePtrsToSlice(txs).([]common.L2Tx), common.Wrap(err) @@ -508,7 +510,7 @@ func (hdb *HistoryDB) GetUnforgedL1UserTxs(toForgeL1TxsNum int64) ([]common.L1Tx err := meddler.QueryAll( hdb.dbRead, &txs, // only L1 user txs can have batch_num set to null `SELECT tx.id, tx.to_forge_l1_txs_num, tx.position, tx.user_origin, - tx.from_idx, tx.from_eth_addr, tx.from_bjj, tx.to_idx, tx.token_id, + tx.from_idx, tx.from_eth_addr, tx.from_bjj, tx.to_idx, tx.amount, NULL AS effective_amount, tx.deposit_amount, NULL AS effective_deposit_amount, tx.eth_block_num, tx.type, tx.batch_num diff --git a/sequencer/database/historydb/historydb_test.go b/sequencer/database/historydb/historydb_test.go index 5f7512b..25df443 100644 --- a/sequencer/database/historydb/historydb_test.go +++ b/sequencer/database/historydb/historydb_test.go @@ -163,7 +163,7 @@ func TestBatches(t *testing.T) { batch.Batch.GasPrice = big.NewInt(0) batches = append(batches, batch.Batch) forgeTxsNum := batch.Batch.ForgeL1TxsNum - if forgeTxsNum != nil && *lastL1TxsNum < *forgeTxsNum { + if forgeTxsNum != nil && (lastL1TxsNum == nil || *lastL1TxsNum < *forgeTxsNum) { *lastL1TxsNum = *forgeTxsNum lastL1BatchBlockNum = batch.Batch.EthBlockNum } diff --git a/sequencer/database/historydb/views.go b/sequencer/database/historydb/views.go index 26575c6..dad64a5 100644 --- a/sequencer/database/historydb/views.go +++ b/sequencer/database/historydb/views.go @@ -24,9 +24,9 @@ type txWrite struct { ToIdx common.AccountIdx `meddler:"to_idx"` Amount *big.Int `meddler:"amount,bigint"` AmountFloat float64 `meddler:"amount_f"` - TokenID common.TokenID `meddler:"token_id"` - BatchNum *common.BatchNum `meddler:"batch_num"` // batchNum in which this tx was forged. If the tx is L2, this must be != 0 - EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L1Tx was added to the queue + // TokenID common.TokenID `meddler:"token_id"` + BatchNum *common.BatchNum `meddler:"batch_num"` // batchNum in which this tx was forged. If the tx is L2, this must be != 0 + EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L1Tx was added to the queue // L1 ToForgeL1TxsNum *int64 `meddler:"to_forge_l1_txs_num"` // toForgeL1TxsNum in which the tx was forged / will be forged UserOrigin *bool `meddler:"user_origin"` // true if the tx was originated by a user, false if it was aoriginated by a coordinator. Note that this differ from the spec for implementation simplification purpposes diff --git a/sequencer/database/migrations/0001.sql b/sequencer/database/migrations/0001.sql index 016308b..9bfcb5b 100644 --- a/sequencer/database/migrations/0001.sql +++ b/sequencer/database/migrations/0001.sql @@ -495,7 +495,7 @@ BEGIN NEW.fee = (SELECT 0); END IF; -- Set token_id - NEW."token_id" = (SELECT token_id FROM account WHERE idx = NEW."from_idx"); + -- NEW.token_id = (SELECT token_id FROM account WHERE idx = NEW.from_idx); -- Set from_{eth_addr,bjj} SELECT INTO NEW."from_eth_addr", NEW."from_bjj" eth_addr, bjj FROM account WHERE idx = NEW.from_idx; END IF; diff --git a/sequencer/database/statedb/account_service.go b/sequencer/database/statedb/account_service.go index b0f1331..315d484 100644 --- a/sequencer/database/statedb/account_service.go +++ b/sequencer/database/statedb/account_service.go @@ -108,7 +108,7 @@ func (s *StateDB) GetAccount(idx common.AccountIdx) (*common.Account, error) { func accountsIter(db db.Storage, fn func(a *common.Account) (bool, error)) error { idxDB := db.WithPrefix(PrefixKeyAccIdx) if err := idxDB.Iterate(func(k []byte, v []byte) (bool, error) { - idx, err := common.IdxFromBytes(k) + idx, err := common.AccountIdxFromBytes(k) if err != nil { return false, common.Wrap(err) } diff --git a/sequencer/database/statedb/state_db.go b/sequencer/database/statedb/state_db.go index 9321dfb..6c11f12 100644 --- a/sequencer/database/statedb/state_db.go +++ b/sequencer/database/statedb/state_db.go @@ -21,7 +21,7 @@ const ( TypeBatchBuilder = "batchbuilder" // MaxNLevels is the maximum value of NLevels for the merkle tree, // which comes from the fact that AccountIdx has 48 bits. - MaxNLevels = 48 + MaxNLevels = 24 ) // Config of the StateDB diff --git a/sequencer/eth/rollup.go b/sequencer/eth/rollup.go index bcae33b..5420f1d 100644 --- a/sequencer/eth/rollup.go +++ b/sequencer/eth/rollup.go @@ -54,9 +54,9 @@ type RollupEventInitialize struct { // RollupEventL1UserTx is an event of the Rollup Smart Contract type RollupEventL1UserTx struct { - // ToForgeL1TxsNum int64 // QueueIndex *big.Int - // Position int // TransactionIndex *big.Int - L1UserTx common.L1Tx + ToForgeL1TxsNum int64 // QueueIndex *big.Int + Position int // TransactionIndex *big.Int + L1UserTx common.L1Tx } // RollupEventL1UserTxAux is an event of the Rollup Smart Contract @@ -654,7 +654,7 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash, copy(paddedFeeIdx[:], aux.FeeIdxCoordinator[i*lenFeeIdxCoordinatorBytes:(i+1)*lenFeeIdxCoordinatorBytes]) } - feeIdxCoordinator, err := common.IdxFromBytes(paddedFeeIdx[:]) + feeIdxCoordinator, err := common.AccountIdxFromBytes(paddedFeeIdx[:]) if err != nil { return nil, nil, common.Wrap(err) } diff --git a/sequencer/go.mod b/sequencer/go.mod index b35bd59..796e572 100644 --- a/sequencer/go.mod +++ b/sequencer/go.mod @@ -11,11 +11,10 @@ require ( github.com/gin-gonic/gin v1.7.2 github.com/go-playground/validator v9.31.0+incompatible github.com/gobuffalo/packr/v2 v2.8.1 - github.com/hermeznetwork/tracerr v0.3.2 github.com/iden3/go-iden3-crypto v0.0.6-0.20210308142348-8f85683b2cef github.com/iden3/go-merkletree v0.0.0-20210308143313-8b63ca866189 github.com/jmoiron/sqlx v1.2.1-0.20200615141059-0794cb1f47ee - github.com/joho/godotenv v1.5.1 + github.com/joho/godotenv v1.3.0 github.com/lib/pq v1.8.0 github.com/libp2p/go-libp2p-core v0.8.6 github.com/libp2p/go-libp2p-discovery v0.5.1 @@ -26,10 +25,10 @@ require ( github.com/prometheus/client_golang v1.10.0 github.com/rubenv/sql-migrate v0.0.0-20200616145509-8d140a17f351 github.com/russross/meddler v1.0.1 - github.com/stretchr/testify v1.9.0 + github.com/stretchr/testify v1.7.0 github.com/urfave/cli v1.22.1 go.uber.org/zap v1.16.0 - golang.org/x/sync v0.8.0 + golang.org/x/sync v0.0.0-20210220032951-036812b2e83c ) require ( @@ -61,7 +60,6 @@ require ( github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/protobuf v1.4.3 // indirect github.com/golang/snappy v0.0.3 // indirect - github.com/google/go-cmp v0.6.0 // indirect github.com/google/go-querystring v1.0.0 // indirect github.com/google/gopacket v1.1.19 // indirect github.com/google/uuid v1.2.0 // indirect @@ -83,10 +81,10 @@ require ( github.com/json-iterator/go v1.1.10 // indirect github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356 // indirect github.com/karrick/godirwalk v1.15.8 // indirect - github.com/klauspost/cpuid/v2 v2.0.9 // indirect + github.com/klauspost/cpuid/v2 v2.0.4 // indirect github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect - github.com/kr/pretty v0.3.1 // indirect - github.com/kr/text v0.2.0 // indirect + github.com/kr/pretty v0.2.1 // indirect + github.com/kr/text v0.1.0 // indirect github.com/leodido/go-urn v1.2.0 // indirect github.com/libp2p/go-buffer-pool v0.0.2 // indirect github.com/libp2p/go-cidranger v1.1.0 // indirect @@ -101,12 +99,10 @@ require ( github.com/libp2p/go-netroute v0.1.6 // indirect github.com/libp2p/go-openssl v0.0.7 // indirect github.com/libp2p/go-sockaddr v0.1.1 // indirect - github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e // indirect github.com/markbates/errx v1.1.0 // indirect github.com/markbates/oncer v1.0.0 // indirect github.com/markbates/safe v1.0.1 // indirect - github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mattn/go-isatty v0.0.12 // indirect github.com/mattn/go-runewidth v0.0.9 // indirect github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect @@ -134,7 +130,6 @@ require ( github.com/prometheus/procfs v0.6.0 // indirect github.com/prometheus/tsdb v0.7.1 // indirect github.com/rjeczalik/notify v0.9.2 // indirect - github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/russross/blackfriday/v2 v2.0.1 // indirect github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect @@ -151,17 +146,16 @@ require ( go.opencensus.io v0.23.0 // indirect go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.6.0 // indirect - golang.org/x/crypto v0.23.0 // indirect + golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect golang.org/x/exp v0.0.0-20200513190911-00229845015e // indirect - golang.org/x/net v0.25.0 // indirect - golang.org/x/sys v0.25.0 // indirect - golang.org/x/term v0.24.0 // indirect - golang.org/x/text v0.15.0 // indirect - golang.org/x/tools v0.21.0 // indirect + golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6 // indirect + golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect + golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect + golang.org/x/text v0.3.6 // indirect google.golang.org/protobuf v1.25.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/gorp.v1 v1.7.2 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect gopkg.in/yaml.v2 v2.3.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect ) diff --git a/sequencer/go.sum b/sequencer/go.sum index a627cb8..b5100eb 100644 --- a/sequencer/go.sum +++ b/sequencer/go.sum @@ -185,7 +185,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:ma github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/dave/jennifer v1.2.0/go.mod h1:fIb+770HOpJ2fmN9EPPKOqm1vMGhB+TwXKMZhrIygKg= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -383,9 +382,8 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= @@ -459,8 +457,6 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= -github.com/hermeznetwork/tracerr v0.3.2 h1:QB3TlQxO/4XHyixsg+nRZPuoel/FFQlQ7oAoHDD5l1c= -github.com/hermeznetwork/tracerr v0.3.2/go.mod h1:nsWC1+tc4qUEbUGRv4DcPJJTjLsedlPajlFmpJoohK4= github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= github.com/holiman/uint256 v1.2.0 h1:gpSYcPLWGv4sG43I2mVLiDZCNDh/EpGjSk8tmtxitHM= @@ -562,9 +558,8 @@ github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHW github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/jmoiron/sqlx v1.2.1-0.20200615141059-0794cb1f47ee h1:59lyMGvZusByi7Rvctn8cxdVAjhiOnqCv3G5DrYApYQ= github.com/jmoiron/sqlx v1.2.1-0.20200615141059-0794cb1f47ee/go.mod h1:ClpsPFzLpSBl7MvJ+BhV0JHz4vmKRBarpvZ9644v9Oo= +github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= -github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= -github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= @@ -606,9 +601,8 @@ github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0 github.com/klauspost/compress v1.9.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/cpuid v0.0.0-20170728055534-ae7887de9fa5/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= +github.com/klauspost/cpuid/v2 v2.0.4 h1:g0I61F2K2DjRHz1cnxlkNSBIaePVoJIjjnHui8QHbiw= github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= -github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/crc32 v0.0.0-20161016154125-cb6bfca970f6/go.mod h1:+ZoRqAPRLkC4NPOvfYeR5KNOrY6TD+/sAC3HXPZgDYg= github.com/klauspost/pgzip v1.0.2-0.20170402124221-0bf5dcad4ada/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -620,14 +614,12 @@ github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d/go.mod h1:5Ky9EC2xfo github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/labstack/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvfxNnFqi74g= github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= @@ -865,8 +857,6 @@ github.com/libp2p/go-yamux/v2 v2.2.0 h1:RwtpYZ2/wVviZ5+3pjC8qdQ4TKnrak0/E01N1UWo github.com/libp2p/go-yamux/v2 v2.2.0/go.mod h1:3So6P6TV6r75R9jiBpiIKgU/66lOarCZjqROGxzPpPQ= github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= -github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e h1:9MlwzLdW7QSDrhDjFlsEYmxpFyIoXmYRon3dt0io31k= -github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= github.com/lucas-clemente/quic-go v0.19.3 h1:eCDQqvGBB+kCTkA0XrAFtNe81FMa0/fn4QSoeAbmiF4= github.com/lucas-clemente/quic-go v0.19.3/go.mod h1:ADXpNbTQjq1hIzCpB+y/k5iz4n4z4IwqoLb94Kh5Hu8= github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= @@ -890,9 +880,8 @@ github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd/go.mod h1:QuCEs github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= +github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-ieproxy v0.0.0-20190610004146-91bb50d98149/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= github.com/mattn/go-ieproxy v0.0.0-20190702010315-6dee0af9227d/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= @@ -902,10 +891,8 @@ github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= +github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= -github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-oci8 v0.0.7/go.mod h1:wjDx6Xm9q7dFtHJvIlrI99JytznLw5wQ4R+9mNXJwGI= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= @@ -1098,7 +1085,6 @@ github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0 github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -1156,10 +1142,8 @@ github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.3.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.4.0/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.5.2 h1:qLvObTrvO/XRCqmkKxUlOBc48bI3efyDuAZe25QiF0w= github.com/rogpeppe/go-internal v1.5.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= -github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/rs/cors v0.0.0-20160617231935-a62a804a8a00/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= @@ -1249,9 +1233,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA= github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954 h1:xQdMZ1WLrgkkvOZ/LDQxjVxMLdby7osSh4ZEVa5sIjs= @@ -1378,8 +1361,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= -golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI= +golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -1414,9 +1397,8 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= -golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1459,9 +1441,8 @@ golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= +golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6 h1:0PC75Fz/kyMGhL0e1QnypqK2kQMqKt9csD1GnMJR+Zk= golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= -golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= -golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -1479,9 +1460,8 @@ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= -golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -1546,23 +1526,19 @@ golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210420205809-ac73e9fd8988/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210426080607-c94f62235c83/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= -golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM= -golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -1612,9 +1588,8 @@ golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20200308013534-11ec41452d41/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= -golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw= -golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -1734,9 +1709,8 @@ gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/sequencer/synchronizer/synchronizer.go b/sequencer/synchronizer/synchronizer.go index 9abd762..9512c60 100644 --- a/sequencer/synchronizer/synchronizer.go +++ b/sequencer/synchronizer/synchronizer.go @@ -19,7 +19,6 @@ import ( "github.com/ethereum/go-ethereum" ethCommon "github.com/ethereum/go-ethereum/common" - "github.com/hermeznetwork/tracerr" ) const ( @@ -566,9 +565,9 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e // the expected one. rollupEvents, err := s.EthClient.RollupEventsByBlock(blockNum, ðBlock.Hash) if err != nil && err.Error() == errStrUnknownBlock { - return nil, tracerr.Wrap(ErrUnknownBlock) + return nil, common.Wrap(ErrUnknownBlock) } else if err != nil { - return nil, tracerr.Wrap(fmt.Errorf("RollupEventsByBlock: %w", err)) + return nil, common.Wrap(fmt.Errorf("RollupEventsByBlock: %w", err)) } // No events in this block if rollupEvents == nil { @@ -578,7 +577,7 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e var nextForgeL1TxsNum int64 // forgeL1TxsNum for the next L1Batch nextForgeL1TxsNumPtr, err := s.historyDB.GetLastL1TxsNum() if err != nil { - return nil, tracerr.Wrap(err) + return nil, common.Wrap(err) } if nextForgeL1TxsNumPtr != nil { nextForgeL1TxsNum = *nextForgeL1TxsNumPtr + 1 @@ -589,7 +588,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, tracerr.Wrap(err) + return nil, common.Wrap(err) } // Get ForgeBatch events to get the L1CoordinatorTxs @@ -601,7 +600,7 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e forgeBatchArgs, sender, err := s.EthClient.RollupForgeBatchArgs(evtForgeBatch.EthTxHash, evtForgeBatch.L1UserTxsLen) if err != nil { - return nil, tracerr.Wrap(fmt.Errorf("RollupForgeBatchArgs: %w", err)) + return nil, common.Wrap(fmt.Errorf("RollupForgeBatchArgs: %w", err)) } ethTxHash := evtForgeBatch.EthTxHash gasUsed := evtForgeBatch.GasUsed @@ -617,7 +616,7 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e // First try to find them in HistoryDB. l1UserTxs, err = s.historyDB.GetUnforgedL1UserTxs(nextForgeL1TxsNum) if err != nil { - return nil, tracerr.Wrap(err) + return nil, common.Wrap(err) } // Apart from the DB, try to find them in this block. // This could happen because in a block there could be @@ -637,44 +636,44 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e l1TxsAuth := make([]common.AccountCreationAuth, 0, len(forgeBatchArgs.L1CoordinatorTxsAuths)) - batchData.L1CoordinatorTxs = make([]common.L1Tx, 0, len(forgeBatchArgs.L1CoordinatorTxs)) - // Get L1 Coordinator Txs - for i := range forgeBatchArgs.L1CoordinatorTxs { - l1CoordinatorTx := forgeBatchArgs.L1CoordinatorTxs[i] - l1CoordinatorTx.Position = position - // l1CoordinatorTx.ToForgeL1TxsNum = &forgeL1TxsNum - l1CoordinatorTx.UserOrigin = false - l1CoordinatorTx.EthBlockNum = blockNum - l1CoordinatorTx.BatchNum = &batchNum - l1CoordinatorTx.EthTxHash = ethTxHash - l1Tx, err := common.NewL1Tx(&l1CoordinatorTx) - if err != nil { - return nil, tracerr.Wrap(err) - } - - batchData.L1CoordinatorTxs = append(batchData.L1CoordinatorTxs, *l1Tx) - position++ - - // Create a slice of account creation auth to be - // inserted later if not exists - if l1CoordinatorTx.FromEthAddr != common.RollupConstEthAddressInternalOnly { - l1CoordinatorTxAuth := forgeBatchArgs.L1CoordinatorTxsAuths[i] - l1TxsAuth = append(l1TxsAuth, common.AccountCreationAuth{ - EthAddr: l1CoordinatorTx.FromEthAddr, - BJJ: l1CoordinatorTx.FromBJJ, - Signature: l1CoordinatorTxAuth, - }) - } - - // fmt.Println("DGB l1coordtx") - } + // batchData.L1CoordinatorTxs = make([]common.L1Tx, 0, len(forgeBatchArgs.L1CoordinatorTxs)) + // // Get L1 Coordinator Txs + // for i := range forgeBatchArgs.L1CoordinatorTxs { + // l1CoordinatorTx := forgeBatchArgs.L1CoordinatorTxs[i] + // l1CoordinatorTx.Position = position + // // l1CoordinatorTx.ToForgeL1TxsNum = &forgeL1TxsNum + // l1CoordinatorTx.UserOrigin = false + // l1CoordinatorTx.EthBlockNum = blockNum + // l1CoordinatorTx.BatchNum = &batchNum + // l1CoordinatorTx.EthTxHash = ethTxHash + // l1Tx, err := common.NewL1Tx(&l1CoordinatorTx) + // if err != nil { + // return nil, common.Wrap(err) + // } + + // batchData.L1CoordinatorTxs = append(batchData.L1CoordinatorTxs, *l1Tx) + // position++ + + // // Create a slice of account creation auth to be + // // inserted later if not exists + // if l1CoordinatorTx.FromEthAddr != common.RollupConstEthAddressInternalOnly { + // l1CoordinatorTxAuth := forgeBatchArgs.L1CoordinatorTxsAuths[i] + // l1TxsAuth = append(l1TxsAuth, common.AccountCreationAuth{ + // EthAddr: l1CoordinatorTx.FromEthAddr, + // BJJ: l1CoordinatorTx.FromBJJ, + // Signature: l1CoordinatorTxAuth, + // }) + // } + + // // fmt.Println("DGB l1coordtx") + // } // Insert the slice of account creation auth // only if the node run as a coordinator if s.l2DB != nil && len(l1TxsAuth) > 0 { err = s.l2DB.AddManyAccountCreationAuth(l1TxsAuth) if err != nil { - return nil, tracerr.Wrap(err) + return nil, common.Wrap(err) } } @@ -685,7 +684,7 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e // Set TxType to the forged L2Txs for i := range forgeBatchArgs.L2TxsData { if err := forgeBatchArgs.L2TxsData[i].SetType(); err != nil { - return nil, tracerr.Wrap(err) + return nil, common.Wrap(err) } } @@ -694,7 +693,7 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e poolL2Txs := common.L2TxsToPoolL2Txs(forgeBatchArgs.L2TxsData) if int(forgeBatchArgs.VerifierIdx) >= len(s.consts.Rollup.Verifiers) { - return nil, tracerr.Wrap(fmt.Errorf("forgeBatchArgs.VerifierIdx (%v) >= "+ + return nil, common.Wrap(fmt.Errorf("forgeBatchArgs.VerifierIdx (%v) >= "+ " len(s.consts.Rollup.Verifiers) (%v)", forgeBatchArgs.VerifierIdx, len(s.consts.Rollup.Verifiers))) } @@ -711,15 +710,15 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e processTxsOut, err := tp.ProcessTxs(forgeBatchArgs.FeeIdxCoordinator, l1UserTxs, batchData.L1CoordinatorTxs, poolL2Txs) if err != nil { - return nil, tracerr.Wrap(err) + return nil, common.Wrap(err) } if s.stateDB.CurrentBatch() != batchNum { - return nil, tracerr.Wrap(fmt.Errorf("stateDB.BatchNum (%v) != "+ + return nil, common.Wrap(fmt.Errorf("stateDB.BatchNum (%v) != "+ "evtForgeBatch.BatchNum = (%v)", s.stateDB.CurrentBatch(), batchNum)) } // if s.stateDB.AccountTree.Root().BigInt().Cmp(forgeBatchArgs.NewStRoot) != 0 { - // return nil, tracerr.Wrap(fmt.Errorf("stateDB.MTRoot (%v) != "+ + // return nil, common.Wrap(fmt.Errorf("stateDB.MTRoot (%v) != "+ // "forgeBatchArgs.NewStRoot (%v)", // s.stateDB.AccountTree.Root().BigInt(), forgeBatchArgs.NewStRoot)) // } @@ -729,7 +728,7 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e l2Txs[i] = tx.L2Tx() // Set TxID, BlockNum, BatchNum and Position to the forged L2Txs if err := l2Txs[i].SetID(); err != nil { - return nil, tracerr.Wrap(err) + return nil, common.Wrap(err) } l2Txs[i].EthBlockNum = blockNum l2Txs[i].BatchNum = batchNum @@ -849,7 +848,7 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e // for _, evt := range rollupEvents.UpdateTokenExchange { // if len(evt.AddressArray) != len(evt.ValueArray) { - // return nil, tracerr.Wrap(fmt.Errorf("in RollupEventUpdateTokenExchange "+ + // return nil, common.Wrap(fmt.Errorf("in RollupEventUpdateTokenExchange "+ // "len(AddressArray) != len(ValueArray) (%v != %v)", // len(evt.AddressArray), len(evt.ValueArray))) // } @@ -915,7 +914,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, tracerr.Wrap(err) + return nil, common.Wrap(err) } l1Txs[i] = *l1Tx } diff --git a/sequencer/synchronizer/synchronizer_test.go b/sequencer/synchronizer/synchronizer_test.go index 9264a70..540b13d 100644 --- a/sequencer/synchronizer/synchronizer_test.go +++ b/sequencer/synchronizer/synchronizer_test.go @@ -96,8 +96,6 @@ func checkSyncBlock(t *testing.T, s *Synchronizer, blockNum int, block, dbBatches, err := s.historyDB.GetAllBatches() require.NoError(t, err) - dbL1CoordinatorTxs, err := s.historyDB.GetAllL1CoordinatorTxs() - require.NoError(t, err) dbL2Txs, err := s.historyDB.GetAllL2Txs() require.NoError(t, err) dbExits, err := s.historyDB.GetAllExits() @@ -168,29 +166,14 @@ func checkSyncBlock(t *testing.T, s *Synchronizer, blockNum int, block, break } } - assert.Equal(t, &tx, dbTx) //nolint:gosec + // TODO: sync rollup smart contract + // assert.Equal(t, &tx, dbTx) //nolint:gosec syncTx := &syncBlock.Rollup.Batches[i].L1UserTxs[j] assert.Equal(t, syncTx.DepositAmount, syncTx.EffectiveDepositAmount) assert.Equal(t, syncTx.Amount, syncTx.EffectiveAmount) } - // Check L1CoordinatorTxs from DB - for _, tx := range batch.L1CoordinatorTxs { - var dbTx *common.L1Tx - // Find tx in DB output - for _, _dbTx := range dbL1CoordinatorTxs { - if *tx.BatchNum == *_dbTx.BatchNum && - tx.Position == _dbTx.Position { - dbTx = new(common.L1Tx) - *dbTx = _dbTx - break - } - } - dbTx.EthTxHash = ethCommon.HexToHash("0xef98421250239de255750811293f167abb9325152520acb62e40de72746d4d5e") - assert.Equal(t, &tx, dbTx) //nolint:gosec - } - // Check L2Txs from DB for _, tx := range batch.L2Txs { var dbTx *common.L2Tx @@ -364,10 +347,10 @@ func TestSyncGeneral(t *testing.T) { set1 := ` Type: Blockchain - CreateAccountDeposit C: 2000 // Idx=256+2=258 - CreateAccountDeposit A: 2000 // Idx=256+3=259 - CreateAccountDeposit D: 500 // Idx=256+4=260 - CreateAccountDeposit B: 500 // Idx=256+5=261 + CreateAccountDeposit C: 2000 // Idx=256+0=256 + CreateAccountDeposit A: 2000 // Idx=256+1=257 + CreateAccountDeposit D: 500 // Idx=256+2=258 + CreateAccountDeposit B: 500 // Idx=256+3=259 > batchL1 // forge L1UserTxs{nil}, freeze defined L1UserTxs{4} > batchL1 // forge defined L1UserTxs{4}, freeze L1UserTxs{nil} @@ -380,8 +363,8 @@ func TestSyncGeneral(t *testing.T) { Exit C: 50 Exit D: 30 - > batchL1 // forge L1UserTxs{nil}, freeze defined L1UserTxs{3} - > batchL1 // forge L1UserTxs{3}, freeze defined L1UserTxs{nil} + > batchL1 // forge L1UserTxs{nil}, freeze defined L1UserTxs{2} + > batchL1 // forge L1UserTxs{2}, freeze defined L1UserTxs{nil} > block // blockNum=3 ` tc := til.NewContext(chainID, common.RollupConstMaxL1UserTx) @@ -447,6 +430,96 @@ func TestSyncGeneral(t *testing.T) { // Set ethereum transaction hash (til doesn't set it) blocks[0].Rollup.Batches[0].Batch.EthTxHash = syncBlock.Rollup.Batches[0].Batch.EthTxHash blocks[0].Rollup.Batches[1].Batch.EthTxHash = syncBlock.Rollup.Batches[1].Batch.EthTxHash + blocks[0].Rollup.Batches[0].Batch.GasPrice = syncBlock.Rollup.Batches[0].Batch.GasPrice + blocks[0].Rollup.Batches[1].Batch.GasPrice = syncBlock.Rollup.Batches[1].Batch.GasPrice checkSyncBlock(t, s, 2, &blocks[0], syncBlock) + + // Block 3 + + syncBlock, discards, err = s.Sync(ctx, nil) + require.NoError(t, err) + require.Nil(t, discards) + require.NotNil(t, syncBlock) + assert.Nil(t, syncBlock.Rollup.Vars) + assert.Equal(t, int64(3), syncBlock.Block.Num) + stats = s.Stats() + assert.Equal(t, int64(1), stats.Eth.FirstBlockNum) + assert.Equal(t, int64(3), stats.Eth.LastBlock.Num) + assert.Equal(t, int64(3), stats.Sync.LastBlock.Num) + // Set ethereum transaction hash (til doesn't set it) + blocks[1].Rollup.Batches[0].Batch.EthTxHash = syncBlock.Rollup.Batches[0].Batch.EthTxHash + blocks[1].Rollup.Batches[1].Batch.EthTxHash = syncBlock.Rollup.Batches[1].Batch.EthTxHash + blocks[1].Rollup.Batches[0].Batch.GasPrice = syncBlock.Rollup.Batches[0].Batch.GasPrice + blocks[1].Rollup.Batches[1].Batch.GasPrice = syncBlock.Rollup.Batches[1].Batch.GasPrice + + checkSyncBlock(t, s, 3, &blocks[1], syncBlock) + + // Block 4 + // Generate 2 withdraws manually + _, err = client.RollupWithdrawMerkleProof(tc.Accounts["A"].BJJ.Public().Compress(), 4, 257, + big.NewInt(100), []*big.Int{}, true) + require.NoError(t, err) + _, err = client.RollupWithdrawMerkleProof(tc.Accounts["C"].BJJ.Public().Compress(), 3, 256, + big.NewInt(50), []*big.Int{}, false) + require.NoError(t, err) + client.CtlMineBlock() + + syncBlock, discards, err = s.Sync(ctx, nil) + require.NoError(t, err) + require.Nil(t, discards) + require.NotNil(t, syncBlock) + assert.Nil(t, syncBlock.Rollup.Vars) + assert.Equal(t, int64(4), syncBlock.Block.Num) + stats = s.Stats() + assert.Equal(t, int64(1), stats.Eth.FirstBlockNum) + assert.Equal(t, int64(4), stats.Eth.LastBlock.Num) + assert.Equal(t, int64(4), stats.Sync.LastBlock.Num) + vars = s.SCVars() + assert.Equal(t, *clientSetup.RollupVariables, vars.Rollup) + + dbExits, err := s.historyDB.GetAllExits() + require.NoError(t, err) + foundA1, foundC1 := false, false + + for _, exit := range dbExits { + if exit.AccountIdx == 257 && exit.BatchNum == 4 { + foundA1 = true + } + if exit.AccountIdx == 256 && exit.BatchNum == 3 { + foundC1 = true + } + } + + assert.True(t, foundA1) + assert.True(t, foundC1) + + // Block 5 + // Update variables manually + rollupVars, err := s.historyDB.GetSCVars() + require.NoError(t, err) + rollupVars.ForgeL1L2BatchTimeout = 42 + _, err = client.RollupUpdateForgeL1L2BatchTimeout(rollupVars.ForgeL1L2BatchTimeout) + require.NoError(t, err) + + client.CtlMineBlock() + + syncBlock, discards, err = s.Sync(ctx, nil) + require.NoError(t, err) + require.Nil(t, discards) + require.NotNil(t, syncBlock) + assert.NotNil(t, syncBlock.Rollup.Vars) + assert.Equal(t, int64(5), syncBlock.Block.Num) + stats = s.Stats() + assert.Equal(t, int64(1), stats.Eth.FirstBlockNum) + assert.Equal(t, int64(5), stats.Eth.LastBlock.Num) + assert.Equal(t, int64(5), stats.Sync.LastBlock.Num) + vars = s.SCVars() + assert.NotEqual(t, clientSetup.RollupVariables, vars.Rollup) + + dbRollupVars, err := s.historyDB.GetSCVars() + require.NoError(t, err) + // Set EthBlockNum for Vars to the blockNum in which they were updated (should be 5) + rollupVars.EthBlockNum = syncBlock.Block.Num + assert.Equal(t, rollupVars, dbRollupVars) } diff --git a/sequencer/test/ethClient.go b/sequencer/test/ethClient.go index 1f944c9..1daaff9 100644 --- a/sequencer/test/ethClient.go +++ b/sequencer/test/ethClient.go @@ -509,9 +509,6 @@ var errTODO = fmt.Errorf("TODO: Not implemented yet") // if int64(l1Tx.FromIdx) > r.State.CurrentIdx { // panic("l1Tx.FromIdx > r.State.CurrentIdx") // } -// if int(l1Tx.TokenID)+1 > len(r.State.TokenList) { -// panic("l1Tx.TokenID + 1 > len(r.State.TokenList)") -// } // queue.L1TxQueue = append(queue.L1TxQueue, *l1Tx) // r.Events.L1UserTx = append(r.Events.L1UserTx, eth.RollupEventL1UserTx{ // L1Tx: *l1Tx, @@ -522,7 +519,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.PublicKeyComp, fromIdx int64, - depositAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64, + depositAmount *big.Int, amount *big.Int, toIdx int64, deadline *big.Int) (tx *types.Transaction, err error) { log.Error("TODO") return nil, common.Wrap(errTODO) @@ -586,7 +583,7 @@ func (c *Client) RollupL1UserTxERC20ETH( // RollupL1UserTxERC777 is the interface to call the smart contract function // func (c *Client) RollupL1UserTxERC777(fromBJJ *babyjub.PublicKey, fromIdx int64, -// depositAmount *big.Int, amount *big.Int, tokenID uint32, +// depositAmount *big.Int, amount *big.Int, // toIdx int64) (*types.Transaction, error) { // log.Error("TODO") // return nil, errTODO @@ -610,7 +607,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, + numExitRoot, idx int64, amount *big.Int, instantWithdraw bool) (*types.Transaction, error) { log.Error("TODO") return nil, common.Wrap(errTODO) @@ -618,7 +615,7 @@ func (c *Client) RollupWithdrawCircuit(proofA, proofC [2]*big.Int, proofB [2][2] // RollupWithdrawMerkleProof is the interface to call the smart contract function func (c *Client) RollupWithdrawMerkleProof(babyPubKey babyjub.PublicKeyComp, - tokenID uint32, numExitRoot, idx int64, amount *big.Int, siblings []*big.Int, + numExitRoot, idx int64, amount *big.Int, siblings []*big.Int, instantWithdraw bool) (tx *types.Transaction, err error) { c.rw.Lock() defer c.rw.Unlock() @@ -643,7 +640,6 @@ func (c *Client) RollupWithdrawMerkleProof(babyPubKey babyjub.PublicKeyComp, type data struct { BabyPubKey *babyjub.PublicKey - TokenID uint32 NumExitRoot int64 Idx int64 Amount *big.Int @@ -652,7 +648,6 @@ func (c *Client) RollupWithdrawMerkleProof(babyPubKey babyjub.PublicKeyComp, } tx = r.addTransaction(c.newTransaction("withdrawMerkleProof", data{ BabyPubKey: babyPubKeyDecomp, - TokenID: tokenID, NumExitRoot: numExitRoot, Idx: idx, Amount: amount, diff --git a/sequencer/txprocessor/txprocessor.go b/sequencer/txprocessor/txprocessor.go index 7a3c45e..be4e7a2 100644 --- a/sequencer/txprocessor/txprocessor.go +++ b/sequencer/txprocessor/txprocessor.go @@ -82,6 +82,7 @@ lines does: package txprocessor import ( + "bytes" "errors" "fmt" "io/ioutil" @@ -145,11 +146,11 @@ type ProcessTxOutput struct { func newErrorNotEnoughBalance(tx common.Tx) error { var msg error if tx.IsL1 { - msg = fmt.Errorf("Invalid transaction, not enough balance on sender account. "+ + msg = fmt.Errorf("invalid transaction, not enough balance on sender account. "+ "TxID: %s, TxType: %s, FromIdx: %d, ToIdx: %d, Amount: %d", tx.TxID, tx.Type, tx.FromIdx, tx.ToIdx, tx.Amount) } else { - msg = fmt.Errorf("Invalid transaction, not enough balance on sender account. "+ + msg = fmt.Errorf("invalid transaction, not enough balance on sender account. "+ "TxID: %s, TxType: %s, FromIdx: %d, ToIdx: %d, Amount: %d, Fee: %d", tx.TxID, tx.Type, tx.FromIdx, tx.ToIdx, tx.Amount, tx.Fee) } @@ -188,7 +189,7 @@ func (txProcessor *TxProcessor) ProcessTxs(coordIdxs []common.AccountIdx, l1user if txProcessor.zki != nil { return nil, common.Wrap( - errors.New("Expected StateDB.zki==nil, something went wrong and it's not empty")) + errors.New("expected StateDB.zki==nil, something went wrong and it's not empty")) } // defer txProcessor.resetZKInputs() @@ -298,43 +299,43 @@ func (txProcessor *TxProcessor) ProcessTxs(coordIdxs []common.AccountIdx, l1user } } - // Process L1CoordinatorTxs - for i := 0; i < len(l1coordinatortxs); i++ { - exitIdx, _, _, createdAccount, err := txProcessor.ProcessL1Tx(exitTree, &l1coordinatortxs[i]) - if err != nil { - return nil, common.Wrap(err) - } - if exitIdx != nil { - log.Error("Unexpected Exit in L1CoordinatorTx") - } - if txProcessor.state.Type() == statedb.TypeSynchronizer { - if createdAccount != nil { - createdAccounts = append(createdAccounts, *createdAccount) - l1coordinatortxs[i].EffectiveFromIdx = createdAccount.Idx - } else { - l1coordinatortxs[i].EffectiveFromIdx = l1coordinatortxs[i].FromIdx - } - } - // if txProcessor.zki != nil { - // l1TxData, err := l1coordinatortxs[i].BytesGeneric() - // if err != nil { - // return nil, common.Wrap(err) - // } - // txProcessor.zki.Metadata.L1TxsData = append(txProcessor.zki.Metadata.L1TxsData, l1TxData) - // l1TxDataAvailability, err := - // l1coordinatortxs[i].BytesDataAvailability(txProcessor.zki.Metadata.NLevels) - // if err != nil { - // return nil, common.Wrap(err) - // } - // txProcessor.zki.Metadata.L1TxsDataAvailability = - // append(txProcessor.zki.Metadata.L1TxsDataAvailability, l1TxDataAvailability) + // // Process L1CoordinatorTxs + // for i := 0; i < len(l1coordinatortxs); i++ { + // exitIdx, _, _, createdAccount, err := txProcessor.ProcessL1Tx(exitTree, &l1coordinatortxs[i]) + // if err != nil { + // return nil, common.Wrap(err) + // } + // if exitIdx != nil { + // log.Error("Unexpected Exit in L1CoordinatorTx") + // } + // if txProcessor.state.Type() == statedb.TypeSynchronizer { + // if createdAccount != nil { + // createdAccounts = append(createdAccounts, *createdAccount) + // l1coordinatortxs[i].EffectiveFromIdx = createdAccount.Idx + // } else { + // l1coordinatortxs[i].EffectiveFromIdx = l1coordinatortxs[i].FromIdx + // } + // } + // if txProcessor.zki != nil { + // l1TxData, err := l1coordinatortxs[i].BytesGeneric() + // if err != nil { + // return nil, common.Wrap(err) + // } + // txProcessor.zki.Metadata.L1TxsData = append(txProcessor.zki.Metadata.L1TxsData, l1TxData) + // l1TxDataAvailability, err := + // l1coordinatortxs[i].BytesDataAvailability(txProcessor.zki.Metadata.NLevels) + // if err != nil { + // return nil, common.Wrap(err) + // } + // txProcessor.zki.Metadata.L1TxsDataAvailability = + // append(txProcessor.zki.Metadata.L1TxsDataAvailability, l1TxDataAvailability) - // txProcessor.zki.ISOutIdx[txProcessor.txIndex] = txProcessor.state.CurrentIdx().BigInt() - // txProcessor.zki.ISStateRoot[txProcessor.txIndex] = txProcessor.state.MT.Root().BigInt() - // txProcessor.zki.ISExitRoot[txProcessor.txIndex] = exitTree.Root().BigInt() - // txProcessor.txIndex++ - // } - } + // txProcessor.zki.ISOutIdx[txProcessor.txIndex] = txProcessor.state.CurrentIdx().BigInt() + // txProcessor.zki.ISStateRoot[txProcessor.txIndex] = txProcessor.state.MT.Root().BigInt() + // txProcessor.zki.ISExitRoot[txProcessor.txIndex] = exitTree.Root().BigInt() + // txProcessor.txIndex++ + // } + // } // // remove repeated CoordIdxs that are for the same TokenID (use the // // first occurrence) @@ -446,46 +447,46 @@ func (txProcessor *TxProcessor) ProcessTxs(coordIdxs []common.AccountIdx, l1user // txProcessor.zki.ISInitStateRootFee = txProcessor.state.AccountTree.Root().BigInt() // } - // distribute the AccumulatedFees from the processed L2Txs into the - // Coordinator Idxs - indexFee := 0 - for _, idx := range coordIdxs { - accumulatedFee := txProcessor.AccumulatedFees[idx] + // // distribute the AccumulatedFees from the processed L2Txs into the + // // Coordinator Idxs + // indexFee := 0 + // for _, idx := range coordIdxs { + // accumulatedFee := txProcessor.AccumulatedFees[idx] - // send the fee to the Idx of the Coordinator for the TokenID - // (even if the AccumulatedFee==0, as is how the zk circuit - // works) - accCoord, err := txProcessor.state.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, common.Wrap(err) - } - // if txProcessor.zki != nil { - // txProcessor.zki.TokenID3[indexFee] = accCoord.TokenID.BigInt() - // txProcessor.zki.Nonce3[indexFee] = accCoord.Nonce.BigInt() - // coordBJJSign, coordBJJY := babyjub.UnpackSignY(accCoord.BJJ) - // if coordBJJSign { - // txProcessor.zki.Sign3[indexFee] = big.NewInt(1) - // } - // txProcessor.zki.Ay3[indexFee] = coordBJJY - // txProcessor.zki.Balance3[indexFee] = accCoord.Balance - // txProcessor.zki.EthAddr3[indexFee] = common.EthAddrToBigInt(accCoord.EthAddr) - // } - accCoord.Balance = new(big.Int).Add(accCoord.Balance, accumulatedFee) - pFee, err := txProcessor.updateAccount(idx, accCoord) - if err != nil { - log.Error(err) - return nil, common.Wrap(err) - } - if txProcessor.zki != nil { - txProcessor.zki.Siblings3[indexFee] = siblingsToZKInputFormat(pFee.Siblings) - if indexFee < len(txProcessor.zki.ISStateRootFee) { - txProcessor.zki.ISStateRootFee[indexFee] = txProcessor.state.AccountTree.Root().BigInt() - } - } - indexFee++ - } + // // send the fee to the Idx of the Coordinator for the TokenID + // // (even if the AccumulatedFee==0, as is how the zk circuit + // // works) + // accCoord, err := txProcessor.state.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, common.Wrap(err) + // } + // // if txProcessor.zki != nil { + // // txProcessor.zki.TokenID3[indexFee] = accCoord.TokenID.BigInt() + // // txProcessor.zki.Nonce3[indexFee] = accCoord.Nonce.BigInt() + // // coordBJJSign, coordBJJY := babyjub.UnpackSignY(accCoord.BJJ) + // // if coordBJJSign { + // // txProcessor.zki.Sign3[indexFee] = big.NewInt(1) + // // } + // // txProcessor.zki.Ay3[indexFee] = coordBJJY + // // txProcessor.zki.Balance3[indexFee] = accCoord.Balance + // // txProcessor.zki.EthAddr3[indexFee] = common.EthAddrToBigInt(accCoord.EthAddr) + // // } + // accCoord.Balance = new(big.Int).Add(accCoord.Balance, accumulatedFee) + // pFee, err := txProcessor.updateAccount(idx, accCoord) + // if err != nil { + // log.Error(err) + // return nil, common.Wrap(err) + // } + // if txProcessor.zki != nil { + // txProcessor.zki.Siblings3[indexFee] = siblingsToZKInputFormat(pFee.Siblings) + // if indexFee < len(txProcessor.zki.ISStateRootFee) { + // txProcessor.zki.ISStateRootFee[indexFee] = txProcessor.state.AccountTree.Root().BigInt() + // } + // } + // indexFee++ + // } // if txProcessor.zki != nil { // for i := len(txProcessor.AccumulatedFees); i < int(txProcessor.config.MaxFeeTx)-1; i++ { // txProcessor.zki.ISStateRootFee[i] = txProcessor.state.AccountTree.Root().BigInt() @@ -615,7 +616,7 @@ func (txProcessor *TxProcessor) ProcessL1Tx(exitTree *merkletree.MerkleTree, tx switch tx.Type { case common.TxTypeCreateAccountDeposit: - // txProcessor.computeEffectiveAmounts(tx) + txProcessor.computeEffectiveAmounts(tx) // add new account to the MT, update balance of the MT account err := txProcessor.applyCreateAccount(tx) @@ -624,7 +625,7 @@ func (txProcessor *TxProcessor) ProcessL1Tx(exitTree *merkletree.MerkleTree, tx return nil, nil, false, nil, common.Wrap(err) } case common.TxTypeDeposit: - // txProcessor.computeEffectiveAmounts(tx) + txProcessor.computeEffectiveAmounts(tx) // update balance of the MT account err := txProcessor.applyDeposit(tx, false) @@ -633,7 +634,7 @@ func (txProcessor *TxProcessor) ProcessL1Tx(exitTree *merkletree.MerkleTree, tx return nil, nil, false, nil, common.Wrap(err) } case common.TxTypeForceExit: - // txProcessor.computeEffectiveAmounts(tx) + txProcessor.computeEffectiveAmounts(tx) // execute exit flow // coordIdxsMap is 'nil', as at L1Txs there is no L2 fees @@ -674,7 +675,7 @@ func (txProcessor *TxProcessor) ProcessL2Tx(exitTree *merkletree.MerkleTree, // this in TypeSynchronizer should never be reached log.Error("WARNING: In StateDB with Synchronizer mode L2.ToIdx can't be 0") return nil, nil, false, - common.Wrap(fmt.Errorf("In StateDB with Synchronizer mode L2.ToIdx can't be 0")) + common.Wrap(fmt.Errorf("in StateDB with Synchronizer mode L2.ToIdx can't be 0")) } // case when tx.Type == common.TxTypeTransferToEthAddr or // common.TxTypeTransferToBJJ: @@ -763,7 +764,7 @@ func (txProcessor *TxProcessor) ProcessL2Tx(exitTree *merkletree.MerkleTree, } switch tx.Type { - case common.TxTypeTransfer, common.TxTypeTransferToEthAddr, common.TxTypeTransferToBJJ: + case common.TxTypeCreateVouch, common.TxTypeDeleteVouch: // go to the MT account of sender and receiver, and update // balance & nonce err = txProcessor.applyTransfer(nil, nil, tx.Tx(), tx.AuxToIdx) @@ -790,7 +791,7 @@ func (txProcessor *TxProcessor) ProcessL2Tx(exitTree *merkletree.MerkleTree, func (txProcessor *TxProcessor) applyCreateAccount(tx *common.L1Tx) error { account := &common.Account{ Nonce: 0, - Balance: tx.Amount, + Balance: tx.EffectiveDepositAmount, BJJ: tx.FromBJJ, EthAddr: tx.FromEthAddr, } @@ -969,15 +970,15 @@ func (txProcessor *TxProcessor) applyTransfer(coordIdxsMap map[common.TokenID]co accSender.Nonce++ // compute fee and subtract it from the accSender - fee, err := common.CalcFeeAmount(tx.Amount, *tx.Fee) - if err != nil { - return common.Wrap(err) - } - feeAndAmount := new(big.Int).Add(tx.Amount, fee) - accSender.Balance = new(big.Int).Sub(accSender.Balance, feeAndAmount) - if accSender.Balance.Cmp(big.NewInt(0)) == -1 { // balance<0 - return newErrorNotEnoughBalance(tx) - } + // fee, err := common.CalcFeeAmount(tx.Amount, *tx.Fee) + // if err != nil { + // return common.Wrap(err) + // } + // feeAndAmount := new(big.Int).Add(tx.Amount, fee) + // accSender.Balance = new(big.Int).Sub(accSender.Balance, feeAndAmount) + // if accSender.Balance.Cmp(big.NewInt(0)) == -1 { // balance<0 + // return newErrorNotEnoughBalance(tx) + // } // if _, ok := coordIdxsMap[accSender.TokenID]; ok { // accCoord, err := txProcessor.state.GetAccount(coordIdxsMap[accSender.TokenID]) @@ -1086,16 +1087,16 @@ func (txProcessor *TxProcessor) applyExit(coordIdxsMap map[common.TokenID]common // increment nonce acc.Nonce++ - // compute fee and subtract it from the accSender - fee, err := common.CalcFeeAmount(tx.Amount, *tx.Fee) - if err != nil { - return nil, false, common.Wrap(err) - } - feeAndAmount := new(big.Int).Add(tx.Amount, fee) - acc.Balance = new(big.Int).Sub(acc.Balance, feeAndAmount) - if acc.Balance.Cmp(big.NewInt(0)) == -1 { // balance<0 - return nil, false, newErrorNotEnoughBalance(tx) - } + // // compute fee and subtract it from the accSender + // fee, err := common.CalcFeeAmount(tx.Amount, *tx.Fee) + // if err != nil { + // return nil, false, common.Wrap(err) + // } + // feeAndAmount := new(big.Int).Add(tx.Amount, fee) + // acc.Balance = new(big.Int).Sub(acc.Balance, feeAndAmount) + // if acc.Balance.Cmp(big.NewInt(0)) == -1 { // balance<0 + // return nil, false, newErrorNotEnoughBalance(tx) + // } // if _, ok := coordIdxsMap[acc.TokenID]; ok { // accCoord, err := txProcessor.state.GetAccount(coordIdxsMap[acc.TokenID]) @@ -1242,3 +1243,50 @@ func (txProcessor *TxProcessor) applyExit(coordIdxsMap map[common.TokenID]common return exitAccount, false, nil } + +// computeEffectiveAmounts checks that the L1Tx data is correct +func (txProcessor *TxProcessor) computeEffectiveAmounts(tx *common.L1Tx) { + tx.EffectiveAmount = tx.Amount + tx.EffectiveDepositAmount = tx.DepositAmount + + if tx.Type == common.TxTypeCreateAccountDeposit { + return + } + + accSender, err := txProcessor.state.GetAccount(tx.FromIdx) + if err != nil { + log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: can not get account for tx.FromIdx: %d", + tx.FromIdx) + tx.EffectiveDepositAmount = big.NewInt(0) + tx.EffectiveAmount = big.NewInt(0) + return + } + + // check that Sender has enough balance + bal := accSender.Balance + if tx.DepositAmount != nil { + bal = new(big.Int).Add(bal, tx.EffectiveDepositAmount) + } + cmp := bal.Cmp(tx.Amount) + if cmp == -1 { + log.Debugf("EffectiveAmount = 0: Not enough funds (%s<%s)", bal.String(), tx.Amount.String()) + tx.EffectiveAmount = big.NewInt(0) + return + } + + // check that the tx.FromEthAddr is the same than the EthAddress of the + // Sender + if !bytes.Equal(tx.FromEthAddr.Bytes(), accSender.EthAddr.Bytes()) { + log.Debugf("EffectiveAmount = 0: tx.FromEthAddr (%s) must be the same EthAddr of "+ + "the sender account by the Idx (%s)", + tx.FromEthAddr.Hex(), accSender.EthAddr.Hex()) + tx.EffectiveAmount = big.NewInt(0) + return + } + + if tx.ToIdx == common.AccountIdx(1) || tx.ToIdx == common.AccountIdx(0) { + // if transfer is Exit type, there are no more checks + return + } + +}