Skip to content

Conversation

@rob-stacks
Copy link
Contributor

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

Description

This patch adds the list of events generated by read-only calls to the output of the readonly endpoints (base and fast).

This is the example output for a simple function:

(define-read-only (printer)
        (begin
        (print 100)
        (print u1000)
        (print \"test\")
        (print true)
        (ok u1)))
{"events":[{"key":"print","sender":"ST2DS4MSWSGJ3W9FBC6BVT0Y92S345HY8N3T6AV7R.hello-world","value":"0000000000000000000000000000000064"},{"key":"print","sender":"ST2DS4MSWSGJ3W9FBC6BVT0Y92S345HY8N3T6AV7R.hello-world","value":"01000000000000000000000000000003e8"},{"key":"print","sender":"ST2DS4MSWSGJ3W9FBC6BVT0Y92S345HY8N3T6AV7R.hello-world","value":"0d0000000474657374"},{"key":"print","sender":"ST2DS4MSWSGJ3W9FBC6BVT0Y92S345HY8N3T6AV7R.hello-world","value":"03"}],"okay":true,"result":"0x070100000000000000000000000000000001"}

Additional info (benefits, drawbacks, caveats)

The patch includes a refactoring of the two endpoints to share the contract call logic (they differs only for the cost tracker and the max_execution_time)

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

@rob-stacks rob-stacks marked this pull request as ready for review December 5, 2025 14:24
@codecov
Copy link

codecov bot commented Dec 5, 2025

Codecov Report

❌ Patch coverage is 44.08163% with 137 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.98%. Comparing base (3da96c1) to head (68ca702).
⚠️ Report is 68 commits behind head on develop.

Files with missing lines Patch % Lines
stackslib/src/net/api/tests/callreadonly.rs 0.00% 52 Missing ⚠️
stackslib/src/net/api/tests/fastcallreadonly.rs 0.00% 52 Missing ⚠️
stackslib/src/net/api/callreadonly.rs 77.60% 28 Missing ⚠️
clarity/src/vm/contexts.rs 50.00% 3 Missing ⚠️
stackslib/src/net/api/tests/getclaritymetadata.rs 0.00% 2 Missing ⚠️

❌ Your project check has failed because the head coverage (68.98%) 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 (68ca702). Click for more details.

HEAD has 22 uploads less than BASE
Flag BASE (3da96c1) HEAD (68ca702)
88 66
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #6741      +/-   ##
===========================================
- Coverage    78.18%   68.98%   -9.20%     
===========================================
  Files          580      582       +2     
  Lines       361096   361659     +563     
===========================================
- Hits        282312   249497   -32815     
- Misses       78784   112162   +33378     
Files with missing lines Coverage Δ
stackslib/src/net/api/fastcallreadonly.rs 86.95% <100.00%> (-4.33%) ⬇️
stackslib/src/net/api/tests/mod.rs 95.00% <ø> (-2.83%) ⬇️
stackslib/src/net/api/tests/getclaritymetadata.rs 36.44% <0.00%> (-63.56%) ⬇️
clarity/src/vm/contexts.rs 90.91% <50.00%> (-1.32%) ⬇️
stackslib/src/net/api/callreadonly.rs 76.51% <77.60%> (-14.71%) ⬇️
stackslib/src/net/api/tests/callreadonly.rs 23.44% <0.00%> (-70.19%) ⬇️
stackslib/src/net/api/tests/fastcallreadonly.rs 43.87% <0.00%> (-52.00%) ⬇️

... and 343 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...68ca702. 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.

Copy link
Member

@jcnelson jcnelson left a comment

Choose a reason for hiding this comment

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

Please see my earlier comment. There is no need to modify the Clarity VM to get events; the Clarity API already offers a way to return the events directly. It just needs to be used in the RPC endpoint implementation. Thanks!

@rob-stacks rob-stacks requested a review from jcnelson December 12, 2025 15:22
brice-stacks
brice-stacks previously approved these changes Dec 12, 2025
Copy link
Contributor

@brice-stacks brice-stacks left a comment

Choose a reason for hiding this comment

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

LGTM just a nit

Copy link
Contributor

@aaronb-stacks aaronb-stacks left a comment

Choose a reason for hiding this comment

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

This looks good to me, and I definitely prefer this approach to the previous one. The only issue to me is still related to the event rollbacks.

As currently implemented, this endpoint will return events for code which is rolled back. This could be a correctness (and eventually a security) issue for consumers of the endpoint: if they only expect events for "successful" executions, they'd be surprised when events are included for executions which would have been rolled back.

I think this is solvable by expanding the callback trait to have like an on_rollback method. This probably needs a "reason" field so that you can tell if the rollback happened because of a tx abort, or because the read only call is explicitly getting rolled back (which I assume you want to ignore).

Copy link
Contributor

@brice-stacks brice-stacks left a comment

Choose a reason for hiding this comment

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

This looks good to me, pending the solution Aaron mentioned above.

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.

4 participants