Coder Social home page Coder Social logo

rzmahmood / ethereum-pos-testnet Goto Github PK

View Code? Open in Web Editor NEW
26.0 4.0 13.0 1 MB

๐Ÿ’ปโ›“๏ธ A Quick and Easy Way to Bootstrap your own Local Ethereum PoS Testnet. Great for testing consensus โ›“๏ธ๐Ÿ’ป

License: MIT License

Shell 100.00%
bootstrap ethereum sepolia testnet go-ethereum local pos proof-of-stake prysm

ethereum-pos-testnet's Introduction

alt text

Deploy your own Local Ethereum PoS Testnet

license stability-experimental testnet-deployment Ceasefire Now

This deployment process allows you to setup and deploy your own local ethereum PoS networks with multiple nodes. This repository is targeted to developers who want to quickly modify client source code and deploy a PoS network. This setup can is can serve as a reference for building your own production deployments but better solutions exist for that use case. I'm personally using this for simulating reorgs and byzantine behaviour.

Installation

This project utilizes Git submodules to reference the client code, notably Go-Ethereum and Prysm. However, the scripts can be configured to reference binaries you build locally, making development quicker.

You will need Go 1.21, JQ and Bazel installed.

git clone --recursive https://github.com/rzmahmood/ethereum-pos-testnet.git

A helper script that builds the submodules, saving the binaries in a known path

./build-dependencies.sh

Running

Start testnet. This will start a test with a two validators. You should expect blocks to be produced. Logs are stored in ./network/node-*/logs The script is idempotent and will clean up every time it is restarted.

./testnet.sh

Running Testnet

In a new shell, you can then attach to any of the generated nodes. If you have geth in your path you can run:

geth attach network/node-0/execution/geth.ipc 

> net.peerCount
> eth.blockNumber

Alternatively, you can use the built version of geth

./dependencies/go-ethereum/build/bin/geth attach network/node-0/execution/geth.ipc 

> net.peerCount
> eth.blockNumber

You can also interact with a beacon node you spin up

curl localhost:4100/eth/v1/node/identity

You can change the number of nodes to run by changing this line in ./testnet.sh

# Change this number for your desired number of nodes
NUM_NODES=2

If you want to try submitting transactions, add your address to the alloc field in ./genesis.json before running the testnet. This will premine your address some funds.

"alloc": {
    // Replace with your address
    "123463a4b065722e99115d6c222f267d9cabb524": {
        "balance": "0x43c33c1937564800000"
    },

You can then send transactions using cast while the network is running

# Get balance of an address
cast balance -r localhost:8000 0xFe8664457176D0f87EAaBd103ABa410855F81010

# Send 0.01 ether to 0x8D...8E
cast send -r localhost:8000 --private-key $PKEY 0x8D512169343cc6e108a8bB6ec5bc116C416eFc8E --value 0.01ether

Reach out to me on Twitter @0xZorz if you have any issues. DMs are open

Coming Soon

  • Deposits and Withdrawals

FAQ / Common Issues

  • go: cannot find main module, but found .git/config in /home/gopal/ethereum-pos-testnet
          to create a module there, run:
          cd ../.. && go mod init
    

    This occurs because the submodules were not cloned. Make sure to clone with the --recursive flag, i.e. git clone --recursive https://github.com/rzmahmood/ethereum-pos-testnet.git

  • Nil finalized block cannot evict old blobs 
    

    This is expected log from Geth until a block is 'finalized'. The first finalized block will occur after 24 blocks.

Acknowledgements

  • The work of Raul Jordan was a great reference starting point. His setup will suffice requirements that don't demand signficant customization and only require 1 node.

ethereum-pos-testnet's People

Contributors

rzmahmood avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ethereum-pos-testnet's Issues

Remove Prebaked Validators in Genesis

Currently, the validators created in Genesis are baked in to Prysm. Ideally we can generate the validators separately, and assign them to different nodes

prysmctl testnet generate-genesis with --deposit-json-file

I try to use prysmctl with deposit-json-file, but process crashed. May be somebody knows how to this this issue ?

+ ./dependencies/prysm/out/prysmctl testnet generate-genesis --fork=capella --num-validators=2 --deposit-json-file=./staking_deposit-cli/validator_keys/deposit_data-1697028676.json --chain-config-file=./config.yml --geth-genesis-json-in=./genesis.json --output-ssz=./network/genesis.ssz --geth-genesis-json-out=./network/genesis.json
INFO[0000] Specified a chain config file: ./config.yml   prefix=genesis
INFO[0000] No genesis time specified, defaulting to now()  prefix=genesis
INFO[0000] reading deposits from JSON at /home/art/dev/go_workspace/ethereum-pos-testnet/staking_deposit-cli/validator_keys/deposit_data-1697028676.json  prefix=genesis
INFO[0000] setting fork geth times                       prefix=genesis shanghai=0xc000835be8
panic: runtime error: integer divide by zero

goroutine 1 [running]:
github.com/prysmaticlabs/prysm/v4/consensus-types/primitives.ValidatorIndex.Mod(...)
        /home/art/dev/eth-custom/testnet/ethereum-pos-testnet/dependencies/prysm/consensus-types/primitives/validator.go:39
github.com/prysmaticlabs/prysm/v4/beacon-chain/core/altair.NextSyncCommitteeIndices({0x21bdd70, 0xc0000560e0}, {0x21e64b8?, 0xc0008b58c0})

Looking for peers

Hi @rzmahmood
Hope you are doing well,
After starting the blockchain some time below error is coming and transactions are going to pending and new block number is not generating.
image

bazel also required

You mention that jq and go are prerequisites, but bazel is also required:

Error: bazel is not installed. Please install bazel first. See https://docs.prylabs.network/docs/install/install-with-bazel#install-bazel-using-bazelisk

I dind't find the instructions at the referenced page particularly clear, and used this on Ubuntu 22.04:

Download bazelisk-linux-amd64 from https://github.com/bazelbuild/bazelisk/releases/download/v1.19.0/bazelisk-linux-amd64
Rename it bazel: mv bazelisk-linux-amd64 bazel
Make it executable: chmod +x bazel
Sudo move it to /usr/local/bin: sudo mv bazel /usr/local/bin

Persist network state

Hi @rzmahmood
thank you for sharing your knowledge. This was extremely helpful!

But what if I want to deploy a private network with persisted state between the sessions (i.e. without clearing ./network folder)?

Not able to connect two nodes after separating the testnet.sh into different files ? (Like bootnode.sh , gethnode.sh , beaconnode.sh , validator.sh)

Hi @rzmahmood !
Hope you are doing well,

I split the 'testnet. sh' files into separate files to monitor two nodes in different terminals. However, when I ran these nodes in separate terminals, they both created two blockchains with the same chain ID. When I tried transferring the native balance, I noticed that the balances were displaying different values on two different RPC URLs, even though they shared the same chain ID. How to check nodes are connected with each other?

Failed generate-genesis

./prysmctl testnet generate-genesis --fork=capella --num-validators=2 --chain-config-file=./config.yml --geth-genesis-json-in=./genesis.json --output-ssz=./genesis.ssz --geth-genesis-json-out=./genesiss.json

INFO[0000] Specified a chain config file: ./config.yml   prefix=genesis
INFO[0000] No genesis time specified, defaulting to now()  prefix=genesis
INFO[0000] Delaying genesis 1696420459 by 0 seconds      prefix=genesis
INFO[0000] Genesis is now 1696420459                     prefix=genesis
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1702abf]

