Skip to content

Merge the 2 Cadence transactions files into a single one - #897

Merged
m-Peter merged 1 commit into
mainfrom
mpeter/merge-cadence-transactions
Oct 10, 2025
Merged

Merge the 2 Cadence transactions files into a single one#897
m-Peter merged 1 commit into
mainfrom
mpeter/merge-cadence-transactions

Conversation

@m-Peter

@m-Peter m-Peter commented Oct 9, 2025

Copy link
Copy Markdown
Collaborator

Description

The 2 Cadence transactions: run.cdc & batch_run.cdc can be merged into a single Cadence transaction, to avoid having to update 2 separate files, when changing the logic.


For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Summary by CodeRabbit

  • New Features

    • Unified transaction execution now accepts multiple hex-encoded transactions in a single request, handling both single and batch runs seamlessly.
  • Bug Fixes

    • Improved error handling for batch executions: operation succeeds if any transaction runs (failed or successful) and provides clearer errors when all are invalid.
  • Refactor

    • Consolidated batch execution into the standard transaction flow for a simpler, consistent submission experience.
  • Chores

    • Removed deprecated batch transaction script to reduce redundancy.

@coderabbitai

coderabbitai Bot commented Oct 9, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Consolidates transaction execution into run.cdc by accepting an array of hex-encoded transactions. Removes batch_run.cdc and updates Go pools to pass array args and reference run.cdc. Adjusts embedding to drop batch_run.cdc. BatchTxPool now invokes run.cdc; SingleTxPool wraps single tx in a Cadence array.

Changes

Cohort / File(s) Summary
Cadence transaction unification
services/requester/cadence/run.cdc, services/requester/cadence/batch_run.cdc
run.cdc now takes [String] and handles single or batch execution via EVM.run/EVM.batchRun with updated assertions; batch_run.cdc removed.
Requester pools argument updates
services/requester/batch_tx_pool.go, services/requester/single_tx_pool.go
Switched script reference from batchRunTxScript to runTxScript. Transaction args changed to pass cadence.Array of hex tx strings for both single and batch submissions.
Embedding cleanup
services/requester/requester.go
Removed embed for batch_run.cdc; other embeds remain.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client
  participant Requester (Go)
  participant Cadence run.cdc
  participant EVM

  Client->>Requester (Go): Submit tx(s)
  Note over Requester (Go): Build Cadence tx<br/>args: [hexEncodedTxs], coinbase
  Requester (Go)->>Cadence run.cdc: execute([hex], coinbase)

  alt exactly one tx
    Cadence run.cdc->>EVM: run(tx, coinbase)
    EVM-->>Cadence run.cdc: txResult
    Cadence run.cdc-->>Requester (Go): assert on status, return
  else multiple txs
    Cadence run.cdc->>EVM: batchRun(txs, coinbase)
    EVM-->>Cadence run.cdc: txResults[]
    alt any result is failed or successful
      Cadence run.cdc-->>Requester (Go): return
    else all invalid
      Cadence run.cdc-->>Requester (Go): assert using first error
    end
  end
  Requester (Go)-->>Client: submission result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • zhangchiqing
  • peterargue

Poem

A whisk of code, a hop so spry,
One path for many—no split to try.
Batch burrow closed, run.cdc the sun,
Arrays of carrots, handled as one.
I thump approval—tidy and bright,
Fewer tunnels, same swift flight. 🥕🐇

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 succinctly describes the PR’s primary change of consolidating two Cadence transaction files into a single file, matching the objective to combine run.cdc and batch_run.cdc. It uses clear and specific language without vague terms, allowing readers to immediately understand the pull request’s intent. The phrasing is concise and avoids unnecessary details, making it a suitable summary.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch mpeter/merge-cadence-transactions

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@m-Peter
m-Peter force-pushed the mpeter/merge-cadence-transactions branch from f54a93b to 3ebc0eb Compare October 9, 2025 07:39

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (1)
services/requester/cadence/run.cdc (1)

3-47: Unified single/batch path LGTM; add a guard for empty input (optional)

Logic mirrors previous semantics: single uses EVM.run with assert; batch uses EVM.batchRun and only fails when all are invalid. Consider guarding against accidental empty input to avoid a no-op submit.

