feat: add create_delegate host function for delegate-spawned delegates#60
Merged
iduartgomez merged 2 commits intomainfrom Mar 9, 2026
Merged
Conversation
Adds the stdlib side of issue freenet/freenet-core#2833, enabling delegates to create child delegates at runtime via a new V2 host function. Changes: - New error codes: ERR_DEPTH_EXCEEDED, ERR_CREATIONS_EXCEEDED, ERR_INVALID_WASM, ERR_STORE_FAILED - New extern block (freenet_delegate_management) with __frnt__delegate__create_delegate - DelegateCtx::create_delegate() ergonomic wrapper
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.
Problem
Delegates cannot create other delegates at runtime. This is needed for use cases where a parent delegate needs to spawn child delegates dynamically (freenet/freenet-core#2833).
Solution
Add the stdlib-side API for the
create_delegateV2 host function:error_codesmodule:ERR_DEPTH_EXCEEDED(-20),ERR_CREATIONS_EXCEEDED(-21),ERR_INVALID_WASM(-23),ERR_STORE_FAILED(-24)freenet_delegate_managementWASM import namespace) with__frnt__delegate__create_delegateDelegateCtx::create_delegate()— ergonomic wrapper returningResult<([u8; 32], [u8; 32]), i32>(key hash + code hash on success)Resource limits enforced by the host side: max depth 4, max 8 creations per
process()call.Testing
test_delegate_creation_e2e) compiles and links correctly; requires Linux loopback for full executionFixes
Stdlib side of freenet/freenet-core#2833