goroutine 1 [running]:
github.com/prysmaticlabs/prysm/v4/cmd/prysmctl/testnet.generateGenesis({0x242da70, 0xc000056120})
        /home/art/dev/eth-custom/devnet/prysm/cmd/prysmctl/testnet/generate_genesis.go:279 +0x6ff
github.com/prysmaticlabs/prysm/v4/cmd/prysmctl/testnet.cliActionGenerateGenesisState(0xc00031fd40)
        /home/art/dev/eth-custom/devnet/prysm/cmd/prysmctl/testnet/generate_genesis.go:179 +0x1c9
github.com/prysmaticlabs/prysm/v4/cmd/prysmctl/testnet.glob..func1(0x32161a0?)
        /home/art/dev/eth-custom/devnet/prysm/cmd/prysmctl/testnet/generate_genesis.go:70 +0x2e
github.com/urfave/cli/v2.(*Command).Run(0x32161a0, 0xc00031fd40, {0xc000b00850, 0x7, 0x7})
        /home/art/go/pkg/mod/github.com/urfave/cli/[email protected]/command.go:274 +0x9eb
github.com/urfave/cli/v2.(*Command).Run(0x3216040, 0xc00031fc40, {0xc000572380, 0x8, 0x8})
        /home/art/go/pkg/mod/github.com/urfave/cli/[email protected]/command.go:267 +0xc4d
github.com/urfave/cli/v2.(*Command).Run(0xc000b0e000, 0xc00031fb00, {0xc000052090, 0x9, 0x9})
        /home/art/go/pkg/mod/github.com/urfave/cli/[email protected]/command.go:267 +0xc4d
github.com/urfave/cli/v2.(*App).RunContext(0xc0002665a0, {0x242da70?, 0xc000056120}, {0xc000052090, 0x9, 0x9})
        /home/art/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:332 +0x616
github.com/urfave/cli/v2.(*App).Run(...)
        /home/art/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:309
main.main()
        /home/art/dev/eth-custom/devnet/prysm/cmd/prysmctl/main.go:23 +0x8e

Hi @SyedMuhamadYasir , @rzmahmood !

          Hi @SyedMuhamadYasir , @rzmahmood !

Hope you both are doing well.

Machine 1: I am running the bootnode
Machine 2: Node-1) Running the geth node with machine 1 bootnode and beacon node without bootstrap node
Node-2) Running 2nd geth node with machine 1 bootnode and beacon node with first beacon bootstrap node.
Machine 3: Node-3) Running 3rd geth node with machine 1 bootnode and beacon node with first beacon bootstrap node.

Here I'm running 2 nodes from machine2 and 1 node from machine3 and machine2 2 nodes are creating separate blockchains and the machine3 node is not connecting with the other 2 nodes, showing looking per peers.

Here i am using the same genesis files and i am creating the new accounts per each node and adding in genesis file extract data to become a validator.

2_beacon_node.txt
1_beacon_node.txt
2_geth_node.txt
1_geth_node.txt

Originally posted by @Gopal-Gurram in #14 (comment)

i am also facing the same issue

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.