EOS的trace_api_plugin插件测试

该插件将序列化的块跟踪数据存储到文件系统中,以便稍后通过HTTP RPC请求检索。

当将诸如区块浏览器和交易所等应用程序与EOSIO区块链集成时,用户可能需要区块链处理的action的完整副本,包括那些从执行智能合约和scheduled transacton产生的操作.

参见:Trace Api Plugin | EOSIO Developer Docs

测试版本:image: eosio/eosio:release_2.2.x

trace配置

plugin=eosio::trace_api_plugin
trace-dir=traces
#trace-rpc-abi=eosio=abis/eosio.abi     
trace-rpc-abi=eosio.token=abis/eosio.token.abi

trace-rpc-abi选项指定合约,以及合约abi文件的目录与文件名。如果指定了某个合约的abi,则再返回的action中会包含params(humanbeing readable)。

  --trace-rpc-abi arg                   ABIs used when decoding trace RPC 
                                        responses.
                                        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 
                                        ABI

发交易

返回交易所在的块号

 cl transfer accountadmin alice '1 SYS' "to alice"
{
  "transaction_id": "a622c8ddaf57ae761b1a2ebaa3a075f723e9cc0b944a172da613bf06d6545818",
  "processed": {
    "id": "a622c8ddaf57ae761b1a2ebaa3a075f723e9cc0b944a172da613bf06d6545818",
    "block_num": 1204,
    "block_time": "2022-05-12T11:48:33.000",
    "producer_block_id": null,
    "receipt": {
      "status": "executed",
      "cpu_usage_us": 314,
      "net_usage_words": 16
    },
    "elapsed": 314,
    "net_usage": 128,
    "scheduled": false,
    "action_traces": [{
        "action_ordinal": 1,
        "creator_action_ordinal": 0,
        "closest_unnotified_ancestor_action_ordinal": 0,
        "receipt": {
          "receiver": "eosio.token",
          "act_digest": "39f99620b86874b54e0c883e07fbf3f47319e05b4bd42048870abd6044743327",
          "global_sequence": 1385,
          "recv_sequence": 27,
          "auth_sequence": [[
              "eosio",
              1334
            ]
          ],
          "code_sequence": 1,
          "abi_sequence": 1
        },
        "receiver": "eosio.token",
        "act": {
          "account": "eosio.token",
          "name": "transfer",
          "authorization": [{
              "actor": "eosio",
              "permission": "active"
            }
          ],
          "data": {
            "from": "eosio",
            "to": "alice",
            "quantity": "1.0000 SYS",
            "memo": ""
          },
          "hex_data": "0000000000ea30550000000000855c341027000000000000045359530000000000"
        },
        "context_free": false,
        "elapsed": 77,
        "console": "",
        "trx_id": "a622c8ddaf57ae761b1a2ebaa3a075f723e9cc0b944a172da613bf06d6545818",
        "block_num": 1204,
        "block_time": "2022-05-12T11:48:33.000",
        "producer_block_id": null,
        "account_ram_deltas": [],
        "account_disk_deltas": [],
        "except": null,
        "error_code": null,
        "return_value_hex_data": ""
      },{
        "action_ordinal": 2,
        "creator_action_ordinal": 1,
        "closest_unnotified_ancestor_action_ordinal": 1,
        "receipt": {
          "receiver": "eosio",
          "act_digest": "39f99620b86874b54e0c883e07fbf3f47319e05b4bd42048870abd6044743327",
          "global_sequence": 1386,
          "recv_sequence": 1335,
          "auth_sequence": [[
              "eosio",
              1335
            ]
          ],
          "code_sequence": 1,
          "abi_sequence": 1
        },
        "receiver": "eosio",
        "act": {
          "account": "eosio.token",
          "name": "transfer",
          "authorization": [{
              "actor": "eosio",
              "permission": "active"
            }
          ],
          "data": {
            "from": "eosio",
            "to": "alice",
            "quantity": "1.0000 SYS",
            "memo": ""
          },
          "hex_data": "0000000000ea30550000000000855c341027000000000000045359530000000000"
        },
        "context_free": false,
        "elapsed": 24,
        "console": "",
        "trx_id": "a622c8ddaf57ae761b1a2ebaa3a075f723e9cc0b944a172da613bf06d6545818",
        "block_num": 1204,
        "block_time": "2022-05-12T11:48:33.000",
        "producer_block_id": null,
        "account_ram_deltas": [],
        "account_disk_deltas": [],
        "except": null,
        "error_code": null,
        "return_value_hex_data": ""
      },{
        "action_ordinal": 3,
        "creator_action_ordinal": 1,
        "closest_unnotified_ancestor_action_ordinal": 1,
        "receipt": {
          "receiver": "alice",
          "act_digest": "39f99620b86874b54e0c883e07fbf3f47319e05b4bd42048870abd6044743327",
          "global_sequence": 1387,
          "recv_sequence": 4,
          "auth_sequence": [[
              "eosio",
              1336
            ]
          ],
          "code_sequence": 1,
          "abi_sequence": 1
        },
        "receiver": "alice",
        "act": {
          "account": "eosio.token",
          "name": "transfer",
          "authorization": [{
              "actor": "eosio",
              "permission": "active"
            }
          ],
          "data": {
            "from": "eosio",
            "to": "alice",
            "quantity": "1.0000 SYS",
            "memo": ""
          },
          "hex_data": "0000000000ea30550000000000855c341027000000000000045359530000000000"
        },
        "context_free": false,
        "elapsed": 4,
        "console": "",
        "trx_id": "a622c8ddaf57ae761b1a2ebaa3a075f723e9cc0b944a172da613bf06d6545818",
        "block_num": 1204,
        "block_time": "2022-05-12T11:48:33.000",
        "producer_block_id": null,
        "account_ram_deltas": [],
        "account_disk_deltas": [],
        "except": null,
        "error_code": null,
        "return_value_hex_data": ""
      }
    ],
    "account_ram_delta": null,
    "except": null,
    "error_code": null,
    "bill_to_accounts": [
      "eosio"
    ]
  }
}
---------------------
executed transaction: a622c8ddaf57ae761b1a2ebaa3a075f723e9cc0b944a172da613bf06d6545818  128 bytes  314 us
#   eosio.token <= eosio.token::transfer        {"from":"eosio","to":"alice","quantity":"1.0000 SYS","memo":""}
#         eosio <= eosio.token::transfer        {"from":"eosio","to":"alice","quantity":"1.0000 SYS","memo":""}
#         alice <= eosio.token::transfer        {"from":"eosio","to":"alice","quantity":"1.0000 SYS","memo":""}

