Giter Club home page Giter Club logo

privatepoaethereum's Introduction

PrivatePOAEthereum

正式使用硬件需求

Hardware Requirements Minimum:

CPU with 2+ cores 4GB RAM 1TB free storage space to sync the Mainnet 8 MBit/sec download Internet service Recommended:

Fast CPU with 4+ cores 16GB+ RAM High-performance SSD with at least 1TB of free space 25+ MBit/sec download Internet service

出块节点: 开放30303 (测试可以开放8545,后续需要关闭) 同步节点:开放30303 8545

安装golang gcc

sudo apt install build-essential

Clone Ethereum Code

git clone https://github.com/ethereum/go-ethereum.git

编译geth工具

 cd go-ethereum && make geth

写入geth的环境变量

vi ~/.bashrc
export ETHPATH=/opt/go-ethereum/build/bin
export PATH=$ETHPATH:$PATH
source ~/.bashrc

生成账户地址

私钥通过用户输入的密码加密存储,可以通过golang解析出账户地址和私钥: https://github.com/yuhuajing/PrivatePOAEthereum/blob/main/parsePrivateKey.go

geth account new --datadir /opt/etherData

Address: 0x430CbEEffa18BD7ad0Ae5BAc062f130b6c8129B6

PrivateKey: 243c630943018e6a6a0c2a183c640fd420dd5ad22e6b0ef93170580393882ae7

geth account new --datadir /opt/etherData

Address: 0x413E129dD6b217E4a8702821ee069e1929D17c6a

PrivateKey: a7f77faf8ff605de37c63c4c3dc97eaf7d4b68d4de9835aac335869d9bca65be

geth account new --datadir /opt/etherData

Address: 0x9449202f3E28Dd4595b0BE3c1736922Ba5aAce71

PrivateKey: 1b336b83fc8288bad83133b061e80b408d1d5ba01fc1852995758145eda06c3c

构造创世区块

1. chainID:自定义的链ID
2. homesteadBlock、eip150Block、eip155Block、eip158Block、byzantiumBlock、constantinopleBlock、petersburgBlock:各项提案和升级的区块高度
3. period:出块时间间隔,0为不允许出空交易块,会等待有交易才出块
4. epoch:更新出块节点列表的周期
5. difficulty:POA下无作用
6. gasLimit:gasLimit限制
7. extradata:POA模式下用来指定验证者地址,账户地址去掉0x后加上64个前缀0和130个后缀0,比如0x+(64个前缀0)+5534F5024146D16a5C1ce60A9f5a2e9794e3F981+(130个后缀0)
8. alloc:用来预置账号以及账号的以太币数量,比如预置0x0B587FFD0BBa122fb5ddc19AD6eEcEB1D2dBbff7地址拥有1000ETH(1000*10^18WEI)

genesis.json

{
   "config":{
      "chainId":12345,
      "homesteadBlock":0,
      "eip150Block":0,
      "eip155Block":0,
      "eip158Block":0,
      "byzantiumBlock":0,
      "constantinopleBlock":0,
      "petersburgBlock":0,
      "istanbulBlock":0,
      "berlinBlock":0,
      "londonBlock": 0,
      "clique":{
         "period":5,
         "epoch":300
      }
   },
   "alloc":{
      "0x6593B47be3F4Bd1154c2faFb8Ad4aC4EFddD618f":{
         "balance":"1000000000000000000000"
      },
      "0x6C345f0771a2f2B2694f97522D3371bF87b6BDF9":{
         "balance":"1000000000000000000000"
      },
      "0xab6bbb89eFd62dF605C881E692960a4951238D71":{
         "balance":"1000000000000000000000"
      }
   },
  "coinbase": "0x6593B47be3F4Bd1154c2faFb8Ad4aC4EFddD618f",
  "difficulty": "1",
  "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000验证者地址0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "gasLimit": "80000000",
  "nonce": "0x0000000000000000",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp": "0x00"
}

节点启动命令--三个节点分布在三台机器,在同个机器的话,需要手动更改默认端口

创建创世区块

geth --datadir "/opt/etherData" init /opt/etherData/genesis.json

节点启动命令--任选一种方式即可

  1. 节点正常启动
nohup geth --identity "myethereum" --datadir /opt/etherData --allow-insecure-unlock --networkid 12345 --http --http.addr 0.0.0.0  --http.corsdomain "*" --ws --ws.addr 0.0.0.0 --ws.origins "*"  --http.api "eth,net,debug,txpool,web3,personal,admin,miner"  --rpc.enabledeprecatedpersonal --miner.gaslimit 80000000 --syncmode "full" --nodiscover >> geth.log 2>&1 &

或者添加矿工节点启动命令--直接在启动时指定矿工账号,一启动就执行挖矿

nohup geth --identity "myethereum" --datadir /opt/etherData/ --networkid 12345 --authrpc.port 8551 --http --http.port 8545  --http.corsdomain "*" --graphql --ws --ws.port 8546 --ws.addr 0.0.0.0 --ws.origins "*" --port 30303 --http.addr 0.0.0.0 --http.api "eth,net,debug,txpool,web3,personal,admin,miner" --allow-insecure-unlock --rpc.enabledeprecatedpersonal --syncmode "full" --mine --miner.etherbase 0x6593b47be3f4bd1154c2fafb8ad4ac4efddd618f --unlock 0x6593b47be3f4bd1154c2fafb8ad4ac4efddd618f --keystore /opt/etherData/keystore/ --password /opt/etherData/password.txt --nodiscover >> geth1.log 2>&1 &
  1. 连接控制台

    geth attach http://localhost:8545

    或者ipc连接

      geth attach /opt/etherData/node0/geth.ipc
  2. 根据节点私钥导入账号,提供节点私钥、加密节点私钥的对称密钥

