(一)基礎概念
1.為什么要對區塊鏈網絡進行監控?
可視化界面的提供,讓外部人員了解到區塊鏈網絡的運行細節,增加對區塊鏈網絡的認識。
2.采用什么手段對區塊鏈網絡進行監控?
采用WEB平台可視化界面的區塊鏈瀏覽器,提供對網絡的監控。
3.網絡中的哪些細節需要被監控?
總體運行概況,節點,區塊、交易、鏈碼、通道等
(二)區塊鏈瀏覽器部署
1.導入鏡像
區塊鏈瀏覽器部署需要如下鏡像:
hyperledger/explorer-db 1.1.4 7d14fd39c018 2 months ago 97.7MB
hyperledger/explorer 1.1.4 805e35d5dd8f 2 months ago 187M
2.啟動容器
目錄 /root/11-blockchain-explorer/2-explorer 下執行,啟動區塊鏈瀏覽器
docker-compose up
注意根據錯誤提示,修改私鑰文件的名字。
提示:
Ctrl + C 強制終止
3.啟動服務
使用上步的命令調試通過后,后台服務方式啟動程序
docker-compose up -d
4.日志分析
更新客戶端網絡和其他信息到數據庫
explorer.mynetwork.com | [2021-04-09T05:33:11.296] [INFO] SyncPlatform - Updating the client network and other details to DB
explorer.mynetwork.com | [2021-04-09T05:33:11.309] [INFO] SyncServices - SyncServices.synchNetworkConfigToDB client first-network channel_name mychannel
explorer.mynetwork.com | [2021-04-09T05:33:11.326] [INFO] FabricUtils - generateBlockHash 0
網關,發送發現請求
explorer.mynetwork.com | [2021-04-09T05:33:11.330] [INFO] FabricGateway - Sending discovery request...
連接失敗 orderer.example.com:7050
explorer.mynetwork.com | 2021-04-09T05:33:14.338Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Committer- name: orderer.example.com:7050, url:grpcs://localhost:7050, connected:false, connectAttempted:true
explorer.mynetwork.com | 2021-04-09T05:33:14.339Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server orderer.example.com:7050 url:grpcs://localhost:7050 timeout:3000
explorer.mynetwork.com | 2021-04-09T05:33:14.339Z - error: [DiscoveryService]: _buildOrderer[be discovery service] - Unable to connect to the discovered orderer orderer.example.com:7050 due to Error: Failed to connect before the deadline on Committer- name: orderer.example.com:7050, url:grpcs://localhost:7050, connected:false, connectAttempted:true
explorer.mynetwork.com | [2021-04-09T05:33:16.391] [INFO] Platform - getClient (id:first-network)
explorer.mynetwork.com | [2021-04-09T05:33:16.439] [INFO] Platform - getClient (id:first-network)
explorer.mynetwork.com | [2021-04-09T05:33:16.441] [INFO] Platform - getClient (id:first-network)
explorer.mynetwork.com | [2021-04-09T05:33:16.455] [INFO] Platform - getClient (id:first-network)
explorer.mynetwork.com | [2021-04-09T05:33:16.458] [INFO] Platform - getClient (id:first-network)
explorer.mynetwork.com | [2021-04-09T05:33:16.462] [INFO] FabricGateway - Sending discovery request...
explorer.mynetwork.com | [2021-04-09T05:33:16.464] [INFO] FabricGateway - Have already been sending a request
explorer.mynetwork.com | 2021-04-09T05:33:17.340Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Endorser- name: peer0.org1.example.com:7051, url:grpcs://localhost:7051, connected:false, connectAttempted:true
explorer.mynetwork.com | 2021-04-09T05:33:17.341Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer0.org1.example.com:7051 url:grpcs://localhost:7051 timeout:3000
explorer.mynetwork.com | 2021-04-09T05:33:17.341Z - error: [DiscoveryService]: _buildPeer[be discovery service] - Unable to connect to the discovered peer peer0.org1.example.com:7051 due to Error: Failed to connect before the deadline on Endorser- name: peer0.org1.example.com:7051, url:grpcs://localhost:7051, connected:false, connectAttempted:true
explorer.mynetwork.com | 2021-04-09T05:33:19.470Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Committer- name: orderer.example.com:7050, url:grpcs://localhost:7050, connected:false, connectAttempted:true
explorer.mynetwork.com | 2021-04-09T05:33:19.470Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server orderer.example.com:7050 url:grpcs://localhost:7050 timeout:3000
explorer.mynetwork.com | 2021-04-09T05:33:19.470Z - error: [DiscoveryService]: _buildOrderer[be discovery service] - Unable to connect to the discovered orderer orderer.example.com:7050 due to Error: Failed to connect before the deadline on Committer- name: orderer.example.com:7050, url:grpcs://localhost:7050, connected:false, connectAttempted:true
explorer.mynetwork.com | 2021-04-09T05:33:20.345Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Endorser- name: peer0.org2.example.com:9051, url:grpcs://localhost:9051, connected:false, connectAttempted:true
explorer.mynetwork.com | 2021-04-09T05:33:20.345Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer0.org2.example.com:9051 url:grpcs://localhost:9051 timeout:3000
explorer.mynetwork.com | 2021-04-09T05:33:20.345Z - error: [DiscoveryService]: _buildPeer[be discovery service] - Unable to connect to the discovered peer peer0.org2.example.com:9051 due to Error: Failed to connect before the deadline on Endorser- name: peer0.org2.example.com:9051, url:grpcs://localhost:9051, connected:false, connectAttempted:true
explorer.mynetwork.com | 2021-04-09T05:33:22.473Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Endorser- name: peer0.org1.example.com:7051, url:grpcs://localhost:7051, connected:false, connectAttempted:true
explorer.mynetwork.com | 2021-04-09T05:33:22.473Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer0.org1.example.com:7051 url:grpcs://localhost:7051 timeout:3000
explorer.mynetwork.com | 2021-04-09T05:33:22.473Z - error: [DiscoveryService]: _buildPeer[be discovery service] - Unable to connect to the discovered peer peer0.org1.example.com:7051 due to Error: Failed to connect before the deadline on Endorser- name: peer0.org1.example.com:7051, url:grpcs://localhost:7051, connected:false, connectAttempted:true
explorer.mynetwork.com | 2021-04-09T05:33:23.348Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Endorser- name: peer0.org3.example.com:11051, url:grpcs://localhost:11051, connected:false, connectAttempted:true
explorer.mynetwork.com | 2021-04-09T05:33:23.348Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer0.org3.example.com:11051 url:grpcs://localhost:11051 timeout:3000
explorer.mynetwork.com | 2021-04-09T05:33:23.348Z - error: [DiscoveryService]: _buildPeer[be discovery service] - Unable to connect to the discovered peer peer0.org3.example.com:11051 due to Error: Failed to connect before the deadline on Endorser- name: peer0.org3.example.com:11051, url:grpcs://localhost:11051, connected:false, connectAttempted:true
explorer.mynetwork.com | [2021-04-09T05:33:23.348] [INFO] FabricGateway - Succeeded to send discovery request
發現組織1
explorer.mynetwork.com | [2021-04-09T05:33:23.349] [INFO] FabricClient - Discovered Org1MSP [ { mspid: 'Org1MSP',
explorer.mynetwork.com | endpoint: 'peer0.org1.example.com:7051',
explorer.mynetwork.com | name: 'peer0.org1.example.com:7051',
explorer.mynetwork.com | ledgerHeight: Long { low: 4, high: 0, unsigned: true },
explorer.mynetwork.com | chaincodes: [ [Object] ] } ]
發現組織2
explorer.mynetwork.com | [2021-04-09T05:33:23.349] [INFO] FabricClient - Discovered Org2MSP [ { mspid: 'Org2MSP',
explorer.mynetwork.com | endpoint: 'peer0.org2.example.com:9051',
explorer.mynetwork.com | name: 'peer0.org2.example.com:9051',
explorer.mynetwork.com | ledgerHeight: Long { low: 4, high: 0, unsigned: true },
explorer.mynetwork.com | chaincodes: [ [Object] ] } ]
發現組織3
explorer.mynetwork.com | [2021-04-09T05:33:23.349] [INFO] FabricClient - Discovered Org3MSP [ { mspid: 'Org3MSP',
explorer.mynetwork.com | endpoint: 'peer0.org3.example.com:11051',
explorer.mynetwork.com | name: 'peer0.org3.example.com:11051',
explorer.mynetwork.com | ledgerHeight: Long { low: 4, high: 0, unsigned: true },
explorer.mynetwork.com | chaincodes: [ [Object] ] } ]
(三)界面展示
1.儀表盤
2.網絡
區塊鏈網絡是分布式網絡,具有多台服務器,多個節點。要了解網絡的整體運行狀況不是一件容易的事情。下圖展示的就是區塊鏈網絡中的節點。
字段含義:
Ledger Height 賬本高度
High
Low
Unsigned 連接狀態,true連接成功
3.區塊
多筆交易形成一個區塊,寫入到區塊鏈網絡各個對等節點的磁盤上。區塊打包的規則可以進行配置。
區塊詳情
4.交易
對世界狀態的一次變更就是一次交易。物理上體現為新增一筆交易記錄。交易記錄最終打包為一個區塊。
交易詳情
5.鏈碼
6.通道
展示當前網路上具有的應用通道,也就是鏈碼通道
(四)監控技術
Fabric提供了SDK作為訪問區塊鏈網絡的接口,提供有node,java,go,python,其中node功能最完整。這里以node為例進行介紹。
采用typescript開發,建議使用vscode作為開發工具,具有自動語法提示。
1.監控指標
大類 |
項目 |
狀態 |
接口測試通過 |
儀表盤 |
區塊數量 |
|
|
交易數量 |
|
|
|
節點數量 |
|
|
|
鏈碼數量 |
|
|
|
節點名字和端口 |
|
|
|
網絡 |
節點名字 |
|
可行 |
請求地址 |
|
|
|
節點類型 |
|
|
|
成員ID |
|
可行 |
|
區塊高度 |
|
|
|
|
簽到狀態 |
|
可行 |
區塊 |
區塊編號 |
|
可行 |
通道名稱 |
|
可行 |
|
交易編號 |
|
可行 |
|
數據哈希 |
|
可行 |
|
區塊哈希 |
|
可行 |
|
之前哈希 |
|
可行 |
|
交易 |
|
|
|
交易 |
創建者 |
|
|
通道名稱 |
|
|
|
交易ID |
|
|
|
類型 |
|
|
|
鏈碼 |
|
|
|
時間戳 |
|
|
|
鏈碼 |
鏈碼名稱 |
|
可行 |
通道名稱 |
|
可行 |
|
路徑 --沒有 |
|
|
|
交易數量 |
|
|
|
版本 |
|
可行 |
|
|
|
|
|
通道 |
|
|
|
通道名稱 |
|
可行 |
|
區塊個數 |
|
|
|
交易個數 |
|
|
|
時間戳 |
|
|
2.SDK文檔
https://hyperledger.github.io/fabric-sdk-node/
https://github.com/hyperledger/fabric-sdk-node
The Hyperledger Fabric Client SDK makes it possible to use APIs to interact with a Hyperledger Fabric blockchain. This readme is directed towards a current or future contributor to this project, and gives an overview of setting up the project locally and running tests. For more information on the SDK, including features and an API reference, please visit the SDK documentation.
This project publishes the following npm packages:
fabric-ca-client - client for the optional component in Hyperledger Fabric, fabric-ca. The fabric-ca component allows applications to enroll Peers and application users to establish trusted identities on the blockchain network. It also provides support for pseudonymous transaction submissions with Transaction Certificates. If the target blockchain network is configured with standard Certificate Authorities for trust anchors, the application does not need to use this package.
fabric-common - encapsulates the common code used by all fabric-sdk-node packages supporting fine grain interactions with the Fabric network to send transaction invocations
fabric-network - This package encapsulates the APIs to connect to a Fabric network, submit transactions and perform queries against the ledger at a higher level of abstraction than through the fabric-common.
fabric-protos - This package encapsulates the protobuffers that are used to communicate over gRPC
3.SDK和網絡交互
應用程序通過sdk和區塊鏈網絡進行交互,需要連接的節點包括排序節點、對等節點。
4.SDK組成
名稱 |
作用 |
備注 |
fabric-ca-client |
CA模塊的客戶端 |
|
fabric-common |
通用代碼封裝,工具模塊 |
|
fabric-network |
網絡連接,提交交易,執行查詢比fabric-common提供的更高級 |
|
fabric-protos |
封裝gRPC協議 |
|
參考文章:
https://www.jianshu.com/p/1224f504bf9e?appinstall=0
SDK接口,使用SDK完成對區塊鏈網絡運行概況的監控,需要用到系統鏈碼,系統鏈碼包如下五大類型。
系統鏈碼名稱 |
功能 |
備注 |
cscc |
配置管理 |
賬本和鏈 |
escc |
背書簽名過程 |
|
lscc |
鏈碼生命周期管理 |
|
qscc |
賬本和鏈碼的信息查詢 |
|
vscc |
驗證系統鏈碼 |
|
cscc
----------------------
GetChannels 通道
qscc
-------------
GetBlockByNumber 區塊
GetChainInfo 鏈信息
lscc
------------
GetChaincodes 鏈碼
5.SDK使用
Sdk使用前需要准備以下材料:
(1) 連接配置文件
(2) 身份信息(證書,私鑰)
注意事項:
調用時配置參數,自動發現為真,作為本地主機為假。
2.2版本的SDK去掉了queryInfo接口
6.常見問題
接入節點peer0.org1.example.com出現如下錯誤:
TLS handshake failed with error EOF server=PeerServer remoteaddress=192.168.60.26:50800
原因:
Sdk調用代碼中,自動發現需要設置為真