Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fac3d28
Merge branch 'feature/testrunners' into feature/state-tests
zilm13 Mar 18, 2019
67d21bc
Merge branch 'develop' into feature/state-tests
zilm13 Mar 19, 2019
5a15a23
Merge branch 'spec/v0.5.0' into feature/state-tests
zilm13 Mar 20, 2019
b06b609
test: State tests implementation start. Tests are read but not executed.
zilm13 Mar 20, 2019
56fc554
test: bump tests repository to 0.5.1 specd
zilm13 Mar 29, 2019
56d3562
Merge branch 'spec/v0.5.1' into feature/state-tests
zilm13 Mar 29, 2019
2cd9acc
test: in the middle of state tests: not all validations performed, re…
zilm13 Mar 29, 2019
1c93c9a
test: state comparators for all fields added
zilm13 Mar 29, 2019
e179417
Merge branch 'spec/v0.5.1' into feature/state-tests
zilm13 Apr 1, 2019
9edcca3
test: finish merging spec v0.5.1
zilm13 Apr 1, 2019
3e29113
types: fix Eth fractional toString output
zilm13 Apr 1, 2019
905f6a0
test: improve exception logging in state test
zilm13 Apr 1, 2019
d1dad23
test: fix attestations comparison in state tests
zilm13 Apr 1, 2019
794458f
test: quick fix plusSat, do it correct after fix in spec/v0.5.1
zilm13 Apr 1, 2019
0e34966
core: add simple toString to ValidatorRecord
zilm13 Apr 1, 2019
e595606
test: state test runner cleanup
zilm13 Apr 1, 2019
97cb608
Merge branch 'spec/v0.5.1' into feature/state-tests
zilm13 Apr 2, 2019
6c31212
Merge branch 'spec/v0.5.1' into feature/state-tests
zilm13 Apr 2, 2019
51b5e22
test: use EmptySlotTransition in state tests runner
zilm13 Apr 2, 2019
93285eb
Merge branch 'develop' into feature/state-tests
mkalinin Apr 3, 2019
c3f0936
Build a spec inside of StateRunner
mkalinin Apr 5, 2019
b81d118
Initialize state tests with initial transition data
mkalinin Apr 5, 2019
f5c9759
Support exists and attester slashings in state tests
mkalinin Apr 5, 2019
019fa4f
Improve test suite output
mkalinin Apr 5, 2019
2ab7882
Count hit ratio in LRUCache
mkalinin Apr 5, 2019
e7c8bae
Set INFO log level for TCK tests
mkalinin Apr 5, 2019
875a175
Exclude state tests failed because of hashing
mkalinin Apr 5, 2019
edabab8
Add Exclusion class to tests for the sake of UX
mkalinin Apr 5, 2019
8c0d317
Indicate in the output if test is excluded
mkalinin Apr 5, 2019
4da1623
Rename Exclusion class to Ignored in test utils
mkalinin Apr 8, 2019
5b35e5b
Reword TODO in StateTests
mkalinin Apr 8, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ work

