Commit c56d778
authored
feat(wasm-runtime-interface): align ABI, register storage host functions, add log/timestamp support (#32)
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.1 parent fc5783c commit c56d778
File tree
5 files changed
+341
-26
lines changed- bins/validator-node/src
- crates/wasm-runtime-interface/src
5 files changed
+341
-26
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
| |||
181 | 182 | | |
182 | 183 | | |
183 | 184 | | |
| 185 | + | |
184 | 186 | | |
185 | 187 | | |
186 | 188 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
30 | | - | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| |||
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
46 | | - | |
| 48 | + | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
24 | 30 | | |
25 | 31 | | |
26 | 32 | | |
| |||
86 | 92 | | |
87 | 93 | | |
88 | 94 | | |
89 | | - | |
90 | | - | |
| 95 | + | |
91 | 96 | | |
92 | | - | |
| 97 | + | |
93 | 98 | | |
94 | 99 | | |
95 | 100 | | |
| |||
104 | 109 | | |
105 | 110 | | |
106 | 111 | | |
107 | | - | |
| 112 | + | |
| 113 | + | |
108 | 114 | | |
109 | 115 | | |
110 | 116 | | |
| |||
120 | 126 | | |
121 | 127 | | |
122 | 128 | | |
123 | | - | |
124 | | - | |
| 129 | + | |
125 | 130 | | |
126 | | - | |
| 131 | + | |
127 | 132 | | |
128 | 133 | | |
129 | 134 | | |
130 | 135 | | |
131 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
132 | 155 | | |
133 | 156 | | |
134 | 157 | | |
| |||
147 | 170 | | |
148 | 171 | | |
149 | 172 | | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | 173 | | |
156 | 174 | | |
157 | 175 | | |
| |||
578 | 596 | | |
579 | 597 | | |
580 | 598 | | |
581 | | - | |
582 | 599 | | |
| 600 | + | |
583 | 601 | | |
584 | 602 | | |
585 | 603 | | |
| |||
678 | 696 | | |
679 | 697 | | |
680 | 698 | | |
681 | | - | |
682 | 699 | | |
| 700 | + | |
683 | 701 | | |
684 | 702 | | |
685 | 703 | | |
| |||
716 | 734 | | |
717 | 735 | | |
718 | 736 | | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
719 | 765 | | |
720 | 766 | | |
721 | 767 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
3 | 7 | | |
4 | | - | |
| 8 | + | |
5 | 9 | | |
6 | 10 | | |
7 | 11 | | |
| |||
103 | 107 | | |
104 | 108 | | |
105 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
106 | 116 | | |
107 | 117 | | |
108 | 118 | | |
| |||
117 | 127 | | |
118 | 128 | | |
119 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
120 | 133 | | |
121 | 134 | | |
122 | 135 | | |
| |||
140 | 153 | | |
141 | 154 | | |
142 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
143 | 160 | | |
144 | 161 | | |
145 | 162 | | |
| |||
155 | 172 | | |
156 | 173 | | |
157 | 174 | | |
| 175 | + | |
| 176 | + | |
158 | 177 | | |
159 | 178 | | |
160 | 179 | | |
| |||
167 | 186 | | |
168 | 187 | | |
169 | 188 | | |
| 189 | + | |
| 190 | + | |
170 | 191 | | |
171 | 192 | | |
172 | 193 | | |
| |||
175 | 196 | | |
176 | 197 | | |
177 | 198 | | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
178 | 203 | | |
179 | 204 | | |
180 | 205 | | |
| |||
242 | 267 | | |
243 | 268 | | |
244 | 269 | | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
245 | 275 | | |
246 | 276 | | |
247 | 277 | | |
| |||
262 | 292 | | |
263 | 293 | | |
264 | 294 | | |
| 295 | + | |
| 296 | + | |
265 | 297 | | |
266 | 298 | | |
267 | 299 | | |
| |||
277 | 309 | | |
278 | 310 | | |
279 | 311 | | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
280 | 319 | | |
281 | 320 | | |
282 | 321 | | |
| |||
436 | 475 | | |
437 | 476 | | |
438 | 477 | | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
439 | 494 | | |
440 | 495 | | |
441 | 496 | | |
| |||
0 commit comments