查询交易所在块的traces

curl http://127.0.0.1:8888/v1/trace_api/get_block -X POST  -H"'Content-type':'application/json'" -d '{"block_num":1204}' |python -m json.tool
{
    "action_mroot": "84a0fff78b7072b9f0830869ae1a4c0d69afea98967970c3c002b30a568c9ae5",
    "id": "000004b4644292f37ea69a51070c583b0f82f70e9e7f94c618e61647ada53b10",
    "number": 1204,
    "previous_id": "000004b37077085e7093cf1fc321ef2822b25bd09873dfe4089660e882df2fd0",
    "producer": "eosio",
    "schedule_version": 0,
    "status": "irreversible",
    "timestamp": "2022-05-12T11:48:33.000Z",
    "transaction_mroot": "ab498c75145782ca461170312bbaff48fe8bd700c8ae071e0c2986b20cfd1146",
    "transactions": [
        {
            "actions": [
                {
                    "account": "eosio",
                    "action": "onblock",
                    "authorization": [
                        {
                            "account": "eosio",
                            "permission": "active"
                        }
                    ],
                    "data": "21611f540000000000ea30550000000004b23ee77392539fafd49de1b904681ae9ef826221d61bdfcd793d111561000000000000000000000000000000000000000000000000000000000000000038ccef1d906af022e4246a354463d2c27ad173d881d9f13b69634a82e99beb1b000000000000",
                    "global_sequence": 1384,
                    "receiver": "eosio",
                    "return_value": ""
                }
            ],
            "bill_to_accounts": [
                "eosio"
            ],
            "cpu_usage_us": 100,
            "id": "adaddc9a1ab302c960ab596e7d84df6672f85c824d065589c43adf5b0410fd55",
            "net_usage_words": 0,
            "signatures": [],
            "status": "executed",
            "transaction_header": {
                "delay_sec": 0,
                "expiration": "1970-01-01T00:00:00",
                "max_cpu_usage_ms": 0,
                "max_net_usage_words": 0,
                "ref_block_num": 0,
                "ref_block_prefix": 0
            }
        },
        {
            "actions": [
                {
                    "account": "eosio.token",
                    "action": "transfer",
                    "authorization": [
                        {
                            "account": "eosio",
                            "permission": "active"
                        }
                    ],
                    "data": "0000000000ea30550000000000855c341027000000000000045359530000000000",
                    "global_sequence": 1385,
                    "params": {      <<<<如果trace-rpc-abi开关中指定了此合约abi,则包含此参数,否则不包含
                        "from": "eosio",
                        "memo": "",
                        "quantity": "1.0000 SYS",
                        "to": "alice"
                    },
                    "receiver": "eosio.token",
                    "return_value": ""
                },
                {
                    "account": "eosio.token",
                    "action": "transfer",
                    "authorization": [
                        {
                            "account": "eosio",
                            "permission": "active"
                        }
                    ],
                    "data": "0000000000ea30550000000000855c341027000000000000045359530000000000",
                    "global_sequence": 1386,
                    "params": {
                        "from": "eosio",
                        "memo": "",
                        "quantity": "1.0000 SYS",
                        "to": "alice"
                    },
                    "receiver": "eosio",
                    "return_value": ""
                },
                {
                    "account": "eosio.token",
                    "action": "transfer",
                    "authorization": [
                        {
                            "account": "eosio",
                            "permission": "active"
                        }
                    ],
                    "data": "0000000000ea30550000000000855c341027000000000000045359530000000000",
                    "global_sequence": 1387,
                    "params": {
                        "from": "eosio",
                        "memo": "",
                        "quantity": "1.0000 SYS",
                        "to": "alice"
                    },
                    "receiver": "alice",
                    "return_value": ""
                }
            ],
            "bill_to_accounts": [
                "eosio"
            ],
            "cpu_usage_us": 314,
            "id": "a622c8ddaf57ae761b1a2ebaa3a075f723e9cc0b944a172da613bf06d6545818",
            "net_usage_words": 16,
            "signatures": [
                "SIG_K1_JwK6gD89UeM2AvBtSnpoWWavhcxVqFxLtLbYoCSYUswWXWghwTgQKjhBFu7SJGhhLboDThA1sN5CTvuXG2rLb8QQy2ELfa"
            ],
            "status": "executed",
            "transaction_header": {
                "delay_sec": 0,
                "expiration": "2022-05-12T11:49:02",
                "max_cpu_usage_ms": 0,
                "max_net_usage_words": 0,
                "ref_block_num": 1202,
                "ref_block_prefix": 3568279379
            }
        }
    ]
}