personal.importRawKey("08a7533871d3a2e01d3a8849320cbfb703eb20c5dd2a9ccd2d9780eba5659c8e","yu201219jing")
  1. 设置矿工地址(验证者地址)
miner.setEtherbase(eth.accounts[0])
  1. 查看矿工账户
eth.coinbase
  1. 解锁账户--需要指定时间,默认解锁300s personal.unlockAccount(address, passphrase, duration),密码和解锁时长都是可选的。如果密码为null,控制台将提示交互输密码。解密的密钥将保存在内存中直到解锁周期超时,默认的解锁周期为300秒。将解锁周期设置为0秒将解锁该密钥直到退出geth程序。
personal.unlockAccount(eth.accounts[0],'passward',0)

矿工设置GasLimit

miner.setGasLimit(80000000)
  1. 启动挖矿(start() 的参数表示挖矿使用的线程数)/关闭挖矿
miner.start()
miner.stop()
  1. 查看节点信息
admin.nodeInfo.enode

通过addPeer命令添加节点.

admin.addPeer("节点信息")

查询链上数据--连接控制台后的操作

  1. 查看所有账户列表
eth.accounts
  1. 查看所有账户余额
eth.getBalance(eth.accounts[0])
balanse=web3.fromWei(eth.getBalance(eth.accounts[0]),'ether')
  1. 查询区块高度
eth.blockNumber
  1. 交易操作 涉及链上交易时,需要先解锁账户。
eth.sendTransaction({from:eth.accounts[0],to:eth.accounts[1],value:web3.toWei(4,'ether')})
  1. 根据交易hash查询交易数据
eth.getTransaction("TxHash")

连接小狐狸钱包

连接网络

RPC: http://xxx:8545 chainId: 12345 名称和代币符号任意。

导入节点

输入节点私钥导入节点账户

新机器操作

数据备份节点

  1. 相同命令启动后,连接控制台
    geth attach http://localhost:8545
    或者ipc连接
      geth attach /opt/etherData/node0/geth.ipc
  2. 建立连接
admin.nodeInfo.enode

通过addPeer命令添加节点.

admin.addPeer("节点信息")

出块节点(创世区块中的验证者地址)

  1. 连接控制台
  2. 根据节点私钥导入账号,提供节点私钥、加密节点私钥的对称密钥
personal.importRawKey("08a7533871d3a2e01d3a8849320cbfb703eb20c5dd2a9ccd2d9780eba5659c8e","KEY")
  1. 设置矿工地址(验证者地址)
miner.setEtherbase(eth.accounts[0])
  1. 查看矿工账户
eth.coinbase
  1. 解锁账户--需要指定时间,默认解锁300s personal.unlockAccount(address, passphrase, duration),密码和解锁时长都是可选的。如果密码为null,控制台将提示交互输密码。解密的密钥将保存在内存中直到解锁周期超时,默认的解锁周期为300秒。将解锁周期设置为0秒将解锁该密钥直到退出geth程序。
personal.unlockAccount(eth.accounts[0],'passward',0)
  1. 启动挖矿
miner.start()

出块节点(新的验证者地址)

新机器执行以下操作

  1. 生成节点
geth account new --datadir /opt/etherData

Address: 0x68d866baAfa993bc002cd35218c13f10aC54221d

PrivateKey: e5ff5392711a137f3a4ac680e85ed29cb896427e89b4e0aa582b785722a84c49

  1. 连接控制台
  2. 根据节点私钥导入新的验证者账号,提供节点私钥、加密节点私钥的对称密钥
personal.importRawKey("e5ff5392711a137f3a4ac680e85ed29cb896427e89b4e0aa582b785722a84c49","KEY")
  1. 在导入创世区块验证者节点的机器上执行以下操作:(需要半数以上的验证者同意)

目前的验证节点通过发起提案增加出块节点,增加后的节点和当前的验证者轮流出块。

clique.propose("新机器上生成的新验证者地址",true)

回到新服务器的终端:

  1. 在新服务器上设置矿工地址(新的验证者地址)
miner.setEtherbase(eth.accounts[0])
  1. 查看矿工账户
eth.coinbase
  1. 解锁账户--需要指定时间,默认解锁300s personal.unlockAccount(address, passphrase, duration),密码和解锁时长都是可选的。如果密码为null,控制台将提示交互输密码。解密的密钥将保存在内存中直到解锁周期超时,默认的解锁周期为300秒。将解锁周期设置为0秒将解锁该密钥直到退出geth程序。
personal.unlockAccount(eth.accounts[0],'passward',0)
  1. 启动挖矿(start() 的参数表示挖矿使用的线程数)/关闭挖矿
miner.start()

关闭节点

ps aux | grep geth | grep -v grep | awk '{print $2}'| xargs kill -15

清除链数据

geth removedb --datadir "/opt/etherData/"

nohup geth --identity "myethereum" --datadir /opt/etherData/ --networkid 12345 --authrpc.port 8551 --http --http.port 8545 --http.corsdomain "" --ws --ws.port 8546 --ws.addr 0.0.0.0 --ws.origins "" --port 30303 --http.addr 0.0.0.0 --http.api "eth,net,web3,personal,admin,miner,debug,txpool" --allow-insecure-unlock --rpc.enabledeprecatedpersonal --syncmode "full" --mine --miner.etherbase 0x430CbEEffa18BD7ad0Ae5BAc062f130b6c8129B6 --unlock 0x430CbEEffa18BD7ad0Ae5BAc062f130b6c8129B6 --keystore /opt/etherData/node0/keystore/ --password /opt/etherData/node0/password.txt --nodiscover >> geth1.log 2>&1 &

privatepoaethereum's People

Contributors

yuhuajing avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.