Skip to content

feat: add create_delegate host function for delegate-spawned delegates#60

Merged
iduartgomez merged 2 commits intomainfrom
feat/delegate-creation-host-function
Mar 9, 2026
Merged

feat: add create_delegate host function for delegate-spawned delegates#60
iduartgomez merged 2 commits intomainfrom
feat/delegate-creation-host-function

Conversation

@iduartgomez
Copy link
Contributor

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_delegate V2 host function:

  • New error codes in error_codes module: ERR_DEPTH_EXCEEDED (-20), ERR_CREATIONS_EXCEEDED (-21), ERR_INVALID_WASM (-23), ERR_STORE_FAILED (-24)
  • New extern block (freenet_delegate_management WASM import namespace) with __frnt__delegate__create_delegate
  • DelegateCtx::create_delegate() — ergonomic wrapper returning Result<([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

  • stdlib builds and passes clippy/fmt
  • freenet-core compiles against this branch with all 73 delegate unit tests passing
  • E2e test (test_delegate_creation_e2e) compiles and links correctly; requires Linux loopback for full execution

Fixes

Stdlib side of freenet/freenet-core#2833

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
@iduartgomez iduartgomez merged commit 26c0fe0 into main Mar 9, 2026
8 checks passed
@iduartgomez iduartgomez deleted the feat/delegate-creation-host-function branch March 9, 2026 13:41
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.

1 participant