From 6489a6bbc541b8278bfc08e8b9049cc6a9110bc3 Mon Sep 17 00:00:00 2001 From: Alonso Rodriguez Date: Thu, 19 Dec 2024 12:40:19 +0100 Subject: [PATCH] Feature/#713 autoclaim l2deposits (#714) * ClaimTxManager claims L2Bridges * e2e wip + fixes * e2e test * gha autoclaiml2l2 e2e * reduce code + linter * order query by id + fix some logs * Update claimcompressor smc to latest version * update test balance due to the new claimcompressor deployment cost --- .github/workflows/test-autoclaiml2l2.yml | 27 ++++ Makefile | 5 + autoclaimservice/autoclaim/autoclaim.go | 2 +- autoclaimservice/blockchainmanager/manager.go | 1 + claimtxman/claimtxman.go | 124 +++++++++++------- claimtxman/config.go | 2 + claimtxman/interfaces.go | 2 + config/config.debug.toml | 1 + config/config.local.toml | 1 + config/default.go | 1 + db/pgstorage/pgstorage.go | 96 +++++++------- docker-compose.yml | 1 + .../smartcontracts/bin/claimcompressor.bin | 2 +- .../claimcompressor/claimcompressor.go | 2 +- synchronizer/synchronizer.go | 10 +- test/e2e/autoclaim_l2_l2_test.go | 84 ++++++++++++ test/e2e/l2_l2_test.go | 2 +- test/scripts/deployclaimcompressor/main.go | 1 + test/scripts/initialClaim/main.go | 7 +- utils/client.go | 7 +- 20 files changed, 270 insertions(+), 108 deletions(-) create mode 100644 .github/workflows/test-autoclaiml2l2.yml create mode 100644 test/e2e/autoclaim_l2_l2_test.go diff --git a/.github/workflows/test-autoclaiml2l2.yml b/.github/workflows/test-autoclaiml2l2.yml new file mode 100644 index 00000000..c19275e6 --- /dev/null +++ b/.github/workflows/test-autoclaiml2l2.yml @@ -0,0 +1,27 @@ +name: Test +on: + push: + branches: + - main + - master + - develop + - update-external-dependencies + pull_request: +jobs: + test-autoclaiml2l2: + strategy: + matrix: + go-version: [ 1.21.x ] + goarch: [ "amd64" ] + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Install Go + uses: actions/setup-go@v1 + with: + go-version: ${{ matrix.go-version }} + env: + GOARCH: ${{ matrix.goarch }} + - name: Test + run: make test-autoclaiml2l2 diff --git a/Makefile b/Makefile index d9eca024..70cbb046 100644 --- a/Makefile +++ b/Makefile @@ -433,6 +433,11 @@ test-l2l2: build-docker stop run-multi-single-bridge ## Runs all tests checking sleep 3 trap '$(STOP)' EXIT; MallocNanoZone=0 go test -v -failfast -race -p 1 -timeout 2400s ./test/e2e/... -count 1 -tags='l2l2' +.PHONY: test-autoclaiml2l2 +test-autoclaiml2l2: build-docker stop run-multi-single-bridge ## Runs all tests checking race conditions + sleep 3 + trap '$(STOP)' EXIT; MallocNanoZone=0 go test -v -failfast -race -p 1 -timeout 2400s ./test/e2e/... -count 1 -tags='autoclaiml2l2' + .PHONY: test-e2ecompress test-e2ecompress: build-docker stop run-multi-single-bridge ## Runs all tests checking race conditions sleep 3 diff --git a/autoclaimservice/autoclaim/autoclaim.go b/autoclaimservice/autoclaim/autoclaim.go index 0b21e72c..7c152a3c 100644 --- a/autoclaimservice/autoclaim/autoclaim.go +++ b/autoclaimservice/autoclaim/autoclaim.go @@ -191,7 +191,7 @@ func (ac *autoclaim) claimGrouped() error { log.Errorf("error compressing claim data, Error: %v", err) return err } - log.Debug("Sending compressed claim tx") + log.Debugf("Sending compressed claim tx with %d claims", len(allClaimData)) tx, err := ac.bm.SendCompressedClaims(compressedTxData) if err != nil { log.Errorf("error sending compressed claims, Error: %v", err) diff --git a/autoclaimservice/blockchainmanager/manager.go b/autoclaimservice/blockchainmanager/manager.go index 3034310a..a27175c5 100644 --- a/autoclaimservice/blockchainmanager/manager.go +++ b/autoclaimservice/blockchainmanager/manager.go @@ -74,6 +74,7 @@ func NewClient(ctx context.Context, cfg *Config) (*Client, error) { return nil, err } logger := log.WithFields("networkID", networkID) + logger.Debug("BlockchainManager client configured") return &Client{ ctx: ctx, diff --git a/claimtxman/claimtxman.go b/claimtxman/claimtxman.go index 4ac2b34f..312be515 100644 --- a/claimtxman/claimtxman.go +++ b/claimtxman/claimtxman.go @@ -2,6 +2,7 @@ package claimtxman import ( "context" + "errors" "fmt" "math/big" "time" @@ -11,6 +12,7 @@ import ( "github.com/0xPolygonHermez/zkevm-bridge-service/etherman" "github.com/0xPolygonHermez/zkevm-bridge-service/log" "github.com/0xPolygonHermez/zkevm-bridge-service/utils" + "github.com/0xPolygonHermez/zkevm-bridge-service/utils/gerror" "github.com/0xPolygonHermez/zkevm-node/state/runtime" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -171,64 +173,96 @@ func (tm *ClaimTxManager) updateDepositsStatus(ger *etherman.GlobalExitRoot) err } func (tm *ClaimTxManager) processDepositStatus(ger *etherman.GlobalExitRoot, dbTx pgx.Tx) error { + var ( + deposits []*etherman.Deposit + globalExitRoot = ger.GlobalExitRoot + err error + ) if ger.BlockID != 0 { // L2 exit root is updated log.Infof("RollupID: %d, Rollup exitroot %v is updated", tm.rollupID, ger.ExitRoots[1]) - if err := tm.storage.UpdateL2DepositsStatus(tm.ctx, ger.ExitRoots[1][:], tm.rollupID, tm.l2NetworkID, dbTx); err != nil { + err = tm.storage.UpdateL2DepositsStatus(tm.ctx, ger.ExitRoots[1][:], tm.rollupID, tm.l2NetworkID, dbTx) + if err != nil { log.Errorf("rollupID: %d, error updating L2DepositsStatus. Error: %v", tm.rollupID, err) return err } + // If L2 claims processor is enabled + if tm.cfg.AreClaimsBetweenL2sEnabled { + log.Debugf("rollupID: %d, getting L2 deposits to autoClaim", tm.rollupID) + deposits, err = tm.storage.GetDepositsFromOtherL2ToClaim(tm.ctx, tm.l2NetworkID, dbTx) + if err != nil { + log.Errorf("rollupID: %d, error getting deposits from other L2 to claim. Error: %v", tm.rollupID, err) + return err + } + if len(deposits) > 0 { + globalExitRoot, err = tm.storage.GetLatestTrustedGERByDeposit(tm.ctx, deposits[0].DepositCount, deposits[0].NetworkID, deposits[0].DestinationNetwork, dbTx) + if errors.Is(err, gerror.ErrStorageNotFound) { + log.Infof("RollupID: %d, not fully synced yet. Retrying in 2s...") + time.Sleep(tm.cfg.RetryInterval.Duration) + globalExitRoot, err = tm.storage.GetLatestTrustedGERByDeposit(tm.ctx, deposits[0].DepositCount, deposits[0].NetworkID, deposits[0].DestinationNetwork, dbTx) + if errors.Is(err, gerror.ErrStorageNotFound) { + log.Infof("RollupID: %d, Still missing. Not fully synced yet. It will retry it later...") + } else if err != nil { + log.Errorf("rollupID: %d, error getting the latest trusted GER by deposit the second time. Error: %v", tm.rollupID, err) + return err + } + } else if err != nil { + log.Errorf("rollupID: %d, error getting the latest trusted GER by deposit. Error: %v", tm.rollupID, err) + return err + } + } + } } else { // L1 exit root is updated in the trusted state log.Infof("RollupID: %d, Mainnet exitroot %v is updated", tm.rollupID, ger.ExitRoots[0]) - deposits, err := tm.storage.UpdateL1DepositsStatus(tm.ctx, ger.ExitRoots[0][:], tm.l2NetworkID, dbTx) + deposits, err = tm.storage.UpdateL1DepositsStatus(tm.ctx, ger.ExitRoots[0][:], tm.l2NetworkID, dbTx) if err != nil { log.Errorf("rollupID: %d, error getting and updating L1DepositsStatus. Error: %v", tm.rollupID, err) return err } - for _, deposit := range deposits { - if tm.l2NetworkID != deposit.DestinationNetwork { - log.Infof("Ignoring deposit id: %d deposit count:%d dest_net: %d, we are:%d", deposit.Id, deposit.DepositCount, deposit.DestinationNetwork, tm.l2NetworkID) - continue - } + } + for _, deposit := range deposits { + if tm.l2NetworkID != deposit.DestinationNetwork { + log.Infof("Ignoring deposit id: %d deposit count:%d dest_net: %d, we are:%d", deposit.Id, deposit.DepositCount, deposit.DestinationNetwork, tm.l2NetworkID) + continue + } - claimHash, err := tm.bridgeService.GetDepositStatus(tm.ctx, deposit.DepositCount, deposit.NetworkID, deposit.DestinationNetwork) - if err != nil { - log.Errorf("rollupID: %d, error getting deposit status for deposit id %d. Error: %v", tm.rollupID, deposit.Id, err) - return err - } - if len(claimHash) > 0 || deposit.LeafType == LeafTypeMessage && !tm.isDepositMessageAllowed(deposit) { - log.Infof("RollupID: %d, Ignoring deposit Id: %d, leafType: %d, claimHash: %s, deposit.OriginalAddress: %s", tm.rollupID, deposit.Id, deposit.LeafType, claimHash, deposit.OriginalAddress.String()) - continue - } + claimHash, err := tm.bridgeService.GetDepositStatus(tm.ctx, deposit.DepositCount, deposit.NetworkID, deposit.DestinationNetwork) + if err != nil { + log.Errorf("rollupID: %d, error getting deposit status for deposit id %d. Error: %v", tm.rollupID, deposit.Id, err) + return err + } + if len(claimHash) > 0 || deposit.LeafType == LeafTypeMessage && !tm.isDepositMessageAllowed(deposit) { + log.Infof("RollupID: %d, Ignoring deposit Id: %d, leafType: %d, claimHash: %s, deposit.OriginalAddress: %s", tm.rollupID, deposit.Id, deposit.LeafType, claimHash, deposit.OriginalAddress.String()) + continue + } - log.Infof("RollupID: %d, create the claim tx for the deposit count %d. Deposit Id: %d", tm.rollupID, deposit.DepositCount, deposit.Id) - ger, proof, rollupProof, err := tm.bridgeService.GetClaimProofForCompressed(ger.GlobalExitRoot, deposit.DepositCount, deposit.NetworkID, dbTx) - if err != nil { - log.Errorf("rollupID: %d, error getting Claim Proof for deposit Id %d. Error: %v", tm.rollupID, deposit.Id, err) - return err - } - var ( - mtProof [mtHeight][keyLen]byte - mtRollupProof [mtHeight][keyLen]byte - ) - for i := 0; i < mtHeight; i++ { - mtProof[i] = proof[i] - mtRollupProof[i] = rollupProof[i] - } - tx, err := tm.l2Node.BuildSendClaim(tm.ctx, deposit, mtProof, mtRollupProof, - ðerman.GlobalExitRoot{ - ExitRoots: []common.Hash{ - ger.ExitRoots[0], - ger.ExitRoots[1], - }}, 1, 1, 1, tm.rollupID, - tm.auth) - if err != nil { - log.Errorf("rollupID: %d, error BuildSendClaim tx for deposit Id: %d. Error: %v", tm.rollupID, deposit.Id, err) - return err - } - if err = tm.addClaimTx(deposit.Id, tm.auth.From, tx.To(), nil, tx.Data(), ger.GlobalExitRoot, dbTx); err != nil { - log.Errorf("rollupID: %d, error adding claim tx for deposit Id: %d Error: %v", tm.rollupID, deposit.Id, err) - return err - } + log.Infof("RollupID: %d, create the claim tx for the deposit count %d. Deposit Id: %d", tm.rollupID, deposit.DepositCount, deposit.Id) + ger, proof, rollupProof, err := tm.bridgeService.GetClaimProofForCompressed(globalExitRoot, deposit.DepositCount, deposit.NetworkID, dbTx) + if err != nil { + log.Errorf("rollupID: %d, error getting Claim Proof for deposit Id %d. Error: %v", tm.rollupID, deposit.Id, err) + return err + } + var ( + mtProof [mtHeight][keyLen]byte + mtRollupProof [mtHeight][keyLen]byte + ) + for i := 0; i < mtHeight; i++ { + mtProof[i] = proof[i] + mtRollupProof[i] = rollupProof[i] + } + tx, err := tm.l2Node.BuildSendClaim(tm.ctx, deposit, mtProof, mtRollupProof, + ðerman.GlobalExitRoot{ + ExitRoots: []common.Hash{ + ger.ExitRoots[0], + ger.ExitRoots[1], + }}, 1, 1, 1, + tm.auth) + if err != nil { + log.Errorf("rollupID: %d, error BuildSendClaim tx for deposit Id: %d. Error: %v", tm.rollupID, deposit.Id, err) + return err + } + if err = tm.addClaimTx(deposit.Id, tm.auth.From, tx.To(), nil, tx.Data(), ger.GlobalExitRoot, dbTx); err != nil { + log.Errorf("rollupID: %d, error adding claim tx for deposit Id: %d Error: %v", tm.rollupID, deposit.Id, err) + return err } } return nil diff --git a/claimtxman/config.go b/claimtxman/config.go index 13f30b16..92781a4e 100644 --- a/claimtxman/config.go +++ b/claimtxman/config.go @@ -20,6 +20,8 @@ type Config struct { RetryNumber int `mapstructure:"RetryNumber"` // AuthorizedClaimMessageAddresses are the allowed address to bridge message with autoClaim AuthorizedClaimMessageAddresses []common.Address `mapstructure:"AuthorizedClaimMessageAddresses"` + // Enables the ability to Claim bridges between L2s automatically + AreClaimsBetweenL2sEnabled bool `mapstructure:"AreClaimsBetweenL2sEnabled"` // GroupingClaims is the configuration for grouping claims GroupingClaims ConfigGroupingClaims `mapstructure:"GroupingClaims"` diff --git a/claimtxman/interfaces.go b/claimtxman/interfaces.go index cb5d5566..ca810dba 100644 --- a/claimtxman/interfaces.go +++ b/claimtxman/interfaces.go @@ -14,6 +14,8 @@ type StorageInterface interface { AddBlock(ctx context.Context, block *etherman.Block, dbTx pgx.Tx) (uint64, error) UpdateL1DepositsStatus(ctx context.Context, exitRoot []byte, destinationNetwork uint32, dbTx pgx.Tx) ([]*etherman.Deposit, error) UpdateL2DepositsStatus(ctx context.Context, exitRoot []byte, rollupID, networkID uint32, dbTx pgx.Tx) error + GetDepositsFromOtherL2ToClaim(ctx context.Context, destinationNetwork uint32, dbTx pgx.Tx) ([]*etherman.Deposit, error) + GetLatestTrustedGERByDeposit(ctx context.Context, depositCnt, networkID, destinationNetwork uint32, dbTx pgx.Tx) (common.Hash, error) AddClaimTx(ctx context.Context, mTx types.MonitoredTx, dbTx pgx.Tx) error UpdateClaimTx(ctx context.Context, mTx types.MonitoredTx, dbTx pgx.Tx) error GetClaimTxsByStatus(ctx context.Context, statuses []types.MonitoredTxStatus, rollupID uint32, dbTx pgx.Tx) ([]types.MonitoredTx, error) diff --git a/config/config.debug.toml b/config/config.debug.toml index acea5610..0ae4b5cf 100644 --- a/config/config.debug.toml +++ b/config/config.debug.toml @@ -18,6 +18,7 @@ PrivateKey = {Path = "../test/test.keystore.claimtx", Password = "testonly"} RetryInterval = "1s" RetryNumber = 10 AuthorizedClaimMessageAddresses = ["0x90F79bf6EB2c4f870365E785982E1f101E93b906"] +AreClaimsBetweenL2sEnabled = false [ClaimTxManager.GroupingClaims] Enabled = false TriggerNumberOfClaims = 20 diff --git a/config/config.local.toml b/config/config.local.toml index 274191c0..f5716d3d 100644 --- a/config/config.local.toml +++ b/config/config.local.toml @@ -18,6 +18,7 @@ PrivateKey = {Path = "/pk/keystore.claimtxmanager", Password = "testonly"} RetryInterval = "1s" RetryNumber = 10 AuthorizedClaimMessageAddresses = ["0x90F79bf6EB2c4f870365E785982E1f101E93b906"] +AreClaimsBetweenL2sEnabled = false [ClaimTxManager.GroupingClaims] Enabled = false TriggerNumberOfClaims = 20 diff --git a/config/default.go b/config/default.go index c4c387f6..9fec5f41 100644 --- a/config/default.go +++ b/config/default.go @@ -29,6 +29,7 @@ PrivateKey = {Path = "./test/test.keystore", Password = "testonly"} RetryInterval = "1s" RetryNumber = 10 AuthorizedClaimMessageAddresses = [] +AreClaimsBetweenL2sEnabled = false [ClaimTxManager.GroupingClaims] Enabled = false FrequencyToProcessCompressedClaims = "10m" diff --git a/db/pgstorage/pgstorage.go b/db/pgstorage/pgstorage.go index ebcee5e3..12efe7e0 100644 --- a/db/pgstorage/pgstorage.go +++ b/db/pgstorage/pgstorage.go @@ -550,22 +550,7 @@ func (p *PostgresStorage) GetDeposits(ctx context.Context, destAddr string, limi return nil, err } - deposits := make([]*etherman.Deposit, 0, len(rows.RawValues())) - - for rows.Next() { - var ( - deposit etherman.Deposit - amount string - ) - err = rows.Scan(&deposit.Id, &deposit.LeafType, &deposit.OriginalNetwork, &deposit.OriginalAddress, &amount, &deposit.DestinationNetwork, &deposit.DestinationAddress, &deposit.DepositCount, &deposit.BlockID, &deposit.BlockNumber, &deposit.NetworkID, &deposit.TxHash, &deposit.Metadata, &deposit.ReadyForClaim) - if err != nil { - return nil, err - } - deposit.Amount, _ = new(big.Int).SetString(amount, 10) //nolint:gomnd - deposits = append(deposits, &deposit) - } - - return deposits, nil + return parseDeposits(rows, true) } // GetDepositCount gets the deposit count for the destination address. @@ -588,32 +573,40 @@ func (p *PostgresStorage) UpdateL1DepositsStatus(ctx context.Context, exitRoot [ return nil, err } - deposits := make([]*etherman.Deposit, 0, len(rows.RawValues())) - for rows.Next() { - var ( - deposit etherman.Deposit - amount string - ) - err = rows.Scan(&deposit.Id, &deposit.LeafType, &deposit.OriginalNetwork, &deposit.OriginalAddress, &amount, &deposit.DestinationNetwork, &deposit.DestinationAddress, &deposit.DepositCount, &deposit.BlockID, &deposit.NetworkID, &deposit.TxHash, &deposit.Metadata, &deposit.ReadyForClaim) - if err != nil { - return nil, err - } - deposit.Amount, _ = new(big.Int).SetString(amount, 10) //nolint:gomnd - deposits = append(deposits, &deposit) - } - return deposits, nil + return parseDeposits(rows, false) } // UpdateL2DepositsStatus updates the ready_for_claim status of L2 deposits. func (p *PostgresStorage) UpdateL2DepositsStatus(ctx context.Context, exitRoot []byte, rollupID, networkID uint32, dbTx pgx.Tx) error { - const updateDepositsStatusSQL = `UPDATE sync.deposit SET ready_for_claim = true + const updateL2DepositsStatusSQL = `UPDATE sync.deposit SET ready_for_claim = true WHERE deposit_cnt <= (SELECT sync.deposit.deposit_cnt FROM mt.root INNER JOIN sync.deposit ON sync.deposit.id = mt.root.deposit_id WHERE mt.root.root = (select leaf from mt.rollup_exit where root = $1 and rollup_id = $2) AND mt.root.network = $3) AND network_id = $3 AND ready_for_claim = false;` - _, err := p.getExecQuerier(dbTx).Exec(ctx, updateDepositsStatusSQL, exitRoot, rollupID, networkID) + _, err := p.getExecQuerier(dbTx).Exec(ctx, updateL2DepositsStatusSQL, exitRoot, rollupID, networkID) return err } +// GetDepositsFromOtherL2ToClaim returns L2 deposits whose destination is an specific L2 +func (p *PostgresStorage) GetDepositsFromOtherL2ToClaim(ctx context.Context, destinationNetwork uint32, dbTx pgx.Tx) ([]*etherman.Deposit, error) { + const getL2DepositsToClaimStatusSQL = `select sync.deposit.id, sync.deposit.leaf_type, sync.deposit.orig_net, sync.deposit.orig_addr, sync.deposit.amount, sync.deposit.dest_net, sync.deposit.dest_addr, sync.deposit.deposit_cnt, sync.deposit.block_id, sync.deposit.network_id, sync.deposit.tx_hash, sync.deposit.metadata, sync.deposit.ready_for_claim FROM sync.deposit where sync.deposit.deposit_cnt not in (select index FROM sync.claim where sync.claim.network_id = $1) and sync.deposit.network_id !=0 and sync.deposit.dest_net = $1 and ready_for_claim =true order by sync.deposit.id desc;` + rows, err := p.getExecQuerier(dbTx).Query(ctx, getL2DepositsToClaimStatusSQL, destinationNetwork) + if err != nil { + return nil, err + } + return parseDeposits(rows, false) +} + +// GetLatestTrustedGERByDeposit return the latest trusted ger for an specific deposit +func (p *PostgresStorage) GetLatestTrustedGERByDeposit(ctx context.Context, depositCnt, networkID, destinationNetwork uint32, dbTx pgx.Tx) (common.Hash, error) { + const getLatestTrustedGERByDeposit = `SELECT sync.exit_root.global_exit_root FROM sync.deposit inner join mt.root on mt.root.deposit_id = sync.deposit.id inner join mt.rollup_exit on mt.rollup_exit.leaf = mt.root.root inner join sync.exit_root on sync.exit_root.exit_roots[2]= mt.rollup_exit.root where deposit_cnt = $1 and sync.deposit.network_id = $2 and dest_net = $3 and mt.rollup_exit.rollup_id = $2 and sync.exit_root.block_id = 0 and sync.exit_root.network_id = sync.deposit.dest_net order by sync.exit_root.id desc limit 1` + var ger common.Hash + err := p.getExecQuerier(dbTx).QueryRow(ctx, getLatestTrustedGERByDeposit, depositCnt, networkID, destinationNetwork).Scan(&ger) + if errors.Is(err, pgx.ErrNoRows) { + return common.Hash{}, gerror.ErrStorageNotFound + } + return ger, err +} + // AddClaimTx adds a claim monitored transaction to the storage. func (p *PostgresStorage) AddClaimTx(ctx context.Context, mTx ctmtypes.MonitoredTx, dbTx pgx.Tx) error { const addMonitoredTxSQL = `INSERT INTO sync.monitored_txs @@ -694,21 +687,10 @@ func (p *PostgresStorage) GetPendingDepositsToClaim(ctx context.Context, destAdd return nil, 0, err } - deposits := make([]*etherman.Deposit, 0, len(rows.RawValues())) - - for rows.Next() { - var ( - deposit etherman.Deposit - amount string - ) - err = rows.Scan(&deposit.Id, &deposit.LeafType, &deposit.OriginalNetwork, &deposit.OriginalAddress, &amount, &deposit.DestinationNetwork, &deposit.DestinationAddress, &deposit.DepositCount, &deposit.BlockID, &deposit.BlockNumber, &deposit.NetworkID, &deposit.TxHash, &deposit.Metadata, &deposit.ReadyForClaim) - if err != nil { - return nil, 0, err - } - deposit.Amount, _ = new(big.Int).SetString(amount, 10) //nolint:gomnd - deposits = append(deposits, &deposit) + deposits, err := parseDeposits(rows, true) + if err != nil { + return nil, 0, err } - return deposits, totalCount, nil } @@ -725,3 +707,25 @@ func (p *PostgresStorage) UpdateBlocksForTesting(ctx context.Context, networkID _, err := p.getExecQuerier(dbTx).Exec(ctx, updateBlocksSQL, networkID, blockNum) return err } + +func parseDeposits(rows pgx.Rows, needBlockNum bool) ([]*etherman.Deposit, error) { + deposits := make([]*etherman.Deposit, 0, len(rows.RawValues())) + for rows.Next() { + var ( + deposit etherman.Deposit + amount string + err error + ) + if needBlockNum { + err = rows.Scan(&deposit.Id, &deposit.LeafType, &deposit.OriginalNetwork, &deposit.OriginalAddress, &amount, &deposit.DestinationNetwork, &deposit.DestinationAddress, &deposit.DepositCount, &deposit.BlockID, &deposit.BlockNumber, &deposit.NetworkID, &deposit.TxHash, &deposit.Metadata, &deposit.ReadyForClaim) + } else { + err = rows.Scan(&deposit.Id, &deposit.LeafType, &deposit.OriginalNetwork, &deposit.OriginalAddress, &amount, &deposit.DestinationNetwork, &deposit.DestinationAddress, &deposit.DepositCount, &deposit.BlockID, &deposit.NetworkID, &deposit.TxHash, &deposit.Metadata, &deposit.ReadyForClaim) + } + if err != nil { + return nil, err + } + deposit.Amount, _ = new(big.Int).SetString(amount, 10) //nolint:gomnd + deposits = append(deposits, &deposit) + } + return deposits, nil +} diff --git a/docker-compose.yml b/docker-compose.yml index 0e4c7a52..0329e0ae 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -476,6 +476,7 @@ services: - ZKEVM_BRIDGE_NETWORKCONFIG_POLYGONBRIDGEADDRESS=0xFe12ABaa190Ef0c8638Ee0ba9F828BF41368Ca0E - ZKEVM_BRIDGE_NETWORKCONFIG_L2POLYGONBRIDGEADDRESSES=0xFe12ABaa190Ef0c8638Ee0ba9F828BF41368Ca0E,0xFe12ABaa190Ef0c8638Ee0ba9F828BF41368Ca0E - ZKEVM_BRIDGE_CLAIMTXMANAGER_GROUPINGCLAIMS_ENABLED=${ZKEVM_BRIDGE_CLAIMTXMANAGER_GROUPINGCLAIMS_ENABLED} + - ZKEVM_BRIDGE_CLAIMTXMANAGER_ARECLAIMSBETWEENL2SENABLED=${ZKEVM_BRIDGE_CLAIMTXMANAGER_ARECLAIMSBETWEENL2SENABLED} volumes: - ./test/test.keystore.claimtx:/pk/keystore.claimtxmanager - ./config/config.local.toml:/app/config.toml diff --git a/etherman/smartcontracts/bin/claimcompressor.bin b/etherman/smartcontracts/bin/claimcompressor.bin index 3320f1d3..b81969e7 100644 --- a/etherman/smartcontracts/bin/claimcompressor.bin +++ b/etherman/smartcontracts/bin/claimcompressor.bin @@ -1 +1 @@ -60c060405234801561001057600080fd5b50604051610e1c380380610e1c83398101604081905261002f9161004b565b6001600160a01b0390911660805263ffffffff1660a05261009a565b6000806040838503121561005e57600080fd5b82516001600160a01b038116811461007557600080fd5b602084015190925063ffffffff8116811461008f57600080fd5b809150509250929050565b60805160a051610d5d6100bf6000396000610442015260006104640152610d5d6000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806304e5557b1461003b57806397b1410f14610064575b600080fd5b61004e6100493660046105fc565b610079565b60405161005b91906106a3565b60405180910390f35b6100776100723660046106f4565b61043b565b005b606060008585604051602001610099929190918252602082015260400190565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815291905290506000805b8481101561042f5760008686838181106100e9576100e9610766565b90506020028101906100fb9190610795565b61010490610992565b9050600082600003610118575060206101aa565b60005b60208110156101a8578888610131600187610a8d565b81811061014057610140610766565b90506020028101906101529190610795565b816020811061016357610163610766565b60200201358360000151826020811061017e5761017e610766565b60200201511461019657610193816001610aa6565b91505b806101a081610ab9565b91505061011b565b505b6040805160f883901b7fff0000000000000000000000000000000000000000000000000000000000000016602082015281516001818303018152602190910190915260005b828110156102465783518290826020811061020c5761020c610766565b6020020151604051602001610222929190610b0d565b6040516020818303038152906040529150808061023e90610ab9565b9150506101ef565b50602083015151600092501561030a57831580610261575084155b1561026f5760209150610305565b60005b6020811015610303578989610288600188610a8d565b81811061029757610297610766565b90506020028101906102a99190610795565b6104000181602081106102be576102be610766565b6020020135846020015182602081106102d9576102d9610766565b6020020151146102f1576102ee816001610aa6565b92505b806102fb81610ab9565b915050610272565b505b600194505b808260405160200161031d929190610b2f565b604051602081830303815290604052905060005b8281101561038a57818460200151826020811061035057610350610766565b6020020151604051602001610366929190610b0d565b6040516020818303038152906040529150808061038290610ab9565b915050610331565b50600083610100015161039e5760006103a1565b60015b6040858101516060870151608088015160a089015160c08a015160e08b0151805187516103e399988c989081901c979096909590949093909291602001610b79565b60405160208183030381529060405290508681604051602001610407929190610cf8565b604051602081830303815290604052965050505050808061042790610ab9565b9150506100cd565b50909695505050505050565b63ffffffff7f0000000000000000000000000000000000000000000000000000000000000000167f000000000000000000000000000000000000000000000000000000000000000063ccaa2d1163f5efcd798585602082610824376020828101610844376108a486905261092061090452604082015b8183018110156105f157803560f81c80156104d357600181146104f15761050b565b856003538560081c6002538560101c6001538560181c60005361050b565b846003538460081c6002538460101c6001538460181c6000535b5060028101906004906001013560f81c60200280838337909101600181019161040001906020903560f81c02808383379190910190610400810190823560f81c9061041701536001820191506008826018830137600882019150606081019050600482601c830137600482019150602081019050601482600c83013760149182019160408201918390604c01376014820191506020810190506020828237602082013560e01c6040820181905260249092019160609091019080838337600091810182905291820191601f80821660200316016109440190808281808b5af150506104b1565b505050505050505050565b6000806000806060858703121561061257600080fd5b8435935060208501359250604085013567ffffffffffffffff8082111561063857600080fd5b818701915087601f83011261064c57600080fd5b81358181111561065b57600080fd5b8860208260051b850101111561067057600080fd5b95989497505060200194505050565b60005b8381101561069a578181015183820152602001610682565b50506000910152565b60208152600082518060208401526106c281604085016020870161067f565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169190910160400192915050565b6000806020838503121561070757600080fd5b823567ffffffffffffffff8082111561071f57600080fd5b818501915085601f83011261073357600080fd5b81358181111561074257600080fd5b86602082850101111561075457600080fd5b60209290920196919550909350505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600082357ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7218336030181126107c957600080fd5b9190910192915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051610120810167ffffffffffffffff81118282101715610826576108266107d3565b60405290565b600082601f83011261083d57600080fd5b60405161040080820182811067ffffffffffffffff82111715610862576108626107d3565b6040528301818582111561087557600080fd5b845b8281101561088f578035825260209182019101610877565b509195945050505050565b803563ffffffff811681146108ae57600080fd5b919050565b803573ffffffffffffffffffffffffffffffffffffffff811681146108ae57600080fd5b600082601f8301126108e857600080fd5b813567ffffffffffffffff80821115610903576109036107d3565b604051601f83017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f01168101908282118183101715610949576109496107d3565b8160405283815286602085880101111561096257600080fd5b836020870160208301376000602085830101528094505050505092915050565b803580151581146108ae57600080fd5b60006108e082360312156109a557600080fd5b6109ad610802565b6109b7368461082c565b81526109c736610400850161082c565b602082015261080083013560408201526109e4610820840161089a565b60608201526109f661084084016108b3565b6080820152610a0861086084016108b3565b60a082015261088083013560c08201526108a083013567ffffffffffffffff811115610a3357600080fd5b610a3f368286016108d7565b60e083015250610a526108c08401610982565b61010082015292915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b81810381811115610aa057610aa0610a5e565b92915050565b80820180821115610aa057610aa0610a5e565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610aea57610aea610a5e565b5060010190565b60008151610b0381856020860161067f565b9290920192915050565b60008351610b1f81846020880161067f565b9190910191825250602001919050565b60008351610b4181846020880161067f565b60f89390931b7fff00000000000000000000000000000000000000000000000000000000000000169190920190815260010192915050565b7fff000000000000000000000000000000000000000000000000000000000000008b60f81b16815260008a51610bb6816001850160208f0161067f565b7fff000000000000000000000000000000000000000000000000000000000000008b60f81b16600182850101527fffffffffffffffff0000000000000000000000000000000000000000000000008a60c01b16600282850101527fffffffff000000000000000000000000000000000000000000000000000000008960e01b16600a82850101527fffffffffffffffffffffffffffffffffffffffff0000000000000000000000008860601b16600e8285010152610c9d6022828501018860601b7fffffffffffffffffffffffffffffffffffffffff000000000000000000000000169052565b8560368285010152610cd86056828501018660e01b7fffffffff00000000000000000000000000000000000000000000000000000000169052565b610ce7605a8285010185610af1565b9d9c50505050505050505050505050565b60008351610d0a81846020880161067f565b835190830190610d1e81836020880161067f565b0194935050505056fea264697066735822122084bcbf2fb5ac30a76f853974feb3c954180779f186c81a3b6a6cd859e4f5209464736f6c63430008140033 \ No newline at end of file +60c060405234801561000f575f80fd5b50604051610dec380380610dec83398101604081905261002e9161004a565b6001600160a01b0390911660805263ffffffff1660a052610095565b5f806040838503121561005b575f80fd5b82516001600160a01b0381168114610071575f80fd5b602084015190925063ffffffff8116811461008a575f80fd5b809150509250929050565b60805160a051610d366100b65f395f61043601525f6104580152610d365ff3fe608060405234801561000f575f80fd5b5060043610610034575f3560e01c806304e5557b1461003857806397b1410f14610061575b5f80fd5b61004b610046366004610600565b610076565b604051610058919061069e565b60405180910390f35b61007461006f3660046106ee565b61042f565b005b60605f8585604051602001610095929190918252602082015260400190565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815291905290505f805b84811015610423575f8686838181106100e3576100e361075a565b90506020028101906100f59190610787565b6100fe90610976565b90505f825f03610110575060206101a0565b5f5b602081101561019e578888610128600187610a6c565b8181106101375761013761075a565b90506020028101906101499190610787565b816020811061015a5761015a61075a565b6020020135835f015182602081106101745761017461075a565b60200201511461018c57610189816001610a85565b91505b8061019681610a98565b915050610112565b505b6040805160f883901b7fff000000000000000000000000000000000000000000000000000000000000001660208201528151600181830301815260219091019091525f5b8281101561023b578351829082602081106102015761020161075a565b6020020151604051602001610217929190610aea565b6040516020818303038152906040529150808061023390610a98565b9150506101e4565b5060208301516103e001515f92501561030157831580610259575084155b1561026757602091506102fc565b5f5b60208110156102fa57898961027f600188610a6c565b81811061028e5761028e61075a565b90506020028101906102a09190610787565b6104000181602081106102b5576102b561075a565b6020020135846020015182602081106102d0576102d061075a565b6020020151146102e8576102e5816001610a85565b92505b806102f281610a98565b915050610269565b505b600194505b8082604051602001610314929190610b0b565b60405160208183030381529060405290505f5b828110156103805781846020015182602081106103465761034661075a565b602002015160405160200161035c929190610aea565b6040516020818303038152906040529150808061037890610a98565b915050610327565b505f836101000151610392575f610395565b60015b6040858101516060870151608088015160a089015160c08a015160e08b0151805187516103d799988c989081901c979096909590949093909291602001610b54565b604051602081830303815290604052905086816040516020016103fb929190610cd2565b604051602081830303815290604052965050505050808061041b90610a98565b9150506100c8565b50909695505050505050565b63ffffffff7f0000000000000000000000000000000000000000000000000000000000000000167f000000000000000000000000000000000000000000000000000000000000000063ccaa2d1163f5efcd798585602082610824376020828101610844376108a486905261092061090452604082015b8183018110156105f557803560f81c80156104c757600181146104e4576104fd565b856003538560081c6002538560101c6001538560181c5f536104fd565b846003538460081c6002538460101c6001538460181c5f535b5060028101906004906001013560f81c60200280838337909101600181019161040001906020903560f81c02808383379190910190610400810190823560f81c9061041701536001820191506008826018830137600882019150606081019050600482601c830137600482019150602081019050601482600c83013760149182019160408201918390604c01376014820191506020810190506020828237602082013560e01c60408201819052602490920191606090910190808383375f9181019190915290810190601f808216602003160161094401622625a05a10156105e3575f80fd5b5f80825f808b621e8480f150506104a5565b505050505050505050565b5f805f8060608587031215610613575f80fd5b8435935060208501359250604085013567ffffffffffffffff80821115610638575f80fd5b818701915087601f83011261064b575f80fd5b813581811115610659575f80fd5b8860208260051b850101111561066d575f80fd5b95989497505060200194505050565b5f5b8381101561069657818101518382015260200161067e565b50505f910152565b602081525f82518060208401526106bc81604085016020870161067c565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169190910160400192915050565b5f80602083850312156106ff575f80fd5b823567ffffffffffffffff80821115610716575f80fd5b818501915085601f830112610729575f80fd5b813581811115610737575f80fd5b866020828501011115610748575f80fd5b60209290920196919550909350505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f82357ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7218336030181126107b9575f80fd5b9190910192915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b604051610120810167ffffffffffffffff81118282101715610814576108146107c3565b60405290565b5f82601f830112610829575f80fd5b60405161040080820182811067ffffffffffffffff8211171561084e5761084e6107c3565b60405283018185821115610860575f80fd5b845b8281101561087a578035825260209182019101610862565b509195945050505050565b803563ffffffff81168114610898575f80fd5b919050565b803573ffffffffffffffffffffffffffffffffffffffff81168114610898575f80fd5b5f82601f8301126108cf575f80fd5b813567ffffffffffffffff808211156108ea576108ea6107c3565b604051601f83017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f01168101908282118183101715610930576109306107c3565b81604052838152866020858801011115610948575f80fd5b836020870160208301375f602085830101528094505050505092915050565b80358015158114610898575f80fd5b5f6108e08236031215610987575f80fd5b61098f6107f0565b610999368461081a565b81526109a936610400850161081a565b602082015261080083013560408201526109c66108208401610885565b60608201526109d8610840840161089d565b60808201526109ea610860840161089d565b60a082015261088083013560c08201526108a083013567ffffffffffffffff811115610a14575f80fd5b610a20368286016108c0565b60e083015250610a336108c08401610967565b61010082015292915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b81810381811115610a7f57610a7f610a3f565b92915050565b80820180821115610a7f57610a7f610a3f565b5f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610ac857610ac8610a3f565b5060010190565b5f8151610ae081856020860161067c565b9290920192915050565b5f8351610afb81846020880161067c565b9190910191825250602001919050565b5f8351610b1c81846020880161067c565b60f89390931b7fff00000000000000000000000000000000000000000000000000000000000000169190920190815260010192915050565b7fff000000000000000000000000000000000000000000000000000000000000008b60f81b1681525f8a51610b90816001850160208f0161067c565b7fff000000000000000000000000000000000000000000000000000000000000008b60f81b16600182850101527fffffffffffffffff0000000000000000000000000000000000000000000000008a60c01b16600282850101527fffffffff000000000000000000000000000000000000000000000000000000008960e01b16600a82850101527fffffffffffffffffffffffffffffffffffffffff0000000000000000000000008860601b16600e8285010152610c776022828501018860601b7fffffffffffffffffffffffffffffffffffffffff000000000000000000000000169052565b8560368285010152610cb26056828501018660e01b7fffffffff00000000000000000000000000000000000000000000000000000000169052565b610cc1605a8285010185610acf565b9d9c50505050505050505050505050565b5f8351610ce381846020880161067c565b835190830190610cf781836020880161067c565b0194935050505056fea2646970667358221220431d4b4962f6e0fedc7eff37b6b46383dff32ef58340bfd8486915afedccad0564736f6c63430008140033 \ No newline at end of file diff --git a/etherman/smartcontracts/claimcompressor/claimcompressor.go b/etherman/smartcontracts/claimcompressor/claimcompressor.go index 4c96a904..9704883b 100644 --- a/etherman/smartcontracts/claimcompressor/claimcompressor.go +++ b/etherman/smartcontracts/claimcompressor/claimcompressor.go @@ -45,7 +45,7 @@ type ClaimCompressorCompressClaimCallData struct { // ClaimcompressorMetaData contains all meta data concerning the Claimcompressor contract. var ClaimcompressorMetaData = &bind.MetaData{ ABI: "[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"__bridgeAddress\",\"type\":\"address\"},{\"internalType\":\"uint32\",\"name\":\"__networkID\",\"type\":\"uint32\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"mainnetExitRoot\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"rollupExitRoot\",\"type\":\"bytes32\"},{\"components\":[{\"internalType\":\"bytes32[32]\",\"name\":\"smtProofLocalExitRoot\",\"type\":\"bytes32[32]\"},{\"internalType\":\"bytes32[32]\",\"name\":\"smtProofRollupExitRoot\",\"type\":\"bytes32[32]\"},{\"internalType\":\"uint256\",\"name\":\"globalIndex\",\"type\":\"uint256\"},{\"internalType\":\"uint32\",\"name\":\"originNetwork\",\"type\":\"uint32\"},{\"internalType\":\"address\",\"name\":\"originAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"destinationAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"metadata\",\"type\":\"bytes\"},{\"internalType\":\"bool\",\"name\":\"isMessage\",\"type\":\"bool\"}],\"internalType\":\"structClaimCompressor.CompressClaimCallData[]\",\"name\":\"compressClaimCalldata\",\"type\":\"tuple[]\"}],\"name\":\"compressClaimCall\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"compressedClaimCalls\",\"type\":\"bytes\"}],\"name\":\"sendCompressedClaims\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", - Bin: "0x60c060405234801561001057600080fd5b50604051610e1c380380610e1c83398101604081905261002f9161004b565b6001600160a01b0390911660805263ffffffff1660a05261009a565b6000806040838503121561005e57600080fd5b82516001600160a01b038116811461007557600080fd5b602084015190925063ffffffff8116811461008f57600080fd5b809150509250929050565b60805160a051610d5d6100bf6000396000610442015260006104640152610d5d6000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806304e5557b1461003b57806397b1410f14610064575b600080fd5b61004e6100493660046105fc565b610079565b60405161005b91906106a3565b60405180910390f35b6100776100723660046106f4565b61043b565b005b606060008585604051602001610099929190918252602082015260400190565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815291905290506000805b8481101561042f5760008686838181106100e9576100e9610766565b90506020028101906100fb9190610795565b61010490610992565b9050600082600003610118575060206101aa565b60005b60208110156101a8578888610131600187610a8d565b81811061014057610140610766565b90506020028101906101529190610795565b816020811061016357610163610766565b60200201358360000151826020811061017e5761017e610766565b60200201511461019657610193816001610aa6565b91505b806101a081610ab9565b91505061011b565b505b6040805160f883901b7fff0000000000000000000000000000000000000000000000000000000000000016602082015281516001818303018152602190910190915260005b828110156102465783518290826020811061020c5761020c610766565b6020020151604051602001610222929190610b0d565b6040516020818303038152906040529150808061023e90610ab9565b9150506101ef565b50602083015151600092501561030a57831580610261575084155b1561026f5760209150610305565b60005b6020811015610303578989610288600188610a8d565b81811061029757610297610766565b90506020028101906102a99190610795565b6104000181602081106102be576102be610766565b6020020135846020015182602081106102d9576102d9610766565b6020020151146102f1576102ee816001610aa6565b92505b806102fb81610ab9565b915050610272565b505b600194505b808260405160200161031d929190610b2f565b604051602081830303815290604052905060005b8281101561038a57818460200151826020811061035057610350610766565b6020020151604051602001610366929190610b0d565b6040516020818303038152906040529150808061038290610ab9565b915050610331565b50600083610100015161039e5760006103a1565b60015b6040858101516060870151608088015160a089015160c08a015160e08b0151805187516103e399988c989081901c979096909590949093909291602001610b79565b60405160208183030381529060405290508681604051602001610407929190610cf8565b604051602081830303815290604052965050505050808061042790610ab9565b9150506100cd565b50909695505050505050565b63ffffffff7f0000000000000000000000000000000000000000000000000000000000000000167f000000000000000000000000000000000000000000000000000000000000000063ccaa2d1163f5efcd798585602082610824376020828101610844376108a486905261092061090452604082015b8183018110156105f157803560f81c80156104d357600181146104f15761050b565b856003538560081c6002538560101c6001538560181c60005361050b565b846003538460081c6002538460101c6001538460181c6000535b5060028101906004906001013560f81c60200280838337909101600181019161040001906020903560f81c02808383379190910190610400810190823560f81c9061041701536001820191506008826018830137600882019150606081019050600482601c830137600482019150602081019050601482600c83013760149182019160408201918390604c01376014820191506020810190506020828237602082013560e01c6040820181905260249092019160609091019080838337600091810182905291820191601f80821660200316016109440190808281808b5af150506104b1565b505050505050505050565b6000806000806060858703121561061257600080fd5b8435935060208501359250604085013567ffffffffffffffff8082111561063857600080fd5b818701915087601f83011261064c57600080fd5b81358181111561065b57600080fd5b8860208260051b850101111561067057600080fd5b95989497505060200194505050565b60005b8381101561069a578181015183820152602001610682565b50506000910152565b60208152600082518060208401526106c281604085016020870161067f565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169190910160400192915050565b6000806020838503121561070757600080fd5b823567ffffffffffffffff8082111561071f57600080fd5b818501915085601f83011261073357600080fd5b81358181111561074257600080fd5b86602082850101111561075457600080fd5b60209290920196919550909350505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600082357ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7218336030181126107c957600080fd5b9190910192915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051610120810167ffffffffffffffff81118282101715610826576108266107d3565b60405290565b600082601f83011261083d57600080fd5b60405161040080820182811067ffffffffffffffff82111715610862576108626107d3565b6040528301818582111561087557600080fd5b845b8281101561088f578035825260209182019101610877565b509195945050505050565b803563ffffffff811681146108ae57600080fd5b919050565b803573ffffffffffffffffffffffffffffffffffffffff811681146108ae57600080fd5b600082601f8301126108e857600080fd5b813567ffffffffffffffff80821115610903576109036107d3565b604051601f83017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f01168101908282118183101715610949576109496107d3565b8160405283815286602085880101111561096257600080fd5b836020870160208301376000602085830101528094505050505092915050565b803580151581146108ae57600080fd5b60006108e082360312156109a557600080fd5b6109ad610802565b6109b7368461082c565b81526109c736610400850161082c565b602082015261080083013560408201526109e4610820840161089a565b60608201526109f661084084016108b3565b6080820152610a0861086084016108b3565b60a082015261088083013560c08201526108a083013567ffffffffffffffff811115610a3357600080fd5b610a3f368286016108d7565b60e083015250610a526108c08401610982565b61010082015292915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b81810381811115610aa057610aa0610a5e565b92915050565b80820180821115610aa057610aa0610a5e565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610aea57610aea610a5e565b5060010190565b60008151610b0381856020860161067f565b9290920192915050565b60008351610b1f81846020880161067f565b9190910191825250602001919050565b60008351610b4181846020880161067f565b60f89390931b7fff00000000000000000000000000000000000000000000000000000000000000169190920190815260010192915050565b7fff000000000000000000000000000000000000000000000000000000000000008b60f81b16815260008a51610bb6816001850160208f0161067f565b7fff000000000000000000000000000000000000000000000000000000000000008b60f81b16600182850101527fffffffffffffffff0000000000000000000000000000000000000000000000008a60c01b16600282850101527fffffffff000000000000000000000000000000000000000000000000000000008960e01b16600a82850101527fffffffffffffffffffffffffffffffffffffffff0000000000000000000000008860601b16600e8285010152610c9d6022828501018860601b7fffffffffffffffffffffffffffffffffffffffff000000000000000000000000169052565b8560368285010152610cd86056828501018660e01b7fffffffff00000000000000000000000000000000000000000000000000000000169052565b610ce7605a8285010185610af1565b9d9c50505050505050505050505050565b60008351610d0a81846020880161067f565b835190830190610d1e81836020880161067f565b0194935050505056fea264697066735822122084bcbf2fb5ac30a76f853974feb3c954180779f186c81a3b6a6cd859e4f5209464736f6c63430008140033", + Bin: "0x60c060405234801561000f575f80fd5b50604051610dec380380610dec83398101604081905261002e9161004a565b6001600160a01b0390911660805263ffffffff1660a052610095565b5f806040838503121561005b575f80fd5b82516001600160a01b0381168114610071575f80fd5b602084015190925063ffffffff8116811461008a575f80fd5b809150509250929050565b60805160a051610d366100b65f395f61043601525f6104580152610d365ff3fe608060405234801561000f575f80fd5b5060043610610034575f3560e01c806304e5557b1461003857806397b1410f14610061575b5f80fd5b61004b610046366004610600565b610076565b604051610058919061069e565b60405180910390f35b61007461006f3660046106ee565b61042f565b005b60605f8585604051602001610095929190918252602082015260400190565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815291905290505f805b84811015610423575f8686838181106100e3576100e361075a565b90506020028101906100f59190610787565b6100fe90610976565b90505f825f03610110575060206101a0565b5f5b602081101561019e578888610128600187610a6c565b8181106101375761013761075a565b90506020028101906101499190610787565b816020811061015a5761015a61075a565b6020020135835f015182602081106101745761017461075a565b60200201511461018c57610189816001610a85565b91505b8061019681610a98565b915050610112565b505b6040805160f883901b7fff000000000000000000000000000000000000000000000000000000000000001660208201528151600181830301815260219091019091525f5b8281101561023b578351829082602081106102015761020161075a565b6020020151604051602001610217929190610aea565b6040516020818303038152906040529150808061023390610a98565b9150506101e4565b5060208301516103e001515f92501561030157831580610259575084155b1561026757602091506102fc565b5f5b60208110156102fa57898961027f600188610a6c565b81811061028e5761028e61075a565b90506020028101906102a09190610787565b6104000181602081106102b5576102b561075a565b6020020135846020015182602081106102d0576102d061075a565b6020020151146102e8576102e5816001610a85565b92505b806102f281610a98565b915050610269565b505b600194505b8082604051602001610314929190610b0b565b60405160208183030381529060405290505f5b828110156103805781846020015182602081106103465761034661075a565b602002015160405160200161035c929190610aea565b6040516020818303038152906040529150808061037890610a98565b915050610327565b505f836101000151610392575f610395565b60015b6040858101516060870151608088015160a089015160c08a015160e08b0151805187516103d799988c989081901c979096909590949093909291602001610b54565b604051602081830303815290604052905086816040516020016103fb929190610cd2565b604051602081830303815290604052965050505050808061041b90610a98565b9150506100c8565b50909695505050505050565b63ffffffff7f0000000000000000000000000000000000000000000000000000000000000000167f000000000000000000000000000000000000000000000000000000000000000063ccaa2d1163f5efcd798585602082610824376020828101610844376108a486905261092061090452604082015b8183018110156105f557803560f81c80156104c757600181146104e4576104fd565b856003538560081c6002538560101c6001538560181c5f536104fd565b846003538460081c6002538460101c6001538460181c5f535b5060028101906004906001013560f81c60200280838337909101600181019161040001906020903560f81c02808383379190910190610400810190823560f81c9061041701536001820191506008826018830137600882019150606081019050600482601c830137600482019150602081019050601482600c83013760149182019160408201918390604c01376014820191506020810190506020828237602082013560e01c60408201819052602490920191606090910190808383375f9181019190915290810190601f808216602003160161094401622625a05a10156105e3575f80fd5b5f80825f808b621e8480f150506104a5565b505050505050505050565b5f805f8060608587031215610613575f80fd5b8435935060208501359250604085013567ffffffffffffffff80821115610638575f80fd5b818701915087601f83011261064b575f80fd5b813581811115610659575f80fd5b8860208260051b850101111561066d575f80fd5b95989497505060200194505050565b5f5b8381101561069657818101518382015260200161067e565b50505f910152565b602081525f82518060208401526106bc81604085016020870161067c565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169190910160400192915050565b5f80602083850312156106ff575f80fd5b823567ffffffffffffffff80821115610716575f80fd5b818501915085601f830112610729575f80fd5b813581811115610737575f80fd5b866020828501011115610748575f80fd5b60209290920196919550909350505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f82357ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7218336030181126107b9575f80fd5b9190910192915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b604051610120810167ffffffffffffffff81118282101715610814576108146107c3565b60405290565b5f82601f830112610829575f80fd5b60405161040080820182811067ffffffffffffffff8211171561084e5761084e6107c3565b60405283018185821115610860575f80fd5b845b8281101561087a578035825260209182019101610862565b509195945050505050565b803563ffffffff81168114610898575f80fd5b919050565b803573ffffffffffffffffffffffffffffffffffffffff81168114610898575f80fd5b5f82601f8301126108cf575f80fd5b813567ffffffffffffffff808211156108ea576108ea6107c3565b604051601f83017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f01168101908282118183101715610930576109306107c3565b81604052838152866020858801011115610948575f80fd5b836020870160208301375f602085830101528094505050505092915050565b80358015158114610898575f80fd5b5f6108e08236031215610987575f80fd5b61098f6107f0565b610999368461081a565b81526109a936610400850161081a565b602082015261080083013560408201526109c66108208401610885565b60608201526109d8610840840161089d565b60808201526109ea610860840161089d565b60a082015261088083013560c08201526108a083013567ffffffffffffffff811115610a14575f80fd5b610a20368286016108c0565b60e083015250610a336108c08401610967565b61010082015292915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b81810381811115610a7f57610a7f610a3f565b92915050565b80820180821115610a7f57610a7f610a3f565b5f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610ac857610ac8610a3f565b5060010190565b5f8151610ae081856020860161067c565b9290920192915050565b5f8351610afb81846020880161067c565b9190910191825250602001919050565b5f8351610b1c81846020880161067c565b60f89390931b7fff00000000000000000000000000000000000000000000000000000000000000169190920190815260010192915050565b7fff000000000000000000000000000000000000000000000000000000000000008b60f81b1681525f8a51610b90816001850160208f0161067c565b7fff000000000000000000000000000000000000000000000000000000000000008b60f81b16600182850101527fffffffffffffffff0000000000000000000000000000000000000000000000008a60c01b16600282850101527fffffffff000000000000000000000000000000000000000000000000000000008960e01b16600a82850101527fffffffffffffffffffffffffffffffffffffffff0000000000000000000000008860601b16600e8285010152610c776022828501018860601b7fffffffffffffffffffffffffffffffffffffffff000000000000000000000000169052565b8560368285010152610cb26056828501018660e01b7fffffffff00000000000000000000000000000000000000000000000000000000169052565b610cc1605a8285010185610acf565b9d9c50505050505050505050505050565b5f8351610ce381846020880161067c565b835190830190610cf781836020880161067c565b0194935050505056fea2646970667358221220431d4b4962f6e0fedc7eff37b6b46383dff32ef58340bfd8486915afedccad0564736f6c63430008140033", } // ClaimcompressorABI is the input ABI used to generate the binding from. diff --git a/synchronizer/synchronizer.go b/synchronizer/synchronizer.go index 0be6dc05..f261f855 100644 --- a/synchronizer/synchronizer.go +++ b/synchronizer/synchronizer.go @@ -217,7 +217,7 @@ func (s *ClientSynchronizer) syncTrustedState() error { } isUpdated, err := s.storage.AddTrustedGlobalExitRoot(s.ctx, ger, nil) if err != nil { - log.Error("networkID: %d, error storing latest trusted globalExitRoot. Error: %v", s.networkID, err) + log.Errorf("networkID: %d, error storing latest trusted globalExitRoot. Error: %v", s.networkID, err) return err } if isUpdated { @@ -488,7 +488,7 @@ func (s *ClientSynchronizer) resetState(blockNumber uint64) error { } depositCnt, err := s.storage.GetNumberDeposits(s.ctx, s.networkID, blockNumber, dbTx) if err != nil { - log.Error("networkID: %d, error getting GetNumberDeposits. Error: %v", s.networkID, err) + log.Errorf("networkID: %d, error getting GetNumberDeposits. Error: %v", s.networkID, err) rollbackErr := s.storage.Rollback(s.ctx, dbTx) if rollbackErr != nil { log.Errorf("networkID: %d, error rolling back state to store block. BlockNumber: %d, rollbackErr: %v, error : %s", @@ -500,7 +500,7 @@ func (s *ClientSynchronizer) resetState(blockNumber uint64) error { err = s.bridgeCtrl.ReorgMT(s.ctx, depositCnt, s.networkID, dbTx) if err != nil { - log.Error("networkID: %d, error resetting ReorgMT the state. Error: %v", s.networkID, err) + log.Errorf("networkID: %d, error resetting ReorgMT the state. Error: %v", s.networkID, err) rollbackErr := s.storage.Rollback(s.ctx, dbTx) if rollbackErr != nil { log.Errorf("networkID: %d, error rolling back state to store block. BlockNumber: %d, rollbackErr: %v, error : %s", @@ -626,8 +626,8 @@ func (s *ClientSynchronizer) processVerifyBatch(verifyBatch etherman.VerifiedBat log.Errorf("networkID: %d, Root: %s doesn't exist!", s.networkID, verifyBatch.LocalExitRoot.String()) rollbackErr := s.storage.Rollback(s.ctx, dbTx) if rollbackErr != nil { - log.Errorf("networkID: %d, error rolling back state. BlockNumber: %d, rollbackErr: %v, error : %s", - s.networkID, verifyBatch.BlockNumber, rollbackErr, err.Error()) + log.Errorf("networkID: %d, error rolling back state. BlockNumber: %d, rollbackErr: %v", + s.networkID, verifyBatch.BlockNumber, rollbackErr) return rollbackErr } return fmt.Errorf("networkID: %d, Root: %s doesn't exist!", s.networkID, verifyBatch.LocalExitRoot.String()) diff --git a/test/e2e/autoclaim_l2_l2_test.go b/test/e2e/autoclaim_l2_l2_test.go new file mode 100644 index 00000000..0910a43f --- /dev/null +++ b/test/e2e/autoclaim_l2_l2_test.go @@ -0,0 +1,84 @@ +//go:build autoclaiml2l2 +// +build autoclaiml2l2 + +package e2e + +import ( + "context" + "math/big" + "os" + "testing" + "time" + + "github.com/0xPolygonHermez/zkevm-bridge-service/test/operations" + "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/require" +) + +// TestAutoClaimL2L2 tests the flow of deposit and withdraw funds using the vector +func TestAutoClaimL2L2(t *testing.T) { + if testing.Short() { + t.Skip() + } + + err := os.Setenv("ZKEVM_BRIDGE_CLAIMTXMANAGER_ARECLAIMSBETWEENL2SENABLED", "true") + require.NoError(t, err) + require.NoError(t, operations.StartBridge3()) + ctx := context.Background() + opsman1, err := operations.GetOpsman(ctx, "http://localhost:8123", "test_db", "8080", "9090", "5435", 1) + require.NoError(t, err) + opsman2, err := operations.GetOpsman(ctx, "http://localhost:8124", "test_db", "8080", "9090", "5435", 2) + require.NoError(t, err) + + t.Run("AutoClaim L2-L2 eth bridge", func(t *testing.T) { + // Check initial globalExitRoot. Must fail because at the beginning, no globalExitRoot event is thrown. + globalExitRootSMC, err := opsman1.GetCurrentGlobalExitRootFromSmc(ctx) + require.NoError(t, err) + t.Logf("initial globalExitRootSMC: %+v,", globalExitRootSMC) + // Send L2 deposit + var destNetwork uint32 = 2 + amount := new(big.Int).SetUint64(10000000000000000001) + tokenAddr := common.Address{} // This means is eth + address := common.HexToAddress("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266") + + l2Balance, err := opsman1.CheckAccountBalance(ctx, operations.L2, &address) + require.NoError(t, err) + t.Logf("Initial L2 Bridge Balance in origin network 1: %v", l2Balance) + err = opsman1.SendL2Deposit(ctx, tokenAddr, amount, destNetwork, &address, operations.L22) + require.NoError(t, err) + l2Balance, err = opsman1.CheckAccountBalance(ctx, operations.L2, &address) + require.NoError(t, err) + t.Logf("Final L2 Bridge Balance in origin network 1: %v", l2Balance) + + // Check globalExitRoot + globalExitRoot, err := opsman1.GetLatestGlobalExitRootFromL1(ctx) + require.NoError(t, err) + t.Logf("GlobalExitRoot %+v: ", globalExitRoot) + require.NotEqual(t, globalExitRoot.ExitRoots[1], globalExitRootSMC.ExitRoots[1]) + require.Equal(t, globalExitRoot.ExitRoots[0], globalExitRootSMC.ExitRoots[0]) + // Check L2 destination funds + balance, err := opsman2.CheckAccountBalance(ctx, operations.L2, &address) + require.NoError(t, err) + v, _ := big.NewInt(0).SetString("99999998433970000000000", 10) + t.Log("balance: ", balance) + require.Equal(t, 0, v.Cmp(balance)) + // This deposit forces the update of the ger to process the previous ready for claim. It is + // needed because of the race condition between both claimtxmanagers (network 1 and network 2). Both claimTxManagers + // run at the same time and network 2 checks if there are some deposit ready for claim before the dbTx of + // claimTxManager (network 1) is commited. With this second deposit we force another ger and claimTxManager rechecks + // if there is some L2Deposit for claim. + err = opsman1.SendL2Deposit(ctx, tokenAddr, amount, 0, &address, operations.L22) + require.NoError(t, err) + // Wait until the claimTxManager claims the first deposit. + time.Sleep(30 * time.Second) + + // Check destination L2 funds to see if the amount has been increased + balance, err = opsman2.CheckAccountBalance(ctx, operations.L2, &address) + require.NoError(t, err) + require.Equal(t, -1, v.Cmp(balance)) + // Check origin L2 funds to see that the amount has been reduced + balance, err = opsman1.CheckAccountBalance(ctx, operations.L2, &address) + require.NoError(t, err) + require.Equal(t, 1, v.Cmp(balance)) + }) +} diff --git a/test/e2e/l2_l2_test.go b/test/e2e/l2_l2_test.go index f32e347d..1d7dc80b 100644 --- a/test/e2e/l2_l2_test.go +++ b/test/e2e/l2_l2_test.go @@ -60,7 +60,7 @@ func TestL2L2(t *testing.T) { // Check L2 destination funds balance, err := opsman2.CheckAccountBalance(ctx, operations.L2, &address) require.NoError(t, err) - v, _ := big.NewInt(0).SetString("99999999209233000000000", 10) + v, _ := big.NewInt(0).SetString("99999999216985000000000", 10) t.Log("balance: ", balance) require.Equal(t, 0, v.Cmp(balance)) // Get the claim data diff --git a/test/scripts/deployclaimcompressor/main.go b/test/scripts/deployclaimcompressor/main.go index 2344e0cf..0c38923d 100644 --- a/test/scripts/deployclaimcompressor/main.go +++ b/test/scripts/deployclaimcompressor/main.go @@ -89,6 +89,7 @@ func deploy(ctx *cli.Context) error { log.Error("Error: ", err) return err } + log.Debug("networkID: ", networkID) log.Debug("auth.From: ", auth.From) balance, err := c.Client.BalanceAt(ctx.Context, auth.From, nil) if err != nil { diff --git a/test/scripts/initialClaim/main.go b/test/scripts/initialClaim/main.go index 3bcf204a..667b8b41 100644 --- a/test/scripts/initialClaim/main.go +++ b/test/scripts/initialClaim/main.go @@ -114,12 +114,7 @@ func main() { if err != nil { log.Fatal("Error: ", err) } - // Get RollupID - rollupID, err := polygonRollupManager.RollupAddressToID(&bind.CallOpts{Pending: false}, polygonRollupManagerAddress) - if err != nil { - log.Fatal("Error: ", err) - } - tx, err := c.BuildSendClaim(ctx, &e, smtProof, smtRollupProof, globalExitRoot, 0, 0, l2GasLimit, rollupID, auth) + tx, err := c.BuildSendClaim(ctx, &e, smtProof, smtRollupProof, globalExitRoot, 0, 0, l2GasLimit, auth) if err != nil { log.Fatal("error: ", err) } diff --git a/utils/client.go b/utils/client.go index 5ca7bf17..8edf5599 100644 --- a/utils/client.go +++ b/utils/client.go @@ -206,7 +206,7 @@ func (c *Client) SendBridgeMessage(ctx context.Context, destNetwork uint32, dest } // BuildSendClaim builds a tx data to be sent to the bridge method SendClaim. -func (c *Client) BuildSendClaim(ctx context.Context, deposit *etherman.Deposit, smtProof [mtHeight][keyLen]byte, smtRollupProof [mtHeight][keyLen]byte, globalExitRoot *etherman.GlobalExitRoot, nonce, gasPrice int64, gasLimit uint64, rollupID uint32, auth *bind.TransactOpts) (*types.Transaction, error) { +func (c *Client) BuildSendClaim(ctx context.Context, deposit *etherman.Deposit, smtProof [mtHeight][keyLen]byte, smtRollupProof [mtHeight][keyLen]byte, globalExitRoot *etherman.GlobalExitRoot, nonce, gasPrice int64, gasLimit uint64, auth *bind.TransactOpts) (*types.Transaction, error) { opts := *auth opts.NoSend = true // force nonce, gas limit and gas price to avoid querying it from the chain @@ -219,7 +219,10 @@ func (c *Client) BuildSendClaim(ctx context.Context, deposit *etherman.Deposit, err error ) mainnetFlag := deposit.NetworkID == 0 - rollupIndex := rollupID - 1 + var rollupIndex uint32 + if !mainnetFlag { + rollupIndex = deposit.NetworkID - 1 + } localExitRootIndex := deposit.DepositCount globalIndex := etherman.GenerateGlobalIndex(mainnetFlag, rollupIndex, localExitRootIndex) if deposit.LeafType == LeafTypeAsset {