diff --git a/internal/handler/frontend_move.go b/internal/handler/frontend_move.go index 5d7aff7..43a6aa2 100644 --- a/internal/handler/frontend_move.go +++ b/internal/handler/frontend_move.go @@ -138,9 +138,9 @@ func (h *FrontendMoveHandler) monitorTransactionStatus(recordID int64, txHash st log.Infof("[FrontendMoveHandler] Transaction %s status updated to %s", txHash, status) // If transaction is successful, mark related records - if receipt.Status == 1 { - h.markRelatedRecords(txHash, receipt.BlockNumber.Int64()) - } + // if receipt.Status == 1 { + // h.markRelatedRecords(txHash, receipt.BlockNumber.Int64()) + // } return } @@ -159,7 +159,7 @@ func (h *FrontendMoveHandler) monitorTransactionStatus(recordID int64, txHash st log.Warnf("[FrontendMoveHandler] Transaction %s monitoring timeout", txHash) } -// markRelatedRecords marks related block and event records +//nolint:unused func (h *FrontendMoveHandler) markRelatedRecords(txHash string, blockNumber int64) { // Mark related blocks err := h.svc.DB.Model(&schema.DisputeGame{}). diff --git a/internal/handler/syncFrontendMove.go b/internal/handler/syncFrontendMove.go index 1056c4c..8f6e48b 100644 --- a/internal/handler/syncFrontendMove.go +++ b/internal/handler/syncFrontendMove.go @@ -1,6 +1,7 @@ package handler import ( + "fmt" "time" "github.com/optimism-java/dispute-explorer/internal/schema" @@ -43,10 +44,12 @@ func processFrontendMoveTransactions(ctx *svc.ServiceContext) error { for i := range unsyncedTransactions { transaction := &unsyncedTransactions[i] - err := syncSingleTransaction(ctx, transaction) - if err != nil { - log.Errorf("[Handler.SyncFrontendMoveTransactions] Failed to sync transaction %s: %s", transaction.TxHash, err) - continue + if transaction.Status == schema.FrontendMoveStatusConfirmed { + err := syncSingleTransaction(ctx, transaction) + if err != nil { + log.Errorf("[Handler.SyncFrontendMoveTransactions] Failed to sync transaction %s: %s", transaction.TxHash, err) + continue + } } } @@ -72,12 +75,19 @@ func syncSingleTransaction(ctx *svc.ServiceContext, transaction *schema.Frontend } // 2. update game_claim_data is_from_frontend column to true - err = tx.Model(&schema.GameClaimData{}). + result := tx.Model(&schema.GameClaimData{}). Where("game_contract = ? AND parent_index = ?", transaction.GameContract, transaction.ParentIndex). - Update("is_from_frontend", true).Error - if err != nil { + Update("is_from_frontend", true) + if result.Error != nil { tx.Rollback() - return err + return result.Error + } + + if result.RowsAffected == 0 { + tx.Rollback() + log.Warnf("[Handler.SyncFrontendMoveTransactions] No matching game_claim_data found for transaction %s (game: %s, parent_index: %s), will retry later", + transaction.TxHash, transaction.GameContract, transaction.ParentIndex) + return fmt.Errorf("no matching game_claim_data found, will retry later") } // 3. update frontend_move_transactions is_synced column to true