【Blockchain】Build Geth Consortium Chain (PoA)

We have explained the PoA consortium chain of HyperLedger Besu before and it has been successfully deployed to the server, so Geth, which is also the Ethereum series, should we also arrange it...it is here today.

As before, this Geth blockchain deployment also uses Docker version deployment to avoid unforeseen situations brought about by different environments.

1. Download the Docker image

First, download the docker image of geth

yuanzhenhui@MacBook-Pro ~ % docker pull ethereum/client-go:latest 
latest: Pulling from ethereum/client-go 
df20fa9351a1: Downloading 
c91bff5b9242: Pulling fs layer 
5f274eeeb65e: Pulling fs layer 
latest: Pulling from ethereum/client-go 
df20a9351a1: Pull complete 
c91bff5b9242: Pull complete
5274eeeb65e: Pull complete
Digest: sha256:094f1baec8ecc6f73142cf2aa135dc9741b8593219b09d88cac672eb715b66c
Status:Downloadednewerimageforethereum/client-go:latest
docker.io/ethereum/client-go:latest

Unlike Besu, the geth boot node image needs to be downloaded separately, as shown in the figure below:

yuanzhenhui@MacBook-Pro ~ % docker pull hawyasunaga/ethereum-bootnode :latest
latest: Pulling from hawyasunaga/ethereum-bootnode 
88286f41530e: Pull complete
c9849f710038: Pull complete
Digest: sha256: c3a855ade 70648864ec263c1cfee3719532677ada69da1d21c4897cdfbfc351e
Status: Downloaded newer image for hawyasunaga/ethereum-bootnode: latest
docker.io/hawvasunaaa/ethereum-bootnode:latest

2. Deploy the bootstrap node

After the image is downloaded, you can configure and deploy the boot node, as follows:

docker run -itd -m 256M --privileged=true \
--memory-swap -1 \
-p 30301:30301/udp \
-p 30301:30301/tcp \
-v /Users/yuanzhenhui/Documents/docker_data/geth/bootnode:/root/bootnode \
--name geth_boot hawyasunaga/ethereum-bootnode:latest \
bootnode --genkey=/root/bootnode/boot.key

Executing the above statement will generate a boot.key file in the bootnode folder, as shown below:

image.png
Then you can run the bootnode node

docker run -itd -m 256M --privileged=true \
--memory-swap -1 \
-p 30301:30301/udp \
-p 30301:30301/tcp \
-v /Users/yuanzhenhui/Documents/docker_data/geth/bootnode:/root/bootnode \
--name gethboot hawyasunaga/ethereum-bootnode:latest bootnode --nodekey=/root/bootnode/boot.key \
-addr 172.17.0.4:30301

Since I am using the docker network here, I use the ip address of 172.17.0.4, which can be configured twice according to the actual situation.

3. Deploy block nodes

Since the docker image is not clear about the data file deployment path of the block node, so first run the image directly and enter the docker image to view it

docker run -d --name geth1 -p 8545:8545 -p 30303:30303 ethereum/client-go:latest

It is found that the data files of geth are stored in the /root/.ethereum folder, so modify the mount addresses of the startup nodes respectively, as follows:
geth1 (node ​​1)

docker run -d --privileged=true \
--name geth1 \
-p 8555:8545 \
-p 30353:30303 \
-v /Users/yuanzhenhui/Documents/docker_data/geth/node1:/root/.ethereum ethereum/client-go:latest

geth2 (node ​​2)

docker run -d --privileged=true \
--name geth2 \
-p 8565:8545 \
-p 30363:30303 \
-v /Users/yuanzhenhui/Documents/docker_data/geth/node2:/root/.ethereum ethereum/client-go:latest 

4. Create account

After the node is created, you can create an account through the CLI, and enter the docker container to call the command to create a new account

geth --datadir /root/.ethereum account new

Since the mount folder is /root/.ethereum, point the account creation to this directory, as shown in the figure below:
image.png
Since the system allows me to save the user name and password, I will generate an account.txt file and save it on the mount point ( It is recommended to use a more secure method in a production environment), the following script:

geth1 (node ​​1)

echo 'account: 0x22d19690c9F15a894DF4A5Ad0b3a28e7EAD8a8E4 password: 123456' >> /root/.ethereum/account.txt

geth2 (node ​​2)

echo 'account: 0x66d546cCBF139F3aF4b4EdeC1e02E8796544F37f password: 123456' >> /root/.ethereum/account.txt

image.png

5. Create the genesis block

Next, you can generate the genesis block. Since you are using the docker version, there is no puppeth tool mentioned on the Internet. Here you can only write the genesis block by hand. Fortunately, I have written it once when I was doing geth for the first time (details You can refer to the article "[Blockchain] Building a Geth Private Chain (PoW)", so the problem is not big.

geth1 (node ​​1)

{
    
    
  "config": {
    
    
    "chainId": 20,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip155Block": 0,
    "eip158Block": 0
  },
  "nonce": "0x0000000000000042",
  "timestamp": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "extraData": "",
  "gasLimit": "0xffffffff",
  "difficulty": "0x40",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x0000000000000000000000000000000000000000",
  "alloc": {
    
    
    "0x22d19690c9F15a894DF4A5Ad0b3a28e7EAD8a8E4":{
    
    
      "balance": "1000000000000000"
    },
    "0xdB10376FD880480c8Aa1a87a46Bb0f11eB89Df0b":{
    
    
      "balance": "70000000000000"
    }
  }
}

geth2 (node ​​2)

{
    
    
  "config": {
    
    
    "chainId": 20,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip155Block": 0,
    "eip158Block": 0
  },
  "nonce": "0x0000000000000042",
  "timestamp": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "extraData": "",
  "gasLimit": "0xffffffff",
  "difficulty": "0x40",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x0000000000000000000000000000000000000000",
  "alloc": {
    
    
    "0x66d546cCBF139F3aF4b4EdeC1e02E8796544F37f": {
    
    
      "balance": "50000000000000"
    }
  }
}

Then shut down the geth1 node and geth2 node of docker and delete the container. Then go to the host data mount folder and delete the geth folder in the node1 and node2 folders. Then you can execute the command to initialize the genesis block, the following script:

geth1 (node ​​1)

docker run -itd --privileged=true \
-v /Users/yuanzhenhui/Documents/docker_data/geth/node1:/root/.ethereum \
--name geth1 ethereum/client-go:latest \
--datadir /root/.ethereum \
--networkid 8765639436932780 init /root/.ethereum/genesis.json

geth2 (node ​​2)

docker run -itd --privileged=true \
-v /Users/yuanzhenhui/Documents/docker_data/geth/node2:/root/.ethereum \
--name geth2 ethereum/client-go:latest \
--datadir /root/.ethereum \
--networkid 8765639736932780 init /root/.ethereum/genesis.json

After execution, geth files will be regenerated under the node1 and node2 folders.

6. Encountered a problem

After the genesis block is written, the startup may encounter the following problems, as shown in the figure below:

Fatal: Failed to write genesis block: unsupported fork ordering: eip150Block not enabled, but eip155Block enabled at 0 genesis block

The geth related files were also unsuccessfully generated. This error is caused by not including the configuration information of eip150Block in the genesis block. Since the latest image contains the optimization of the "EIP150" proposal (EIP150 proposal: solve the denial of service attack, and prevent the attack by increasing the gas related to IO operations), so this time it will be added.

7. Results

After the above operations are completed, you can delete the geth container in docker and write the final configuration to start the node.

Guess you like

Origin blog.csdn.net/kida_yuan/article/details/130054492