Skip to content

feat: add /v3/transactions/simulate endpoint - #7424

Open
brice-stacks wants to merge 16 commits into
stacks-network:mainfrom
brice-stacks:feat/txsimulate
Open

feat: add /v3/transactions/simulate endpoint#7424
brice-stacks wants to merge 16 commits into
stacks-network:mainfrom
brice-stacks:feat/txsimulate

Conversation

@brice-stacks

Copy link
Copy Markdown
Contributor

Added a new authenticated RPC endpoint POST /v3/transactions/simulate which simulates a single transaction on top of the canonical chain tip (discarding all state changes) and reports its result, events, and execution cost.

Applicable issues

Additional info (benefits, drawbacks, caveats)

Checklist

  • Test coverage for new or modified code paths
  • For new Clarity features or consensus changes, add property tests (see docs/property-testing.md)
  • Changelog fragment(s) or "no changelog" label added (see changelog.d/README.md)
  • Required documentation changes (e.g., rpc/openapi.yaml for RPC endpoints, event-dispatcher.md for new events)
  • New clarity functions have corresponding PR in clarity-benchmarking repo

Added a new authenticated RPC endpoint `POST /v3/transactions/simulate`
which simulates a single transaction on top of the canonical chain tip
(discarding all state changes) and reports its result, events, and
execution cost.

Copilot AI 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.

Pull request overview

Adds a new authenticated RPC endpoint to simulate a single signed Stacks transaction against the canonical chain tip, returning the execution result, events, and execution cost without persisting any state.

Changes:

  • Implement POST /v3/transactions/simulate request/response handling and simulation logic in an ephemeral Nakamoto tenure/block context.
  • Register the endpoint in the RPC router and add API tests covering success + auth/nonce failures.
  • Document the endpoint in OpenAPI and add a changelog fragment.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
stackslib/src/net/api/txsimulate.rs Implements the new /v3/transactions/simulate RPC handler, simulation logic, and client request/response helpers.
stackslib/src/net/api/tests/txsimulate.rs Adds tests for request parsing, error cases, and successful simulation behavior.
stackslib/src/net/api/tests/mod.rs Wires the new txsimulate test module into the API test suite.
stackslib/src/net/api/mod.rs Registers the new RPC endpoint in StacksHttp.
docs/rpc/openapi.yaml Documents the new endpoint contract and response shape.
changelog.d/tx-simulate-endpoint.added Changelog entry announcing the new endpoint.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread stackslib/src/net/api/txsimulate.rs Outdated
Comment thread docs/rpc/openapi.yaml
Make `from_receipt` return a `Result` and properly handle a json
serialization failure.

Copilot AI 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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread stackslib/src/net/api/txsimulate.rs Outdated
Comment thread docs/rpc/openapi.yaml

@francesco-stacks francesco-stacks 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.

Overall LGTM, just a couple of points:

  • the OpenAPI CI step is failing
  • could we also add the same memory limit mechanism we use on the miners/signers to guarantee that the transaction we are executing actually stays within the limits and would be accepted by the miners/singers?

Comment thread stackslib/src/net/api/txsimulate.rs Outdated

Copilot AI 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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Comment thread stackslib/src/net/api/tests/txsimulate.rs
Comment thread docs/rpc/openapi.yaml
Comment thread docs/rpc/openapi.yaml Outdated

Copilot AI 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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread stackslib/src/net/api/txsimulate.rs
@coveralls

coveralls commented Jul 21, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 31536447506

Coverage increased (+0.005%) to 86.585%

Details

  • Coverage increased (+0.005%) from the base build.
  • Patch coverage: 54 uncovered changes across 1 file (239 of 293 lines covered, 81.57%).
  • 103 coverage regressions across 24 files.

Uncovered Changes

File Changed Covered %
stackslib/src/net/api/txsimulate.rs 291 237 81.44%
Total (2 files) 293 239 81.57%

Coverage Regressions

103 previously-covered lines in 24 files lost coverage.

Top 10 Files by Coverage Loss Lines Losing Coverage Coverage
stackslib/src/net/p2p.rs 20 74.09%
stackslib/src/net/stackerdb/sync.rs 12 76.57%
stacks-node/src/neon_node.rs 11 83.23%
stacks-common/src/util/pipe.rs 6 89.82%
stacks-signer/src/chainstate/v2.rs 6 88.38%
stackslib/src/chainstate/nakamoto/miner.rs 5 84.22%
stackslib/src/chainstate/nakamoto/mod.rs 5 84.77%
stacks-signer/src/v0/signer_state.rs 5 92.73%
stacks-common/src/deps_common/bitcoin/network/encodable.rs 4 88.71%
stacks-signer/src/client/stacks_client.rs 4 86.76%

Coverage Stats

Coverage Status
Relevant Lines: 233295
Covered Lines: 201999
Line Coverage: 86.59%
Coverage Strength: 19270263.63 hits per line

💛 - Coveralls

@rob-stacks

rob-stacks commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

I like it, given that the block simulation rpc endpoint supports running transactions in any arbitrary block in the chain, can we have the same feature here?

@brice-stacks

Copy link
Copy Markdown
Contributor Author

I like it, given that the block simulation rpc endpoint supports running transactions in any arbitrary block in the chain, can we have the same feature here?

Yup, that should be simple to support the standard tip query parameter that is used everywhere else. I'll add it.

@francesco-stacks francesco-stacks 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.

LGTM!

@brice-stacks

Copy link
Copy Markdown
Contributor Author

@rob-stacks can I get a re-review on this?

@federico-stacks federico-stacks 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.

LGTM! just added a small check.

heads-up: CI is red and the code currently fails to compile (tested locally)

Comment thread stackslib/src/net/api/txsimulate.rs Outdated
@brice-stacks

Copy link
Copy Markdown
Contributor Author

Fixing the errors from upstream changes merged in now.

@francesco-stacks francesco-stacks 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.

LGTM

Separate errors in tx simulation from errors from chainstate.

@federico-stacks federico-stacks 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.

LGTM!

Comment thread docs/rpc/openapi.yaml
Comment on lines +2526 to +2527
the current tenure. The transaction must be fully signed and valid
(correct nonce, sufficient balance for the fee). The simulation

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.

What happens if there is a transaction in the node's mempool for the same nonce, but the fee for the new transaction is too low to be considered a valid RBF?

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.

Transaction simulation endpoint

7 participants