Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
8bb7871
Update beacon chain spec to v0.8.2
mkalinin Aug 14, 2019
63bd590
Update fork choice rule to v0.8.2
mkalinin Aug 14, 2019
b250719
Bump tests to v0.8.2
zilm13 Aug 15, 2019
3e32b39
temp mix-in pojo-like testcase
zilm13 Aug 15, 2019
19861c1
Revert "temp mix-in pojo-like testcase"
zilm13 Aug 15, 2019
f68c636
Revert "Revert "temp mix-in pojo-like testcase""
zilm13 Aug 15, 2019
2b4826c
Bump tests to v0.8.2 with fixes, remove spec configs
zilm13 Aug 20, 2019
2bcf5c2
crypto: fixed domain was handled is big endian
zilm13 Aug 20, 2019
8f75c49
consensus: fixed duplication of start shard calculation in EpochProce…
zilm13 Aug 20, 2019
9902fa8
test: move tests to new format with separate yaml files
zilm13 Aug 20, 2019
6a367ab
test: use ssz as data input when possible
zilm13 Aug 21, 2019
c7db44d
test: move to new format of ssz static tests
zilm13 Aug 21, 2019
18bc511
test: add uint, boolean, bitvector ssz_generic tests
zilm13 Aug 22, 2019
96202c8
test: bitlist ssz_generic tests added
zilm13 Aug 22, 2019
97a2827
test: move subtype checking in runner constructor for ssz_generic types
zilm13 Aug 22, 2019
9c711af
ssz: fix typo
zilm13 Aug 22, 2019
2d2a97c
test: add basic vector ssz_generic tests
zilm13 Aug 22, 2019
b21df44
test: update javadoc for SszBasicVectorRunner
zilm13 Aug 22, 2019
2076689
test: ssz_generic containers tests added
zilm13 Aug 23, 2019
7afb881
add caching of spec tests repo
zilm13 Aug 23, 2019
182b5b2
circleci fix1
zilm13 Aug 23, 2019
401eb79
circleci fix2
zilm13 Aug 23, 2019
96d7dc0
circleci fix3
zilm13 Aug 23, 2019
e49c543
circleci fix4
zilm13 Aug 23, 2019
446dd97
test: disable static ssz tests
zilm13 Aug 23, 2019
e6aa7d7
circleci fix5
zilm13 Aug 23, 2019
610026b
circleci fix6
zilm13 Aug 23, 2019
be60b0d
test: ignore minimal ssz_static tests instead. mainnet are much faste…
zilm13 Aug 23, 2019
7f9687a
circleci: change caching key creation to hack env_variable limitations
zilm13 Aug 23, 2019
38a7fe7
circleci fix cache key
zilm13 Aug 23, 2019
5fb8df3
circleci fix storing cache setup
zilm13 Aug 23, 2019
27e2913
test: add debug lines for circleci
zilm13 Aug 23, 2019
bd723c2
test: fix ignore was not working on CI
zilm13 Aug 23, 2019
f5b1133
circleci verifying cache usage
zilm13 Aug 24, 2019
98c9889
test: ignore git fail when cache is used
zilm13 Aug 25, 2019
2f69bee
Merge pull request #172 from harmony-dev/test/v0.8.2
zilm13 Aug 25, 2019
5a25ffa
Update to v0.8.3 with test fixes
zilm13 Aug 26, 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
20 changes: 20 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
sudo sh -c "echo 'deb http://ftp.debian.org/debian stretch-backports main' >> /etc/apt/sources.list"
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt-get update && sudo apt-get install -y git-lfs

- run:
name: Downloading dependencies
command: ./gradlew allDependencies
Expand All @@ -46,6 +47,19 @@ jobs:
destination: jars
when: always

- run:
name: Save commit of tests repo in env var
command: eval cd $(echo $CIRCLE_WORKING_DIRECTORY)/test/src/test/resources/ && git submodule status eth2.0-spec-tests/ | awk '{print $1;}' > /tmp/tests-version

- run:
name: Verify tests repo commit is saved
command: cat /tmp/tests-version

- restore_cache:
name: Restoring spec tests repo
keys:
- v1-tests-dir-{{ checksum "/tmp/tests-version" }}

- run:
name: Running tests
command: ./gradlew --info clean cleanTest test --continue
Expand Down Expand Up @@ -80,6 +94,12 @@ jobs:
done
when: always

