Skip to content

日志订阅

工作流订阅

image-20241101145139143

工作流订阅条件

logType工作流类型
logLevel工作流级别
chainId链ID
apiScope订阅的API范围logType != 1时无效
hash订阅的交易hashlogType != 4时无效

1.建议订阅时按链id工作流类型分类存储

2.除排查接口问题外,不建议监听接口调用的工作流

推送的信息(公有)

chainId链Id当工作流跟链无关时可能为空
flowLevel工作流级别1:一般级别,2:错误级别
info信息一般级别时的信息
error错误信息错误级别时的信息
timestamp时间戳

表1 工作流类型

1接口调用必须传递接口前缀¹,不能接受所有节点调用的工作流(没必要)
2节点连接在订阅之前的连接工作流不会推送
3节点握手在订阅之前的握手工作流不会推送
4交易执行可选参数:hash,订阅指定交易的执行工作流
5守护区块
6共识阶段
7以链建链

 rpc接口method方法名,如订阅wallet_相关接口,前缀为wallet_

订阅示例1

订阅所有工作流,{} 不能删除

json
{
    "jsonrpc": "2.0",
    "method": "node_subscribe",
    "params": [
       "workflow",
        {  
        }
    ],
    "id": 481
}

等价于

json
{
    "jsonrpc": "2.0",
    "method": "node_subscribe",
    "params": [
       "workflow",
        {  
            "logType": 0,
            "logLevel": 0,
            "chainID": 0,
            "apiScope": "",
            "hash": ""
        }
    ],
    "id": 481
}

订阅示例2

订阅交易0x12的执行过程

json
{
    "jsonrpc": "2.0",
    "method": "node_subscribe",
    "params": [
       "workflow",
        {
            "logType": 4,
            "hash": "0x123"
        }
    ],
    "id": 481
}

订阅示例3

只订阅链123的Error工作流

json
{
    "jsonrpc": "2.0",
    "method": "node_subscribe",
    "params": [
       "workflow",
        {
            "logLevel": 2,
            "chainID": "123"
        }
    ],
    "id": 481
}

1.接口调用

.........
method接口方法
params接口参数
return接口返回值与公有的info不同是return在整个流程成功后才会返回

订阅”latc_getCurrentDBlock“

json
{
    "jsonrpc": "2.0",
    "method": "node_subscribe",
    "params": [
       "workflow",
        {
            "logType": 1,
            "apiScope": "latc_getCurrentDBlock",
            "chainId": xxx
        }
    ],
    "id": 481
}

正常流程:

  • serverd

  • return

2.节点连接

iNodeInfo连接节点的信息/节点hash

订阅:

{
    "jsonrpc": "2.0",
    "method": "node_subscribe",
    "params": [
       "workflow",
        {
            "logType": 2
        }
    ],
    "id": 481
}

参考流程

2.1 节点的连接流程

  • listen peer connected
  • network coneect
  • handle new peer success

2.2 节点断开流程

  • listen peer disconnected
  • network disconnected
  • peer removed

3.节点握手

peerId节点信息
{
    "jsonrpc": "2.0",
    "method": "node_subscribe",
    "params": [
       "workflow",
        {
            "logType": 3
        }
    ],
    "id": 481
}

参考流程:

  • rec confirm handshake
  • handle new peer
  • receive handshake, reply handshake
  • initiate handshake
  • send handshake message to this pid
  • handshake success
  • peer manager register success
  • hardSyncer register peer success

4.TBlock

hash交易区块hash
height交易区块高度
json
{
    "jsonrpc": "2.0",
    "method": "node_subscribe",
    "params": [
       "workflow",
        {
            "logType": 4,
            "chainId": 120
        }
    ],
    "id": 481
}

参考流程:

  • AddLocalWitnessTBlocks

  • addLocalWitnessTBlocks

  • addLocalWitnessTBlocks: broadcastWTBlock

  • addWitnessTBlock

  • handle witnessing signature, from

  • CommitTBlock

  • commitBlock

  • sign witness block

  • add sig

  • broadcast signature

  • witness commit signature

  • add sig

  • block sig enough

  • confirm block

  • Accountant write a transaction block to chain

  • transaction block has quoted on daemon block, dbNumber: %s, dbHash: %s

5.DBlock

hash守护区块hash
height守护区块高度

订阅:

json
{
    "jsonrpc": "2.0",
    "method": "node_subscribe",
    "params": [
       "workflow",
        {
            "logType": 5,
            "chainId": 120
        }
    ],
    "id": 481
}
  • new dblock has been mined
  • Reach delay time, delay: 979.329526ms
  • sign witness block
  • add sig
  • broadcast signature
  • handle witnessing signature, from:xxx
  • witness commit signature
  • add sig
  • block sig enough
  • confirm block
  • block finalize
  • write dblock start
  • Accountant write a daemon block to chain

6. Consensus

订阅:

json
{
    "jsonrpc": "2.0",
    "method": "node_subscribe",
    "params": [
       "workflow",
        {
            "logType": 6,
            "chainId": 120
        }
    ],
    "id": 481
}

参考流程PoA:

  • Miner receive db num
  • commitNewWork
  • commitNewWork parentDB hash:0x7c743b90391372153c204c803468c65d9b3481e376ad7a82e7f48d32ddda7526, parentNumber: 67294
  • Chains120 successfully sealed new daemon block, number: 67295, hash: 0x08ee73deb095e3c2ca5781d56dcd2d7a38436b774a897ce534cd68b09420f6f3, elapsed: 1.408m
  • committing end

7.ChainByChain

childChainId正在创建或连接的链的id
chainByChainType以链建链的操作类型:新建链,停止链 ...

订阅:

{
    "jsonrpc": "2.0",
    "method": "node_subscribe",
    "params": [
       "workflow",
        {
            "logType": 6,
            "chainId": 120
        }
    ],
    "id": 481
}

以链建链的情况和流程较多。

Released under the MIT License.