trace_api_plugin provides a consumer-focused long-term API for retrieving retired actions and related metadata from a specified block. The plugin stores serialized block trace data to the filesystem for later retrieval via HTTP RPC requests. For detailed information about the definition of this application programming interface see the Trace API reference.
While integrating applications such as block explorers and exchanges with an EOSIO blockchain, the user might require a complete transcript of actions processed by the blockchain, including those spawned from the execution of smart contracts and scheduled transactions. The
trace_api_plugin serves this need. The purpose of the plugin is to provide:
- A transcript of retired actions and related metadata
- A consumer-focused long-term API to retrieve blocks
- Maintainable resource commitments at the EOSIO nodes
Therefore, one crucial goal of the
trace_api_plugin is to improve the maintenance of node resources (file system, disk space, memory used, etc.). This goal is different from the existing
history_plugin which provides far more configurable filtering and querying capabilities, or the existing
state_history_plugin which provides a binary streaming interface to access structural chain data, action data, as well as state deltas.
plugin = eosio::trace_api_plugin
nodeos ... --plugin eosio::trace_api_plugin [options]
These can be specified from both the
nodeos command-line or the
Config Options for eosio::trace_api_plugin:
--trace-dir arg (="traces") the location of the trace directory
(absolute path or relative to
application data dir)
--trace-slice-stride arg (=10000) the number of blocks each "slice" of
trace data will contain on the
--trace-minimum-irreversible-history-blocks arg (=-1)
Number of blocks to ensure are kept
past LIB for retrieval before "slice"
files can be automatically removed.
A value of -1 indicates that automatic
removal of "slice" files will be turned
--trace-minimum-uncompressed-irreversible-history-blocks arg (=-1)
Number of blocks to ensure are
uncompressed past LIB. Compressed
"slice" files are still accessible but
may carry a performance loss on
A value of -1 indicates that automatic
compression of "slice" files will be
--trace-rpc-abi arg ABIs used when decoding trace RPC
There must be at least one ABI
specified OR the flag trace-no-abis
must be used.
ABIs are specified as "Key=Value" pairs
in the form <account-name>=<abi-def>
Where <abi-def> can be:
an absolute path to a file
containing a valid JSON-encoded ABI
a relative path from `data-dir` to a
file containing a valid JSON-encoded
--trace-no-abis Use to indicate that the RPC responses
will not use ABIs.
Failure to specify this option when
there are no trace-rpc-abi
configuations will result in an Error.
This option is mutually exclusive with
The following plugins are loaded with default settings if not specified on the command line or
plugin = eosio::chain_plugin
plugin = eosio::http_plugin
nodeos ... --plugin eosio::chain_plugin [options] \
--plugin eosio::http_plugin [options]
Here is a
nodeos configuration example for the
trace_api_plugin when tracing some EOSIO reference contracts:
nodeos --data-dir data_dir --config-dir config_dir --trace-dir traces_dir
This section provides an overview of slices, the trace log contents, and the clog format. Mastery of these concepts is beneficial for an effective use of the
In the context of the
trace_api_plugin, a slice is defined as a collection of all relevant trace data between a given starting block height (inclusive) and a given ending block height (exclusive). For instance, a slice from 0 to 10,000 is a collection of all blocks with block numbers greater than or equal to 0 and less than 10,000. The trace directory contains a collection of slices. Each slice consists of a trace data log file and a trace index metadata log file:
<E> are the starting and ending block numbers for the slice padded with leading 0's to a stride. For instance if the start block is 5, the last is 15, and the stride is 10, then the resulting
The trace data log is an append only log that stores the actual binary serialized block data. The contents include the transaction and action trace data needed to service the RPC requests augmented by the per-action ABIs. Two block types are supported:
The data log begins with a basic header that includes versioning information about the data stored in the log.
block_trace_v0 includes the block ID, block number, previous block ID, the production timestamp, the producer that signed the block, and the actual trace data.
block_trace_v1 adds both merkle root hashes for the list of transactions and the list of actions included in the block as well as the production schedule count since genesis.
The log may include blocks that have been forked out of the blockchain as part of the normal operations of the chain. The next entry in the file will always have a block number one higher than the previous one or the same number or less because of forking. Every trace entry will have a corresponding entry in the corresponding slice file for trace indexes. Note that forked blocks can be avoided by running nodeos in
The trace index log or metadata log is an append only log that stores a sequence of binary-serialized types. Currently two types are supported:
The index log begins with a basic header that includes versioning information about the data stored in the log.
block_entry_v0 includes the block ID and block number with an offset to the location of that block within the data log. This entry is used to locate the offsets of both
lib_entry_v0 includes an entry for the latest known LIB. The reader module uses the LIB information for reporting to users an irreversible status.
Compressed trace log files have the
.clog file extension (see Compression of log files below). The clog is a generic compressed file with an index of seek-able decompression points appended at the end. The clog format layout looks as follows:
The data is compressed into raw zlib form with full-flush seek points placed at regular intervals. A decompressor can start from any of these seek points without reading previous data and it can also traverse a seek point without issue if it appears within the data.
As the file is being compressed, the seek point index records the original uncompressed offset with the new compressed offset creating a mapping so that the original index values (uncompressed offsets) can be mapped to the nearest seek point before the uncompressed offset. This dramatically reduces the seek time to parts of the uncompressed file that appear later in the stream.
One of the main design goals of the
trace_api_plugin is to minimize the manual housekeeping and maintenance of filesystem resources. To that end, the plugin facilitates the automatic removal of trace log files and the automatic reduction of their disk footprint through data compression.
To allow the removal of previous trace log files created by the
trace_api_plugin, you can use the following option:
--trace-minimum-irreversible-history-blocks N (=-1)
If the argument
N is 0 or greater, the plugin will only keep
N blocks on disk before the current LIB block. Any trace log file with block numbers lesser than then previous
N blocks will be scheduled for automatic removal.
trace_api_plugin also supports an option to optimize disk space by applying data compression on the trace log files:
--trace-minimum-uncompressed-irreversible-history-blocks N (=-1)
If the argument
N is 0 or greater, the plugin automatically sets a background thread to compress the irreversible sections of the trace log files. The previous N irreversible blocks past the current LIB block are left uncompressed.
If resource usage cannot be effectively managed via the
trace-minimum-uncompressed-irreversible-history-blocks options, then there might be a need for periodic manual maintenance. In that case, the user may opt to manage resources through an external system or recurrent process.
trace-dir option defines the directory on the filesystem where the trace log files are stored by the
trace_api_plugin. These files are stable once the LIB block has progressed past a given slice and then can be deleted at any time to reclaim filesystem space. The deployed EOSIO system will tolerate any out-of-process management system that removes some or all of these files in this directory regardless of what data they represent, or whether there is a running
nodeos instance accessing them or not. Data which would nominally be available, but is no longer so due to manual maintenance, will result in a HTTP 404 response from the appropriate API endpoint(s).