ethereum-pocr / kerleano

Information on the Kerleano test network
3 stars 1 forks source link

Node Set-up PowerShell #38

Closed andrerochet closed 1 year ago

andrerochet commented 1 year ago

1. Prepare the environment

Open Windows PowerShell. Create a folder to host the environment. Type this command and press Enter:

New-Item -ItemType Directory -Path "C:\XXX\XXX\Documents\Environnement\Kerleano"

(replace XXX by your computer informations)

2. Get geth binary

geth is the binary of the Ethereum client implemented in golang. We'll download it from the repository.

Download from the repository

Change to the newly created directory. Type this command and press Enter:

cd "C:\XXX\XXX\Documents\Environnement\Kerleano"

Create a bin folder. Type this command and press Enter:

New-Item -ItemType Directory -Path ".\bin" Download the geth binary. Type this command and press Enter:

Invoke-WebRequest -Uri "https://github.com/ethereum-pocr/go-ethereum/releases/download/v1.10.26-pocr-2.0.0/geth" -OutFile ".\bin\geth.exe"

Add the bin folder to your PATH environment variable. Type this command and press Enter:

$env:Path += ";C:\XXX\XXX\Documents\Environnement\Kerleano\bin" Check that geth is functional in your environment. Type this command and press Enter:

geth version

3. Initialize the network data

Download the Kerleano genesis file. Type this command and press Enter:

Invoke-WebRequest -Uri "https://github.com/ethereum-pocr/ethereum-pocr.github.io/releases/download/v2.0.0/kerleano.json" -OutFile "genesis.json" Get the boot nodes

Download the list of live boot nodes. Type this command and press Enter

Invoke-WebRequest -Uri "https://raw.githubusercontent.com/ethereum-pocr/kerleano/main/BOOTNODES" -OutFile "bootnodes"

Initialize the network database

geth init --datadir ".\ethereum" ".\genesis.json"

4. Start the node as a client node

cd C:\Users\test4\Documents\Environnement\Kerleano Next, we will convert the bootnodes file into a comma-separated list, get the value of the chain Id, and use it as the network Id as well.

$BOOTNODES = (Get-Content .\bootnodes) -join ","
$NETWORK_ID = (Get-Content .\genesis.json | Select-String -Pattern 'chainId' | ForEach-Object { $_ -replace '[^0-9]+', '' })
$PUBLIC_IP = Invoke-RestMethod -Uri 'http://ifconfig.me/ip'
$SYNCMODE = "snap"

Now, start the geth client:

geth --networkid $NETWORK_ID --datadir ".\ethereum" --bootnodes "$BOOTNODES" --syncmode $SYNCMODE --http --http.addr="0.0.0.0" --http.port=8545 --http.api="web3,eth,net,clique" --http.corsdomain="*" --http.vhosts="*" --ws --ws.addr="0.0.0.0" --ws.port=8546 --ws.api="web3,eth,net,clique" --ws.origins="*" --nat extip:$PUBLIC_IP

Error :

Here starts the sync, at 98% sync I get a bad block error that goes on and on for hours even after resetting badblock

Question is why ?

Synchronization issues: The synchronization process stops at a certain point and cannot proceed further. This may be caused by a bad block, which may be recent or not.

Compatibility issues: There may be compatibility issues between Geth and LevelDB under Windows due to several reasons, such as an incompatible version of LevelDB or errors in the LevelDB data files. This can cause synchronization problems as well.

Scripting errors: It may be caused by errors in my script.

guenoledc commented 1 year ago

Hi @andrerochet

Unfortunately I could not replicate the problem and got my windows env to work fine

When running with your script all goes well and I get the synchronization fine to the end and a node synchronizing then block by block:

