Skip to content

Conversation

d4mr
Copy link
Member

@d4mr d4mr commented Sep 14, 2025

  • Moved the cached transaction count update logic to ensure it always executes, regardless of the presence of transactions to confirm.
  • Added error logging for cases where the latest fetched transaction count is lower than the cached count, indicating potential re-orgs or RPC block lag.
  • This change enhances the robustness of transaction management and improves error handling in the EoaExecutorWorker.

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of transaction confirmations by synchronizing the on-chain transaction count earlier in the process.
    • Prevents stale status when no pending transactions exist, ensuring up-to-date confirmation checks in all paths.
    • Maintains error/warning logs when network reorgs or RPC lag are detected, with no change to user-facing messaging.

- Moved the cached transaction count update logic to ensure it always executes, regardless of the presence of transactions to confirm.
- Added error logging for cases where the latest fetched transaction count is lower than the cached count, indicating potential re-orgs or RPC block lag.
- This change enhances the robustness of transaction management and improves error handling in the EoaExecutorWorker.
Copy link

coderabbitai bot commented Sep 14, 2025

Walkthrough

The confirm worker now updates the cached on-chain transaction count at the start of the confirmation flow, before collecting waiting transactions, and removes the previous post-processing cache update. If the latest count is less than the cached value, it logs an error and still updates the cache.

Changes

Cohort / File(s) Summary
EOA confirm flow cache update reordering
executors/src/eoa/worker/confirm.rs
Move chain tx-count cache refresh to the start of the confirm routine; remove the later, redundant refresh. Preserve error logging for latest < cached scenarios. Ensures cache is refreshed even when no pending txs are processed.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant W as ConfirmWorker
  participant C as Cache
  participant R as Chain RPC
  participant Q as PendingTxQueue

  rect rgba(200,230,255,0.25)
  note over W: New flow
  W->>R: fetch latest tx count
  R-->>W: latestCount
  W->>C: read cachedCount
  alt latestCount < cachedCount
    W->>W: log error (reorg/RPC lag)
  end
  W->>C: update cachedCount = latestCount
  W->>Q: gather waiting txs
  W->>R: fetch receipts for waiting txs
  R-->>W: receipts
  W->>W: build confirmation report
  end
Loading
sequenceDiagram
  autonumber
  participant W as ConfirmWorker
  participant C as Cache
  participant R as Chain RPC
  participant Q as PendingTxQueue

  rect rgba(255,240,200,0.25)
  note over W: Old flow
  W->>Q: gather waiting txs
  W->>R: fetch receipts for waiting txs
  R-->>W: receipts
  W->>W: build confirmation report
  W->>R: fetch latest tx count
  R-->>W: latestCount
  W->>C: read cachedCount
  alt latestCount < cachedCount
    W->>W: log error (reorg/RPC lag)
  end
  W->>C: update cachedCount = latestCount
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title accurately and concisely summarizes the main change: a refactor of the transaction count update logic in EoaExecutorWorker. It names the affected component and highlights the core behavioral change, making the intent clear to reviewers. The phrasing is specific and free of noisy or generic wording.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pb/always-update-cached-tx-count

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Comment @coderabbitai help to get the list of available commands and usage tips.

@d4mr d4mr merged commit f649ddb into main Sep 14, 2025
2 of 3 checks passed
@d4mr d4mr deleted the pb/always-update-cached-tx-count branch September 14, 2025 23:21
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
executors/src/eoa/worker/confirm.rs (2)

152-159: Enrich error log context (EOA, chain_id) and tighten wording.

Adding identifiers makes incidents actionable; small grammar fixes improve clarity.

-                tracing::error!(
-                    current_chain_transaction_count = transaction_counts.latest,
-                    cached_transaction_count = cached_transaction_count,
-                    "Fresh fetched chain transaction count is lower than cached transaction count. \
-                    This indicates a re-org or RPC block lag. Engine will use the newest fetched transaction count from now (assuming re-org).\
-                    Transactions already confirmed will not be attempted again, even if their nonce was higher than the new chain transaction count.
-                    In case this is RPC misbehaviour not reflective of actual chain state, Engine's nonce management might be affected."
-                );
+                tracing::error!(
+                    eoa = ?self.eoa,
+                    chain_id = self.chain_id,
+                    current_chain_transaction_count = transaction_counts.latest,
+                    cached_transaction_count = cached_transaction_count,
+                    "Freshly fetched chain transaction count is lower than cached transaction count. \
+                    This indicates a re-org or RPC block lag. Engine will use the newly fetched transaction count from now (assuming re-org). \
+                    Transactions already confirmed will not be attempted again, even if their nonce was higher than the new chain transaction count. \
+                    If this reflects RPC misbehaviour (not actual chain state), Engine's nonce management might be affected."
+                );

162-165: Add a post-update debug log for before/after values.

Helps correlate incidents without re-reading store state.

             self.store
                 .update_cached_transaction_count(transaction_counts.latest)
                 .await?;
+            tracing::debug!(
+                cached_transaction_count_before = cached_transaction_count,
+                cached_transaction_count_after = transaction_counts.latest,
+                "Updated cached transaction count"
+            );
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3c8240e and 646d63c.

📒 Files selected for processing (1)
  • executors/src/eoa/worker/confirm.rs (1 hunks)
🔇 Additional comments (2)
executors/src/eoa/worker/confirm.rs (2)

149-165: Always-update cached tx count before scanning waiting txs — good change.

This fixes the early-return stale-cache path and surfaces nonce regressions.


149-165: No duplicate cached tx-count updates remain; only the initial sync and the intended update exist.

Found calls at executors/src/eoa/worker/confirm.rs:64 (initial "Nonce sync required" branch) and executors/src/eoa/worker/confirm.rs:163 (current always-update block); function defined at executors/src/eoa/store/atomic.rs:410. No other occurrences detected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant