feat(runtime): add promise_yield_create2 host function#15602
Draft
feat(runtime): add promise_yield_create2 host function#15602
Conversation
Introduce a new host function `promise_yield_create2` that allows smart contracts to provide a custom 32-byte yield ID and timeout when creating yield/resume promises. This avoids the storage cost of persisting runtime-generated data IDs for use cases like in-contract mempools. The runtime generates data_id normally and stores bidirectional yield_id <-> data_id mappings in the trie for duplicate detection and cleanup. The derived data_id is written to a register for use with the existing `promise_yield_resume`. Mappings are cleaned up automatically when yields are resumed or time out. Currently only a timeout of 200 blocks is accepted; this will be expanded in a future change. Gated behind the `YieldCreate2` nightly protocol feature (version 153). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Update auto-generated OpenAPI/OpenRPC specs and protocol schema to reflect the new yield_create2_host_fns config field and new TrieKey variants (YieldIdToDataId, DataIdToYieldId). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Update build_chain genesis hash snapshot (config change affects hash) - Update runtime_config_view snapshots with yield_create2_host_fns field - Regenerate 153.json snapshot after rebase onto latest master - Add YieldIdToDataId and DataIdToYieldId intervals to resharding test Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #15602 +/- ##
==========================================
+ Coverage 69.38% 69.40% +0.01%
==========================================
Files 940 940
Lines 212231 212583 +352
Branches 212231 212583 +352
==========================================
+ Hits 147252 147536 +284
- Misses 59125 59173 +48
- Partials 5854 5874 +20
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The previous generation had cargo build stderr mixed into the JSON. Regenerated with stderr redirected. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add VMLogic-level unit tests for promise_yield_create, promise_yield_resume, and promise_yield_create2 covering: - successful create and resume flow - empty method name validation - malformed data_id rejection - unknown data_id resume (returns false) - yield_create2 with valid and invalid yield IDs - yield_create2 timeout validation (only 200 accepted) - view call prohibition Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
promise_yield_create2host function that allows contracts to provide a custom 32-byte yield ID and timeout when creating yield/resume promisesyield_id ↔ data_idmappings in the trie for duplicate detection and cleanup on resume/timeoutYieldCreate2nightly protocol feature (version 153)Motivation
The current
promise_yield_createreturns a runtime-generateddata_idthat contracts must store in state to later callpromise_yield_resume. For use cases like in-contract mempools (NEP-0616 wallet extensions, Aurora), this storage cost is prohibitive.promise_yield_create2lets contracts provide their own deterministic yield ID, avoiding expensive storage.Context: https://near.zulipchat.com/#narrow/channel/295558-core/topic/yield_create2
Host function signature
Key design decisions
generate_data_id(), not derived from yield_idYieldIdToDataIdandDataIdToYieldIdfor duplicate detection and cleanupYieldIdAlreadyExistsif yield_id is already pendingpromise_yield_resume— data_id written to registerTest plan
create2_then_resumenightly test passescreate2_and_resume_in_one_callnightly test passescargo checkwith nightly features passes🤖 Generated with Claude Code