INFO [05-09|20:16:55.186] Imported new chain segment               blocks=1     txs=0  mgas=0.000 elapsed=10.572ms  mgasps=0.000 number=3,146,057 hash=199b39..f6eb1e dirty=415.82KiB
INFO [05-09|20:16:55.194] Unindexed transactions                   blocks=1     txs=0  tail=796,058 elapsed=0s
INFO [05-09|20:16:59.710] πŸ’΅ Sealer earnings                        block=3,146,058 node=0xCca833ec5Bb4FCeb5145fa2fD65c94c446028Ff6 rank=1.0000 blockReward=2602303029039446153 feeAdjustment=0              burnt=0
INFO [05-09|20:16:59.719] Imported new chain segment               blocks=1     txs=0  mgas=0.000 elapsed=9.584ms   mgasps=0.000 number=3,146,058 hash=5f718a..61cff5 dirty=416.07KiB
INFO [05-09|20:16:59.727] Unindexed transactions                   blocks=1     txs=0  tail=796,059 elapsed=0s
INFO [05-09|20:17:03.365] πŸ’΅ Sealer earnings                        block=3,146,059 node=0xeC3F218D9876BFC01E9A4601575Fe60F1b2C8F76 rank=0.8100 blockReward=2107865060143245622 feeAdjustment=0              burnt=0
INFO [05-09|20:17:03.375] Imported new chain segment               blocks=1     txs=0  mgas=0.000 elapsed=11.224ms  mgasps=0.000 number=3,146,059 hash=7d0601..9a75d7 dirty=415.83KiB
INFO [05-09|20:17:03.386] Unindexed transactions                   blocks=1     txs=0  tail=796,060 elapsed=0s
INFO [05-09|20:17:07.696] πŸ’΅ Sealer earnings                        block=3,146,060 node=0x1311aEF86D1DB33Db945fc488eEFF1C6105b9593 rank=0.9000 blockReward=2342071935007342596 feeAdjustment=0              burnt=0
INFO [05-09|20:17:07.706] Imported new chain segment               blocks=1     txs=0  mgas=0.000 elapsed=9.997ms   mgasps=0.000 number=3,146,060 hash=e8e1dd..3fea52 dirty=416.86KiB
INFO [05-09|20:17:07.714] Unindexed transactions                   blocks=1     txs=0  tail=796,061 elapsed=0s
INFO [05-09|20:17:11.194] πŸ’΅ Sealer earnings                        block=3,146,061 node=0x20C8f6D7E11C42C83C9af2f6144c963315106Fc9 rank=0.6561 blockReward=1707370153847469240 feeAdjustment=0              burnt=0
INFO [05-09|20:17:11.203] Imported new chain segment               blocks=1     txs=0  mgas=0.000 elapsed=10.012ms  mgasps=0.000 number=3,146,061 hash=abdab9..e0348f dirty=413.70KiB
INFO [05-09|20:17:11.213] Unindexed transactions                   blocks=1     txs=0  tail=796,062 elapsed=0s
INFO [05-09|20:17:15.166] πŸ’΅ Sealer earnings                        block=3,146,062 node=0xC16c63Da5F6e464148Ffc0Bcef9e761A16Af6004 rank=0.7290 blockReward=1897077716433448054 feeAdjustment=0              burnt=0
INFO [05-09|20:17:15.176] Imported new chain segment               blocks=1     txs=0  mgas=0.000 elapsed=10.641ms  mgasps=0.000 number=3,146,062 hash=87c115..896c4d dirty=410.10KiB
INFO [05-09|20:17:15.186] Unindexed transactions                   blocks=1     txs=0  tail=796,063 elapsed=0s
INFO [05-09|20:17:19.678] πŸ’΅ Sealer earnings                        block=3,146,063 node=0xCca833ec5Bb4FCeb5145fa2fD65c94c446028Ff6 rank=1.0000 blockReward=2602301040244170271 feeAdjustment=0              burnt=0
INFO [05-09|20:17:19.688] Imported new chain segment               blocks=1     txs=0  mgas=0.000 elapsed=10.117ms  mgasps=0.000 number=3,146,063 hash=ec679d..8a7612 dirty=410.35KiB
INFO [05-09|20:17:19.698] Unindexed transactions                   blocks=1     txs=0  tail=796,064 elapsed=0s
INFO [05-09|20:17:23.350] πŸ’΅ Sealer earnings                        block=3,146,064 node=0xeC3F218D9876BFC01E9A4601575Fe60F1b2C8F76 rank=0.8100 blockReward=2107863449219679578 feeAdjustment=0              burnt=0
INFO [05-09|20:17:23.359] Imported new chain segment               blocks=1     txs=0  mgas=0.000 elapsed=9.552ms   mgasps=0.000 number=3,146,064 hash=fd6916..0e8846 dirty=410.12KiB
INFO [05-09|20:17:23.371] Unindexed transactions                   blocks=1     txs=0  tail=796,065 elapsed=0s
INFO [05-09|20:17:27.684] πŸ’΅ Sealer earnings                        block=3,146,065 node=0x1311aEF86D1DB33Db945fc488eEFF1C6105b9593 rank=0.9000 blockReward=2342070145092815892 feeAdjustment=0              burnt=0
INFO [05-09|20:17:27.694] Imported new chain segment               blocks=1     txs=0  mgas=0.000 elapsed=10.051ms  mgasps=0.000 number=3,146,065 hash=43925c..0ddbab dirty=409.96KiB
INFO [05-09|20:17:27.702] Unindexed transactions                   blocks=1     txs=0  tail=796,066 elapsed="525.2Β΅s"