# logs
/logs
test/logs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public class DefaultBeaconChain implements MutableBeaconChain {

private final BeaconChainSpec spec;
private final BlockTransition<BeaconStateEx> initialTransition;
private final EmptySlotTransition emptySlotTransition;
private final BlockTransition<BeaconStateEx> onBlockTransition;
private final EmptySlotTransition preBlockTransition;
private final BlockTransition<BeaconStateEx> blockTransition;
private final BeaconBlockVerifier blockVerifier;
private final BeaconStateVerifier stateVerifier;

Expand All @@ -47,16 +47,16 @@ public class DefaultBeaconChain implements MutableBeaconChain {
public DefaultBeaconChain(
BeaconChainSpec spec,
BlockTransition<BeaconStateEx> initialTransition,
EmptySlotTransition emptySlotTransition,
BlockTransition<BeaconStateEx> onBlockTransition,
EmptySlotTransition preBlockTransition,
BlockTransition<BeaconStateEx> blockTransition,
BeaconBlockVerifier blockVerifier,
BeaconStateVerifier stateVerifier,
BeaconChainStorage chainStorage,
Schedulers schedulers) {
this.spec = spec;
this.initialTransition = initialTransition;
this.emptySlotTransition = emptySlotTransition;
this.onBlockTransition = onBlockTransition;
this.preBlockTransition = preBlockTransition;
this.blockTransition = blockTransition;
this.blockVerifier = blockVerifier;
this.stateVerifier = stateVerifier;
this.chainStorage = chainStorage;
Expand Down Expand Up @@ -117,7 +117,7 @@ public synchronized boolean insert(BeaconBlock block) {

BeaconStateEx parentState = pullParentState(block);

BeaconStateEx preBlockState = emptySlotTransition.apply(parentState, block.getSlot());
BeaconStateEx preBlockState = preBlockTransition.apply(parentState, block.getSlot());
VerificationResult blockVerification =
blockVerifier.verify(block, preBlockState);
if (!blockVerification.isPassed()) {
Expand All @@ -126,7 +126,7 @@ public synchronized boolean insert(BeaconBlock block) {
return false;
}

BeaconStateEx postBlockState = onBlockTransition.apply(preBlockState, block);
BeaconStateEx postBlockState = blockTransition.apply(preBlockState, block);

VerificationResult stateVerification =
stateVerifier.verify(postBlockState, block);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.ethereum.beacon.chain.storage.BeaconChainStorage;
import org.ethereum.beacon.chain.storage.BeaconChainStorageFactory;
import org.ethereum.beacon.consensus.BeaconChainSpec;
import org.ethereum.beacon.consensus.StateTransitions;
import org.ethereum.beacon.consensus.TestUtils;
import org.ethereum.beacon.consensus.transition.EmptySlotTransition;
import org.ethereum.beacon.consensus.transition.ExtendedSlotTransition;
Expand Down Expand Up @@ -87,13 +88,8 @@ public SlotNumber getGenesisSlot() {
chainStart = new ChainStart(Time.of(genesisTime.getSeconds()), eth1Data, deposits);

InitialStateTransition initialTransition = new InitialStateTransition(chainStart, spec);
PerSlotTransition perSlotTransition = new PerSlotTransition(spec);
PerBlockTransition perBlockTransition = new PerBlockTransition(spec);
PerEpochTransition perEpochTransition = new PerEpochTransition(spec);
StateCachingTransition stateCaching = new StateCachingTransition(spec);
ExtendedSlotTransition extendedSlotTransition =
new ExtendedSlotTransition(stateCaching, perEpochTransition, perSlotTransition, spec);
EmptySlotTransition emptySlotTransition = new EmptySlotTransition(extendedSlotTransition);
EmptySlotTransition preBlockTransition = StateTransitions.preBlockTransition(spec);
PerBlockTransition blockTransition = StateTransitions.blockTransition(spec);

db = new InMemoryDatabase();
beaconChainStorage = BeaconChainStorageFactory.get().create(db);
Expand All @@ -106,8 +102,8 @@ public SlotNumber getGenesisSlot() {
beaconChain = new DefaultBeaconChain(
spec,
initialTransition,
emptySlotTransition,
perBlockTransition,
preBlockTransition,
blockTransition,
blockVerifier,
stateVerifier,
beaconChainStorage,
Expand All @@ -124,7 +120,7 @@ public SlotNumber getGenesisSlot() {
attestationsSteam,
beaconChain.getBlockStatesStream(),
spec,
emptySlotTransition,
preBlockTransition,
schedulers);
observableStateProcessor.start();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.ethereum.beacon.consensus;

import org.ethereum.beacon.consensus.transition.EmptySlotTransition;
import org.ethereum.beacon.consensus.transition.ExtendedSlotTransition;
import org.ethereum.beacon.consensus.transition.PerBlockTransition;
import org.ethereum.beacon.consensus.transition.PerEpochTransition;
import org.ethereum.beacon.consensus.transition.PerSlotTransition;
import org.ethereum.beacon.consensus.transition.StateCachingTransition;

/** Instantiates high level state transitions. */
public abstract class StateTransitions {
public StateTransitions() {}

public static EmptySlotTransition preBlockTransition(BeaconChainSpec spec) {
PerSlotTransition perSlotTransition = new PerSlotTransition(spec);
PerEpochTransition perEpochTransition = new PerEpochTransition(spec);
StateCachingTransition stateCachingTransition = new StateCachingTransition(spec);
ExtendedSlotTransition extendedSlotTransition =
new ExtendedSlotTransition(
stateCachingTransition, perEpochTransition, perSlotTransition, spec);
return new EmptySlotTransition(extendedSlotTransition);
}

public static PerBlockTransition blockTransition(BeaconChainSpec spec) {
return new PerBlockTransition(spec);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ default void process_block_header(MutableBeaconState state, BeaconBlock block) {
// Verify that the slots match
assertTrue(block.getSlot().equals(state.getSlot()));
// Verify that the parent matches
assertTrue(block.getPreviousBlockRoot().equals(signed_root(state.getLatestBlockHeader())));
// FIXME: signed_root should match
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not forget this thing

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd better create an issue and point this out in the issue.

// assertTrue(block.getPreviousBlockRoot().equals(signed_root(state.getLatestBlockHeader())));
// Save current block as the new latest block
state.setLatestBlockHeader(get_temporary_block_header(block));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ public class ValidatorRecord {
/** Status flags. */
@SSZ private final Boolean slashed;

public ValidatorRecord(BLSPubkey pubKey,
Hash32 withdrawalCredentials, EpochNumber activationEpoch,
EpochNumber exitEpoch, EpochNumber withdrawableEpoch,
Boolean initiatedExit, Boolean slashed) {
public ValidatorRecord(
BLSPubkey pubKey,
Hash32 withdrawalCredentials,
EpochNumber activationEpoch,
EpochNumber exitEpoch,
EpochNumber withdrawableEpoch,
Boolean initiatedExit,
Boolean slashed) {
this.pubKey = pubKey;
this.withdrawalCredentials = withdrawalCredentials;
this.activationEpoch = activationEpoch;
Expand Down Expand Up @@ -94,6 +98,26 @@ public Builder builder() {
return Builder.fromRecord(this);
}

@Override
public String toString() {
return "ValidatorRecord{"
+ "pubKey="
+ pubKey
+ ", withdrawalCredentials="
+ withdrawalCredentials
+ ", activationEpoch="
+ activationEpoch
+ ", exitEpoch="
+ exitEpoch
+ ", withdrawableEpoch="
+ withdrawableEpoch
+ ", initiatedExit="
+ initiatedExit
+ ", slashed="
+ slashed
+ '}';
}

public static class Builder {

private BLSPubkey pubKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public static ShardNumber of(int i) {
return new ShardNumber(UInt64.valueOf(i));
}

public static ShardNumber of(long i) {
return new ShardNumber(UInt64.valueOf(i));
}

public static ShardNumber of(UInt64 i) {
return new ShardNumber(i);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public static ValidatorIndex of(int index) {
return new ValidatorIndex(UInt64.valueOf(index));
}

public static ValidatorIndex of(long index) {
return new ValidatorIndex(UInt64.valueOf(index));
}

public ValidatorIndex(UInt64 uint) {
super(uint);
}
Expand Down
2 changes: 1 addition & 1 deletion start/config/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ dependencies {
implementation project(':consensus')
implementation project(':crypto')
implementation project(':types')
implementation project(':util')

implementation 'commons-beanutils:commons-beanutils'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml'
implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation 'com.google.guava:guava'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import com.google.common.base.Charsets;
import com.google.common.io.CharStreams;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.PropertyUtils;
import org.ethereum.beacon.util.Objects;
import org.javatuples.Pair;

import java.io.DataInputStream;
Expand All @@ -13,7 +12,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -43,105 +41,6 @@ public ConfigBuilder(Class<C> type) {
supportedConfig = type;
}

/**
* "copyProperties" method from <a
* href="https://stackoverflow.com/a/24866702">https://stackoverflow.com/a/24866702</a>
*
* <p>Copies all properties from sources to destination, does not copy null values and any nested
* objects will attempted to be either cloned or copied into the existing object. This is
* recursive. Should not cause any infinite recursion.
*
* @param dest object to copy props into (will mutate)
* @param sources
* @param <T> dest
* @return
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
private static <T> T copyProperties(T dest, Object... sources)
throws IllegalAccessException, InvocationTargetException {
// to keep from any chance infinite recursion lets limit each object to 1 instance at a time in
// the stack
final List<Object> lookingAt = new ArrayList<>();

BeanUtilsBean recursiveBeanUtils =
new BeanUtilsBean() {

/**
* Check if the class name is an internal one
*
* @param name
* @return
*/
private boolean isInternal(String name) {
return name.startsWith("java.")
|| name.startsWith("javax.")
|| name.startsWith("com.sun.")
|| name.startsWith("javax.")
|| name.startsWith("oracle.");
}

/**
* Override to ensure that we dont end up in infinite recursion
*
* @param dest
* @param orig
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
@Override
public void copyProperties(Object dest, Object orig)
throws IllegalAccessException, InvocationTargetException {
try {
// if we have an object in our list, that means we hit some sort of recursion, stop
// here.
if (lookingAt.stream().anyMatch(o -> o == dest)) {
return; // recursion detected
}
lookingAt.add(dest);
super.copyProperties(dest, orig);
} finally {
lookingAt.remove(dest);
}
}

@Override
public void copyProperty(Object dest, String name, Object value)
throws IllegalAccessException, InvocationTargetException {
// dont copy over null values
if (value != null) {
// attempt to check if the value is a pojo we can clone using nested calls
if (!value.getClass().isPrimitive()
&& !value.getClass().isSynthetic()
&& !isInternal(value.getClass().getName())) {
try {
Object prop = super.getPropertyUtils().getProperty(dest, name);
// get current value, if its null then clone the value and set that to the value
if (prop == null) {
super.setProperty(dest, name, super.cloneBean(value));
} else {
// get the destination value and then recursively call
copyProperties(prop, value);
}
} catch (NoSuchMethodException e) {
return;
} catch (InstantiationException e) {
throw new RuntimeException("Nested property could not be cloned.", e);
}
} else {
super.copyProperty(dest, name, value);
}
}
}
};

for (Object source : sources) {
recursiveBeanUtils.copyProperties(dest, source);
}

return dest;
}

/**
* Adds Yaml config as source of configuration
*
Expand Down Expand Up @@ -235,7 +134,7 @@ public C build() {
ConfigSource nextConfigSource = configs.get(i);
Config nextConfig = getConfigSupplier(nextConfigSource).getConfig();
try {
firstConfig = copyProperties(firstConfig, nextConfig);
firstConfig = Objects.copyProperties(firstConfig, nextConfig);
} catch (Exception ex) {
throw new RuntimeException(
String.format("Failed to merge config %s into main config", nextConfigSource), ex);
Expand All @@ -245,7 +144,7 @@ public C build() {
// Handling string pathValue pairs config overrides
for (Pair<String, Object> pathValue : pathValueOverrides) {
try {
PropertyUtils.setNestedProperty(firstConfig, pathValue.getValue0(), pathValue.getValue1());
Objects.setNestedProperty(firstConfig, pathValue.getValue0(), pathValue.getValue1());
} catch (Exception e) {
throw new RuntimeException(
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public SpecConstants buildSpecConstants() {
return buildSpecConstants(spec.getSpecConstants());
}

public SpecConstants buildSpecConstants(SpecConstantsData specConstants) {
public static SpecConstants buildSpecConstants(SpecConstantsData specConstants) {

DepositContractParametersData depositContractParameters = specConstants
.getDepositContractParameters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.ethereum.beacon.emulator.config.Config;
import org.ethereum.beacon.emulator.config.YamlPrinter;

@JsonIgnoreProperties(ignoreUnknown = true)
public class SpecData implements Config {
public static final SpecData NOT_DEFINED = new SpecData();

@JsonDeserialize(as = SpecConstantsData.class)
private SpecConstantsData specConstants;
private SpecHelpersData specHelpersOptions = new SpecHelpersData();

Expand Down
Loading