以太坊PoA共识引擎算法介绍(3)

PoA私链搭建

go-ethereum自带puppeth工具, 可以方便地部署支持PoA的以太坊私链,以本地部署2节点的以太坊私有链为例, 部署步骤如下:

  1. geth1.6版本后自带puppeth工具(编译geth时用 make all )
  2. 创建两个文件夹,用来保存2个节点数据, 创建后进入到testnet文件夹
      testnet
      |-- node1
      |-- node2
  1. 创建2个账户作为signer,生成的2个地址保存为变量: {ADDR1} 和 {ADDR2}
      $ geth --datadir node1 account new
      $ geth --datadir node2 account new
  1. 通过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>
  1. 启动节点, 在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
  1. 连接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地址

  1. 启动"挖矿"
      > personal.unlockAccount(eth.coinbase)
      > eth.defaultAccount = eth.coinbase
      > miner.start()

一切顺利的话,就开始定时出块.
注意:

  • 出块时间如果配置为0, 代表没有固定的出块时间, 只有当有新交易产生时才触发出块.



作者:shi_qinfeng
链接:https://www.jianshu.com/p/82e0e1424a53
來源:简书

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值