Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM gcr.io/whiteblock/base:ubuntu1804

RUN apt-get update
RUN apt-get install -y openjdk-8-jdk

# 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.
RUN git clone https://github.com/libp2p/jvm-libp2p --branch feature/cleanup
WORKDIR /jvm-libp2p
RUN ./gradlew build -x test
RUN ./gradlew publishToMavenLocal
WORKDIR /

# Cloning Harmony
RUN git clone https://github.com/harmony-dev/beacon-chain-java.git
WORKDIR /beacon-chain-java
# TODO: switch to develop when merged
RUN git checkout interop
WORKDIR /

# Building Harmony
WORKDIR /beacon-chain-java
RUN ./gradlew build -x test
WORKDIR start/node/build/distributions/
RUN tar -xf node*.tar
RUN ln -s /beacon-chain-java/start/node/build/distributions/node-*/bin/node /usr/bin/harmony
WORKDIR /

# Copying start script
RUN mkdir /launch
RUN cp /beacon-chain-java/scripts/whiteblock_start.sh /launch/start.sh
RUN chmod +x /launch/start.sh

EXPOSE 8545 8546 9000 30303 30303/udp

ENTRYPOINT ["/bin/bash"]
87 changes: 87 additions & 0 deletions scripts/whiteblock_start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash

<<COMMENT
Used by Whiteblock for simulated network testing.

Based upon:
https://github.com/whiteblock/dockerfiles/blob/a31b412d32d0384de12aa8392e43bac32837b6bc/ethereum/interop-example/launch/start.sh

Here's an example script used for testing:

./whiteblock_start.sh \
--identity=55c7fc76505ddeb6cf750b1f9f43d6d12c1a53b77ada018a390d7592a7f36dbck \
--peers=/ip4/192.168.0.1/tcp/9000 \
--validator-keys=/tmp/keygen_10_validators.yaml \
--gen-state=/tmp/genesis.ssz \
--port=9008

The example script was run in the target/release directory of lighthouse.
The following change was made to this script:

YAML_KEY_FILE="/tmp/keygen_10_validators.yaml"
COMMENT

# Flags
IDENTITY=""
PEERS=""
YAML_KEY_FILE="/tmp/keygen_10_validators.yaml"
GEN_STATE=""
PORT="8000"

# Constants
BEACON_LOG_FILE="/tmp/beacon.log"
VALIDATOR_LOG_FILE="/tmp/validator.log"

usage() {
echo "--identity=<hex prepresentation of the priv key for libp2p>"
echo "--peers=<peer>"
echo "--validator-keys=<path to /launch/keys.yaml>"
echo "--gen-state=<path to /launch/state.ssz>"
echo "--port=<port>"
}

CMD_LINE_ADDON=""
while [ "$1" != "" ];
do
PARAM=`echo $1 | awk -F= '{print $1}'`
VALUE=`echo $1 | sed 's/^[^=]*=//g'`

case $PARAM in
--identity)
IDENTITY=$VALUE
CMD_LINE_ADDON=$CMD_LINE_ADDON"--node-key=$IDENTITY "
;;
--peers)
[ ! -z "$PEERS" ] && PEERS+=","
PEERS+="$VALUE"
CMD_LINE_ADDON=$CMD_LINE_ADDON"--connect=$PEERS "
;;
--validator-keys)
VALIDATOR_KEYS=$VALUE
CMD_LINE_ADDON=$CMD_LINE_ADDON"--validators-file=$VALIDATOR_KEYS "
;;
--gen-state)
GEN_STATE=$VALUE
CMD_LINE_ADDON=$CMD_LINE_ADDON"--initial-state=$GEN_STATE "
;;
--port)
PORT=$VALUE
CMD_LINE_ADDON=$CMD_LINE_ADDON"--listen=$PORT "
;;
--help)
usage
exit
;;
*)
echo "ERROR: unknown parameter \"$PARAM\""
usage
exit 1
;;
esac
shift
done

/usr/bin/harmony default $CMD_LINE_ADDON

trap 'trap - SIGTERM && kill 0' SIGINT SIGTERM EXIT

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.ethereum.beacon.emulator.config.node;

import com.fasterxml.jackson.annotation.JsonProperty;

public class KeyData {
private String privkey;
@JsonProperty
private String pubkey;

public String getPrivkey() {
return privkey;
}

public void setPrivkey(String privkey) {
this.privkey = privkey;
}

public String getPubkey() {
return pubkey;
}

public void setPubkey(String pubkey) {
this.pubkey = pubkey;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.ethereum.beacon.emulator.config.node;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import java.io.File;
import java.io.IOException;
import java.util.List;

/** Reads YAML file with keys {@link KeyData}*/
public class KeyDataReader {
private final File file;
private ObjectMapper mapper;

public KeyDataReader(File file) {
this.file = file;
this.mapper = new ObjectMapper(new YAMLFactory());
}

public List<KeyData> readKeys() {
try {
return mapper.readValue(file, new TypeReference<List<KeyData>>(){});
} catch (IOException e) {
throw new RuntimeException(String.format("Error thrown when reading file %s", file), e);
}
}
}
26 changes: 26 additions & 0 deletions start/node/src/main/java/org/ethereum/beacon/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ public class Node implements Runnable {
)
private Integer listenPort;

@CommandLine.Option(
names = {"--node-key"},
paramLabel = "key",
description = "Private key of p2p node (32 bytes)"
)
private String nodeKey;

@CommandLine.Option(
names = {"--connect"},
paramLabel = "URL",
Expand All @@ -71,6 +78,17 @@ public class Node implements Runnable {
)
private List<String> validators;

@CommandLine.Option(
names = {"--validators-file"},
paramLabel = "key",
split = ",",
description = {
"Validator registry as yaml file. Entries are pairs of privkey and pubkey",
"Example: --validators-file=keygen_10_validators.yaml"
}
)
private String validatorsFile;

@CommandLine.Option(
names = {"--name"},
paramLabel = "node-name",
Expand Down Expand Up @@ -184,6 +202,10 @@ public Integer getListenPort() {
return listenPort;
}

public String getNodeKey() {
return nodeKey;
}

public List<String> getActivePeers() {
return activePeers;
}
Expand All @@ -192,6 +214,10 @@ public List<String> getValidators() {
return validators;
}

public String getValidatorsFile() {
return validatorsFile;
}

public String getGenesisTime() {
return genesisTime;
}
Expand Down
Loading