Apply at the start of execute:

 transaction(hexEncodedTxs: [String], coinbase: String) {
     execute {
+        // Guard against accidental empty submissions
+        assert(hexEncodedTxs.length > 0, message: "no_evm_txs_provided")

Optionally, avoid the second pass when all invalid by asserting only on the first item (same behavior, less work):

-        for txResult in txResults {
-            assert(
-                txResult.status == EVM.Status.failed || txResult.status == EVM.Status.successful,
-                message: "evm_error=\(txResult.errorMessage);evm_error_code=\(txResult.errorCode)"
-            )
-        }
+        let first = txResults[0]
+        assert(
+            first.status == EVM.Status.failed || first.status == EVM.Status.successful,
+            message: "evm_error=\(first.errorMessage);evm_error_code=\(first.errorCode)"
+        )
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 25b8222 and 3ebc0eb.

📒 Files selected for processing (5)
  • services/requester/batch_tx_pool.go (2 hunks)
  • services/requester/cadence/batch_run.cdc (0 hunks)
  • services/requester/cadence/run.cdc (1 hunks)
  • services/requester/requester.go (0 hunks)
  • services/requester/single_tx_pool.go (1 hunks)
💤 Files with no reviewable changes (2)
  • services/requester/cadence/batch_run.cdc
  • services/requester/requester.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Test
🔇 Additional comments (3)
services/requester/batch_tx_pool.go (2)

221-228: Switched to runTxScript for batch path — aligned with merged Cadence entrypoint

Using replaceAddresses(runTxScript, ...) is correct given batch_run.cdc removal and the new unified transaction.


257-264: Wrap single tx in an array for submitSingleTransaction — correct for new signature

Passing cadence.NewArray([]cadence.Value{hexEncodedTx}) ensures run.cdc takes the expected [String].

services/requester/single_tx_pool.go (1)

101-108: Arg shape update to array is correct
Ensure no leftover batch_run.cdc or batchRunTxScript references remain and that all runTxScript invocations use cadence.NewArray.

@janezpodhostnik janezpodhostnik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice simplification

@m-Peter
m-Peter force-pushed the mpeter/merge-cadence-transactions branch from 3ebc0eb to 070cab1 Compare October 10, 2025 07:43

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (1)
services/requester/cadence/run.cdc (1)

5-8: Consider using map for cleaner array transformation.

The manual loop works correctly, but Cadence's functional approach would be more idiomatic and concise.

Apply this diff to use map:

-        let txs: [[UInt8]] = []
-        for tx in hexEncodedTxs {
-            txs.append(tx.decodeHex())
-        }
+        let txs: [[UInt8]] = hexEncodedTxs.map(fun (tx: String): [UInt8] {
+            return tx.decodeHex()
+        })
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3ebc0eb and 070cab1.

📒 Files selected for processing (5)
  • services/requester/batch_tx_pool.go (2 hunks)
  • services/requester/cadence/batch_run.cdc (0 hunks)
  • services/requester/cadence/run.cdc (1 hunks)
  • services/requester/requester.go (0 hunks)
  • services/requester/single_tx_pool.go (1 hunks)
💤 Files with no reviewable changes (2)
  • services/requester/cadence/batch_run.cdc
  • services/requester/requester.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • services/requester/batch_tx_pool.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Test
🔇 Additional comments (4)
services/requester/single_tx_pool.go (1)

106-106: LGTM! Single transaction correctly wrapped in array.

The change correctly wraps the single transaction in a Cadence array to align with the updated run.cdc signature that now accepts [String] instead of String.

services/requester/cadence/run.cdc (3)

3-3: LGTM! Signature updated to accept transaction array.

The parameter change from hexEncodedTx: String to hexEncodedTxs: [String] successfully consolidates the single and batch transaction logic into one file, addressing the PR objective of eliminating duplicate files.


12-22: Verify necessity of separate single-transaction path.

The single-transaction path calls EVM.run, while the batch path calls EVM.batchRun. If both produce identical results for single transactions, this branching adds unnecessary complexity.

Please confirm whether:

  1. EVM.run and EVM.batchRun(txs: [singleTx], ...) have different gas costs or behavior
  2. This optimization is measurable and justified

If the behaviors are identical, consider simplifying by always using EVM.batchRun, which would eliminate lines 12-22 and reduce code paths.


24-47: Verify handling of empty transaction array. If hexEncodedTxs can be empty, EVM.batchRun returns an empty txResults, both loops are skipped, and the Cadence transaction succeeds silently. Ensure Go callers never pass an empty slice or add an explicit Cadence check, for example:

assert(txResults.length > 0, message: "no transactions provided")

@m-Peter
m-Peter merged commit c8b1afc into main Oct 10, 2025
2 checks passed
@m-Peter
m-Peter deleted the mpeter/merge-cadence-transactions branch October 10, 2025 07:49
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.

2 participants