You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document outlines the design and implementation details for a custom tracer for Sui. The goal is to create a flexible and minimally intrusive tracing framework that integrates seamlessly into the existing Sui infrastructure while maintaining compatibility with Sentio's custom functionalities.
Developed a trace service that depends on sui_replay to invoke the trace API.
Modified sui_replay to use executor for transaction replay and call trace retrieval.
Altered the download_latest_object method in sui_replay, replacing block_on with a thread channel to convert the asynchronous method to synchronous, ensuring it operates correctly within the API service (replay.rs).
Added call_trace to the PTB context and introduced execution_mode::DevCallTrace.
Implemented dev_transaction_call_trace in sui_executor to call execute_transaction_to_effects::<execution_mode::DevCallTrace>, which in turn calls the VM's call trace method.
Integrated the call_trace method into the VM runtime down to the interpreter level.
Background
The Sentio debugger feature (e.g., example transaction) obtains call traces of historical transactions to compute fund flows. The current changes to Sentio's SUI fork are tightly coupled with Sentio's requirements and include custom call trace data structures and methods within the Move VM. These modifications lead to duplicated code and hinder upstream contributions. Periodic merges from upstream are required, causing maintenance challenges. The objective is to refactor and redesign the solution to be more generic, facilitating integration with Sentio's call trace requirements and existing SUI features like gas profiling.
For reference, Geth's custom tracer API can be reviewed here.
Requirements
Minimize intrusiveness to existing Move VM code.
Maintain feature parity for Sentio's call trace feature and SUI gas profiler.
Extensibility to support instruction-level debugging.
Include in the debug build.
Enable or disable tracers via cargo build feature flags.
Initial design targets CLI usage (phase 1), with potential API implementation (persisting log files generated by the tracer).
Trace API support is covered in a separate section, which can be considered as phase 2.
High-Level Flow
Detailed Design
Changes We Propose - Phase 1 (CLI Support)
Add a new tracer trait for customized tracers.
Add two new methods into the GasMeter to initialize and retrieve the customized tracers.
Add a new module move_tracer with several useful macros to control the on/off state of each tracer.
Add logic to invoke the customized tracers within the interpreter's execution logic.
The current design is tailored for CLI use and is not optimized for API services. For API support in a separate service based on the replay method, additional changes are needed. The existing method dev_inspect_transaction in the executor returns only transaction effects, and tracer output is written to a separate log file. Implementing an API would require adding a new method like dev_transaction_call_trace, which may not be accepted upstream. A potential solution involves invoking the CLI and using an asynchronous approach to fetch local log files in the API service and obtain trace results, which is to be determined.
We will discuss the API version in the next section.
Open Questions - Phase 1
Tracers are placed in the same place as the gas profiler, i.e., GasMeter, which may not be ideal. To avoid changing the signature by introducing a new parameter in the VM and interpreter, are there any alternative approaches? One approach is to add a new container for the GasMeter and pass the object of this new container into the VM.
Add a new execution mode DevTrace into the execution engine.
Add an optional trace result in the VM result.
Extend the tracer trait to obtain the trace result.
Implement tracer-related logic in the PTB executor if needed.
API Specification: sui_devTraceTransactionBlock
Description
This endpoint replays a historic transaction block and returns the VM tracing result, providing detailed information about the execution of the transaction block.
Parameters
Index
Type
Description
0
string
Required. Sender address.
1
string
Required. BCS encoded TransactionKind (as opposed to TransactionData, which includes gasBudget and gasPrice).
2
number
Optional. Gas is not charged, but gas usage is still calculated. Defaults to use reference gas price.
3
number
Optional. The epoch to perform the call. Will be set from the system state object
if not provided. |
| 4 | string | Optional. Tracer name, native tracer by default. |
| 5 | null | Optional. Additional arguments for tracer. |
Does the new API need to be proposed and reviewed by the community?
Do the Move VM changes need to be merged into the official Move VM, or is it specific to SUI?
Backward Compatibility
VM traces should be available for all the historical transactions. And in the execution layer, changes will be added in the latest version.
In the Move VM layer, since the tracer related code is behind the feature flag and will be no included in the release build, so it would not affect the normal transaction execution.
Conclusion
This design aims to create a modular and maintainable tracing framework for the Sui blockchain, addressing both current requirements and potential future enhancements. The proposed approach minimizes disruption to existing codebases and provides a path for integrating advanced debugging and profiling features.
The text was updated successfully, but these errors were encountered:
Design Document for Sui Custom Tracer
Summary
This document outlines the design and implementation details for a custom tracer for Sui. The goal is to create a flexible and minimally intrusive tracing framework that integrates seamlessly into the existing Sui infrastructure while maintaining compatibility with Sentio's custom functionalities.
Changes We've Made
Entry Point of Sentio's Trace Service: Sui Trace Server
sui_replay
to invoke the trace API.sui_replay
to useexecutor
for transaction replay and call trace retrieval.download_latest_object
method insui_replay
, replacingblock_on
with a thread channel to convert the asynchronous method to synchronous, ensuring it operates correctly within the API service (replay.rs).call_trace
to the PTB context and introducedexecution_mode::DevCallTrace
.dev_transaction_call_trace
insui_executor
to callexecute_transaction_to_effects::<execution_mode::DevCallTrace>
, which in turn calls the VM's call trace method.call_trace
method into the VM runtime down to the interpreter level.Background
The Sentio debugger feature (e.g., example transaction) obtains call traces of historical transactions to compute fund flows. The current changes to Sentio's SUI fork are tightly coupled with Sentio's requirements and include custom call trace data structures and methods within the Move VM. These modifications lead to duplicated code and hinder upstream contributions. Periodic merges from upstream are required, causing maintenance challenges. The objective is to refactor and redesign the solution to be more generic, facilitating integration with Sentio's call trace requirements and existing SUI features like gas profiling.
For reference, Geth's custom tracer API can be reviewed here.
Requirements
High-Level Flow
Detailed Design
Changes We Propose - Phase 1 (CLI Support)
GasMeter
to initialize and retrieve the customized tracers.move_tracer
with several useful macros to control the on/off state of each tracer.Tracer Trait
Each tracer will have its own feature flag (e.g.,
gas_profiler
). Tracers will be added to the tracer pool only when their feature flag is enabled.Modifications to
GasStatus
Initialization
Macros
Usage During Execution
Limitations - Phase 1
The current design is tailored for CLI use and is not optimized for API services. For API support in a separate service based on the replay method, additional changes are needed. The existing method
dev_inspect_transaction
in the executor returns only transaction effects, and tracer output is written to a separate log file. Implementing an API would require adding a new method like dev_transaction_call_trace, which may not be accepted upstream. A potential solution involves invoking the CLI and using an asynchronous approach to fetch local log files in the API service and obtain trace results, which is to be determined.We will discuss the API version in the next section.
Open Questions - Phase 1
Changes We Propose - Phase 2 (API Support)
sui_devTraceTransactionBlock
like sui_devInspectTransactionBlock.DevTrace
into the execution engine.API Specification: sui_devTraceTransactionBlock
Description
This endpoint replays a historic transaction block and returns the VM tracing result, providing detailed information about the execution of the transaction block.
Parameters
if not provided. |
| 4 | string | Optional. Tracer name, native tracer by default. |
| 5 | null | Optional. Additional arguments for tracer. |
Example Request Body
Response
vm_trace
Example Response Body
Tracer Trait
Definition of the New VM Result
Open Questions - Phase 2
Backward Compatibility
VM traces should be available for all the historical transactions. And in the execution layer, changes will be added in the latest version.
In the Move VM layer, since the tracer related code is behind the feature flag and will be no included in the release build, so it would not affect the normal transaction execution.
Conclusion
This design aims to create a modular and maintainable tracing framework for the Sui blockchain, addressing both current requirements and potential future enhancements. The proposed approach minimizes disruption to existing codebases and provides a path for integrating advanced debugging and profiling features.
The text was updated successfully, but these errors were encountered: