Skip to content

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

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open

feat: forc call tracing #7196

wants to merge 24 commits into from

Conversation

zees-dev
Copy link
Contributor

@zees-dev zees-dev commented May 23, 2025

Description

Resolves #6706

Introduces forc-call transaction tracing - for verbosity levels 3+ (-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
image
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:

image

Copilot Description

This pull request introduces changes to the forc-call CLI, focusing on:

  • improving ABI handling
  • error reporting
  • transaction processing
    It refactors the call_function and transfer operations, introduces new structures for ABI management, and enhances the verbosity options for debugging transaction outputs.

Enhancements to ABI Handling:

  • Introduced a new Abi struct to encapsulate ProgramABI, UnifiedProgramABI, and a type lookup map, simplifying ABI parsing and usage (forc-plugins/forc-client/src/op/call/mod.rs).
  • Updated call_function to use the new Abi 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:

  • Enhanced the process_transaction_output function to include CallData 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).
  • Refactored receipt handling in 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:

  • Removed redundant ProgramABI usage in the transfer function and updated it to use the new transaction processing logic (forc-plugins/forc-client/src/op/call/transfer.rs).
  • Consolidated imports and removed unused dependencies across multiple files to streamline the codebase (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:

  • Added a new 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).
  • Renamed script to script_json in CallResponse for clarity and consistency with JSON output conventions (forc-plugins/forc-client/src/op/call/mod.rs).

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@zees-dev zees-dev requested review from a team as code owners May 23, 2025 04:37
@zees-dev zees-dev temporarily deployed to fuel-sway-bot May 23, 2025 04:37 — with GitHub Actions Inactive
@zees-dev zees-dev self-assigned this May 23, 2025
@zees-dev zees-dev temporarily deployed to fuel-sway-bot May 23, 2025 04:55 — with GitHub Actions Inactive
@zees-dev zees-dev added enhancement New feature or request forc dev-experience Anything to do with the developer experience forc-call Everything related to the `forc-call` plugin in `forc-client` package team:tooling Tooling Team labels May 23, 2025
@zees-dev zees-dev requested review from a team as code owners May 23, 2025 05:02
@zees-dev zees-dev temporarily deployed to fuel-sway-bot May 23, 2025 05:03 — with GitHub Actions Inactive
@zees-dev zees-dev temporarily deployed to fuel-sway-bot May 23, 2025 05:05 — with GitHub Actions Inactive
@zees-dev
Copy link
Contributor Author

Potential improvements to the tracing will be captured in GH issue: #7197

@zees-dev zees-dev force-pushed the feat/forc-call-tracing branch from 87cc1e6 to 7609925 Compare May 27, 2025 11:51
@zees-dev zees-dev temporarily deployed to fuel-sway-bot May 27, 2025 11:51 — with GitHub Actions Inactive
Copy link
Member

@kayagokalp kayagokalp left a 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!!

@zees-dev zees-dev temporarily deployed to fuel-sway-bot May 28, 2025 06:17 — with GitHub Actions Inactive
@zees-dev zees-dev temporarily deployed to fuel-sway-bot May 28, 2025 06:34 — with GitHub Actions Inactive
@zees-dev zees-dev temporarily deployed to fuel-sway-bot May 28, 2025 10:20 — with GitHub Actions Inactive
Copy link
Member

@kayagokalp kayagokalp left a 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev-experience Anything to do with the developer experience enhancement New feature or request forc forc-call Everything related to the `forc-call` plugin in `forc-client` package team:tooling Tooling Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Transaction trace
2 participants