Skip to content

Add /v3/contracts/fast-call-read endpoint for (authorized) read only calls without cost tracking #6207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jul 9, 2025

Conversation

rdeioris
Copy link
Contributor

@rdeioris rdeioris commented Jun 17, 2025

This patch adds a new endpoint /v3/contracts/fast-call-read allowing read-only calls to be executed without the cost-tracker.

Given that cost tracking for readonly calls is here mostly for security reasons (avoid run-away calls), the max_execution_time feature of contract calls is automatically enabled (default 30 seconds) and HTTP authorization is required too (not setting the auth-token will basically disable this endpoint) .

The max_execution_time can be configured with the read_only_max_execution_time_secs connection options:

[connection_options]
read_only_max_execution_time_secs = 40

The main reason for this feature is to improve performance of readonly calls (the default cost tracker linearly increases execution times based on the clarity code complexity).

Description

Applicable issues

Additional info (benefits, drawbacks, caveats)

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
  • New integration test(s) added to bitcoin-tests.yml

@rdeioris rdeioris marked this pull request as ready for review June 17, 2025 10:16
@rdeioris rdeioris requested review from a team as code owners June 17, 2025 10:16
@aldur aldur added this to the 3.1.0.0.13 milestone Jun 17, 2025
@aldur aldur requested review from Jiloc and kantai June 17, 2025 15:09
@aldur aldur moved this to Status: In Review in Stacks Core Eng Jun 17, 2025
@rdeioris
Copy link
Contributor Author

@kantai as discussed in the nakameeting it does not make too much sense to allow the user to decide about the cost tracking strategy. At this point is not better to just use free cost tracking and enforce max_execution time ? this will result in faster readonly calls "by default" and zero work for builders/users

Copy link
Contributor

@Jiloc Jiloc left a comment

Choose a reason for hiding this comment

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

If I am not mistaken, the FreeCostTracker doesn't even track memory usage. Could a read-only operation potentially consume significant memory? If so, we might consider implementing a third cost tracker option, something like "MemoryOnly"—that would track memory consumption while still returning zero for runtime costs.

Regarding how to handle the choice between Limited and MemoryOnly trackers: since using FreeTracker can be a security risk, we could restrict the cost_tracker= parameter to authenticated requests only (similar to our current implementation in /v3/block_proposal and /v3/blocks/upload). This would allow trusted clients to specify their preferred tracker while forcing untrusted clients to use the Limited tracker by default

@kantai kantai moved this from Status: In Review to Status: 💻 In Progress in Stacks Core Eng Jun 24, 2025
@rdeioris rdeioris changed the title Allow to set the cost tracking policy when doing readonly calls via RPC Add /v3/contracts/fast-call-read endpoint for (authorized) read only calls wthotu cost tracking Jun 27, 2025
@rdeioris rdeioris changed the title Add /v3/contracts/fast-call-read endpoint for (authorized) read only calls wthotu cost tracking Add /v3/contracts/fast-call-read endpoint for (authorized) read only calls without cost tracking Jun 27, 2025
@rdeioris rdeioris moved this from Status: 💻 In Progress to Status: In Review in Stacks Core Eng Jun 27, 2025
@obycode obycode modified the milestones: 3.1.0.0.13, 3.1.0.0.14 Jul 1, 2025
@rdeioris rdeioris requested a review from a team as a code owner July 2, 2025 14:39
@aldur aldur requested a review from obycode July 3, 2025 14:54
@rdeioris rdeioris requested review from obycode and Jiloc July 8, 2025 10:27
Copy link
Contributor

@Jiloc Jiloc left a comment

Choose a reason for hiding this comment

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

Just missing the timeout error in the open api spec, everything else lgtm!

Copy link
Contributor

@Jiloc Jiloc left a comment

Choose a reason for hiding this comment

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

lgtm!

Copy link
Contributor

@obycode obycode left a comment

Choose a reason for hiding this comment

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

LGTM!

@github-project-automation github-project-automation bot moved this from Status: In Review to Status: 💻 In Progress in Stacks Core Eng Jul 8, 2025
@rdeioris rdeioris added this pull request to the merge queue Jul 9, 2025
Merged via the queue into stacks-network:develop with commit c76743e Jul 9, 2025
236 of 240 checks passed
@rdeioris rdeioris deleted the feat/zerocost_readonly branch July 9, 2025 04:31
@github-project-automation github-project-automation bot moved this from Status: 💻 In Progress to Status: ✅ Done in Stacks Core Eng Jul 9, 2025
Copy link

codecov bot commented Jul 9, 2025

Codecov Report

Attention: Patch coverage is 89.29889% with 58 lines in your changes missing coverage. Please review.

Project coverage is 76.63%. Comparing base (bc58a1e) to head (997c318).
Report is 19 commits behind head on develop.

Files with missing lines Patch % Lines
stackslib/src/net/api/tests/fastcallreadonly.rs 87.80% 30 Missing ⚠️
stackslib/src/net/api/fastcallreadonly.rs 91.30% 20 Missing ⚠️
stackslib/src/net/http/error.rs 52.94% 8 Missing ⚠️

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

Additional details and impacted files
@@             Coverage Diff              @@
##           develop    #6207       +/-   ##
============================================
+ Coverage    45.49%   76.63%   +31.13%     
============================================
  Files          536      543        +7     
  Lines       343845   345656     +1811     
  Branches         0      323      +323     
============================================
+ Hits        156439   264896   +108457     
+ Misses      187406    80752   -106654     
- Partials         0        8        +8     
Files with missing lines Coverage Δ
stackslib/src/config/mod.rs 70.80% <100.00%> (+20.77%) ⬆️
stackslib/src/net/api/callreadonly.rs 93.27% <ø> (+27.80%) ⬆️
stackslib/src/net/api/mod.rs 92.42% <100.00%> (+0.48%) ⬆️
stackslib/src/net/api/tests/mod.rs 89.22% <100.00%> (+9.80%) ⬆️
stackslib/src/net/connection.rs 79.02% <100.00%> (+23.70%) ⬆️
stackslib/src/net/http/mod.rs 51.02% <ø> (+6.12%) ⬆️
stackslib/src/net/httpcore.rs 81.88% <100.00%> (+8.76%) ⬆️
stackslib/src/net/http/error.rs 50.37% <52.94%> (+0.58%) ⬆️
stackslib/src/net/api/fastcallreadonly.rs 91.30% <91.30%> (ø)
stackslib/src/net/api/tests/fastcallreadonly.rs 87.80% <87.80%> (ø)

... and 427 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 bc58a1e...997c318. 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

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
Status: Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

4 participants