diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 400bb05a..37ae0e15 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,6 +29,6 @@ jobs: uses: goreleaser/goreleaser-action@v2 with: version: latest - args: release --rm-dist + args: release --clean env: GITHUB_TOKEN: ${{ secrets.TOKEN_RELEASE }} \ No newline at end of file diff --git a/claimtxman/claimtxman.go b/claimtxman/claimtxman.go index 57db1cbd..8e60358f 100644 --- a/claimtxman/claimtxman.go +++ b/claimtxman/claimtxman.go @@ -101,6 +101,7 @@ func (tm *ClaimTxManager) updateDepositsStatus(ger *etherman.GlobalExitRoot) err } if ger.BlockID != 0 { // L2 exit root is updated log.Infof("Rollup exitroot %v is updated", ger.ExitRoots[1]) + // TODO Include networkID as input in UpdateL2DepositsStatus to handle multiple networkIDs in the query if err := tm.storage.UpdateL2DepositsStatus(tm.ctx, ger.ExitRoots[1][:], dbTx); err != nil { return err } @@ -300,7 +301,7 @@ func (tm *ClaimTxManager) monitorTxs(ctx context.Context) error { // tx infinitely if allHistoryTxMined && len(mTx.History) >= maxHistorySize { mTx.Status = ctmtypes.MonitoredTxStatusFailed - mTxLog.Infof("marked as failed because reached the history size limit") + mTxLog.Infof("marked as failed because reached the history size limit (%d)", maxHistorySize) // update monitored tx changes into storage err = tm.storage.UpdateClaimTx(ctx, mTx, dbTx) if err != nil { @@ -325,6 +326,14 @@ func (tm *ClaimTxManager) monitorTxs(ctx context.Context) error { } } + // GasPrice is set here to use always the proper and most accurate value right before sending it to L2 + gasPrice, err := tm.l2Node.SuggestGasPrice(ctx) + if err != nil { + mTxLog.Errorf("failed to get suggested gasPrice. Error: %v", err) + continue + } + mTx.GasPrice = gasPrice + var signedTx *types.Transaction // rebuild transaction tx := mTx.Tx() @@ -353,7 +362,7 @@ func (tm *ClaimTxManager) monitorTxs(ctx context.Context) error { err := tm.l2Node.SendTransaction(ctx, signedTx) if err != nil { if strings.Contains(err.Error(), "nonce") { - mTxLog.Infof("nonce error detected, resetting nonce cache") + mTxLog.Infof("nonce error detected, resetting nonce cache. Nonce used: %d", signedTx.Nonce()) tm.nonceCache.Remove(mTx.From.Hex()) } mTx.RemoveHistory(signedTx) diff --git a/claimtxman/types/monitoredtx.go b/claimtxman/types/monitoredtx.go index 7a095f09..d648c3da 100644 --- a/claimtxman/types/monitoredtx.go +++ b/claimtxman/types/monitoredtx.go @@ -60,6 +60,9 @@ type MonitoredTx struct { // Gas is a tx gas Gas uint64 + // GasPrice is the tx gas price + GasPrice *big.Int + // Status of this monitoring Status MonitoredTxStatus @@ -83,11 +86,12 @@ type MonitoredTx struct { // Tx uses the current information to build a tx func (mTx MonitoredTx) Tx() *types.Transaction { tx := types.NewTx(&types.LegacyTx{ - To: mTx.To, - Nonce: mTx.Nonce, - Value: mTx.Value, - Data: mTx.Data, - Gas: mTx.Gas, + To: mTx.To, + Nonce: mTx.Nonce, + Value: mTx.Value, + Data: mTx.Data, + Gas: mTx.Gas, + GasPrice: mTx.GasPrice, }) return tx diff --git a/db/pgstorage/migrations/0003.sql b/db/pgstorage/migrations/0003.sql index c8fca251..cbb88fa3 100644 --- a/db/pgstorage/migrations/0003.sql +++ b/db/pgstorage/migrations/0003.sql @@ -37,6 +37,8 @@ $$ LANGUAGE plpgsql; UPDATE mt.root SET deposit_cnt = deposit_cnt + 1; +DROP INDEX IF EXISTS mt.rht_key_idx; + -- +migrate Up ALTER TABLE mt.rht DROP COLUMN IF EXISTS root_id; @@ -54,10 +56,13 @@ ALTER TABLE mt.rht ALTER COLUMN deposit_id DROP DEFAULT; UPDATE mt.root SET deposit_cnt = deposit_cnt - 1; -DELETE FROM mt.rht a -WHERE a.ctid <> (SELECT min(b.ctid) - FROM mt.rht b - WHERE a.key = b.key); +-- Create indexes +CREATE INDEX IF NOT EXISTS rht_key_idx ON mt.rht(key); + +-- Delete duplicates +CREATE TABLE mt.rht_temp AS (SELECT key, min(value), max(deposit_id) FROM mt.rht GROUP BY key HAVING count(key) > 1); +DELETE FROM mt.rht where key in (select key FROM mt.rht_temp); +INSERT INTO mt.rht(key, value, deposit_id) (SELECT b.key, b.min, b.max FROM mt.rht_temp b); -- +migrate StatementBegin DO $$ diff --git a/db/pgstorage/migrations/0003_test.go b/db/pgstorage/migrations/0003_test.go index 2a2a944d..37d86bea 100644 --- a/db/pgstorage/migrations/0003_test.go +++ b/db/pgstorage/migrations/0003_test.go @@ -84,6 +84,18 @@ func (m migrationTest0003) RunAssertsAfterMigrationUp(t *testing.T, db *sql.DB) assert.NoError(t, err) assert.Equal(t, maxDepositCnt, 1) assert.Equal(t, rootCount, 2) + + indexes := []string{"rht_key_idx"} + + // Check indexes adding + for _, idx := range indexes { + // getIndex + const getIndex = `SELECT count(*) FROM pg_indexes WHERE indexname = $1;` + row := db.QueryRow(getIndex, idx) + var result int + assert.NoError(t, row.Scan(&result)) + assert.Equal(t, 1, result) + } } func (m migrationTest0003) RunAssertsAfterMigrationDown(t *testing.T, db *sql.DB) { @@ -94,6 +106,17 @@ func (m migrationTest0003) RunAssertsAfterMigrationDown(t *testing.T, db *sql.DB assert.NoError(t, err) assert.Equal(t, maxDepositCnt, 2) assert.Equal(t, rootCount, 2) + + indexes := []string{"rht_key_idx"} + // Check indexes removing + for _, idx := range indexes { + // getIndex + const getIndex = `SELECT count(*) FROM pg_indexes WHERE indexname = $1;` + row := db.QueryRow(getIndex, idx) + var result int + assert.NoError(t, row.Scan(&result)) + assert.Equal(t, 0, result) + } } func TestMigration0003(t *testing.T) { diff --git a/db/pgstorage/migrations/0004.sql b/db/pgstorage/migrations/0004.sql index 73369c16..d8ee304c 100644 --- a/db/pgstorage/migrations/0004.sql +++ b/db/pgstorage/migrations/0004.sql @@ -6,8 +6,6 @@ ALTER TABLE sync.deposit DROP COLUMN ready_for_claim; ALTER TABLE sync.block DROP CONSTRAINT block_hash_unique; -DROP INDEX IF EXISTS mt.rht_key_idx; - -- +migrate Up ALTER TABLE @@ -88,6 +86,3 @@ WHERE AND network = 1 ) AND network_id != 0; - --- Create indexes -CREATE INDEX IF NOT EXISTS rht_key_idx ON mt.rht(key); \ No newline at end of file diff --git a/db/pgstorage/migrations/0004_test.go b/db/pgstorage/migrations/0004_test.go index 613ce24e..647defe5 100644 --- a/db/pgstorage/migrations/0004_test.go +++ b/db/pgstorage/migrations/0004_test.go @@ -44,10 +44,6 @@ func (m migrationTest0004) RunAssertsAfterMigrationUp(t *testing.T, db *sql.DB) common.FromHex("0xa4bfa0908dc7b06d98da4309f859023d6947561bc19bc00d77f763dea1a0b9f5"), []byte{}).Scan(&depositID) assert.NoError(t, err) - // Insert a new root - const addRoot = "INSERT INTO mt.root (root, deposit_cnt, network, deposit_id) VALUES ($1, $2, $3, $4)" - _, err = db.Exec(addRoot, common.FromHex("0x5a2dce0a8a7f68bb74560f8f71837c2c2ebbcbf7fffb42ae1896f13f7c7479a0"), 1, 0, depositID) - assert.NoError(t, err) // Insert a new node to the rht table const addNode = "INSERT INTO mt.rht (key, value, deposit_id) VALUES ($1, $2, $3)" _, err = db.Exec(addNode, common.FromHex("0x5a2dce0a8a7f68bb74560f8f71837c2c2ebbcbf7fffb42ae1896f13f7c7479a0"), [][]byte{ @@ -85,31 +81,14 @@ func (m migrationTest0004) RunAssertsAfterMigrationUp(t *testing.T, db *sql.DB) common.FromHex("0xad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5"), 0, time.Now()).Scan(&blockID) assert.NoError(t, err) assert.Equal(t, blockID, uint64(1)) - - indexes := []string{"rht_key_idx"} - - // Check indexes adding - for _, idx := range indexes { - // getIndex - const getIndex = `SELECT count(*) FROM pg_indexes WHERE indexname = $1;` - row := db.QueryRow(getIndex, idx) - var result int - assert.NoError(t, row.Scan(&result)) - assert.Equal(t, 1, result) - } } func (m migrationTest0004) RunAssertsAfterMigrationDown(t *testing.T, db *sql.DB) { - indexes := []string{"rht_key_idx"} - // Check indexes removing - for _, idx := range indexes { - // getIndex - const getIndex = `SELECT count(*) FROM pg_indexes WHERE indexname = $1;` - row := db.QueryRow(getIndex, idx) - var result int - assert.NoError(t, row.Scan(&result)) - assert.Equal(t, 0, result) - } + // Insert a monitored tx + _, err := db.Exec(`INSERT INTO sync.monitored_txs + (id, block_id, from_addr, to_addr, nonce, value, data, gas, status, history, created_at, updated_at) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)`, 0, 1, common.FromHex("0x6B175474E89094C44Da98b954EedeAC495271d0F"), common.FromHex("0x6B175474E89094C44Da98b954EedeAC495271d0F"), 1, "10000", []byte{}, 5000000, "crerated", nil, time.Now(), time.Now()) + assert.Error(t, err) } func TestMigration0004(t *testing.T) { diff --git a/synchronizer/mock_storage.go b/synchronizer/mock_storage.go index a0c6695e..70d9dcaf 100644 --- a/synchronizer/mock_storage.go +++ b/synchronizer/mock_storage.go @@ -153,13 +153,16 @@ func (_m *storageMock) AddTrustedGlobalExitRoot(ctx context.Context, trustedExit ret := _m.Called(ctx, trustedExitRoot, dbTx) var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *etherman.GlobalExitRoot, pgx.Tx) (bool, error)); ok { + return rf(ctx, trustedExitRoot, dbTx) + } if rf, ok := ret.Get(0).(func(context.Context, *etherman.GlobalExitRoot, pgx.Tx) bool); ok { r0 = rf(ctx, trustedExitRoot, dbTx) } else { r0 = ret.Get(0).(bool) } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, *etherman.GlobalExitRoot, pgx.Tx) error); ok { r1 = rf(ctx, trustedExitRoot, dbTx) } else { @@ -330,6 +333,10 @@ func (_m *storageMock) GetLatestL1SyncedExitRoot(ctx context.Context, dbTx pgx.T ret := _m.Called(ctx, dbTx) var r0 *etherman.GlobalExitRoot + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, pgx.Tx) (*etherman.GlobalExitRoot, error)); ok { + return rf(ctx, dbTx) + } if rf, ok := ret.Get(0).(func(context.Context, pgx.Tx) *etherman.GlobalExitRoot); ok { r0 = rf(ctx, dbTx) } else { @@ -338,7 +345,6 @@ func (_m *storageMock) GetLatestL1SyncedExitRoot(ctx context.Context, dbTx pgx.T } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, pgx.Tx) error); ok { r1 = rf(ctx, dbTx) } else { diff --git a/synchronizer/synchronizer.go b/synchronizer/synchronizer.go index c969be4d..15237e71 100644 --- a/synchronizer/synchronizer.go +++ b/synchronizer/synchronizer.go @@ -95,11 +95,7 @@ func (s *ClientSynchronizer) Sync() error { // If there is no lastEthereumBlock means that sync from the beginning is necessary. If not, it continues from the retrieved ethereum block // Get the latest synced block. If there is no block on db, use genesis block log.Infof("NetworkID: %d, Synchronization started", s.networkID) - dbTx, err := s.storage.BeginDBTransaction(s.ctx) - if err != nil { - log.Fatalf("networkID: %d, error creating db transaction to get latest block", s.networkID) - } - lastBlockSynced, err := s.storage.GetLastBlock(s.ctx, s.networkID, dbTx) + lastBlockSynced, err := s.storage.GetLastBlock(s.ctx, s.networkID, nil) if err != nil { if err == gerror.ErrStorageNotFound { log.Warnf("networkID: %d, error getting the latest ethereum block. No data stored. Setting genesis block. Error: %w", s.networkID, err) @@ -113,16 +109,7 @@ func (s *ClientSynchronizer) Sync() error { log.Fatalf("networkID: %d, unexpected error getting the latest block. Error: %s", s.networkID, err.Error()) } } - err = s.storage.Commit(s.ctx, dbTx) - if err != nil { - log.Errorf("networkID: %d, error committing dbTx, err: %s", s.networkID, err.Error()) - rollbackErr := s.storage.Rollback(s.ctx, dbTx) - if rollbackErr != nil { - log.Fatalf("networkID: %d, error rolling back state. RollbackErr: %s, err: %s", - s.networkID, rollbackErr.Error(), err.Error()) - } - log.Fatalf("networkID: %d, error committing dbTx, err: %s", s.networkID, err.Error()) - } + log.Debugf("NetworkID: %d, initial lastBlockSynced: %+v", s.networkID, lastBlockSynced) for { select { case <-s.ctx.Done(): @@ -132,7 +119,7 @@ func (s *ClientSynchronizer) Sync() error { //Sync L1Blocks if lastBlockSynced, err = s.syncBlocks(lastBlockSynced); err != nil { log.Warn("error syncing blocks: ", err) - lastBlockSynced, err = s.storage.GetLastBlock(s.ctx, s.networkID, dbTx) + lastBlockSynced, err = s.storage.GetLastBlock(s.ctx, s.networkID, nil) if err != nil { log.Fatal("error getting lastBlockSynced to resume the synchronization... Error: ", err) } @@ -310,7 +297,7 @@ func (s *ClientSynchronizer) processBlockRange(blocks []etherman.Block, order ma } // Add block information blocks[i].NetworkID = s.networkID - log.Infof("NetworkID: %d. Syncing block: %d", s.networkID, &blocks[i].BlockNumber) + log.Infof("NetworkID: %d. Syncing block: %d", s.networkID, blocks[i].BlockNumber) blockID, err := s.storage.AddBlock(s.ctx, &blocks[i], dbTx) if err != nil { log.Errorf("networkID: %d, error storing block. BlockNumber: %d, error: %v", s.networkID, blocks[i].BlockNumber, err) @@ -524,7 +511,7 @@ func (s *ClientSynchronizer) checkTrustedState(batch etherman.Batch, dbTx pgx.Tx batch.Coinbase == tBatch.Coinbase { return false, nil } - log.Errorf("networkID: %d, TRUSTED REORG DETECTED! Batch: ", s.networkID, batch.BatchNumber) + log.Errorf("networkID: %d, TRUSTED REORG DETECTED! Batch: %d", s.networkID, batch.BatchNumber) log.Warnf("networkID: %d, BatchL2Data. Virtual: %s, Trusted: %s", s.networkID, hex.EncodeToString(batch.BatchL2Data), hex.EncodeToString(tBatch.BatchL2Data)) log.Warnf("networkID: %d, GlobalExitRoot. Virtual: %s, Trusted: %s", s.networkID, batch.GlobalExitRoot.String(), tBatch.GlobalExitRoot.String()) log.Warnf("networkID: %d, Timestamp. Virtual: %d, Trusted: %d", s.networkID, batch.Timestamp.Unix(), tBatch.Timestamp.Unix()) diff --git a/synchronizer/synchronizer_test.go b/synchronizer/synchronizer_test.go index 39ae6a65..cd2e06fa 100644 --- a/synchronizer/synchronizer_test.go +++ b/synchronizer/synchronizer_test.go @@ -28,7 +28,7 @@ type mocks struct { func TestTrustedStateReorg(t *testing.T) { type testCase struct { Name string - getTrustedBatch func(*mocks, context.Context, etherman.SequencedBatch) *etherman.Batch + getTrustedBatch func(*mocks, etherman.SequencedBatch) *etherman.Batch } setupMocks := func(m *mocks, tc *testCase) Synchronizer { @@ -37,163 +37,147 @@ func TestTrustedStateReorg(t *testing.T) { SyncInterval: cfgTypes.Duration{Duration: 1 * time.Second}, SyncChunkSize: 10, } - ctxMatchBy := mock.MatchedBy(func(ctx context.Context) bool { return ctx != nil }) - m.Etherman.On("GetNetworkID", ctxMatchBy).Return(uint(0), nil) + ctx := mock.MatchedBy(func(ctx context.Context) bool { return ctx != nil }) + m.Etherman.On("GetNetworkID", ctx).Return(uint(0), nil) m.Storage.On("GetLatestL1SyncedExitRoot", context.Background(), nil).Return(ðerman.GlobalExitRoot{}, gerror.ErrStorageNotFound) chEvent := make(chan *etherman.GlobalExitRoot) sync, err := NewSynchronizer(m.Storage, m.BridgeCtrl, m.Etherman, m.ZkEVMClient, genBlockNumber, chEvent, cfg) require.NoError(t, err) - // state preparation - m.Storage. - On("BeginDBTransaction", ctxMatchBy). - Run(func(args mock.Arguments) { - ctx := args[0].(context.Context) - parentHash := common.HexToHash("0x111") - ethHeader := &types.Header{Number: big.NewInt(1), ParentHash: parentHash} - ethBlock := types.NewBlockWithHeader(ethHeader) - lastBlock := ðerman.Block{BlockHash: ethBlock.Hash(), BlockNumber: ethBlock.Number().Uint64()} - var networkID uint = 0 - - m.Storage. - On("GetLastBlock", ctx, networkID, m.DbTx). - Return(lastBlock, nil). - Once() - m.Storage. - On("Commit", ctx, m.DbTx). - Return(nil). - Once() + parentHash := common.HexToHash("0x111") + ethHeader := &types.Header{Number: big.NewInt(1), ParentHash: parentHash} + ethBlock := types.NewBlockWithHeader(ethHeader) + lastBlock := ðerman.Block{BlockHash: ethBlock.Hash(), BlockNumber: ethBlock.Number().Uint64()} + var networkID uint = 0 - m.Etherman. - On("EthBlockByNumber", ctx, lastBlock.BlockNumber). - Return(ethBlock, nil). - Once() + m.Storage. + On("GetLastBlock", ctx, networkID, nil). + Return(lastBlock, nil). + Once() - var n *big.Int - m.Etherman. - On("HeaderByNumber", ctx, n). - Return(ethHeader, nil). - Once() + m.Etherman. + On("EthBlockByNumber", ctx, lastBlock.BlockNumber). + Return(ethBlock, nil). + Once() - sequencedBatch := etherman.SequencedBatch{ - BatchNumber: uint64(1), - Sequencer: common.HexToAddress("0x222"), - TxHash: common.HexToHash("0x333"), - PolygonZkEVMBatchData: polygonzkevm.PolygonZkEVMBatchData{ - Transactions: []byte{}, - GlobalExitRoot: [32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}, - Timestamp: uint64(time.Now().Unix()), - MinForcedTimestamp: 0, - }, - } + var n *big.Int + m.Etherman. + On("HeaderByNumber", ctx, n). + Return(ethHeader, nil). + Once() - ethermanBlock := etherman.Block{ - BlockHash: ethBlock.Hash(), - SequencedBatches: [][]etherman.SequencedBatch{{sequencedBatch}}, - NetworkID: 0, - } - blocks := []etherman.Block{ethermanBlock} - order := map[common.Hash][]etherman.Order{ - ethBlock.Hash(): { - { - Name: etherman.SequenceBatchesOrder, - Pos: 0, - }, - }, - } + sequencedBatch := etherman.SequencedBatch{ + BatchNumber: uint64(1), + Sequencer: common.HexToAddress("0x222"), + TxHash: common.HexToHash("0x333"), + PolygonZkEVMBatchData: polygonzkevm.PolygonZkEVMBatchData{ + Transactions: []byte{}, + GlobalExitRoot: [32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}, + Timestamp: uint64(time.Now().Unix()), + MinForcedTimestamp: 0, + }, + } - fromBlock := ethBlock.NumberU64() + 1 - toBlock := fromBlock + cfg.SyncChunkSize + ethermanBlock := etherman.Block{ + BlockHash: ethBlock.Hash(), + SequencedBatches: [][]etherman.SequencedBatch{{sequencedBatch}}, + NetworkID: 0, + } + blocks := []etherman.Block{ethermanBlock} + order := map[common.Hash][]etherman.Order{ + ethBlock.Hash(): { + { + Name: etherman.SequenceBatchesOrder, + Pos: 0, + }, + }, + } - m.Etherman. - On("GetRollupInfoByBlockRange", ctx, fromBlock, &toBlock). - Return(blocks, order, nil). - Once() + fromBlock := ethBlock.NumberU64() + 1 + toBlock := fromBlock + cfg.SyncChunkSize - m.Storage. - On("BeginDBTransaction", ctx). - Return(m.DbTx, nil). - Once() + m.Etherman. + On("GetRollupInfoByBlockRange", ctx, fromBlock, &toBlock). + Return(blocks, order, nil). + Once() - block := ðerman.Block{ - ID: 0, - BlockNumber: ethermanBlock.BlockNumber, - BlockHash: ethermanBlock.BlockHash, - ParentHash: ethermanBlock.ParentHash, - NetworkID: 0, - ReceivedAt: ethermanBlock.ReceivedAt, - SequencedBatches: ethermanBlock.SequencedBatches, - } + m.Storage. + On("BeginDBTransaction", ctx). + Return(m.DbTx, nil). + Once() - m.Storage. - On("AddBlock", ctx, block, m.DbTx). - Return(uint64(1), nil). - Once() + block := ðerman.Block{ + ID: 0, + BlockNumber: ethermanBlock.BlockNumber, + BlockHash: ethermanBlock.BlockHash, + ParentHash: ethermanBlock.ParentHash, + NetworkID: 0, + ReceivedAt: ethermanBlock.ReceivedAt, + SequencedBatches: ethermanBlock.SequencedBatches, + } - trustedBatch := tc.getTrustedBatch(m, ctx, sequencedBatch) + m.Storage. + On("AddBlock", ctx, block, m.DbTx). + Return(uint64(1), nil). + Once() - m.Storage. - On("GetBatchByNumber", ctx, sequencedBatch.BatchNumber, m.DbTx). - Return(trustedBatch, nil). - Once() + trustedBatch := tc.getTrustedBatch(m, sequencedBatch) - m.Storage. - On("ResetTrustedState", ctx, sequencedBatch.BatchNumber-1, m.DbTx). - Return(nil). - Once() + m.Storage. + On("GetBatchByNumber", ctx, sequencedBatch.BatchNumber, m.DbTx). + Return(trustedBatch, nil). + Once() - b := ðerman.Batch{ - BatchNumber: sequencedBatch.BatchNumber, - Coinbase: sequencedBatch.Sequencer, - BatchL2Data: sequencedBatch.Transactions, - Timestamp: time.Unix(int64(sequencedBatch.Timestamp), 0), - GlobalExitRoot: sequencedBatch.GlobalExitRoot, - } + m.Storage. + On("ResetTrustedState", ctx, sequencedBatch.BatchNumber-1, m.DbTx). + Return(nil). + Once() - m.Storage. - On("AddBatch", ctx, b, m.DbTx). - Return(nil). - Once() + b := ðerman.Batch{ + BatchNumber: sequencedBatch.BatchNumber, + Coinbase: sequencedBatch.Sequencer, + BatchL2Data: sequencedBatch.Transactions, + Timestamp: time.Unix(int64(sequencedBatch.Timestamp), 0), + GlobalExitRoot: sequencedBatch.GlobalExitRoot, + } - m.Etherman. - On("EthBlockByNumber", ctx, uint64(1)). - Return(ethBlock, nil) + m.Storage. + On("AddBatch", ctx, b, m.DbTx). + Return(nil). + Once() - m.Storage. - On("Commit", ctx, m.DbTx). - Run(func(args mock.Arguments) { sync.Stop() }). - Return(nil). - Once() + m.Storage. + On("Commit", ctx, m.DbTx). + Run(func(args mock.Arguments) { sync.Stop() }). + Return(nil). + Once() - rpcResponse := &rpcTypes.Batch{ - GlobalExitRoot: common.HexToHash("0xb14c74e4dddf25627a745f46cae6ac98782e2783c3ccc28107c8210e60d58861"), - MainnetExitRoot: common.HexToHash("0xc14c74e4dddf25627a745f46cae6ac98782e2783c3ccc28107c8210e60d58862"), - RollupExitRoot: common.HexToHash("0xd14c74e4dddf25627a745f46cae6ac98782e2783c3ccc28107c8210e60d58863"), - } - m.ZkEVMClient. - On("BatchNumber", ctx). - Return(uint64(1), nil). - Once() + rpcResponse := &rpcTypes.Batch{ + GlobalExitRoot: common.HexToHash("0xb14c74e4dddf25627a745f46cae6ac98782e2783c3ccc28107c8210e60d58861"), + MainnetExitRoot: common.HexToHash("0xc14c74e4dddf25627a745f46cae6ac98782e2783c3ccc28107c8210e60d58862"), + RollupExitRoot: common.HexToHash("0xd14c74e4dddf25627a745f46cae6ac98782e2783c3ccc28107c8210e60d58863"), + } + m.ZkEVMClient. + On("BatchNumber", ctx). + Return(uint64(1), nil). + Once() - m.ZkEVMClient. - On("BatchByNumber", ctx, big.NewInt(1)). - Return(rpcResponse, nil). - Once() + m.ZkEVMClient. + On("BatchByNumber", ctx, big.NewInt(1)). + Return(rpcResponse, nil). + Once() - ger := ðerman.GlobalExitRoot{ - GlobalExitRoot: rpcResponse.GlobalExitRoot, - ExitRoots: []common.Hash{ - rpcResponse.MainnetExitRoot, - rpcResponse.RollupExitRoot, - }, - } + ger := ðerman.GlobalExitRoot{ + GlobalExitRoot: rpcResponse.GlobalExitRoot, + ExitRoots: []common.Hash{ + rpcResponse.MainnetExitRoot, + rpcResponse.RollupExitRoot, + }, + } - m.Storage. - On("AddTrustedGlobalExitRoot", ctx, ger, nil). - Return(false, nil). - Once() - }). - Return(m.DbTx, nil). + m.Storage. + On("AddTrustedGlobalExitRoot", ctx, ger, nil). + Return(false, nil). Once() return sync @@ -202,7 +186,7 @@ func TestTrustedStateReorg(t *testing.T) { testCases := []testCase{ { Name: "Transactions are different", - getTrustedBatch: func(m *mocks, ctx context.Context, sequencedBatch etherman.SequencedBatch) *etherman.Batch { + getTrustedBatch: func(m *mocks, sequencedBatch etherman.SequencedBatch) *etherman.Batch { return ðerman.Batch{ BatchL2Data: []byte{1}, GlobalExitRoot: sequencedBatch.GlobalExitRoot, @@ -213,7 +197,7 @@ func TestTrustedStateReorg(t *testing.T) { }, { Name: "Global Exit Root is different", - getTrustedBatch: func(m *mocks, ctx context.Context, sequencedBatch etherman.SequencedBatch) *etherman.Batch { + getTrustedBatch: func(m *mocks, sequencedBatch etherman.SequencedBatch) *etherman.Batch { return ðerman.Batch{ BatchL2Data: sequencedBatch.Transactions, GlobalExitRoot: common.HexToHash("0x999888777"), @@ -224,7 +208,7 @@ func TestTrustedStateReorg(t *testing.T) { }, { Name: "Timestamp is different", - getTrustedBatch: func(m *mocks, ctx context.Context, sequencedBatch etherman.SequencedBatch) *etherman.Batch { + getTrustedBatch: func(m *mocks, sequencedBatch etherman.SequencedBatch) *etherman.Batch { return ðerman.Batch{ BatchL2Data: sequencedBatch.Transactions, GlobalExitRoot: sequencedBatch.GlobalExitRoot, @@ -235,7 +219,7 @@ func TestTrustedStateReorg(t *testing.T) { }, { Name: "Coinbase is different", - getTrustedBatch: func(m *mocks, ctx context.Context, sequencedBatch etherman.SequencedBatch) *etherman.Batch { + getTrustedBatch: func(m *mocks, sequencedBatch etherman.SequencedBatch) *etherman.Batch { return ðerman.Batch{ BatchL2Data: sequencedBatch.Transactions, GlobalExitRoot: sequencedBatch.GlobalExitRoot, diff --git a/test/operations/manager.go b/test/operations/manager.go index 48aacf5c..b5bd59b6 100644 --- a/test/operations/manager.go +++ b/test/operations/manager.go @@ -559,10 +559,6 @@ func (m *Manager) SendL2Claim(ctx context.Context, deposit *pb.Deposit, smtProof return err } - if deposit.LeafType == utils.LeafTypeAsset { - auth.GasPrice = big.NewInt(0) - } - err = client.SendClaim(ctx, deposit, smtProof, globalExitRoot, auth) return err } @@ -656,9 +652,6 @@ func (m *Manager) ApproveERC20(ctx context.Context, erc20Addr, bridgeAddr common if err != nil { return err } - if network == L2 { - auth.GasPrice = big.NewInt(0) - } return client.ApproveERC20(ctx, erc20Addr, bridgeAddr, amount, auth) } diff --git a/test/scripts/claim/main.go b/test/scripts/claim/main.go index 705d82a2..40d96fd8 100644 --- a/test/scripts/claim/main.go +++ b/test/scripts/claim/main.go @@ -2,7 +2,6 @@ package main import ( "context" - "math/big" "github.com/0xPolygonHermez/zkevm-bridge-service/etherman" clientUtils "github.com/0xPolygonHermez/zkevm-bridge-service/test/client" @@ -32,7 +31,6 @@ func main() { if err != nil { log.Fatal("Error: ", err) } - auth.GasPrice = big.NewInt(0) // Get Claim data cfg := clientUtils.Config{ diff --git a/test/test.keystore.claimtx b/test/test.keystore.claimtx index 3bdc0de5..96b662b7 100644 --- a/test/test.keystore.claimtx +++ b/test/test.keystore.claimtx @@ -1 +1 @@ -{"address":"0d36c07e49a80f2c84f09ed89dc9e002a29e2a2f","crypto":{"cipher":"aes-128-ctr","ciphertext":"8b1607f33974bb3a11d1e5bcd36c8b18a329b8a8990800d8c626bb449c8605e5","cipherparams":{"iv":"ec2268b7e4cb77f54525ac688c36c8db"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"a78dd695e7c4172b040c9cf71acb0e642ad162915421c92e2deb212f0cbae713"},"mac":"7105e4b4b968665a8fa37eaaf55fba2703ba2e9139cfc926a5fff3cfc2964290"},"id":"2c258b37-c94e-4b6d-9450-ccdaf76fcfad","version":3} \ No newline at end of file +{"address":"f39fd6e51aad88f6f4ce6ab8827279cfffb92266","crypto":{"cipher":"aes-128-ctr","ciphertext":"d005030a7684f3adad2447cbb27f63039eec2224c451eaa445de0d90502b9f3d","cipherparams":{"iv":"dc07a54bc7e388efa89c34d42f2ebdb4"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"cf2ec55ecae11171de575112cfb16963570533a9c46fb774473ceb11519eb24a"},"mac":"3eb180d405a5da6e462b2adc00091c14856c91d574bf27348714506357d6e177"},"id":"035454db-6b6d-477f-8a79-ce24c10b185f","version":3} \ No newline at end of file diff --git a/test/vectors/src/e2e-test.json b/test/vectors/src/e2e-test.json index adb1ddd4..258bf032 100644 --- a/test/vectors/src/e2e-test.json +++ b/test/vectors/src/e2e-test.json @@ -132,7 +132,7 @@ "0x0000000000000000000000000000000000000000000000000000000000000000" ], "gasLimit": 2000000, - "gasPrice": "0", + "gasPrice": "1", "data": "0x122650ff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008ac7230489e8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000c949254d682d8c9ad5682521675b8f43b102aec4000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001843cb84814162b93794ad9087a037a1948f9aff051838ba3a93db0ac92b9f719000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000ad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5b4c11951957c6f8f642c4af61cd6b24640fec6dc7fc607ee8206a99e92410d3021ddb9a356815c3fac1026b6dec5df3124afbadb485c9ba5a3e3398a04b7ba85e58769b32a1beaf1ea27375a44095a0d1fb664ce2dd358e7fcbfb78c26a193440eb01ebfc9ed27500cd4dfc979272d1f0913cc9f66540d7e8005811109e1cf2d887c22bd8750d34016ac3c66b5ff102dacdd73f6b014e710b51e8022af9a1968ffd70157e48063fc33c97a050f7f640233bf646cc98d9524c6b92bcf3ab56f839867cc5f7f196b93bae1e27e6320742445d290f2263827498b54fec539f756afcefad4e508c098b9a7e1d8feb19955fb02ba9675585078710969d3440f5054e0f9dc3e7fe016e050eff260334f18a5d4fe391d82092319f5964f2e2eb7c1c3a5f8b13a49e282f609c317a833fb8d976d11517c571d1221a265d25af778ecf8923490c6ceeb450aecdc82e28293031d10c7d73bf85e57bf041a97360aa2c5d99cc1df82d9c4b87413eae2ef048f94b4d3554cea73d92b0f7af96e0271c691e2bb5c67add7c6caf302256adedf7ab114da0acfe870d449a3a489f781d659e8beccda7bce9f4e8618b6bd2f4132ce798cdc7a60e7e1460a7299e3c6342a579626d22733e50f526ec2fa19a22b31e8ed50f23cd1fdf94c9154ed3a7609a2f1ff981fe1d3b5c807b281e4683cc6d6315cf95b9ade8641defcb32372f1c126e398ef7a5a2dce0a8a7f68bb74560f8f71837c2c2ebbcbf7fffb42ae1896f13f7c7479a0b46a28b6f55540f89444f63de0378e3d121be09e06cc9ded1c20e65876d36aa0c65e9645644786b620e2dd2ad648ddfcbf4a7e5b1a3a4ecfe7f64667a3f0b7e2f4418588ed35a2458cffeb39b93d26f18d2ab13bdce6aee58e7b99359ec2dfd95a9c16dc00d6ef18b7933a6f8dc65ccb55667138776f7dea101070dc8796e3774df84f40ae0c8229d0d6069e5c8f39a7c299677a09d367fc7b05e3bc380ee652cdc72595f74c7b1043d0e1ffbab734648c838dfb0527d971b602bc216c9619ef0abf5ac974a1ed57f4050aa510dd9c74f508277b39d7973bb2dfccc5eeb0618db8cd74046ff337f0a7bf2c8e03e10f642c1886798d71806ab1e888d9e5ee87d0838c5655cb21c6cb83313b5a631175dff4963772cce9108188b34ac87c81c41e662ee4dd2dd7b2bc707961b1e646c4047669dcb6584f0d8d770daf5d7e7deb2e388ab20e2573d171a88108e79d820e98f26c0b84aa8b2f4aa4968dbb818ea32293237c50ba75ee485f4c22adf2f741400bdf8d6a9cc7df7ecae576221665d7358448818bb4ae4562849e949e17ac16e0be16688e156b5cf15e098c627c0056a9", "chainId": 1001, "reason": "", @@ -153,7 +153,7 @@ "0xc949254d682d8c9ad5682521675b8f43b102aec4" ], "gasLimit": 2000000, - "gasPrice": "0", + "gasPrice": "1", "data": "0x0e21fbd700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c949254d682d8c9ad5682521675b8f43b102aec4", "chainId": 1001, "reason": "",