feat(wasm-runtime): align host ABI, register storage functions, add log/timestamp - #32
Conversation
…ons, add log/timestamp support Fix critical ABI mismatches in network host functions and implement missing storage host function registrations to align the host-side runtime with the guest SDK expectations. Network ABI fixes (network.rs): - Remove extra resp_len param from http_get and dns_resolve signatures to match the guest SDK 4-param ABI (req_ptr, req_len, resp_ptr) with default buffer sizes (64KB for HTTP, 4KB for DNS). - Add extra _extra param to http_post to align with guest expectations. - Add log_message host function: reads message string from WASM memory and dispatches to tracing::info/warn/error based on level parameter. - Add get_timestamp host function: returns UTC millis, with support for a fixed_timestamp_ms in RuntimeState for deterministic consensus. Storage host functions (storage.rs): - Implement StorageHostFunctions struct with HostFunctionRegistrar trait, registering storage_get and storage_set under platform_storage module. - storage_get reads key from WASM memory, fetches from backend, writes value back to WASM memory, tracks bytes_read and operations_count. - storage_set reads key+value from WASM memory, validates against config constraints (key/value limits, consensus gating), writes via backend, tracks bytes_written and operations_count. - Add helper functions for WASM memory read/write with bounds checking. - Add StorageOperation::Set variant and HOST_STORAGE_SET constant. - Update StorageHostState::new to accept a StorageBackend Arc parameter. Runtime integration (runtime.rs): - Extend InstanceConfig and RuntimeState with storage_state, storage_backend, storage_host_config, and fixed_timestamp_ms fields. - Register both NetworkHostFunctions and StorageHostFunctions with the linker during instance creation. - Add storage state reset and counter accessors to ChallengeInstance. Module exports (lib.rs): - Export StorageHostFunctions, HOST_STORAGE_SET, HOST_LOG_MESSAGE, and HOST_GET_TIMESTAMP from the crate root. Downstream update (wasm_executor.rs): - Use ..Default::default() in InstanceConfig construction to pick up new fields without breaking existing call sites.
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Aligns the WASM host-side ABI with the guest SDK signatures, registers missing
platform_storagehost functions, and addslog_message/get_timestamputility host functions.Changes
ABI Fixes (
network.rs)http_getsignature: removeresp_lenparam, use default buffer size (64KB) to match guest SDK 4-param ABIdns_resolvesignature: removeresp_lenparam, use default buffer size (4KB)http_postto accept extra unused param for forward compatibilityNew Host Functions (
network.rs)log_message(level, msg_ptr, msg_len): reads string from WASM memory and routes totracing::info!/warn!/error!based on levelget_timestamp() -> i64: returns UTC millis, with optional fixed timestamp fromRuntimeStatefor deterministic consensus executionStorage Host Functions (
storage.rs)StorageHostFunctionsstruct implementingHostFunctionRegistrarstorage_get(key_ptr, key_len, value_ptr) -> i32underplatform_storagemodulestorage_set(key_ptr, key_len, value_ptr, value_len) -> i32with consensus-gated write supportget_memoryutilityStorageOperation::Setvariant and exportHOST_STORAGE_SETconstantStorageHostStateto useStorageBackendviaArcRuntime Integration (
runtime.rs)InstanceConfigwithstorage_host_config,storage_backend, andfixed_timestamp_msRuntimeStatewithstorage_stateandfixed_timestamp_msNetworkHostFunctionsandStorageHostFunctionsin the linker during instance creationreset_storage_state()and storage metric accessors toChallengeInstanceExports (
lib.rs)StorageHostFunctions,HOST_STORAGE_SET,HOST_LOG_MESSAGE,HOST_GET_TIMESTAMPValidator Node (
wasm_executor.rs)..Default::default()for newInstanceConfigfields