Skip to content

Conversation

@rob-stacks
Copy link
Contributor

@rob-stacks rob-stacks commented Dec 1, 2025

Description

This patch introduces a new (protected) endpoint based on the block_replay, able to "simulate" a block (at a specific height) with a brand new set of transactions.

Transactions have to be passed as the HTTP body as a json array of hex strings (the serialized transaction).

The output is the same structure of the block replay endpoint. (so events and results are included)

This endpoint can be used for quick testing of contracts deploys/calls, or for reproducing specific scenarios in security checks/auditing.

The profiler feature of the block_replay is included too (only for linux x86-64)

Applicable issues

Additional info (benefits, drawbacks, caveats)

The patch refactors the block-replay endpoint too for allowing sharing of code between the two (replay and simulation).

A new option "disable_fees" has been added to the endpoint for allowing transactions to be executed without accounting for fees. This is is useful for those situation where the sender of a simulated transaction cannot get STXs assigned easily (for example when it is randomly generated)

Checklist

  • Test coverage for new or modified code paths
  • Changelog is updated
  • Required documentation changes (e.g., docs/rpc/openapi.yaml and rpc-endpoints.md for v2 endpoints, event-dispatcher.md for new events)
  • New clarity functions have corresponding PR in clarity-benchmarking repo

@codecov
Copy link

codecov bot commented Dec 15, 2025

Codecov Report

❌ Patch coverage is 53.05785% with 284 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.16%. Comparing base (3da96c1) to head (a2232de).

Files with missing lines Patch % Lines
stackslib/src/net/api/blocksimulate.rs 17.14% 145 Missing ⚠️
stackslib/src/net/api/tests/blocksimulate.rs 58.43% 101 Missing ⚠️
stackslib/src/net/api/blockreplay.rs 80.23% 33 Missing ⚠️
stackslib/src/chainstate/stacks/db/mod.rs 0.00% 3 Missing ⚠️
stackslib/src/chainstate/stacks/db/transactions.rs 75.00% 2 Missing ⚠️

❌ Your project check has failed because the head coverage (63.16%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

❗ There is a different number of reports uploaded between BASE (3da96c1) and HEAD (a2232de). Click for more details.

HEAD has 32 uploads less than BASE
Flag BASE (3da96c1) HEAD (a2232de)
88 56
Additional details and impacted files
@@             Coverage Diff              @@
##           develop    #6724       +/-   ##
============================================
- Coverage    78.18%   63.16%   -15.02%     
============================================
  Files          580      582        +2     
  Lines       361096   361566      +470     
============================================
- Hits        282312   228373    -53939     
- Misses       78784   133193    +54409     
Files with missing lines Coverage Δ
stackslib/src/clarity_vm/clarity.rs 80.69% <100.00%> (-12.48%) ⬇️
stackslib/src/net/api/mod.rs 93.33% <100.00%> (+0.18%) ⬆️
stackslib/src/net/api/tests/mod.rs 92.83% <ø> (-5.00%) ⬇️
stackslib/src/chainstate/stacks/db/transactions.rs 76.00% <75.00%> (-20.95%) ⬇️
stackslib/src/chainstate/stacks/db/mod.rs 82.80% <0.00%> (-2.00%) ⬇️
stackslib/src/net/api/blockreplay.rs 82.63% <80.23%> (-4.02%) ⬇️
stackslib/src/net/api/tests/blocksimulate.rs 58.43% <58.43%> (ø)
stackslib/src/net/api/blocksimulate.rs 17.14% <17.14%> (ø)

... and 401 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3da96c1...a2232de. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

debug!("Process transaction {} ({})", tx.txid(), tx.payload.name());
let epoch = clarity_block.get_epoch();

let no_fees = clarity_block.block.no_fees;
Copy link
Member

Choose a reason for hiding this comment

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

Correct me if I'm wrong, but the purpose of this endpoint is to faithfully re-execute a block. The block will almost certainly contain transactions for transferring assets between accounts (including STX). Disabling fee payment along with the commensurate nonce increment would likely invalidate or otherwise alter the execution of transactions, leading to an unfaithful block re-execution.

Can you help me understand what purpose is served by this feature?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The block simulator allows you to execute "brand-new" transactions in a block (mainly as a quick-test mechanism). The (current) main usage is to run contract deploys and calls at specific heights (for example i am using it as the base for some integration tests for the python bindings). It happens sometime (especially when randomly generating keys) that having STXs is convoluted (in practice you are running your functions in the past). For this reason having the ability to run stuff "for free" is quite handy. Obviously if it does pose some risk it is definitely a feature that can be removed without harming the main goal of the patch.

@rob-stacks rob-stacks marked this pull request as ready for review December 17, 2025 12:28
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.

2 participants