這篇文章主要為大家展示了“Hyperledger Fabric網(wǎng)絡(luò)構(gòu)架的示例分析”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“Hyperledger Fabric網(wǎng)絡(luò)構(gòu)架的示例分析”這篇文章吧。
在定邊等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站建設(shè)、成都做網(wǎng)站 網(wǎng)站設(shè)計制作定制網(wǎng)站開發(fā),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),成都全網(wǎng)營銷推廣,外貿(mào)營銷網(wǎng)站建設(shè),定邊網(wǎng)站建設(shè)費用合理。
tx: transaction 交易,操作。
比如去超市買狗糧的時候,從自己的電子錢包轉(zhuǎn)帳到咖啡店這個請求,可以看作是一個tx。
比如你收到快遞,你通過快遞公司的應(yīng)用,點擊了“查收”,這個操作可以看作一個tx。
每次一你準(zhǔn)備更新賬本的操作,都可以視為tx。
Fabric是做聯(lián)盟鏈的。跟公鏈不同,任何你想對賬本的操作,讀取,寫入,都需要通過 智能合約 才可以發(fā)生的。
Hyperledger Fabric smart contracts are written in chaincode and are invoked by an application external to the blockchain when that application needs to interact with the ledger.
所以,在Fabric里,智能合約 = chaincode
chaincode很重要,也很關(guān)鍵了。不懂chaincode就么有辦法玩Fabric網(wǎng)絡(luò),但chaincode是用Go寫的,你需要先回去學(xué)習(xí)Go語言,怕怕了吧?o(∩∩)o...哈哈,這個部分經(jīng)過Composer的封裝后,可以用JS來寫了。比起完全自己寫chaincode,用composer的話,可以簡化不少流程呢。所以,未來的鏟S官寫完這篇博文后,就去學(xué)JS。
In most cases, chaincode interacts ONLY with the database component of the ledger, the world state (querying it, for example), and NOT the transaction log.
Chaincode can be implemented in several programming languages. The currently supported chaincode language is Go with support for Java and other languages coming in future releases.
細(xì)心的童靴應(yīng)該注意到了 the world state 這個詞。這個就是賬本的意思么?跟賬本是什么關(guān)系呢?
Ledger
原來,一個賬本里面包含了兩部分: the world state 和 Blockchain
The world state represents the current values of all ledger states.
簡單粗暴的說,就是區(qū)塊鏈里面記錄的信息,最終的狀態(tài),是由 the world state 來儲存的。主要用于上面chaincode的快速查詢使用。不用反推所有區(qū)塊鏈里面的交易真假。百無聊賴的時候,就可以從 Blockchain 來計算一下,得到新的 the world state。目前存儲 the world state可以用: an embedded LevelDB 或者 an external CouchDB。
而賬本里面的區(qū)塊鏈?zhǔn)牵?任何操作的記錄
The blockchain is a transaction log, structured as interlinked blocks, where each block contains a sequence of transactions, each of which represents a query or update to the world state.
智能合約 又叫做 chaincode,所有的對區(qū)塊鏈的操作,都需要通過 chaincode。chaincode 目前支持Go語言,對于這個部分的編程,如果使用 Composer 的話,可以簡化流程和節(jié)約時間。
通過 chaincode ,我們可以查詢,讀寫 Blockchain Ledger,Blockchain Ledger 又叫做賬本。由 the world state 和 Blockchain 組成。the world state 主要服務(wù)于 chaincode 的查詢。而 Blockchain是用于流水線式記錄交易。
目標(biāo)
通過動手啟動一個最簡單的Hyperledger Fabric網(wǎng)絡(luò),來進(jìn)一步了解Hyperledger Fabric的網(wǎng)絡(luò)構(gòu)成。
這里介紹的步驟,以及代碼可能不適用于最新Docker Image,我們在這里主要關(guān)注網(wǎng)絡(luò)結(jié)構(gòu)。
這個網(wǎng)絡(luò)將包含:
兩個參與方
每個參與方有兩個節(jié)點
有一個 排序節(jié)點
準(zhǔn)備
Prerequisites(http://hyperledger-fabric.readthedocs.io/en/release-1.1/prereqs.html)
Hyperledger Fabric Samples(http://hyperledger-fabric.readthedocs.io/en/release-1.1/samples.html)
我們將會使用: first-network來演示。
開啟我們的第一網(wǎng)絡(luò)
打開目標(biāo)目錄
cd fabric-samples/first-network
在first-network的文件夾下面,有一個包含了我們啟動所需要全部步驟(兩個參與方,每個參與方維護兩個節(jié)點,有一個獨立的排序節(jié)點)的腳本文件 byfn.sh,這個腳本文件附帶注解,有興趣的童靴可以研究一下。
* 查詢 byfn.sh的文檔 ./byfn.sh --help Usage: byfn.sh -m up|down|restart|generate Typically, one would first generate the required certificates and genesis block, then bring up the network. e.g.: byfn.sh -m generate -c mychannel byfn.sh -m up -c mychannel -s couchdb byfn.sh -m up -c mychannel -s couchdb -i 1.0.6 byfn.sh -m down -c mychannel Taking all defaults: byfn.sh -m generate byfn.sh -m up byfn.sh -m down
生成網(wǎng)絡(luò)需要的要素
./byfn.sh -m generate Generating certs and genesis block for with channel 'mychannel' and CLI timeout of '10' Continue (y/n)?
生成證書,以及一個叫做'mychannel'的通道,并為此通道配置一個區(qū)塊,最長等待請求的時長為10秒? 輸入y。 你可以通過參數(shù)來個性化配置網(wǎng)絡(luò)
然后屏幕上就生成了一大堆的輸出。根本就不想看對吧?不想看的童鞋可以直接跳到下一個步驟。
########################################################## ##### Generate certificates using cryptogen tool ################################################################### org1.example.com org2.example.com 通過 cryptogen tool 生成數(shù)字證書 ########################################################## ######### Generating Orderer Genesis block ############### ######################################################### 2018-06-23 13:32:34.246 JST [common/configtx/tool] main -> INFO 001 Loading configuration 2018-06-23 13:32:34.416 JST [common/configtx/tool] doOutputBlock -> INFO 002 Generating genesis block 2018-06-23 13:32:34.417 JST [common/configtx/tool] doOutputBlock -> INFO 003 Writing genesis block 生成排序節(jié)點,以及創(chuàng)世紀(jì)區(qū)塊(第一個區(qū)塊) ################################################################# ### Generating channel configuration transaction 'channel.tx' ### ################################################################# 2018-06-23 13:32:34.462 JST [common/configtx/tool] main -> INFO 001 Loading configuration 2018-06-23 13:32:34.464 JST [common/configtx/tool] doOutputChannelCreateTx -> INFO 002 Generating new channel configtx 2018-06-23 13:32:34.464 JST [common/configtx/tool] doOutputChannelCreateTx -> INFO 003 Writing new channel tx 生成渠道配置交易:'channel.tx' ################################################################# ####### Generating anchor peer update for Org1MSP ########## ################################################################# 2018-06-23 13:32:34.475 JST [common/configtx/tool] main -> INFO 001 Loading configuration 2018-06-23 13:32:34.479 JST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update 2018-06-23 13:32:34.480 JST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update ################################################################# ####### Generating anchor peer update for Org2MSP ######### ################################################################## 2018-06-23 13:32:34.490 JST [common/configtx/tool] main -> INFO 001 Loading configuration 2018-06-23 13:32:34.494 JST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update 2018-06-23 13:32:34.494 JST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update
生成anchor peer,別且將其分配給各個參與方
啟動網(wǎng)絡(luò)
./byfn.sh -m up Starting with channel 'mychannel' and CLI timeout of '10'Continue (y/n)? 啟動'mychannel'? 輸入y。
然后屏幕上又出現(xiàn)了一堆代碼,不想看的童靴可以跳過。
Creating network "net_byfn" with the default driver 生成網(wǎng)絡(luò) Creating volume "net_orderer.example.com" with default driver 生成排序節(jié)點數(shù)據(jù) volume是Docker里面,存儲數(shù)據(jù)的一種方法。詳細(xì)可以參照:https://docs.docker.com/storage/volumes/ Creating volume "net_peer0.org1.example.com" with default driver Creating volume "net_peer1.org1.example.com" with default driver Creating volume "net_peer0.org2.example.com" with default driver Creating volume "net_peer1.org2.example.com" with default driver 生成四個節(jié)點數(shù)據(jù) Creating peer0.org2.example.com ... done Creating peer1.org1.example.com ... done Creating peer1.org2.example.com ... done Creating peer0.org1.example.com ... done 生成四個節(jié)點 Creating orderer.example.com ... done 生成排序節(jié)點 Creating cli ... done生成命令行接口
Channel name : mychannel Creating channel...
生成渠道
Query Result: 90 2018-06-23 04:57:52.496 UTC [main] main -> INFO 008 Exiting..... ===================== Query on PEER3 on channel 'mychannel' is successful ===================== ========= All GOOD, BYFN execution completed ===========
網(wǎng)絡(luò)啟動后,然后自動執(zhí)行一連串的點對點的交易,如果交易都順利完成了,你將看到這個提示。
具體交易流程和內(nèi)容,可以更加輸出的log來確認(rèn)。我們下次再學(xué)習(xí)了。
docker ps
查看Docker的狀態(tài)
CONTAINER ID IMAGE COMMAND PORTS NAMES 91f7854cce55 dev-peer1.org2.example.com-mycc-1.0-26c2ef32838554aac4f7ad6f100aca865e87959c9a126e86d764c8d01f8346ab "chaincode -peer.add…" dev-peer1.org2.example.com-mycc-1.0dc4a6df35ca5 dev-peer0.org1.example.com-mycc-1.0-384f11f484b9302df90b453200cfb25174305fce8f53f4e94d45ee3b6cab0ce9 "chaincode -peer.add…" dev-peer0.org1.example.com-mycc-1.0d60e45ed340a dev-peer0.org2.example.com-mycc-1.0-15b571b3ce849066b7ec74497da3b27e54e0df1345daff3951b94245ce09c42b "chaincode -peer.add…" dev-peer0.org2.example.com-mycc-1.0各個節(jié)點上生成的智能合約。(好像少了一個,沒有dev-peer1.org1.example.com-mycc-1.0) ec0de22dfda5 hyperledger/fabric-peer:latest "peer node start" 0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp peer0.org1.example.comfbbddcc6e511 hyperledger/fabric-peer:latest "peer node start" 0.0.0.0:10051->7051/tcp, 0.0.0.0:10053->7053/tcp peer1.org2.example.comacb521a4dff8 hyperledger/fabric-peer:latest "peer node start" 0.0.0.0:8051->7051/tcp, 0.0.0.0:8053->7053/tcp peer1.org1.example.com555938e16fcb hyperledger/fabric-peer:latest "peer node start" 0.0.0.0:9051->7051/tcp, 0.0.0.0:9053->7053/tcp peer0.org2.example.com節(jié)點7f6f7b69635c hyperledger/fabric-orderer:latest "orderer" 0.0.0.0:7050->7050/tcp orderer.example.com
排序節(jié)點
關(guān)閉網(wǎng)絡(luò)
在完成交易之后,你希望Docker釋放生成的所有: containers, the crypto material, four artifacts, 以及the chaincode images
./byfn.sh -m down Stopping with channel 'mychannel' and CLI timeout of '10'Continue (y/n)? 關(guān)閉通道'mychannel'? 輸入y。 Stopping orderer.example.com ... done Stopping peer1.org2.example.com ... done Stopping peer1.org2.example.com ... done Stopping peer1.org1.example.com ... done Stopping peer0.org2.example.com ... done Removing cli ... done Removing orderer.example.com ... done Removing peer0.org1.example.com ... done Removing peer1.org2.example.com ... done Removing peer1.org1.example.com ... done Removing peer0.org2.example.com ... done Removing network net_byfn
再次查看Docker的狀態(tài)
docker ps
所有的containers都消失了。
以上是“Hyperledger Fabric網(wǎng)絡(luò)構(gòu)架的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
當(dāng)前名稱:HyperledgerFabric網(wǎng)絡(luò)構(gòu)架的示例分析
網(wǎng)址分享:http://www.rwnh.cn/article44/gspgee.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司、網(wǎng)站導(dǎo)航、品牌網(wǎng)站設(shè)計、營銷型網(wǎng)站建設(shè)、ChatGPT、做網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)