- save_cache:
name: Caching spec tests repo
paths:
- ~/beacon-chain/test/src/test/resources/eth2.0-spec-tests
key: v1-tests-dir-{{ checksum "/tmp/tests-version" }}

- store_artifacts:
name: Uploading reports
path: ~/reports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,15 @@ assert data.target.epoch in (get_previous_epoch(state), get_current_epoch(state)
return false;
}

/* committee = get_crosslink_committee(state, data.target.epoch, data.crosslink.shard)
assert len(attestation.aggregation_bits) == len(attestation.custody_bits) == len(committee) */
List<ValidatorIndex> committee =
get_crosslink_committee(state, data.getTarget().getEpoch(), data.getCrosslink().getShard());
if (attestation.getAggregationBits().size() != attestation.getCustodyBits().size()
|| attestation.getAggregationBits().size() != committee.size()) {
return false;
}

/* if data.target.epoch == get_current_epoch(state):
assert data.source == state.current_justified_checkpoint
else:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package org.ethereum.beacon.consensus.spec;

import static java.util.stream.Collectors.toList;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import org.ethereum.beacon.core.BeaconState;
import org.ethereum.beacon.core.MutableBeaconState;
import org.ethereum.beacon.core.operations.attestation.Crosslink;
Expand All @@ -19,14 +26,6 @@
import tech.pegasys.artemis.util.uint.UInt64;
import tech.pegasys.artemis.util.uint.UInt64s;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toList;

/**
* Epoch processing part.
*
Expand Down Expand Up @@ -80,7 +79,7 @@ def get_unslashed_attesting_indices(state: BeaconState,
output = set() # type: Set[ValidatorIndex]
for a in attestations:
output = output.union(get_attesting_indices(state, a.data, a.aggregation_bits))
return set(filter(lambda index: not state.validators[index].slashed, list(output)))
return set(filter(lambda index: not state.validators[index].slashed, output))
*/
default List<ValidatorIndex> get_unslashed_attesting_indices(BeaconState state, List<PendingAttestation> attestations) {
return attestations.stream()
Expand All @@ -103,10 +102,10 @@ def get_winning_crosslink_and_attesting_indices(state: BeaconState,
epoch: Epoch,
shard: Shard) -> Tuple[Crosslink, List[ValidatorIndex]]:
attestations = [a for a in get_matching_source_attestations(state, epoch) if a.data.crosslink.shard == shard]
crosslinks = list(filter(
crosslinks = filter(
lambda c: hash_tree_root(state.current_crosslinks[shard]) in (c.parent_root, hash_tree_root(c)),
[a.data.crosslink for a in attestations]
))
)
# Winning crosslink has the crosslink data root with the most balance voting for it (ties broken lexicographically)
winning_crosslink = max(crosslinks, key=lambda c: (
get_attesting_balance(state, [a for a in attestations if a.data.crosslink == c]), c.data_root
Expand Down Expand Up @@ -596,11 +595,6 @@ default void process_final_updates(MutableBeaconState state) {
}
}

/* Update start shard
state.latest_start_shard = (state.latest_start_shard + get_shard_delta(state, current_epoch)) % SHARD_COUNT */
state.setStartShard(state.getStartShard()
.plusModulo(get_shard_delta(state, current_epoch), getConstants().getShardCount()));

/* # Set active index root
index_epoch = Epoch(next_epoch + ACTIVATION_EXIT_DELAY)
index_root_position = index_epoch % EPOCHS_PER_HISTORICAL_VECTOR
Expand Down Expand Up @@ -637,6 +631,12 @@ default void process_final_updates(MutableBeaconState state) {
state.getHistoricalRoots().add(hash_tree_root(historical_batch));
}

/* # Update start shard
state.start_shard = Shard((state.start_shard + get_shard_delta(state, current_epoch)) % SHARD_COUNT) */
state.setStartShard(state
.getStartShard()
.plusModulo(get_shard_delta(state, current_epoch), getConstants().getShardCount()));

/* # Rotate current/previous epoch attestations
state.previous_epoch_attestations = state.current_epoch_attestations
state.current_epoch_attestations = [] */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,27 @@ public interface ForkChoice extends HelperFunction {
/*
def get_ancestor(store: Store, root: Hash, slot: Slot) -> Hash:
block = store.blocks[root]
assert block.slot >= slot
return root if block.slot == slot else get_ancestor(store, block.parent_root, slot)
if block.slot > slot:
return get_ancestor(store, block.parent_root, slot)
elif block.slot == slot:
return root
else:
return Bytes32() # root is older than queried slot: no results.
*/
default Optional<Hash32> get_ancestor(Store store, Hash32 root, SlotNumber slot) {
Optional<BeaconBlock> aBlock = store.getBlock(root);
if (!aBlock.isPresent()) {
return Optional.empty();
}
if (aBlock.get().getSlot().less(slot)) {
return Optional.empty();
}

BeaconBlock block = aBlock.get();
return block.getSlot().equals(slot) ?
Optional.of(root) : get_ancestor(store, block.getParentRoot(), slot);
if (block.getSlot().greater(slot)) {
return get_ancestor(store, block.getParentRoot(), slot);
} else if (block.getSlot().equals(slot)) {
return Optional.of(root);
} else {
return Optional.of(Hash32.ZERO);
}
}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.ethereum.beacon.crypto;

import tech.pegasys.artemis.ethereum.core.Hash32;
import tech.pegasys.artemis.util.bytes.Bytes32;
import tech.pegasys.artemis.util.bytes.Bytes8;
import tech.pegasys.artemis.util.bytes.BytesValue;
import tech.pegasys.artemis.util.uint.UInt64;

/**
Expand All @@ -17,6 +15,14 @@
*/
public interface MessageParameters {

static MessageParameters create(Hash32 hash, Bytes8 domain) {
return new Impl(hash, domain);
}

static MessageParameters create(Hash32 hash, UInt64 domain) {
return new Impl(hash, domain.toBytes8LittleEndian());
}

/**
* Returns a hash of the message.
*
Expand All @@ -31,14 +37,6 @@ public interface MessageParameters {
*/
Bytes8 getDomain();

static MessageParameters create(Hash32 hash, Bytes8 domain) {
return new Impl(hash, domain);
}

static MessageParameters create(Hash32 hash, UInt64 domain) {
return new Impl(hash, domain.toBytesBigEndian());
}

/** A straightforward implementation of {@link MessageParameters}. */
class Impl implements MessageParameters {
private final Hash32 hash;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package org.ethereum.beacon.ssz.access.basic;

import net.consensys.cava.bytes.Bytes;
import org.ethereum.beacon.ssz.visitor.SSZReader;
import org.ethereum.beacon.ssz.visitor.SSZWriter;
import net.consensys.cava.ssz.SSZException;
import org.ethereum.beacon.ssz.SSZSchemeException;
import org.ethereum.beacon.ssz.access.SSZBasicAccessor;
import org.ethereum.beacon.ssz.access.SSZField;
import org.ethereum.beacon.ssz.SSZSchemeException;
import org.ethereum.beacon.ssz.visitor.SSZReader;
import org.ethereum.beacon.ssz.visitor.SSZWriter;
import tech.pegasys.artemis.util.bytes.BytesValue;
import tech.pegasys.artemis.util.uint.UInt16;
import tech.pegasys.artemis.util.uint.UInt24;
import tech.pegasys.artemis.util.uint.UInt256;
import tech.pegasys.artemis.util.uint.UInt32;
import tech.pegasys.artemis.util.uint.UInt64;
import tech.pegasys.artemis.util.uint.UInt8;

import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
Expand All @@ -32,7 +36,10 @@ public class UIntCodec implements SSZBasicAccessor {
private static Set<Class> supportedClassTypes = new HashSet<>();

static {
classToNumericType.put(UInt8.class, NumericType.of(Type.LONG, 8));
classToNumericType.put(UInt16.class, NumericType.of(Type.LONG, 16));
classToNumericType.put(UInt24.class, NumericType.of(Type.LONG, 24));
classToNumericType.put(UInt32.class, NumericType.of(Type.LONG, 32));
classToNumericType.put(UInt64.class, NumericType.of(Type.LONG, 64));
classToNumericType.put(UInt256.class, NumericType.of(Type.BIGINT, 256));
}
Expand All @@ -41,7 +48,10 @@ public class UIntCodec implements SSZBasicAccessor {
}

static {
supportedClassTypes.add(UInt8.class);
supportedClassTypes.add(UInt16.class);
supportedClassTypes.add(UInt24.class);
supportedClassTypes.add(UInt32.class);
supportedClassTypes.add(UInt64.class);
supportedClassTypes.add(UInt256.class);
}
Expand Down Expand Up @@ -82,13 +92,34 @@ public void encode(Object value, SSZField field, OutputStream result) {
NumericType numericType = parseFieldType(field);

switch (numericType.size) {
case 8:
{
UInt8 uValue = (UInt8) value;
Bytes bytes = SSZWriter.encodeULong(uValue.getValue(), numericType.size);
writeBytes(bytes, result);
break;
}
case 16:
{
UInt16 uValue = (UInt16) value;
Bytes bytes = SSZWriter.encodeULong(uValue.getValue(), numericType.size);
writeBytes(bytes, result);
break;
}
case 24:
{
UInt24 uValue = (UInt24) value;
Bytes bytes = SSZWriter.encodeULong(uValue.getValue(), numericType.size);
writeBytes(bytes, result);
break;
}
case 32:
{
UInt32 uValue = (UInt32) value;
Bytes bytes = SSZWriter.encodeULong(uValue.getValue(), numericType.size);
writeBytes(bytes, result);
break;
}
case 64:
{
UInt64 uValue = (UInt64) value;
Expand Down Expand Up @@ -129,10 +160,22 @@ public Object decode(SSZField field, SSZReader reader) {
private Object decodeLong(NumericType type, SSZReader reader) {
// XXX: reader.readULong is buggy
switch (type.size) {
case 8:
{
return UInt8.valueOf(reader.readUnsignedBigInteger(type.size).intValue());
}
case 16:
{
return UInt16.valueOf(reader.readUnsignedBigInteger(type.size).intValue());
}
case 24:
{
return UInt24.valueOf(reader.readUnsignedBigInteger(type.size).intValue());
}
case 32:
{
return UInt32.valueOf(reader.readUnsignedBigInteger(type.size).intValue());
}
case 64:
{
return UInt64.valueOf(reader.readUnsignedBigInteger(type.size).longValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.ethereum.beacon.ssz.SSZSerializeException;
import org.ethereum.beacon.ssz.access.SSZField;
import org.ethereum.beacon.ssz.type.SSZType;
import org.ethereum.beacon.ssz.type.list.SSZListType;
import tech.pegasys.artemis.util.collections.ReadList;
import tech.pegasys.artemis.util.collections.ReadVector;

Expand Down Expand Up @@ -54,23 +55,26 @@ public ListInstanceBuilder createInstanceBuilder(SSZType sszType) {
return new SimpleInstanceBuilder() {
@Override
protected Object buildImpl(List<Object> children) {
return sszType.isFixedSize()
SSZListType listType = (SSZListType) sszType;
return listType.isVector()
? ReadVector.wrap(
children,
resolveIndexConverter(
(Class<?>)
sszType
.getTypeDescriptor()
.getParametrizedType()
.getActualTypeArguments()[0]))
.getActualTypeArguments()[0]),
listType.getVectorLength())
: ReadList.wrap(
children,
resolveIndexConverter(
(Class<?>)
sszType
.getTypeDescriptor()
.getParametrizedType()
.getActualTypeArguments()[0]));
.getActualTypeArguments()[0]),
listType.getMaxSize());
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,13 @@ public <C> C createObject(Class<? extends C> clazz,
clazz.getField(currentField.getName()).set(result, values[i]);
} catch (Exception e) {
try { // Try to set using setter
fieldSetters.get(currentField.getName()).invoke(result, values[i]);
Method setter = fieldSetters.get(currentField.getName());
if (setter == null && currentField.getName().length() == 1) { // Bug in inspector with single letter fields
setter = fieldSetters.get(currentField.getName().toLowerCase());
}
setter.invoke(result, values[i]);
} catch (Exception ex) { // Cannot set the field
throw new SSZSchemeException(String.format("Setter net found for field %s", currentField.getName()), ex);
throw new SSZSchemeException(String.format("Setter not found for field %s", currentField.getName()), ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public int getSize() {
return getElementType().getSize() * getVectorLength();
}

public boolean isVector() {
return getVectorLength() > VARIABLE_SIZE;
}

public long getMaxSize() {
return maxSize;
}
Expand Down
1 change: 1 addition & 0 deletions test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ task activateLfs(type:Exec) {
task submodulesUpdate(type:Exec) {
description 'Updates (and inits) git submodules'
dependsOn(activateLfs)
ignoreExitValue true // CI hack for cache use
commandLine 'git', 'submodule', 'update', '--init', '--recursive'
group 'Build Setup'
}
Expand Down
Loading