diff --git a/claimtxman/claimtxman.go b/claimtxman/claimtxman.go index 5d3e16b80..a7bf94d16 100644 --- a/claimtxman/claimtxman.go +++ b/claimtxman/claimtxman.go @@ -205,6 +205,48 @@ func (tm *ClaimTxManager) getDeposits(ger *etherman.GlobalExitRoot) ([]*etherman return deposits, nil } +func (tm *ClaimTxManager) handleDeposit(deposit *etherman.Deposit, dbTx pgx.Tx) (error, bool) { + claimHash, err := tm.bridgeService.GetDepositStatus(tm.ctx, deposit.DepositCount, deposit.DestinationNetwork) + if err != nil { + log.Errorf("error getting deposit status for deposit %d. Error: %v", deposit.DepositCount, err) + tm.rollbackStore(dbTx) + return err, false + } + if len(claimHash) > 0 || deposit.LeafType == LeafTypeMessage && !tm.isDepositMessageAllowed(deposit) { + log.Infof("Ignoring deposit: %d, leafType: %d, claimHash: %s, deposit.OriginalAddress: %s", deposit.DepositCount, deposit.LeafType, claimHash, deposit.OriginalAddress.String()) + return nil, true + } + log.Infof("create the claim tx for the deposit %d", deposit.DepositCount) + ger, proves, err := tm.bridgeService.GetClaimProof(deposit.DepositCount, deposit.NetworkID, dbTx) + if err != nil { + log.Errorf("error getting Claim Proof for deposit %d. Error: %v", deposit.DepositCount, err) + tm.rollbackStore(dbTx) + return err, false + } + var mtProves [mtHeight][keyLen]byte + for i := 0; i < mtHeight; i++ { + mtProves[i] = proves[i] + } + tx, err := tm.l2Node.BuildSendClaim(tm.ctx, deposit, mtProves, + ðerman.GlobalExitRoot{ + ExitRoots: []common.Hash{ + ger.ExitRoots[0], + ger.ExitRoots[1], + }}, 1, 1, 1, + tm.auth) + if err != nil { + log.Errorf("error BuildSendClaim tx for deposit %d. Error: %v", deposit.DepositCount, err) + tm.rollbackStore(dbTx) + return err, false + } + if err = tm.addClaimTx(deposit.DepositCount, tm.auth.From, tx.To(), nil, tx.Data(), dbTx); err != nil { + log.Errorf("error adding claim tx for deposit %d. Error: %v", deposit.DepositCount, err) + tm.rollbackStore(dbTx) + return err, false + } + return nil, false +} + func (tm *ClaimTxManager) processDepositStatusL1(ger *etherman.GlobalExitRoot) error { deposits, err := tm.getDeposits(ger) if err != nil { @@ -217,44 +259,12 @@ func (tm *ClaimTxManager) processDepositStatusL1(ger *etherman.GlobalExitRoot) e if err != nil { return err } - claimHash, err := tm.bridgeService.GetDepositStatus(tm.ctx, deposit.DepositCount, deposit.DestinationNetwork) - if err != nil { - log.Errorf("error getting deposit status for deposit %d. Error: %v", deposit.DepositCount, err) - tm.rollbackStore(dbTx) + + if err, ctn := tm.handleDeposit(deposit, dbTx); err != nil { return err - } - if len(claimHash) > 0 || deposit.LeafType == LeafTypeMessage && !tm.isDepositMessageAllowed(deposit) { - log.Infof("Ignoring deposit: %d, leafType: %d, claimHash: %s, deposit.OriginalAddress: %s", deposit.DepositCount, deposit.LeafType, claimHash, deposit.OriginalAddress.String()) + } else if ctn { continue } - log.Infof("create the claim tx for the deposit %d", deposit.DepositCount) - ger, proves, err := tm.bridgeService.GetClaimProof(deposit.DepositCount, deposit.NetworkID, dbTx) - if err != nil { - log.Errorf("error getting Claim Proof for deposit %d. Error: %v", deposit.DepositCount, err) - tm.rollbackStore(dbTx) - return err - } - var mtProves [mtHeight][keyLen]byte - for i := 0; i < mtHeight; i++ { - mtProves[i] = proves[i] - } - tx, err := tm.l2Node.BuildSendClaim(tm.ctx, deposit, mtProves, - ðerman.GlobalExitRoot{ - ExitRoots: []common.Hash{ - ger.ExitRoots[0], - ger.ExitRoots[1], - }}, 1, 1, 1, - tm.auth) - if err != nil { - log.Errorf("error BuildSendClaim tx for deposit %d. Error: %v", deposit.DepositCount, err) - tm.rollbackStore(dbTx) - return err - } - if err = tm.addClaimTx(deposit.DepositCount, tm.auth.From, tx.To(), nil, tx.Data(), dbTx); err != nil { - log.Errorf("error adding claim tx for deposit %d. Error: %v", deposit.DepositCount, err) - tm.rollbackStore(dbTx) - return err - } err = tm.storage.Commit(tm.ctx, dbTx) if err != nil { @@ -293,38 +303,7 @@ func (tm *ClaimTxManager) processDepositStatus(ger *etherman.GlobalExitRoot, dbT return err } for _, deposit := range deposits { - claimHash, err := tm.bridgeService.GetDepositStatus(tm.ctx, deposit.DepositCount, deposit.DestinationNetwork) - if err != nil { - log.Errorf("error getting deposit status for deposit %d. Error: %v", deposit.DepositCount, err) - return err - } - if len(claimHash) > 0 || deposit.LeafType == LeafTypeMessage && !tm.isDepositMessageAllowed(deposit) { - log.Infof("Ignoring deposit: %d, leafType: %d, claimHash: %s, deposit.OriginalAddress: %s", deposit.DepositCount, deposit.LeafType, claimHash, deposit.OriginalAddress.String()) - continue - } - log.Infof("create the claim tx for the deposit %d", deposit.DepositCount) - ger, proves, err := tm.bridgeService.GetClaimProof(deposit.DepositCount, deposit.NetworkID, dbTx) - if err != nil { - log.Errorf("error getting Claim Proof for deposit %d. Error: %v", deposit.DepositCount, err) - return err - } - var mtProves [mtHeight][keyLen]byte - for i := 0; i < mtHeight; i++ { - mtProves[i] = proves[i] - } - tx, err := tm.l2Node.BuildSendClaim(tm.ctx, deposit, mtProves, - ðerman.GlobalExitRoot{ - ExitRoots: []common.Hash{ - ger.ExitRoots[0], - ger.ExitRoots[1], - }}, 1, 1, 1, - tm.auth) - if err != nil { - log.Errorf("error BuildSendClaim tx for deposit %d. Error: %v", deposit.DepositCount, err) - return err - } - if err = tm.addClaimTx(deposit.DepositCount, tm.auth.From, tx.To(), nil, tx.Data(), dbTx); err != nil { - log.Errorf("error adding claim tx for deposit %d. Error: %v", deposit.DepositCount, err) + if err, _ := tm.handleDeposit(deposit, dbTx); err != nil { return err } }