-
Notifications
You must be signed in to change notification settings - Fork 5.4k
feat: forc call tracing #7196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat: forc call tracing #7196
Conversation
Potential improvements to the tracing will be captured in GH issue: #7197 |
87cc1e6
to
7609925
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left couple of questions and nit(s) nothing serious but we should probably remove the left over dead_code
if we do not have a strong reason to keep it in the code. Otherwise looks good to me!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Description
Resolves #6706
Introduces
forc-call
transaction tracing - for verbosity levels3+
(-v=3
or-vvv
).The tracing primarily utilizes transaction receipts, generating a call tree structure, then rendering this tree to
stdout
.Example usage output:
> forc-call --abi ./demo/demo-caller/out/release/demo-caller-abi.json 9275a76531bce733cfafdbcb6727ea533ebbdc358d685152169b3c4eaa47b965 call_increment_count -vvv
Output receipts for the trace above
```json { "receipts": [ { "Call": { "id": "0000000000000000000000000000000000000000000000000000000000000000", "to": "9275a76531bce733cfafdbcb6727ea533ebbdc358d685152169b3c4eaa47b965", "amount": 0, "asset_id": "f8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07", "gas": 124116, "param1": 10480, "param2": 10508, "pc": 11928, "is": 11928 } }, { "Call": { "id": "9275a76531bce733cfafdbcb6727ea533ebbdc358d685152169b3c4eaa47b965", "to": "b792b1e233a2c06bccec611711acc3bb61bdcb28f16abdde86d1478ee02f6e42", "amount": 0, "asset_id": "0000000000000000000000000000000000000000000000000000000000000000", "gas": 111500, "param1": 67107840, "param2": 67106816, "pc": 19064, "is": 19064 } }, { "ReturnData": { "id": "b792b1e233a2c06bccec611711acc3bb61bdcb28f16abdde86d1478ee02f6e42", "ptr": 0, "len": 0, "digest": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "pc": 21004, "is": 19064, "data": [] } }, { "LogData": { "id": "9275a76531bce733cfafdbcb6727ea533ebbdc358d685152169b3c4eaa47b965", "ra": 0, "rb": 10098701174489624218, "ptr": 67104256, "len": 25, "digest": "392232ec5cf9a0ef3c155ad19684907344847572e913a7a374d703fb9c9d8b5d", "pc": 15804, "is": 11928, "data": [ 0, 0, 0, 0, 0, 0, 0, 17, 105, 110, 99, 114, 101, 109, 101, 110, 116, 101, 100, 32, 99, 111, 117, 110, 116 ] } }, { "Call": { "id": "9275a76531bce733cfafdbcb6727ea533ebbdc358d685152169b3c4eaa47b965", "to": "b792b1e233a2c06bccec611711acc3bb61bdcb28f16abdde86d1478ee02f6e42", "amount": 0, "asset_id": "0000000000000000000000000000000000000000000000000000000000000000", "gas": 86284, "param1": 67103232, "param2": 67102208, "pc": 19072, "is": 19072 } }, { "ReturnData": { "id": "b792b1e233a2c06bccec611711acc3bb61bdcb28f16abdde86d1478ee02f6e42", "ptr": 67099904, "len": 8, "digest": "cd04a4754498e06db5a13c5f371f1f04ff6d2470f24aa9bd886540e5dce77f70", "pc": 21352, "is": 19072, "data": [ 0, 0, 0, 0, 0, 0, 0, 2 ] } }, { "LogData": { "id": "9275a76531bce733cfafdbcb6727ea533ebbdc358d685152169b3c4eaa47b965", "ra": 0, "rb": 1515152261580153489, "ptr": 67098880, "len": 8, "digest": "cd04a4754498e06db5a13c5f371f1f04ff6d2470f24aa9bd886540e5dce77f70", "pc": 15976, "is": 11928, "data": [ 0, 0, 0, 0, 0, 0, 0, 2 ] } }, { "LogData": { "id": "9275a76531bce733cfafdbcb6727ea533ebbdc358d685152169b3c4eaa47b965", "ra": 0, "rb": 10098701174489624218, "ptr": 67097856, "len": 12, "digest": "a3d2743e2a3ab241ba31ffc7133a43daabe6a8e624c7edc92410068a3896c871", "pc": 16072, "is": 11928, "data": [ 0, 0, 0, 0, 0, 0, 0, 4, 100, 111, 110, 101 ] } }, { "Call": { "id": "9275a76531bce733cfafdbcb6727ea533ebbdc358d685152169b3c4eaa47b965", "to": "b792b1e233a2c06bccec611711acc3bb61bdcb28f16abdde86d1478ee02f6e42", "amount": 0, "asset_id": "0000000000000000000000000000000000000000000000000000000000000000", "gas": 72699, "param1": 67096832, "param2": 67095808, "pc": 19064, "is": 19064 } }, { "ReturnData": { "id": "b792b1e233a2c06bccec611711acc3bb61bdcb28f16abdde86d1478ee02f6e42", "ptr": 0, "len": 0, "digest": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "pc": 21004, "is": 19064, "data": [] } }, { "Call": { "id": "9275a76531bce733cfafdbcb6727ea533ebbdc358d685152169b3c4eaa47b965", "to": "b792b1e233a2c06bccec611711acc3bb61bdcb28f16abdde86d1478ee02f6e42", "amount": 0, "asset_id": "0000000000000000000000000000000000000000000000000000000000000000", "gas": 48287, "param1": 67093248, "param2": 67092224, "pc": 19072, "is": 19072 } }, { "ReturnData": { "id": "b792b1e233a2c06bccec611711acc3bb61bdcb28f16abdde86d1478ee02f6e42", "ptr": 67089920, "len": 8, "digest": "d5688a52d55a02ec4aea5ec1eadfffe1c9e0ee6a4ddbe2377f98326d42dfc975", "pc": 21352, "is": 19072, "data": [ 0, 0, 0, 0, 0, 0, 0, 3 ] } }, { "ReturnData": { "id": "9275a76531bce733cfafdbcb6727ea533ebbdc358d685152169b3c4eaa47b965", "ptr": 67088896, "len": 8, "digest": "d5688a52d55a02ec4aea5ec1eadfffe1c9e0ee6a4ddbe2377f98326d42dfc975", "pc": 12608, "is": 11928, "data": [ 0, 0, 0, 0, 0, 0, 0, 3 ] } }, { "Return": { "id": "0000000000000000000000000000000000000000000000000000000000000000", "val": 1, "pc": 10388, "is": 10368 } }, { "ScriptResult": { "result": "Success", "gas_used": 89279 } } ] } ```The tracing is inspired by transaction trace provided by
cast run <tx-hash>
tool from foundry.Example usage/output of
cast run
:Copilot Description
This pull request introduces changes to the
forc-call
CLI, focusing on:It refactors the
call_function
andtransfer
operations, introduces new structures for ABI management, and enhances the verbosity options for debugging transaction outputs.Enhancements to ABI Handling:
Abi
struct to encapsulateProgramABI
,UnifiedProgramABI
, and a type lookup map, simplifying ABI parsing and usage (forc-plugins/forc-client/src/op/call/mod.rs
).call_function
to use the newAbi
struct and refactored ABI parsing to improve error handling during contract function calls (forc-plugins/forc-client/src/op/call/call_function.rs
) [1] [2].Improvements in Transaction Processing:
process_transaction_output
function to includeCallData
for better handling of ABI and contract-related data. Also, added support for printing transaction traces and logs with higher verbosity levels (forc-plugins/forc-client/src/op/call/mod.rs
).call_function
to include detailed error reporting and optional ABI mappings for debugging (forc-plugins/forc-client/src/op/call/call_function.rs
).Code Simplification and Refactoring:
ProgramABI
usage in thetransfer
function and updated it to use the new transaction processing logic (forc-plugins/forc-client/src/op/call/transfer.rs
).forc-plugins/forc-client/src/op/call/call_function.rs
,forc-plugins/forc-client/src/op/call/mod.rs
,forc-plugins/forc-client/src/op/call/transfer.rs
) [1] [2] [3].Enhanced Debugging and Verbosity:
print_receipts_and_trace
function to format and display transaction receipts and traces based on verbosity levels, aiding in debugging complex transactions (forc-plugins/forc-client/src/op/call/mod.rs
).script
toscript_json
inCallResponse
for clarity and consistency with JSON output conventions (forc-plugins/forc-client/src/op/call/mod.rs
).Checklist
Breaking*
orNew Feature
labels where relevant.