My guess is that you did not compile the right geth source code: In the screen you gave me earlier we have image

The commit indicated is ea9e62ca3d5c33aa7438ebf39c189afd53c6bf8 is not in the https://github.com/ethereum-pocr/go-ethereum (correct repo) but the https://github.com/ethereum/go-ethereum (the original ethereum repo) on version 1.11.6 stable.

So given that you are running a different version of the code (hence of the consensus) it is quite normal that the calculated merkle root (the root hash of the tree of hashes of all the states) you have locally differ from the hash in the downloaded block.

Could you

andrerochet commented 1 year ago

Hi @guenoledc here is my reply step by step until the troubleshooting error when attempting to verify the connection (3.3 Connect and interact with the node of your tutorial as well as attempted solutions)

Tutorial: Setting up Kerleano PoCR Node using Git Bash on Windows

Introduction

This tutorial will guide you through the process of setting up the Kerleano Proof of Custody and Retrieval (PoCR) Node on a Windows PC using Git Bash. The process involves cloning the required repositories, building the necessary binaries, and initializing your Ethereum node.

We have also indicated in the last part troubleshooting issues and attempted solutions that were this far not resolved.

The commands we will be using are written for Git Bash, which is a shell interface for Git command-line features.

Important Note: The exact paths used in this tutorial may differ from your personal setup. Replace /path/to/your/workspace with the correct path on your local machine.

Chapter 1: Cloning the Repository

1.1 Navigating to your workspace

Open Git Bash and navigate to your workspace using the cd command.

$ cd /path/to/your/workspace

1.2 Cloning the Repository

Clone the Ethereum PoCR repository from Github using the git clone command.

$ git clone --depth=1 https://github.com/ethereum-pocr/go-ethereum.git

Expected Output:

Cloning into 'go-ethereum'...
remote: Enumerating objects: 2102, done.
remote: Counting objects: 100% (2102/2102), done.
remote: Compressing objects: 100% (1802/1802), done.
remote: Total 2102 (delta 293), reused 1314 (delta 173), pack-reused 0
Receiving objects: 100% (2102/2102), 13.12 MiB | 10.58 MiB/s, done.
Resolving deltas: 100% (293/293), done.
Updating files: 100% (1854/1854), done.

This output indicates that the repository has been successfully cloned into your workspace.

Chapter 2: Building Geth Binary

2.1 Navigate into the cloned repository

Change your current directory to the cloned repository.

$ cd /path/to/your/workspace/go-ethereum

2.2 Building Geth

Build the Geth binary using the make command.

$ make geth

Expected Output:

env GO111MODULE=on go run build/ci.go install ./cmd/geth
>>> "C:\\Program Files\\Go\\bin\\go" build -ldflags "-X main.gitCommit=d1d5193135c353184bc8e3eed8c7d9130d0857f4 -X main.gitDate=20230303" -tags urfave_cli_no_docs -trimpath -v -o /path/to/your/workspace/go-ethereum/build/bin/geth.exe ./cmd/geth
Done building.
Run "./build/bin/geth" to launch geth.

