Skip to content

Beacon chain node

ericsson49 edited this page Sep 9, 2019 · 18 revisions

A tiny command line utility to run beacon chain node.

Installation guide

Prerequisites

To run a node you need to install Java 8 or later. There are many guidelines in Internet, even the official one, from Oracle.

LibP2P

Harmony implementation depends on JVM libp2p implementation, which is not in a public repository yet. So, one should build it manually and push to a local maven repository, to be able to build the node command.

git clone https://github.com/libp2p/jvm-libp2p --branch feature/cleanup
cd jvm-libp2p
gradlew build
gradlew publishToMavenLocal

Build from sources

Note: Currently, all work is performed in the interop branch.

Clone the repo (interop branch) and execute build command:

git clone --branch interop https://github.com/harmony-dev/beacon-chain-java.git
cd beacon-chain-java
./gradlew clean build -x test

Unpack the distribution:

unzip start/node/build/distributions/node-0.2.0.zip

Use default config to check it out:

cd node-0.2.0/bin
./node default --validators=0-15

Command line options

./node --help
Usage: node [-hV] [--force-db-clean] [--db-prefix=db-prefix]
            [--genesis-time=time] [--initial-state=initial-state]
            [--listen=port] [--loglevel=level]
            [--metrics-endpoint=matrics-endpoint] [--name=node-name]
            [--spec-constants=spec-constants] [--start-mode=start-mode]
            [--connect=URL[,URL...]]... [--validators=key[,key...]]... config.
            yml
Beacon chain node
      config.yml            A path to a file containing node config in YAML format.
                            Use 'default' to run a node with default setup.
      --connect=URL[,URL...]
                            Peers that node is actively connecting to.
                            URL format: <multiaddress>:<node id hex>
                            URL sample: /ip4/10.0.0.128/tcp/40001:
                              1111111111111111111111111111111111111111111111111111111
                              1111111111111
      --db-prefix=db-prefix Specifies db-prefix, used to construct db directory
      --force-db-clean      When an initial-state is specified, but db is not empty
                            specifies how to resolve the problem:
                              force-db-clean=true  - tries to clean db
                              force-db-clean=false - exits with failure status.
                            False by default.
      --genesis-time=time   Genesis time in GMT+0 timezone. In either form:
                              '2019-05-24 11:23'
                              '11:23' (current day is taken)
                            Defaults to the beginning of the current hour.
      --initial-state=initial-state
                            Path to an initial state file (SSZ format)
      --listen=port         TCP port to listen for inbound connections.
      --loglevel=level      Log verbosity level: all, debug, info, error.
                            info is set by default.
      --metrics-endpoint=matrics-endpoint
                            Interface and port, Prometheus collection endpoint will
                              be served from.
                            Should have form of interface:port.
                            Default endpoint is 0.0.0.0:8008.
      --name=node-name      Node identity for logs output
                            Useful when several nodes are running
      --spec-constants=spec-constants
                            Path to a spec constants file in yaml format (flat
                              format)
      --start-mode=start-mode
                            Specifies how to deal with the existing or absent
                              storage. Possible modes:
                              initial - starts from an empty storage only. If it's
                              not, --force-db-clean can be specified.
                              storage - starts from a previously initialized storage
                              only,
                                        ignoring contract/initial-state parameters
                              auto    - starts from an existing storage, if it's non
                              empty
                                        initializes from contract/initial-state
                              parameters otherwise
                            By default, set to auto, if no initial-state is
                              specified,
                                        and to initial, if an initial-state is
                              specified.
      --validators=key[,key...]
                            Validator registry. Entry is either:
                              private key in a hex format prepended with '0x'
                              an index or a range specifying a keypair(s) in
                              emulated deposit contract
                            Example: --validators=1,2,5-9,0x1234567[...]ef
  -h, --help                Show this help message and exit.
  -V, --version             Print version information and exit.

Run a small chain

In order to start building a chain you have to run a node with several validators. There is a built-in default config that can be used for a quick start.

To run a node that carries 16 validators use following command:

./node default --listen=40001 --validators=0-15 --name=V

Let's add a couple of nodes and connect them with validators:

./node default --listen=40002 --connect=tcp://localhost:40001,tcp://localhost:40003 --name=1
./node default --listen=40003 --connect=tcp://localhost:40001,tcp://localhost:40002 --name=2

Check out logs:

#V:
15:33:55.007 #V  INFO  - validator 8: attested to head: Block[6d2ae3fe <~ f7f11046, @slot 203, state=a48c35cc, randao=c000...0000, Eth1Data{depositRoot=b3f59c3f, depositCount=16, block=078cbf50}, sig=c000...0000, atts: [epoch=50/0/f7f11046/0+1+2+3]] in a slot: #203
15:33:55.009 #V  INFO  - validator 11: attested to head: Block[6d2ae3fe <~ f7f11046, @slot 203, state=a48c35cc, randao=c000...0000, Eth1Data{depositRoot=b3f59c3f, depositCount=16, block=078cbf50}, sig=c000...0000, atts: [epoch=50/0/f7f11046/0+1+2+3]] in a slot: #203
15:33:55.010 #V  INFO  - validator 14: attested to head: Block[6d2ae3fe <~ f7f11046, @slot 203, state=a48c35cc, randao=c000...0000, Eth1Data{depositRoot=b3f59c3f, depositCount=16, block=078cbf50}, sig=c000...0000, atts: [epoch=50/0/f7f11046/0+1+2+3]] in a slot: #203
15:33:55.012 #V  INFO  - validator 13: attested to head: Block[6d2ae3fe <~ f7f11046, @slot 203, state=a48c35cc, randao=c000...0000, Eth1Data{depositRoot=b3f59c3f, depositCount=16, block=078cbf50}, sig=c000...0000, atts: [epoch=50/0/f7f11046/0+1+2+3]] in a slot: #203
15:34:00.048 #V  INFO  - validator 7: proposed a Block[5c631e0d <~ 6d2ae3fe, @slot 204, state=84a7b69d, randao=c000...0000, Eth1Data{depositRoot=b3f59c3f, depositCount=16, block=078cbf50}, sig=c000...0000]:
  Attestation[AttestationData[shard=1, beaconBlock=6d2ae3fe, targetEpoch=50, targetRoot=cc142219, shardBlock=00000000, previousCrosslinkRoot=11a86088, sourceEpoch=49, sourceRoot=617a935b], attesters=0+1+2+3, cusodyBits=0b00000000, sig=c000...0000]
 in 0.001s
15:34:00.077 #V  INFO  - new block inserted: Block[5c631e0d <~ 6d2ae3fe, @slot 204, state=84a7b69d, randao=c000...0000, Eth1Data{depositRoot=b3f59c3f, depositCount=16, block=078cbf50}, sig=c000...0000, atts: [epoch=50/1/6d2ae3fe/0+1+2+3]] in 0.029s
15

#1:
15:34:00.125 #1  INFO  - new block inserted: Block[5c631e0d <~ 6d2ae3fe, @slot 204, state=84a7b69d, randao=c000...0000, Eth1Data{depositRoot=b3f59c3f, depositCount=16, block=078cbf50}, sig=c000...0000, atts: [epoch=50/1/6d2ae3fe/0+1+2+3]] in 0.039s

#2:
15:34:00.125 #2  INFO  - new block inserted: Block[5c631e0d <~ 6d2ae3fe, @slot 204, state=84a7b69d, randao=c000...0000, Eth1Data{depositRoot=b3f59c3f, depositCount=16, block=078cbf50}, sig=c000...0000, atts: [epoch=50/1/6d2ae3fe/0+1+2+3]] in 0.036s

Config parameters

config:
  db: db
  networks:
    # Libp2p based network conforming to spec
    - type: libp2p
      # TCP port the node should listen for incoming connections
      # listenPort: 40001

  validator:
    contract: !emulator
      keys:
        - !interop
          count: 16
      interopCredentials: true
      # eth1BlockHash: 0x4242424242424242424242424242424242424242424242424242424242424242
#    signer: !insecure
#      keys:
#        - !generate
#          count: 16
#          seed: 0

chainSpec:
  specConstants:
    initialValues:
      GENESIS_SLOT: 0
    miscParameters:
      SHARD_COUNT: 4
      TARGET_COMMITTEE_SIZE: 2
    timeParameters:
      SECONDS_PER_SLOT: 10
      MIN_ATTESTATION_INCLUSION_DELAY: 1
      SLOTS_PER_EPOCH: 4
      SLOTS_PER_HISTORICAL_ROOT: 64

    honestValidatorParameters:
      ETH1_FOLLOW_DISTANCE: 1
    stateListLengths:
      EPOCHS_PER_HISTORICAL_VECTOR: 64
      EPOCHS_PER_SLASHINGS_VECTOR: 64

  specHelpersOptions:
    blsVerify: false
    blsVerifyProofOfPossession: false
    blsSign: false
    enableCache: false
    # for interop, genesis time should be overridden with the specified value, so ignore computation
    computableGenesisTime: false
Clone this wiki locally