以太坊PoA共識引擎演算法介紹(3)
阿新 • • 發佈:2019-02-19
PoA私鏈搭建
go-ethereum自帶puppeth工具, 可以方便地部署支援PoA的以太坊私鏈,以本地部署2節點的以太坊私有鏈為例, 部署步驟如下:
- geth1.6版本後自帶puppeth工具(編譯geth時用
make all
) - 建立兩個資料夾,用來儲存2個節點資料, 建立後進入到testnet資料夾
testnet
|-- node1
|-- node2
- 建立2個賬戶作為signer,生成的2個地址儲存為變數:
{ADDR1} 和 {ADDR2}
$ geth --datadir node1 account new $ geth --datadir node2 account new
- 通過puppeth建立genesis檔案
$ puppeth Please specify a network name to administer (no spaces, please) > testnet What would you like to do? (default = stats) 1. Show network stats 2. Configure new genesis 3. Track new remote server 4. Deploy network components > 2 Which consensus engine to use? (default = clique) 1. Ethash - proof-of-work 2. Clique - proof-of-authority > 2 How many seconds should blocks take? (default = 15) > 10 Which accounts are allowed to seal? (mandatory at least one) (addresses from the account creation above, replace with your own) > 0x{ADDR1} > 0x{ADDR2} > 0x<ENTER> Which accounts should be pre-funded? (advisable at least one) > 0x{ADDR1} > 0x{ADDR2} > 0x<ENTER> Specify your chain/network ID if you want an explicit one (default = random) > <ENTER> Anything fun to embed into the genesis block? (max 32 bytes) > <ENTER> What would you like to do? (default = stats) 1. Show network stats 2. Save existing genesis 3. Track new remote server 4. Deploy network components > 2 Which file to save the genesis into? (default = testnet.json) > <ENTER> What would you like to do? (default = stats) 1. Show network stats 2. Save existing genesis 3. Track new remote server 4. Deploy network components > <CTRL-C>
- 啟動節點, 在2個終端上分別執行:
serv1$ geth --datadir node1 init testnet.json
serv1$ geth --datadir node1 --port 3000 --syncmode "full" console
serv2$ geth --datadir node2 init testnet.json
serv2$ geth --datadir node2 --port 3002 --syncmode "full" console
啟動後也可以通過attach到geth節點
console1$ geth attach ipc:node1/geth.ipc console2$ geth attach ipc:node2/geth.ipc
- 連線2個節點
console2> admin.nodeInfo.enode
{ENODE-URL}
console1> admin.addPeer({ENODE-URL})
console1> admin.nodeInfo.enode
{ENODE-URL}
console2> admin.addPeer({ENODE-URL})
在客戶端上 net.peerCount
應該可以看到數量是1
如果2個節點部署在2個主機上,那麼ENODE-URL中的[::]需要替換為對應主機的IP地址
- 啟動"挖礦"
> personal.unlockAccount(eth.coinbase)
> eth.defaultAccount = eth.coinbase
> miner.start()
一切順利的話,就開始定時出塊.
注意:
- 出塊時間如果配置為0, 代表沒有固定的出塊時間, 只有當有新交易產生時才觸發出塊.
作者:shi_qinfeng
連結:https://www.jianshu.com/p/82e0e1424a53
來源:簡書