This output indicates that the geth binary has been successfully built.

Chapter 3: Setting up the Node

3.1 Creating a bin directory and copying geth

Return to your workspace and create a bin directory (if it doesn't exist already). Copy the geth binary into this directory.

$ cd /path/to/your/workspace
$ mkdir -p bin
$ cp go-ethereum/build/bin/geth bin/geth

3.2 Updating the PATH

Update your PATH environment variable to include the bin directory.

$ export PATH=$PATH:/path/to/your/workspace/bin

You can confirm the geth command is available by using the which command.

$ which geth

Expected Output:

/path/to/your/workspace/bin/geth

This output indicates that the geth binary is available in your PATH.

3.3 Downloading the Genesis File

Download the Kerleano Genesis file using the curl command.

$ curl -o genesis.json -L https://github.com/ethereum-pocr/ethereum-pocr.github.io/releases/download/v2.0.0/kerleano.json

3.4 Downloading the Bootnodes File

Download the Bootnodes file using the curl command.

$ curl -o bootnodes -L https://raw.githubusercontent.com/ethereum-pocr/kerleano/main/BOOTNODES

Chapter 4: Initializing the Node

4.1 Initialize Geth with the Genesis File

Initialize the Geth node with the downloaded Genesis file using the geth init command. The --datadir option specifies the directory where the blockchain data will be stored.

$ ./bin/geth init --datadir .ethereum ./genesis.json

After running the command, you should see the following output:

INFO [05-10|12:34:19.567] Maximum peer count                       ETH=50 LES=0 total=50
INFO [05-10|12:34:19.605] Set global gas cap                       cap=50,000,000
INFO [05-10|12:34:19.607] Allocated cache and file handles         database=/path/to/your/workspace/.ethereum/geth/chaindata cache=16.00MiB handles=16
INFO [05-10|12:34:19.784] Opened ancient database                  database=/path/to/your/workspace/.ethereum/geth/chaindata/ancient/chain readonly=false
INFO [05-10|12:34:19.784] Writing custom genesis block
INFO [05-10|12:34:19.785] Persisted trie from memory database      nodes=13 size=1.80KiB time=0s gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [05-10|12:34:19.786] Successfully wrote genesis state         database=chaindata hash=23dafd..0f9e5d
INFO [05-10|12:34:19.786] Allocated cache and file handles         database=/path/to/your/workspace/.ethereum/geth/lightchaindata cache=16.00MiB handles=16
INFO [05-10|12:34:19.840] Opened ancient database                  database=/path/to/your/workspace/.ethereum/geth/lightchaindata/ancient/chain readonly=false
INFO [05-10|12:34:19.840] Writing custom genesis block
INFO [05-10|12:34:19.840] Persisted trie from memory database      nodes=13 size=1.80KiB time=0s gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [05-10|12:34:19.842] Successfully wrote genesis state         database=lightchaindata hash=23dafd..0f9e5d

This output indicates that the Geth node has been successfully initialized with the provided Genesis file, and the data directories have been configured.

Chapter 5: Running the Node

5.1 Setting Up the Environment Variables

In this step, we will be setting up some necessary environment variables. These are used by the geth command to configure your node.

$ BOOTNODES=$(readarray -t ARRAY < bootnodes; IFS=,; echo "${ARRAY[*]}") # convert the file into a comma separated list
$ NETWORK_ID=$(grep chainId genesis.json | grep -Eo '[0-9]+') # get the value of the chain Id and use it as network id as well
$ PUBLIC_IP=$(curl -s ifconfig.me/ip) # needed to expose your node to other, else you will not be reachable in discovery
$ SYNCMODE=snap # tells to synchronize without validating the transactions (faster but imply you trust the bootnodes)

5.2 Launching the Nodes

Now you can start your node with the geth command. The --networkid option is used to specify the network id. --datadir option is used to specify the data directory. The --bootnodes option is used to specify the bootnodes. The --syncmode option is used to specify the sync mode.

$ ./bin/geth --networkid $NETWORK_ID --datadir .ethereum --bootnodes "$BOOTNODES" --syncmode $SYNCMODE --http --http.addr=0.0.0.0 --http.port=8545 --http.api=web3,eth,net,clique --http.corsdomain=* --http.vhosts=* --ws --ws.addr=0.0.0.0 --ws.port=8546 --ws.api=web3,eth,net,clique --ws.origins=* --nat extip:$PUBLIC_IP

If you encounter the error bash: /c/XXXX/XXX/bin/geth: cannot execute binary file: Exec format error, it means that the binary file of geth is not executable or the file is not compatible with your system.

You might have to download the appropriate geth binary for your system or you can change the permissions of the geth binary to make it executable by using the chmod command:

$ chmod +x /path/to/your/workspace/bin/geth

Once the permissions are updated, try running the geth command again.

Remember to replace /path/to/your/workspace with the actual directory path of your workspace. image Expected output (CTRL + C to end it)

Troubleshooting Connection Issues

Our attempts to attach our Ethereum node to our private network have not been successful so far. We've received multiple errors indicating that our attempts to connect to geth have been actively refused.

$ ./bin/geth attach ws://localhost:8546
Fatal: Unable to attach to remote geth: dial tcp [::1]:8546: connectex: No connection could be made because the target machine actively refused it.

This error can occur if the Ethereum node is not running or if there are network restrictions blocking the connection.

Attempted Solution

To solve this issue, we will attempt to run our Ethereum node with the start_node.sh script.

$ chmod +x start_node.sh
$ ./start_node.sh
nohup: redirecting stderr to stdout

After starting the node, we will try to attach it again.

$ ./bin/geth attach ws://localhost:8546
Fatal: Unable to attach to remote geth: dial tcp [::1]:8546: connectex: No connection could be made because the target machine actively refused it.

Unfortunately, the issue persists. This could be due to the fact that the Ethereum node is not properly set up or is not running as expected.

Verifying Geth Version

To ensure that geth is installed and running properly, we can verify its version.

$ ./geth version
Geth
Version: 1.10.26-pocr-2.0.0
Git Commit: d1d5193135c353184bc8e3eed8c7d9130d0857f4
Git Commit Date: 20230303
Architecture: amd64
Go Version: go1.20.4
Operating System: windows
GOPATH=C:\Users\test4\go
GOROOT=

The output shows that geth is indeed installed and the version details are displayed correctly.

Note: The issues might be specific to the system configuration or network settings.

guenoledc commented 1 year ago

For the attachement to the node you should

Can you share your logs, lsof result for 8545 and 8546?

guenoledc commented 1 year ago

@andrerochet are we closing this thread?

andrerochet commented 1 year ago

Hello @guenoledc here is my final reply with the solution, let me know what you think of it. I tried to imput as many details as possible. We can close the thread afterwards if you wish.

Tutorial: Setting up Kerleano PoCR Node using Git Bash on Windows

This tutorial will guide you through the process of setting up the Kerleano Proof of Custody and Retrieval (PoCR) Node on a Windows PC using Git Bash. Git Bash is a shell interface for Git command-line features, it allows us to use various Linux command-line utilities in a Windows environment.

Prerequisites

Important Note: The exact paths used in this tutorial may differ from your personal setup. Replace /path/to/your/workspace with the correct path on your local machine.

Chapter 1: Cloning the Repository

This step involves getting a copy of the Ethereum PoCR repository onto your local machine for us to work with. This is achieved using the git clone command.

1.1 Navigating to your workspace

First, we need to navigate to the folder where we want to keep our project. For this, we use the cd command, which stands for "change directory". Open Git Bash and navigate to your workspace using the cd command.

$ cd /path/to/your/workspace

image

1.2 Cloning the Repository

Now that we're in the right folder, we can get a copy of the repository. We do this using the git clone command.

$ git clone --depth=1 https://github.com/ethereum-pocr/go-ethereum.git

Expected Output:

Cloning into 'go-ethereum'...
remote: Enumerating objects: 2102, done.
remote: Counting objects: 100% (2102/2102), done.
remote: Compressing objects: 100% (1802/1802), done.
remote: Total 2102 (delta 293), reused 1314 (delta 173), pack-reused 0
Receiving objects: 100% (2102/2102), 13.12 MiB | 10.58 MiB/s, done.
Resolving deltas: 100% (293/293), done.
Updating files: 100% (1854/1854), done.

The output above indicates that the repository has been successfully cloned into your workspace. image

Chapter 2: Building Geth Binary

In this step, we will build a binary for Geth (Go Ethereum), which is a command-line interface for running a full Ethereum node.

2.1 Navigate into the cloned repository

To do this, we need to move into the cloned repository. We can do this with the cd command.

$ cd /path/to/your/workspace/go-ethereum

image

2.2 Building Geth

To build the Geth binary, we use the make command.

$ make geth

Expected Output:

env GO111MODULE=on go run build/ci.go install ./cmd/geth
>>> "C:\\Program Files\\Go\\bin\\go" build -ldflags "-X main.gitCommit=d1d5193135c353184bc8e3eed8c7d9130d0857f4 -X main.gitDate=20230303" -tags urfave_cli_no_docs -trimpath -v -o /path/to/your/workspace/go-ethereum/build/bin/geth.exe ./cmd/geth
Done building.
Run "./build/bin/geth" to launch geth.

image

The output above indicates that the Geth binary has been successfully built.

Chapter 3: Setting up the Node

Now, we are going to set up the node by creating a directory for the binary and making sure the system knows where to find it.

3.1 Creating a bin directory and copying geth

Return to your workspace with the cd command, create a directory named "bin" using the mkdir command (it stands for "make directory"), and then copy the geth binary into this new directory using the cp command (which stands for "copy").

$ cd /path/to/your/workspace
$ mkdir -p bin
$ cp go-ethereum/build/bin/geth bin/geth

image

image

image

3.2 Updating the PATH

Now, we need to let the system know where to find the geth binary. This is done by adding its directory to the PATH environment variable using the export command.

$ export PATH=$PATH:/path/to/your/workspace/bin

image

To confirm that the geth command is now available, use the which command. This command shows the location of the binary associated with the provided command.

$ which geth

image

Expected Output:

/path/to/your/workspace/bin/geth

This output indicates that the geth binary is available in your PATH.

3.3 Downloading the Genesis File

The Genesis file is a JSON file which defines the initial state of your blockchain. We'll download it using the curl command.

$ curl -o genesis.json -L https://github.com/ethereum-pocr/ethereum-pocr.github.io/releases/download/v2.0.0/kerleano.json

image

3.4 Downloading the Bootnodes File

The Bootnodes file is a list of nodes in the network that our node can initially connect to. We'll also download this using the curl command.

$ curl -o bootnodes -L https://raw.githubusercontent.com/ethereum-pocr/kerleano/main/BOOTNODES

image

Chapter 4: Initializing the Node

With all the necessary files and binaries in place, it's time to initialize our node.

4.1 Initialize Geth with the Genesis File

We'll initialize our Geth node with the Genesis file we downloaded. The --datadir option specifies the directory where the blockchain data will be stored.

$ ./bin/geth init --datadir .ethereum ./genesis.json

Expected Output:

INFO [05-10|12:34:19.785] Persisted trie from memory database      nodes=13 size=1.80KiB time=0s gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [05-10|12:34:19.786] Successfully wrote genesis state         database=chaindata hash=23dafd..0f9e5d
INFO [05-10|12:34:19.786] Allocated cache and file handles         database=/path/to/your/workspace/.ethereum/geth/lightchaindata cache=16.00MiB handles=16
INFO [05-10|12:34:19.840] Opened ancient database                  database=/path/to/your/workspace/.ethereum/geth/lightchaindata/ancient/chain readonly=false
INFO [05-10|12:34:19.840] Writing custom genesis block
INFO [05-10|12:34:19.840] Persisted trie from memory database      nodes=13 size=1.80KiB time=0s gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [05-10|12:34:19.842] Successfully wrote genesis state         database=lightchaindata hash=23dafd..0f9e5d

image

This output indicates that the Geth node has been successfully initialized with the provided Genesis file, and the data directories have been configured.

Chapter 5: Running the Node

Finally, it's time to start running our node!

5.1 Setting Up the Environment Variables

In this step, we will be setting up some necessary environment variables. These are used by the geth command to configure your node.

$ BOOTNODES=$(readarray -t ARRAY < bootnodes; IFS=,; echo "${ARRAY[*]}") # convert the file into a comma separated list
$ NETWORK_ID=$(grep chainId genesis.json | grep -Eo '[0-9]+') # get the value of the chain Id and use it as network id as well
$ PUBLIC_IP=$(curl -s ifconfig.me/ip) # needed to expose your node to other, else you will not be reachable in discovery
$ SYNCMODE=snap # tells to synchronize without validating the transactions (faster but imply you trust the bootnodes)

image

5.2 Launching the Nodes

Now you can start your node with the geth command. The --networkid option is used to specify the network id. --datadir option is used to specify the data directory. The --bootnodes option is used to specify the bootnodes. The --syncmode option is used to specify the sync mode.

$ ./bin/geth --networkid $NETWORK_ID --datadir .ethereum --bootnodes "$BOOTNODES" --syncmode $SYNCMODE --http --http.addr=0.0.0.0 --http.port=8545 --http.api=web3,eth,net,clique --http.corsdomain=* --http.vhosts=* --ws --ws.addr=0.0.0.0 --ws.port=8546 --ws.api=web3,eth,net,clique --ws.origins=* --nat extip:$PUBLIC_IP

image

Wait until the network sync (can take up to 15+ minutes depending on when you sync).

Now Make sure you keep Gitbash opened and running and you open a second gitbash for the rest of the tutorial.

Chapter 6: Script

6.1 Create a Startup Script

Let's pretend this is a recipe we're making. We'll put the instructions into a file named start_node.sh.

Step 1: Open Git Bash

First, open your Git Bash application. This is a program where you can type commands to your computer.

Step 2: Create a new file

We're going to create a new text file to hold our recipe. In Git Bash, type the following command and then press enter:

touch start_node.sh

image

This is like saying to your computer, "Hey, make me a new blank file named start_node.sh."

image

What it looks like on your computer

Step 3: Open the file in a text editor

Next, we'll open our new file in a text editor so we can write in it. Type the following command and press enter:

nano start_node.sh

image

This tells your computer, "I want to write in the start_node.sh file, please open it for me."

Step 4: Write the recipe

Now, we're going to write down our recipe. In the nano editor, type or copy-paste the following:

#!/bin/bash

BOOTNODES=$(readarray -t ARRAY < bootnodes; IFS=,; echo "${ARRAY[*]}") # convert the file into a comma separated list
NETWORK_ID=$(grep chainId genesis.json | grep -Eo '[0-9]+') # get the value of the chain Id and use it as network id as well
PUBLIC_IP=$(curl -s ifconfig.me/ip) # needed to expose your node to other, else you will not be reachable in discovery
SYNCMODE=snap # tells to synchronize without validating the transactions (faster but imply you trust the bootnodes)

nohup geth --networkid $NETWORK_ID --datadir .ethereum --bootnodes "$BOOTNODES" --syncmode $SYNCMODE \
      --http --http.addr=0.0.0.0 --http.port=8545 --http.api=web3,eth,net,clique --http.corsdomain=* --http.vhosts=* \
      --ws --ws.addr=0.0.0.0 --ws.port=8546 --ws.api=web3,eth,net,clique --ws.origins=* \
      --nat extip:$PUBLIC_IP 2>&1 1>> geth.log &

image

This is like the cooking instructions in a recipe.

Step 5: Save and close the file

Once you've typed all that in, you need to save your recipe. In nano, you do this by pressing Ctrl + O, then Enter to confirm. To close nano, press Ctrl + X.

image After pressing Ctrl + O

image After pressing Enter

image After pressing Ctrl + X

Step 6: Make the file executable

Finally, we need to tell our computer that it's safe to use this recipe. Type the following command and press enter:

chmod +x start_node.sh

image

This is like putting a seal of approval on your recipe, saying "This is safe to cook."

6.2 Connecting and Interacting with the Node

Now that your node is up and running, you can start talking to it! The node has two places where you can chat: an HTTP (port 8545) and a Websocket (port 8546). These are like the node's ears, and they're listening for your instructions.

To start a conversation with your node, try saying "Hello!" using these commands:

geth attach http://localhost:8545
# or
geth attach ws://localhost:8546

Now you're talking to your node! You can also connect your Metamask (or any compatible wallet) to your node, just like adding a friend on a social network.

image

Chapter 7: Join the consensus

7.0 Turning Your Node into a Sealer

Now let's take a big step forward: turning your node into a sealer.

7.1 Creating the Sealer Etherbase Wallet

A sealer is like a trusted messenger in the network. It needs to have a special key, a private key, to sign the blocks. This key is identified by a public address, also known as miner.etherbase or coinbase.

Creating this key is like making a special signature for your sealer. Geth provides a tool to create this signature in the Web3 Secret Storage format. Run this command:

geth account new --keystore .keystore 

image

When you run this command, it will ask you for a password. Remember, this password is super secret, don't forget it, and never share it with anyone!

Once you've got your password, save it .

image

7.2 Modifying the Script to Act as a Sealer

Now, we need to modify our recipe (the startup script we talked about earlier) to make our node act as a sealer. It's like adding some secret ingredients to our cake recipe.

Okay, let's update the 'start_node.sh' file without exiting Git Bash:

  1. Open Git Bash: If it's not already open, find the Git Bash application on your computer and open it.

  2. Navigate to the correct directory

  3. Create or Update the 'start_node.sh' file: You can use the echo command in Git Bash to write the new content into 'start_node.sh'. Here's how:

Type the following commands one line at a time, hitting enter after each line:

echo '#!/bin/bash' > start_node.sh

echo 'BOOTNODES=$(readarray -t ARRAY < bootnodes; IFS=,; echo "${ARRAY[*]}")' >> start_node.sh

echo 'NETWORK_ID=$(grep chainId genesis.json | grep -Eo '[0-9]+')' >> start_node.sh

echo 'PUBLIC_IP=$(curl -s ifconfig.me/ip)' >> start_node.sh

echo 'SYNCMODE=full' >> start_node.sh

echo 'ETHERBASE=0x64d0eFdeFb40E39A5ea946A0E132Dc0b690BD2c1' >> start_node.sh

echo 'nohup geth --networkid $NETWORK_ID --datadir .ethereum --bootnodes "$BOOTNODES" --syncmode $SYNCMODE \' >> start_node.sh

echo '--keystore .keystore --miner.etherbase $ETHERBASE --unlock $ETHERBASE --password .keystore/password \' >> start_node.sh

echo '--miner.extradata="Your name as sealer (32b max)" \' >> start_node.sh

echo '--mine --miner.gasprice 1000000000 \' >> start_node.sh

echo '--nat extip:$PUBLIC_IP 2>&1 1>> geth.log &' >> start_node.sh

The > character tells Git Bash to write the content that follows into 'start_node.sh', replacing any existing content. The >> characters tell Git Bash to append the content that follows to 'start_node.sh', adding to the existing content instead of replacing it.

Remember, replace ETHERBASE with the address of the wallet you created earlier.

image

  1. Check the contents: To make sure the file was updated correctly, you can display its contents using the cat command: cat start_node.sh.

image

7.3 Requesting to Join the Consensus

After you've done all this, you might notice that you're not able to sign blocks yet. This is because you have to be accepted as a sealer in the network first, just like being accepted into a club.

To join the club, you have to make a request. You do this by submitting an issue with your sealer address (the one you created earlier). You also have to tell everyone who you are and why you want to join, just like introducing yourself at a party.

Once you're accepted by a majority of the sealers, your node will start creating blocks. It's like being given the power to contribute to the network. This process is a bit more strict on the real network, which is explained in the whitepaper.

To connect to your node after you've been accepted, use this command:

./geth attach .ethereum/geth.ipc 

And that's it! You've turned your node into a sealer and are now part of the consensus. Congratulations!

guenoledc commented 1 year ago

Thanks @andrerochet

I have added your guide into the repo and referenced it in the ./docs/README.md

I close the issue now.