Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
d03ebb3
Initial draft version of Libp2p integration
Nashatyrev Sep 6, 2019
c9f349f
Working libp2p version (two Node validator instances)
Nashatyrev Sep 7, 2019
2eba58b
Merge branch 'interop' into feature/libp2p-integration
Nashatyrev Sep 7, 2019
75a0cbf
Disable tests relying on legacy network
Nashatyrev Sep 7, 2019
e6665ca
Hook Mettrics.peerAdded/Removed to another place
Nashatyrev Sep 7, 2019
dbeb95d
--db-prefix option added
ericsson49 Sep 7, 2019
32ea847
Add some comments, fix format
Nashatyrev Sep 9, 2019
4a00f59
Merge remote-tracking branch 'origin/feature/libp2p-integration' into…
Nashatyrev Sep 9, 2019
3b433b6
Single peerConnection and wireSync instances per Peer object. Resolve…
Nashatyrev Sep 9, 2019
f04fce3
Merge pull request #183 from harmony-dev/feature/libp2p-integration
ericsson49 Sep 9, 2019
1196bb7
--initial-deposit-count (--validator-count) option added to aid quick…
ericsson49 Sep 9, 2019
f4dde01
--dump-tuples option implemented
ericsson49 Sep 9, 2019
216762f
Dump genesis state to file as well
mkalinin Sep 9, 2019
c6a1d2c
Change to address:peerId to common scheme: /ip4/<ip>/tcp/<port>/p2p/<…
Nashatyrev Sep 9, 2019
5f0bb56
Merge remote-tracking branch 'origin/interop' into interop
Nashatyrev Sep 9, 2019
f3bc071
Add debug wire logging options
Nashatyrev Sep 9, 2019
2905c3d
Enable BLS in default node config
mkalinin Sep 9, 2019
8b66a42
Fix post state dumper
mkalinin Sep 9, 2019
0545991
Hack around block hash in initalize storage
mkalinin Sep 10, 2019
1e8bfeb
Metrics updated according to recent spec changes.
ericsson49 Sep 10, 2019
af2c760
According to spec wire ssz top-most containers with a single child sh…
Nashatyrev Sep 10, 2019
62635d8
Merge remote-tracking branch 'origin/interop' into interop
Nashatyrev Sep 10, 2019
7207f75
When doing RPC via stream, concat response buffers until remote mux s…
Nashatyrev Sep 10, 2019
7e9a65d
Add pubsub logs
mkalinin Sep 10, 2019
e178ceb
Adopt odd chunks chunks behaviour in req/resp
mkalinin Sep 10, 2019
8dc8d2e
Remove dereference of chunks in Libp2pMethodHandler
mkalinin Sep 10, 2019
27fe139
Temp fix: Rely on the message length in the prefix rather than stream…
Nashatyrev Sep 11, 2019
dba69c0
Add a shortcut for a minimal spec constants
mkalinin Sep 11, 2019
c18eb74
Merge branch 'interop' of github.com:harmony-dev/beacon-chain-java in…
mkalinin Sep 11, 2019
cec808b
FeedSync tool initial implementation.
ericsson49 Sep 11, 2019
14d0a30
Add Identify protocol stub support
Nashatyrev Sep 11, 2019
99982c5
Merge remote-tracking branch 'origin/interop' into interop
Nashatyrev Sep 11, 2019
bad892b
Add start with genesis time supplied in unix timestamp format
mkalinin Sep 11, 2019
dfcb813
Merge branch 'interop' of github.com:harmony-dev/beacon-chain-java in…
mkalinin Sep 11, 2019
36a86ee
Delay chain start when genesis is in the future
mkalinin Sep 11, 2019
4d3da67
WIP: Dockerfile for genesis state start
Sep 12, 2019
4805144
head root calculation at boundary slot fixed
ericsson49 Sep 12, 2019
836147c
Fix head root calculation.
ericsson49 Sep 12, 2019
c34ca25
Update Dockerfile for whiteblock
zilm13 Sep 12, 2019
666e92c
Merge branch 'interop' into atoulme-wip-dockerfile
zilm13 Sep 12, 2019
38e1759
Fix FFG vote calculations.
ericsson49 Sep 12, 2019
c896638
Merge pull request #185 from harmony-dev/feature/feedsync
mkalinin Sep 12, 2019
b18a093
Simple bugfix
ericsson49 Sep 12, 2019
3852fbd
Merge branch 'interop' of https://github.com/harmony-dev/beacon-chain…
ericsson49 Sep 12, 2019
003bbd2
node: add validator keys file option and private node key
zilm13 Sep 12, 2019
ba977ff
Emulate go-libp2p identify message for interop with JS
Nashatyrev Sep 12, 2019
0e36dd0
Merge remote-tracking branch 'origin/interop' into interop
Nashatyrev Sep 12, 2019
e0bf77c
node: expose ports in dockerfile
zilm13 Sep 12, 2019
e0c9916
node: switch to interop branch as this will be merged
zilm13 Sep 12, 2019
b15c64b
Merge pull request #187 from harmony-dev/atoulme-wip-dockerfile
mkalinin Sep 12, 2019
3933578
Use minimal spec constants (fast interop settings)
zilm13 Sep 12, 2019
1bcc7d5
typo fixed in whiteblock_start.sh
zilm13 Sep 12, 2019
be1ace3
Add volatile to fields accessed from different threads.
ericsson49 Sep 21, 2019
0fc1464
Add finalized checkpoint comparision to equals.
ericsson49 Sep 25, 2019
b954008
Fix problem with SingleValueSource: valueKey is the same as the stora…
ericsson49 Sep 26, 2019
935974b
Resolve Libp2p artifact from Bintray
Nashatyrev Oct 2, 2019
20e072f
Merge branch 'develop' into interop
mkalinin Oct 2, 2019
cb3ae45
test: Fixing communit test resources
zilm13 Oct 2, 2019
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"]
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ allprojects {

repositories {
jcenter()
maven { url "https://jitpack.io" }
maven { url "https://dl.bintray.com/libp2p/jvm-libp2p" }
}

task allDependencies(type: DependencyReportTask) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import org.apache.logging.log4j.Logger;
import org.ethereum.beacon.chain.storage.BeaconChainStorage;
import org.ethereum.beacon.chain.storage.BeaconTupleStorage;
import org.ethereum.beacon.consensus.BeaconChainSpec;
import org.ethereum.beacon.consensus.BeaconStateEx;
import org.ethereum.beacon.consensus.BlockTransition;
import org.ethereum.beacon.consensus.BeaconChainSpec;
import org.ethereum.beacon.consensus.transition.EmptySlotTransition;
import org.ethereum.beacon.consensus.verifier.BeaconBlockVerifier;
import org.ethereum.beacon.consensus.verifier.BeaconStateVerifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
import org.ethereum.beacon.core.state.Checkpoint;
import tech.pegasys.artemis.ethereum.core.Hash32;

/**
* Utility functions to initialize storage from an initial state.
*/
/** Utility functions to initialize storage from an initial state. */
public class StorageUtils {
/**
* Creates a BeaconTuple consisting of the initialState and corresponding block.
* Currently, the block is empty, but could be re-constructed from the state's block header,
* in general.
* Creates a BeaconTuple consisting of the initialState and corresponding block. Currently, the
* block is empty, but could be re-constructed from the state's block header, in general.
*/
public static BeaconTuple createInitialBeaconTuple(
BeaconChainSpec spec, BeaconStateEx initialState) {
Expand All @@ -26,16 +23,16 @@ public static BeaconTuple createInitialBeaconTuple(
}

/**
* An utility to properly initialize a storage with a specified initial state.
* Supports only initial state currently. Could be extended in theory, to support
* finalized states.
* An utility to properly initialize a storage with a specified initial state. Supports only
* initial state currently. Could be extended in theory, to support finalized states.
*/
public static void initializeStorage(
BeaconChainStorage storage, BeaconChainSpec spec, BeaconStateEx initialState) {
assert storage.getTupleStorage().isEmpty();
BeaconTuple tuple = createInitialBeaconTuple(spec, initialState);
Hash32 genesisRoot = spec.signing_root(tuple.getBlock());
storage.getTupleStorage().put(tuple);
storage.getStateStorage().put(tuple.getBlock().getStateRoot(), tuple.getState());
storage.getBlockStorage().put(genesisRoot, tuple.getBlock());
storage
.getJustifiedStorage()
.set(new Checkpoint(initialState.getCurrentJustifiedCheckpoint().getEpoch(), genesisRoot));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.ethereum.beacon.chain;

import java.util.Collections;
import java.util.stream.IntStream;
import org.ethereum.beacon.chain.MutableBeaconChain.ImportResult;
import org.ethereum.beacon.chain.storage.BeaconChainStorage;
import org.ethereum.beacon.chain.storage.impl.SSZBeaconChainStorageFactory;
Expand Down Expand Up @@ -32,9 +34,6 @@
import tech.pegasys.artemis.ethereum.core.Hash32;
import tech.pegasys.artemis.util.uint.UInt64;

import java.util.Collections;
import java.util.stream.IntStream;

public class DefaultBeaconChainTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.ethereum.beacon.chain.storage.util.StorageUtils;
import org.ethereum.beacon.consensus.BeaconChainSpec;
import org.ethereum.beacon.consensus.BeaconStateEx;
import org.ethereum.beacon.consensus.ChainStart;
import org.ethereum.beacon.consensus.StateTransitions;
import org.ethereum.beacon.consensus.TestUtils;
import org.ethereum.beacon.consensus.transition.EmptySlotTransition;
Expand All @@ -30,7 +31,6 @@
import org.ethereum.beacon.core.types.Time;
import org.ethereum.beacon.crypto.BLS381.KeyPair;
import org.ethereum.beacon.db.InMemoryDatabase;
import org.ethereum.beacon.consensus.ChainStart;
import org.ethereum.beacon.schedulers.Schedulers;
import org.javatuples.Pair;
import org.reactivestreams.Publisher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ && getPreviousEpochAttestations().equals(other.getPreviousEpochAttestations())
&& getCurrentEpochAttestations().equals(other.getCurrentEpochAttestations())
&& getPreviousJustifiedCheckpoint().equals(other.getPreviousJustifiedCheckpoint())
&& getCurrentJustifiedCheckpoint().equals(other.getCurrentJustifiedCheckpoint())
&& getFinalizedCheckpoint().equals(other.getFinalizedCheckpoint())
&& getPreviousCrosslinks().equals(other.getPreviousCrosslinks())
&& getCurrentCrosslinks().equals(other.getCurrentCrosslinks())
&& getBlockRoots().equals(other.getBlockRoots())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.ethereum.beacon.db;

import java.util.function.Function;

import org.ethereum.beacon.crypto.Hashes;
import org.ethereum.beacon.db.source.impl.HashMapDataSource;

/**
Expand All @@ -9,7 +11,7 @@
public class InMemoryDatabase extends XorKeyDatabase {

public InMemoryDatabase() {
super(new HashMapDataSource<>(), Function.identity());
super(new HashMapDataSource<>(), Hashes::sha256);
}

@Override
Expand Down
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 --spec-constants=minimal $CMD_LINE_ADDON

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

Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,11 @@ interface VoidBasicAccessor extends Void, SSZBasicAccessor {}
* Specifies custom container accessor for SSZ serializable class
*/
Class<? extends SSZContainerAccessor> containerAccessor() default VoidContainerAccessor.class;

/**
* Applicable to SSZ Containers with a single child only
* When set to true the wrapping container is not serialized, and its child
* is serialized the same way as if it was serialized directly
*/
boolean skipContainer() default false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

import org.ethereum.beacon.ssz.type.SSZBasicType;
import org.ethereum.beacon.ssz.type.SSZContainerType;
import org.ethereum.beacon.ssz.type.list.SSZListType;
import org.ethereum.beacon.ssz.type.SSZType;
import org.ethereum.beacon.ssz.type.SSZUnionType;
import org.ethereum.beacon.ssz.type.list.SSZListType;

public class SSZVisitorHost {

Expand All @@ -29,7 +29,7 @@ public <ResultType, ParamType> ResultType handleAny(
handleAny(unionType.getChildTypes().get(idx), param, visitor));
} else if (type.getType() == CONTAINER) {
SSZContainerType containerType = (SSZContainerType) type;
return visitor.visitComposite(containerType, value, (idx, param) ->
return visitor.visitContainer(containerType, value, (idx, param) ->
handleAny(containerType.getChildTypes().get(idx), param, visitor));
} else {
throw new IllegalArgumentException("Unknown type: " + type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
import java.util.List;
import net.consensys.cava.bytes.Bytes;
import org.ethereum.beacon.ssz.access.SSZCompositeAccessor.CompositeInstanceBuilder;
import org.ethereum.beacon.ssz.annotation.SSZSerializable;
import org.ethereum.beacon.ssz.type.SSZBasicType;
import org.ethereum.beacon.ssz.type.SSZCompositeType;
import org.ethereum.beacon.ssz.type.SSZContainerType;
import org.ethereum.beacon.ssz.type.list.SSZListType;
import org.ethereum.beacon.ssz.type.SSZType;
import org.ethereum.beacon.ssz.type.SSZUnionType;
import org.ethereum.beacon.ssz.type.list.SSZListType;
import org.javatuples.Pair;

/**
Expand Down Expand Up @@ -51,6 +52,26 @@ public Object visitUnion(SSZUnionType type, Bytes bytes,
return instanceBuilder.build();
}

@Override
public Object visitContainer(SSZContainerType type, Bytes param,
ChildVisitor<Bytes, Object> childVisitor) {
SSZSerializable annotation = type.getTypeDescriptor().getRawClass()
.getAnnotation(SSZSerializable.class);
if (annotation != null && annotation.skipContainer()) {
if (type.getChildTypes().size() != 1) {
throw new IllegalArgumentException(
"Only container with a single child can be skipped: " + type);
}
CompositeInstanceBuilder instanceBuilder =
type.getAccessor().createInstanceBuilder(type);
Object child = childVisitor.apply(0, param);
instanceBuilder.setChild(0, child);
return instanceBuilder.build();
} else {
return visitComposite(type, param, childVisitor);
}
}

/**
* Decodes composite value
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package org.ethereum.beacon.ssz.visitor;

import static org.ethereum.beacon.ssz.visitor.SosDeserializer.BYTES_PER_LENGTH_OFFSET;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;
import org.ethereum.beacon.ssz.access.SSZUnionAccessor.UnionInstanceAccessor;
import org.ethereum.beacon.ssz.annotation.SSZSerializable;
import org.ethereum.beacon.ssz.type.SSZBasicType;
import org.ethereum.beacon.ssz.type.SSZCompositeType;
import org.ethereum.beacon.ssz.type.list.SSZListType;
import org.ethereum.beacon.ssz.type.SSZContainerType;
import org.ethereum.beacon.ssz.type.SSZUnionType;
import org.ethereum.beacon.ssz.type.list.SSZListType;
import tech.pegasys.artemis.util.bytes.BytesValue;
import tech.pegasys.artemis.util.bytes.BytesValues;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;

import static org.ethereum.beacon.ssz.visitor.SosDeserializer.BYTES_PER_LENGTH_OFFSET;

/** SSZ serializer with offset-based encoding of variable sized elements */
public class SosSerializer implements SSZVisitor<SosSerializer.SerializerResult, Object> {

Expand Down Expand Up @@ -66,6 +67,23 @@ public SerializerResult visitComposite(
return visitComposite(type, rawValue, childVisitor, 0, type.getChildrenCount(rawValue));
}

@Override
public SerializerResult visitContainer(SSZContainerType type, Object param,
ChildVisitor<Object, SerializerResult> childVisitor) {

SSZSerializable annotation = type.getTypeDescriptor().getRawClass()
.getAnnotation(SSZSerializable.class);
if (annotation != null && annotation.skipContainer()) {
if (type.getChildTypes().size() != 1) {
throw new IllegalArgumentException(
"Only container with a single child can be skipped: " + type);
}
return childVisitor.apply(0, type.getChild(param, 0));
} else {
return visitComposite(type, param, childVisitor);
}
}

private SerializerResult visitComposite(
SSZCompositeType type,
Object rawValue,
Expand Down
Loading