查询交易所在的block(其中不包含trace)

cl get block 1204
{
  "timestamp": "2022-05-12T11:48:33.000",
  "producer": "eosio",
  "confirmed": 0,
  "previous": "000004b37077085e7093cf1fc321ef2822b25bd09873dfe4089660e882df2fd0",
  "transaction_mroot": "ab498c75145782ca461170312bbaff48fe8bd700c8ae071e0c2986b20cfd1146",
  "action_mroot": "84a0fff78b7072b9f0830869ae1a4c0d69afea98967970c3c002b30a568c9ae5",
  "schedule_version": 0,
  "new_producers": null,
  "producer_signature": "SIG_K1_KBDk7Xe4RPogtEPEW7ChkiTCrfb6q1W9uzLbuhy46TEJggGXUFAqsG2SbJB9USQPwgamTqYNMuxHC3AFTXCSRDTPLuQ1Vg",
  "transactions": [{
      "status": "executed",
      "cpu_usage_us": 314,
      "net_usage_words": 16,
      "trx": {
        "id": "a622c8ddaf57ae761b1a2ebaa3a075f723e9cc0b944a172da613bf06d6545818",
        "signatures": [
          "SIG_K1_JwK6gD89UeM2AvBtSnpoWWavhcxVqFxLtLbYoCSYUswWXWghwTgQKjhBFu7SJGhhLboDThA1sN5CTvuXG2rLb8QQy2ELfa"
        ],
        "compression": "none",
        "packed_context_free_data": "",
        "context_free_data": [],
        "packed_trx": "2ef47c62b204539fafd4000000000100a6823403ea3055000000572d3ccdcd010000000000ea305500000000a8ed3232210000000000ea30550000000000855c34102700000000000004535953000000000000",
        "transaction": {
          "expiration": "2022-05-12T11:49:02",
          "ref_block_num": 1202,
          "ref_block_prefix": 3568279379,
          "max_net_usage_words": 0,
          "max_cpu_usage_ms": 0,
          "delay_sec": 0,
          "context_free_actions": [],
          "actions": [{
              "account": "eosio.token",
              "name": "transfer",
              "authorization": [{
                  "actor": "eosio",
                  "permission": "active"
                }
              ],
              "data": {
                "from": "eosio",
                "to": "alice",
                "quantity": "1.0000 SYS",
                "memo": ""
              },
              "hex_data": "0000000000ea30550000000000855c341027000000000000045359530000000000"
            }
          ]
        }
      }
    }
  ],
  "id": "000004b4644292f37ea69a51070c583b0f82f70e9e7f94c618e61647ada53b10",
  "block_num": 1204,
  "ref_block_prefix": 1369089662
}

trace文件

# tree data
data
├── keosd
│   ├── default.wallet
│   ├── wallet.lock
│   └── walletpwd.txt
└── nodeos
    ├── abis
    │   ├── eosio.abi
    │   └── eosio.token.abi
    ├── blocks
    │   ├── archive
    │   ├── blocks.index
    │   ├── blocks.log
    │   └── reversible
    │       └── shared_memory.bin
    ├── snapshots
    ├── state
    │   └── shared_memory.bin
    └── traces
        ├── trace_0002560000-0002570000.log
        └── trace_index_0002560000-0002570000.log

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值