Skip to content

Commit 7eb5654

Browse files
committed
README.md: document all trace record kinds
1 parent 0aec17f commit 7eb5654

1 file changed

Lines changed: 53 additions & 2 deletions

File tree

README.md

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,67 @@ curl -s http://localhost:8000 -H 'Content-Type: application/json' \
130130
"jsonrpc": "2.0",
131131
"id": 1,
132132
"result": [
133+
{"pos": null, "instr": ["callContract"],
134+
"from": {"type": "address", "addrType": "account", "value": "03a107bff3ce10be1d70dd18e74bc09967e4d6309ba50d5f1ddc8664125531b8"},
135+
"to": {"type": "address", "addrType": "contract", "value": "6a20fec1a9081773a5f23ce370f925f236346e510438ddd6d40f6b2711c134e0"},
136+
"function": "foo", "args":[], "depth":1, "storage":[]
137+
},
133138
{"pos": 3, "instr": ["const", "i32", 1048576], "stack": [], "locals": {}},
134139
{"pos": 11, "instr": ["const", "i32", 1048576], "stack": [], "locals": {}},
135140
{"pos": 19, "instr": ["const", "i32", 1048576], "stack": [], "locals": {}},
136141
{"pos": null, "instr": ["block"], "stack": [], "locals": {}},
137-
{"pos": 3, "instr": ["const", "i64", 2], "stack": [], "locals": {}}
142+
{"pos": 3, "instr": ["const", "i64", 2], "stack": [], "locals": {}},
143+
{"pos": null, "instr": ["endWasm"], "success":true, "depth":1, "result": {"type": "void"}}
138144
]
139145
}
140146
```
141147

142-
Each trace record captures the VM state at instruction entry: `pos` is the instruction's byte offset in the binary (`null` for synthetic instructions), `instr` is the instruction and its operands, and `stack`/`locals` are the value stack and locals as `[type, value]` pairs. See [docs/interpreter.md](docs/interpreter.md) for the full trace format.
148+
A trace can contain five kinds of records:
149+
150+
- `callContract`
151+
- Wasm instruction records
152+
- `hostCall`
153+
- `contractData`
154+
- `endWasm`
155+
156+
The example above only has three of these: `callContract`, instruction records, and `endWasm`. `foo()` doesn't touch storage or call any host functions, so no `contractData` or `hostCall` records show up.
157+
158+
Here's what each record type carries:
159+
160+
- `callContract`: logged for each contract call in the transaction, including contract-to-contract calls. Records the caller, the callee, the function name, the arguments, the call depth, and the callee's storage before the call runs.
161+
- Instruction records: logged at each WebAssembly instruction's entry. `pos` is the instruction's byte offset in the binary (`null` for synthetic instructions), `instr` is the instruction and its operands, and `stack`/`locals` are the value stack and locals as `[type, value]` pairs.
162+
- `hostCall`: logged when the contract calls a host function. `instr` gives `["hostCall", moduleId, functionId]`, identifying which host function ran. `locals` holds the function's arguments, indexed by position. Host calls don't use the stack, so `stack` is absent.
163+
Here's a `hostCall` record for a call to `put_contract_data`, module id `l`, function id `_`:
164+
```jsonc
165+
{
166+
"pos": null,
167+
"instr": ["hostCall", "l", "_"],
168+
"locals": {"2": ["i64",0], "1": ["i64",530242871224172548], "0": ["i64",45954062]}
169+
}
170+
```
171+
172+
- `contractData`: logged for storage updates. Gives the contract and the storage type (`instance`, `persistent`, or `temporary`). A `put` carries the key and value as its two args; a `del` carries only the key.
173+
Here's a `contractData` record for a `put`, followed by a `del` on the same key:
174+
```jsonc
175+
{
176+
"pos": null,
177+
"instr": ["contractData", "put", "temporary"],
178+
"contract": {"type": "address", "addrType": "contract", "value": "746573742d7363"},
179+
"args": [{"type": "symbol", "value": "foo"}, {"type": "u32", "value": 123456789}]
180+
}
181+
{
182+
"pos": null,
183+
"instr": ["contractData", "del", "temporary"],
184+
"contract": {"type": "address", "addrType": "contract", "value": "746573742d7363"},
185+
"args": [{"type": "symbol", "value": "foo"}]
186+
}
187+
```
188+
189+
- `endWasm`: logged once at the end of a call. Records whether the call succeeded, its depth, and its result.
190+
191+
192+
193+
See [docs/interpreter.md](docs/interpreter.md) for the full trace format.
143194

144195
---
145196

0 commit comments

Comments
 (0)