caliper的應用之三Raft版本的分析使用

一、安裝使用

在分析好Solo版本之後,其實都明白,實際應用中,不可能會使用這個版本的,因爲,這個不是一個真正的應用環境。早先Caliper使用的是Kafka共識排序,現在新的版本提供了Raft共識排序。爲什麼要換成Raft呢?主要原因在於,前者是等於利用的另外一個框架,其版本的迭代,必然會影響到Caliper自身的變化。而且Kafka本身也不是爲了Caliper量身定製的。大量的相差的功能其實是沒有什麼用處的。而如果換成自己的Raft,一個是隨時可以升級,可插拔。另外一個,維護和管理上,方便許多。
Raft版本的安裝和普通的安裝沒有什麼區別,區別在於啓動測試命令時,對配置的需求不同,及配置文件內對相差參數的設置的修改。具體的命令,可以參看第一篇文章內的命令分析和說明。

二、配置文件分析

配置文件在開源項目中有以下內容:

[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳
在這裏插入圖片描述

在前面也提到過,在新的1.4版本以上,提供了Couchdb版本,所以在這個配置文件裏其實是有兩大類,一個大類是leveldb版本,另外一個就是CouchDb版本,這裏對這個數據庫的配置要求只需要按需求來設置即可,不影響測試配置的普適性。目前普遍仍然是使用LevelDb爲主。所以上面的圖裏只是展示了這個版本。
這裏只是測試自帶的下載版本,不包括具體的安裝好的環境。這個在下一篇具體分析。在這裏,一般來說,需要處理以下幾個問題:
1、鏈本身的配置文件
2、鏈的容器配置
3、Caliper相差配置。
由於1和2不屬於本文的分析範圍,所以這裏不做分析。只分析Caliper本身的配置文件。
看一下版本的配置文件:

name: Fabric
version: "1.0"
mutual-tls: false

caliper:
  blockchain: fabric
  command:
    start: export FABRIC_VERSION=1.4.1;docker-compose -f networks/fabric/docker-compose/2org1peergoleveldb_raft/docker-compose-tls.yaml up -d;sleep 3s
    end: docker-compose -f networks/fabric/docker-compose/2org1peergoleveldb_raft/docker-compose-tls.yaml down;(test -z \"$(docker ps -aq)\") || docker rm $(docker ps -aq);(test -z \"$(docker images dev* -q)\") || docker rmi $(docker images dev* -q);rm -rf /tmp/hfc-*

info:
  Version: 1.4.1
  Size: 2 Orgs with 1 Peer
  Orderer: Raft
  Distribution: Single Host
  StateDB: GoLevelDB

clients:
  client0.org1.example.com:
    client:
      organization: Org1
      credentialStore:
        path: /tmp/hfc-kvs/org1
        cryptoStore:
          path: /tmp/hfc-cvs/org1
      clientPrivateKey:
        path: networks/fabric/config_raft/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/key.pem
      clientSignedCert:
        path: networks/fabric/config_raft/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts/[email protected]

  client0.org2.example.com:
    client:
      organization: Org3
      credentialStore:
        path: /tmp/hfc-kvs/org2
        cryptoStore:
          path: /tmp/hfc-cvs/org2
      clientPrivateKey:
        path: networks/fabric/config_raft/crypto-config/peerOrganizations/org2.example.com/users/[email protected]/msp/keystore/key.pem
      clientSignedCert:
        path: networks/fabric/config_raft/crypto-config/peerOrganizations/org2.example.com/users/[email protected]/msp/signcerts/[email protected]


channels:
  mychannel:
    configBinary: networks/fabric/config_raft/mychannel.tx
    created: false
    orderers:
    - orderer0.example.com
    - orderer1.example.com
    - orderer2.example.com
    peers:
      peer0.org1.example.com:
        eventSource: true
      peer0.org2.example.com:
        eventSource: true

    chaincodes:
    - id: marbles
      version: v0
      language: golang
      path: fabric/samples/marbles/go
      metadataPath: src/fabric/samples/marbles/go/metadata
    - id: drm
      version: v0
      language: golang
      path: fabric/scenario/drm/go
    - id: simple
      version: v0
      language: golang
      path: fabric/scenario/simple/go
    - id: smallbank
      version: v0
      language: golang
      path: fabric/scenario/smallbank/go

organizations:
  Org1:
    mspid: Org1MSP
    peers:
    - peer0.org1.example.com
    certificateAuthorities:
    - ca.org1.example.com
    adminPrivateKey:
      path: networks/fabric/config_raft/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/key.pem
    signedCert:
      path: networks/fabric/config_raft/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts/[email protected]

  Org2:
    mspid: Org2MSP
    peers:
    - peer0.org2.example.com
    certificateAuthorities:
    - ca.org2.example.com
    adminPrivateKey:
      path: networks/fabric/config_raft/crypto-config/peerOrganizations/org2.example.com/users/[email protected]/msp/keystore/key.pem
    signedCert:
      path: networks/fabric/config_raft/crypto-config/peerOrganizations/org2.example.com/users/[email protected]/msp/signcerts/[email protected]

orderers:
  orderer0.example.com:
    url: grpcs://localhost:7050
    grpcOptions:
      ssl-target-name-override: orderer0.example.com
    tlsCACerts:
        path: networks/fabric/config_raft/crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
  orderer1.example.com:
    url: grpcs://localhost:8050
    grpcOptions:
        ssl-target-name-override: orderer1.example.com
    tlsCACerts:
        path: networks/fabric/config_raft/crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
  orderer2.example.com:
      url: grpcs://localhost:9050
      grpcOptions:
          ssl-target-name-override: orderer2.example.com
      tlsCACerts:
          path: networks/fabric/config_raft/crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

peers:
  peer0.org1.example.com:
    url: grpcs://localhost:7051
    grpcOptions:
      ssl-target-name-override: peer0.org1.example.com
      grpc.keepalive_time_ms: 600000
    tlsCACerts:
        path: networks/fabric/config_raft/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp/tlscacerts/tlsca.org1.example.com-cert.pem

  peer0.org2.example.com:
    url: grpcs://localhost:8051
    grpcOptions:
      ssl-target-name-override: peer0.org2.example.com
      grpc.keepalive_time_ms: 600000
    tlsCACerts:
        path: networks/fabric/config_raft/crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp/tlscacerts/tlsca.org2.example.com-cert.pem

certificateAuthorities:
  ca.org1.example.com:
    url: https://localhost:7054
    httpOptions:
      verify: false
    tlsCACerts:
        path: networks/fabric/config_raft/crypto-config/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem
    registrar:
    - enrollId: admin
      enrollSecret: adminpw

  ca.org2.example.com:
    url: https://localhost:8054
    httpOptions:
      verify: false
    tlsCACerts:
        path: networks/fabric/config_raft/crypto-config/peerOrganizations/org2.example.com/tlsca/tlsca.org2.example.com-cert.pem
    registrar:
    - enrollId: admin
      enrollSecret: adminpw

此處最簡單的方法是不要動任何配置,直接啓動,正常的情況下,會自動下載相差的鏡像,並開始測試。下面對幾個主要的部分進行一下分析:
1、Caliper:
這一個項目,主要是分爲測試鏈的目標是哪種,比如這裏是Fabric,命令如何操作,啓動和結束時如何處理相着的腳本和數據。
2、Info
主要配置一下,節點的數量,鏈的版本,排序的類型和使用數據庫等。
3、Client
這個主要是配置相差的客戶端的認證存儲的路徑和相差的證書的路徑。注意,這裏使用了相當多的臨時路徑,意思是可以刪除。
4、Channel
設置通道名稱,比如“mychannel”, 語言,相關路徑,是否已經創建。如果創建爲Ture,默認爲未創建,False。
5、Organizatons
這個主要是對組織的名稱,節點的名稱(域名),數量,證書私鑰等的路徑進行配置。
6、Orders
排序節點的配置,主要是排序節點的名稱(域名),IP地址和端口,相差的Tls的證書路徑。名稱和數量與組織內的配置保持一致。
7、Peers:
類似上面的排序節點,配置名稱,IP和端口以及相差的證書。需要注意的是,這些域名和數量要和上面的組織內的配置保持一致。
8、CertificateAuthorities:
這個就是上面的配置的證書的節點,同上面的排序和Peers兩個節點一樣。
上面的這些配置,可以參照Caliper的相差幫助文檔,凡是可選的,都是可以註釋掉的。不過要註釋掉時,要保持相關節點的依賴一致。舉一個例子,在客戶端的配置中,如果把私鑰的可選配置註釋,下面的簽名的配置同樣也要註釋,因爲後者需要前者來進行簽名動作。

三、總結

用這種方式來進行Solo測試還是可以接受的,如果應用於Raft的測試,還不是有多好,畢竟都下載到了同一臺機器內,對機器的硬件的要求琮是比較高的。測試出來的結果也不會有多的代表性,重點還是要使用這種機制來測試已經安裝好的相關的Fabric環境。在下一篇的文章中,會繼續分析下頭的配置文件。
Caliper的應用還是比較普遍的,特別是國內某些人修改了一下這個框架就開始拿來主義。學明白了,至少不會被忽悠。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章