Skip to content

feat: Treat already-monitored GER tx as expected #1490#1503

Merged
joanestebanr merged 2 commits intodevelopfrom
feat/aggoracle_already_monitored_GER-1490
Mar 2, 2026
Merged

feat: Treat already-monitored GER tx as expected #1490#1503
joanestebanr merged 2 commits intodevelopfrom
feat/aggoracle_already_monitored_GER-1490

Conversation

@joanestebanr
Copy link
Copy Markdown
Collaborator

@joanestebanr joanestebanr commented Mar 2, 2026

@joanestebanr joanestebanr self-assigned this Mar 2, 2026
@claude
Copy link
Copy Markdown

claude Bot commented Mar 2, 2026

Claude finished @joanestebanr's task in 1m 12s —— View job


📋 Code Review Complete ✅


🚀 What's New

This PR improves error handling in the GER (Global Exit Root) transaction submission logic to properly handle the ErrAlreadyExists case. When a transaction already exists in the monitoring database, the code now continues monitoring instead of failing immediately, and logs an appropriate message to distinguish between newly submitted transactions and already-monitored ones.

🐛 Bug Fixes

  • Fixed GER transaction monitoring for duplicate submissions: Previously, when ethTxMan.Add() returned ErrAlreadyExists, the function would fail with an error. Now it correctly continues monitoring the existing transaction until it's mined, which prevents unnecessary failures when the same GER is submitted multiple times.

📋 Config Updates

None.

⚠️ Breaking Changes

None.


Code Review Feedback

✅ Overall Assessment

This is a good bug fix that addresses a real issue with the transaction monitoring logic. The code changes are minimal, focused, and well-tested. The test coverage for the new case is excellent.

Code Quality & Best Practices

🟢 Positive Observations:

  1. Excellent test coverage: The new test case TestEVMChainGERSender_SubmitTransaction includes a specific scenario for ErrAlreadyExists, ensuring the fix is properly validated.
  2. Clear error handling: The refactored error handling logic properly distinguishes between three cases: success, already exists, and actual errors.
  3. Appropriate logging: Different log messages for new submissions vs. already-existing transactions help with debugging.
  4. Import hygiene: Correctly added the errors import to handle errors.Is().

🟡 Suggested Improvements:

  1. Logic flow could be simplified (aggoracle/chaingersender/evm.go:231-240)

    The current implementation has a slightly awkward flow with two separate if err != nil blocks. Consider this cleaner approach:

    id, err := c.ethTxMan.Add(ctx, targetAddr, common.Big0, txInput, c.gasOffset, nil)
    if err != nil {
        if errors.Is(err, ethtxmanager.ErrAlreadyExists) {
            c.logger.Infof("%s GER transaction already exists in monitoring DB with ID: %s. GER: %s", action, id.Hex(), ger.Hex())
        } else {
            return fmt.Errorf("failed to add %s GER transaction: %w", action, err)
        }
    } else {
        c.logger.Infof("%s GER transaction submitted with ID: %s. GER: %s", action, id.Hex(), ger.Hex())
    }

    This structure is more conventional: check for error first, handle the special case, then handle the success case. It eliminates the need to check if err != nil twice.

  2. Test naming convention (aggoracle/chaingersender/evm_test.go:397)

    The test case name is quite long: "ErrAlreadyExists is not an error - monitoring continues until mined". Consider shortening to: "transaction already exists - continues monitoring" for consistency with other test names in the file.

Security & Performance

✅ No security issues identified. The error handling change doesn't introduce any security vulnerabilities.

✅ No performance concerns. The change has negligible performance impact.

Correctness Analysis

🟢 Logic is correct: The fix properly handles the ErrAlreadyExists case by:

  1. Not treating it as a fatal error (continues execution)
  2. Logging appropriately to distinguish from new submissions
  3. Continuing to monitor the transaction until completion

One potential consideration:

🟡 Return value when ErrAlreadyExists (aggoracle/chaingersender/evm.go:231)

When ethTxMan.Add() returns ErrAlreadyExists, the id variable should still contain the transaction ID of the existing transaction (based on the test expectations at line 401). However, it would be good to verify this assumption is documented in the EthTxManager interface or implementation. If id could potentially be empty/zero when ErrAlreadyExists is returned, calling id.Hex() at line 239 could log a zero hash, which might be confusing.

Consider adding a defensive check:

if err != nil {
    if errors.Is(err, ethtxmanager.ErrAlreadyExists) {
        if id != (common.Hash{}) {
            c.logger.Infof("%s GER transaction already exists in monitoring DB with ID: %s. GER: %s", action, id.Hex(), ger.Hex())
        } else {
            c.logger.Warnf("%s GER transaction already exists in monitoring DB but ID not returned. GER: %s", action, ger.Hex())
        }
    } else {
        return fmt.Errorf("failed to add %s GER transaction: %w", action, err)
    }
}

However, if the contract guarantees id is always returned with ErrAlreadyExists, the current implementation is fine.


Summary

This PR effectively fixes a bug where duplicate GER transaction submissions would cause failures instead of continuing to monitor the existing transaction. The changes are well-tested and follow Go best practices. The suggested improvements are minor style/clarity enhancements that don't affect correctness.

Recommendation:Approve with optional minor refinements

@joanestebanr joanestebanr changed the title feat: cherry-pick #1490 and add unittest feat: cherry-pick #1490 to avoid logging an error if a tx for GER is already in DB Mar 2, 2026
@joanestebanr joanestebanr marked this pull request as ready for review March 2, 2026 11:49
@joanestebanr joanestebanr changed the title feat: cherry-pick #1490 to avoid logging an error if a tx for GER is already in DB feat: Treat already-monitored GER tx as expected #1490 Mar 2, 2026
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Mar 2, 2026

@joanestebanr joanestebanr merged commit 9eaeaa1 into develop Mar 2, 2026
24 of 25 checks passed
@joanestebanr joanestebanr deleted the feat/aggoracle_already_monitored_GER-1490 branch March 2, 2026 13:22
joanestebanr added a commit that referenced this pull request Mar 27, 2026
## 🔄 Changes Summary

Cherry-pick of #1503 and #1557 into \`release/0.8\`

### #1503 - Treat already-monitored GER tx as expected
- Treats \`ErrAlreadyExists\` from \`ethtxmanager\` as expected behavior
(not an error) in \`submitTransaction\`
- Updates \`zkevm-ethtx-manager\` from v0.2.17 to v0.2.18

### #1557 - Adjust REST timeouts
- Increases \`defaultDBQueryTimeout\` from \`60s\` to \`5m\`
- Increases REST server \`ReadTimeout\` and \`WriteTimeout\` from \`2s\`
to \`5m\`
- Motivation: previous values were too short for slow queries and
long-running REST requests (e.g. aggchain proof generation can take up
to 1h)

## ⚠️ Breaking Changes
None

## 📋 Config Updates
- \`defaultDBQueryTimeout\`: \`60s\` → \`5m\`
- \`REST.ReadTimeout\` / \`REST.WriteTimeout\`: \`2s\` → \`5m\`

## ✅ Testing
- 🤖 **Automatic**: Unittest

## 🐞 Issues
- Related: #1503, #1490, #1557, #1540

## 🔗 Related PRs
- #1503 (cherry-pick against \`develop\`)
- #1557 (cherry-pick against \`develop\`)

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: convert Error failed to add propose GER transaction: failed to add tx to get monitored: already exists into Info

2 participants