Skip to content

Casper Local Testnet

Jake Pospischil edited this page Apr 11, 2018 · 3 revisions

Setting Up Bootstrap and Miner Nodes

  1. Clone the testnet nodes repository at https://github.com/karlfloersch/docker-pyeth-dev.git

  2. Edit {repo_path}/docker-compose.yml and replace the service configurations with the following:

bootstrap:
  container_name: bootstrap
  build: "./bootstrap"
  image: localethereum/pyethapp-bootstrap
  restart: always
  ports:
    - "40002:30303"
    - "40002:30303/udp"
    - "41002:8545"
  networks:
    back:
        ipv4_address: 172.18.250.2
miner1:
  container_name: miner1
  build: "./miner"
  image: localethereum/pyethapp-miner
  environment:
    - BOOTSTRAP_NODE=enode://d3260a710a752b926bb3328ebe29bfb568e4fb3b4c7ff59450738661113fb21f5efbdf42904c706a9f152275890840345a5bc990745919eeb2dfc2c481d778ee@172.18.250.2:30303
    - MINE_PERCENT=50
    - SLEEPTIME=1
  restart: always
  ports:
    - "40003:30303"
    - "40003:30303/udp"
    - "41003:8545"
  networks:
    back:
        ipv4_address: 172.18.250.3
miner2:
  container_name: miner2
  build: "./miner"
  image: localethereum/pyethapp-miner
  environment:
    - BOOTSTRAP_NODE=enode://d3260a710a752b926bb3328ebe29bfb568e4fb3b4c7ff59450738661113fb21f5efbdf42904c706a9f152275890840345a5bc990745919eeb2dfc2c481d778ee@172.18.250.2:30303
    - MINE_PERCENT=50
    - SLEEPTIME=1
  restart: always
  ports:
    - "40004:30303"
    - "40004:30303/udp"
    - "41004:8545"
  networks:
    back:
        ipv4_address: 172.18.250.4
miner3:
  container_name: miner3
  build: "./miner"
  image: localethereum/pyethapp-miner
  environment:
    - BOOTSTRAP_NODE=enode://d3260a710a752b926bb3328ebe29bfb568e4fb3b4c7ff59450738661113fb21f5efbdf42904c706a9f152275890840345a5bc990745919eeb2dfc2c481d778ee@172.18.250.2:30303
    - MINE_PERCENT=50
    - SLEEPTIME=1
  restart: always
  ports:
    - "40005:30303"
    - "40005:30303/udp"
    - "41005:8545"
  networks:
    back:
        ipv4_address: 172.18.250.5

This will set up 1 bootstrap node and 3 miner nodes, and open the listener & discovery / JSON-RPC ports between containers, and expose them externally with the values on the left.

  1. Run $ make new-account to build a pyethapp container and run the account creation command. This will generate a new keystore and account password under {repo_path}/validator/data/config/. Do this once for every validator to be run. Note the addresses created under {repo_path}/validator/data/config/keystore/.

  2. Edit the following files and make the same changes to all:

{repo_path}/bootstrap/data/config/config.yaml
{repo_path}/miner/default_data/config/config.yaml
{repo_path}/validator/default_data/config/config.yaml
{repo_path}/validator/data/config/config.yaml
  • Replace the network_id key with a custom private network ID
  • Replace the genesis block data with a custom genesis block

Here is an example network ID & genesis block (Note that difficulty is low and gas limit is high, for fast testing):

network_id: 11
genesis: {
  "nonce": "0x0000000000000011",
  "difficulty": "0x400",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x0000000000000000000000000000000000000000",
  "timestamp": "0x00",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "gasLimit": "0x5f5e100",
  "alloc": {}
}
  1. Clear the genesis data 'alloc' key and add entries using your new addresses from step 3 to seed the validator accounts with funds, e.g.:
"alloc": {
  "0d465641d393b03cd7a3c0cba037f82e1d992104": {
    "balance": "1001002003004005006007008"
  },
  "34e237283e028dcae089ca7d37e851df42986b30": {
    "balance": "1001002003004005006007008"
  },
  "c17c338f2b41a42b3f6a3b95368805b5bf86f25f": {
    "balance": "1001002003004005006007008"
  }
}
  1. Run $ docker-compose build and $ docker-compose up to build and launch the bootstrap and miner nodes.

  2. Verify all nodes (bootstrap & miners) are on the correct network by running the following commands:

$ docker exec -it (nodename) bash
$ python
> from web3 import Web3, HTTPProvider
> provider_uri = 'http://0.0.0.0:8545'
> web3 = Web3(HTTPProvider(provider_uri))
> web3.eth.getBlock(0)

The genesis block details should match those of the genesis data from step 4. Note that for some reason, web3.version.network always returns the ID for Rinkeby, instead of the real network ID. Ignore this value and simply check the details of block 0.

Running the Validator Nodes

  1. Edit {repo_path}/Makefile and remove the following lines:
-v $(current_dir)/validator/data/config:/root/.config/pyethapp \
-v $(current_dir)/validator/data/log:/root/log \
  1. Edit {repo_path}/validator/Dockerfile and add the following line to the top of the command block at line 3:
COPY data/config /root/.config/pyethapp

This will ensure that the account keystore is copied to the validator image filesystem and each validator has its own data directory to write to. The default configuration uses a data directory on the local filesystem, which does not allow for multiple validators running on the same host.

  1. Run $ make run-node validate=true deposit=DEPOSIT_AMOUNT network_name=NETWORK_ID bootstrap_node=enode://[email protected]:30303 validator_name=VALIDATOR_NAME account=ACCOUNT_INDEX, where:
  • DEPOSIT_AMOUNT is the amount of ether to deposit to casper (e.g. 5000)
  • NETWORK_ID is the ID of the network created for the project by Docker (should be dockerpyethdev_back -- this can be checked by running $ docker network ls)
  • ENODE_ID is d3260a710a752b926bb3328ebe29bfb568e4fb3b4c7ff59450738661113fb21f5efbdf42904c706a9f152275890840345a5bc990745919eeb2dfc2c481d778ee
  • VALIDATOR_NAME is the name of the container for the validator to run. Use a new name for each validator instance, e.g. validator1, validator2, validator3.
  • ACCOUNT_INDEX is the index of the account to use for the validator to run. Use a new account for each validator instance, e.g. 1, 2, 3. Note that step 3 must have been run once for each account required.

Note that you will need to have correctly seeded funds in step 5 above to be able to make a deposit.

The bootstrap node can instead be accessed by the port exposed to the host OS by Docker (40002), if the validator is run outside the Docker network.

  1. Verify the nodes are on the correct network as per step 7 above. Casper epochs should also increase every 50 blocks.
Clone this wiki locally