Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
8b9e319
Temp draft commit
Nashatyrev Mar 25, 2019
97e61b0
Temp commit: refactor draft version 1
Nashatyrev Mar 29, 2019
4be6e14
Very dirty draft ssz refactor version where serialization works (SSZT…
Nashatyrev Apr 4, 2019
ece9947
Next round of SSZ refactor. Working serialize/deserialize
Nashatyrev Apr 5, 2019
4a5d832
Eliminate obsolete SSZSerializable.encode & SSZ.skipContainer attributes
Nashatyrev Apr 5, 2019
b702dd4
Add ability to annotate methods (predecessor methods as well) with @SSZ
Nashatyrev Apr 5, 2019
2707033
Some ssz package and class renames
Nashatyrev Apr 5, 2019
8f28224
Support BytesHasher
Nashatyrev Apr 6, 2019
ae041a7
Adjust incremental hasher
Nashatyrev Apr 7, 2019
29b9de4
Adjust SSZBuilder
Nashatyrev Apr 7, 2019
679ae0b
Move SSZSchemeBuilder to ssz.access.container package. Extract SSZFie…
Nashatyrev Apr 7, 2019
28c1b3a
Encapsulate SSZField fields. Remove duplicate member
Nashatyrev Apr 7, 2019
e219b03
Add byte primitive codec
Nashatyrev Apr 8, 2019
5a677c2
Add @SSZSerializable.accessor attribute
Nashatyrev Apr 8, 2019
0dbefae
Add BytesValue accessor
Nashatyrev Apr 8, 2019
cdf145e
Fix SubclassCodec bug
Nashatyrev Apr 8, 2019
99f9293
Fix test
Nashatyrev Apr 8, 2019
eada042
Fix array creation of the right class
Nashatyrev Apr 8, 2019
2b75e3a
Current SSZ encoding is no more Cava compatible
Nashatyrev Apr 8, 2019
a9616f9
Fix BytesValueAccessor
Nashatyrev Apr 8, 2019
29bd1f1
Add @SSZSerializable.serializeAs attribute support to ListAccessor
Nashatyrev Apr 8, 2019
1d5a688
Fix equals for BeaconState and ReadList
Nashatyrev Apr 8, 2019
ba763bc
Creating deserialized ReadList index via reflection
Nashatyrev Apr 8, 2019
b56f6ff
Remove variable-size BytesValue from basic values for now. Treat them…
Nashatyrev Apr 8, 2019
03eadff
Annotate BeaconState interface members with @SSZ instead of implement…
Nashatyrev Apr 8, 2019
7bdef8c
Merge remote-tracking branch 'origin/develop' into feature/incrementa…
Nashatyrev Apr 8, 2019
bb859ba
Resolve merge compile conflicts
Nashatyrev Apr 8, 2019
19ec99f
Define BeaconState vector sizes via external var resolver
Nashatyrev Apr 9, 2019
2e1980e
Optimize deserializer by operating directly on cava Bytes instead of …
Nashatyrev Apr 9, 2019
a2c007c
Fix bug with spec constant resolver
Nashatyrev Apr 9, 2019
ff435ff
Fix BytesValue.concat bug
Nashatyrev Apr 9, 2019
a6b1a20
Process empty list without requesting child element type. This preven…
Nashatyrev Apr 9, 2019
d937526
Now need to pass specConstants to every serializer and hasher (due to…
Nashatyrev Apr 9, 2019
b683551
Rollback accidentally committed test change
Nashatyrev Apr 9, 2019
a0b418d
Detect List element type from value when hashing raw list value
Nashatyrev Apr 9, 2019
35a15a9
Shouldn't compare against golden values until we are sure these value…
Nashatyrev Apr 9, 2019
908b33d
Fix mix in length: required only for variable-size lists
Nashatyrev Apr 9, 2019
2f5a50b
Merge remote-tracking branch 'origin/develop' into feature/incrementa…
Nashatyrev Apr 9, 2019
1b14116
Fix Read/WriteList to create a copy of backed list
Nashatyrev Apr 9, 2019
e34fa67
Fix annotation
Nashatyrev Apr 9, 2019
bb0da59
Fix truncate hash size calculation bug
Nashatyrev Apr 9, 2019
6534a5a
Remove obsolete classes
Nashatyrev Apr 9, 2019
b687f90
Change BeaconState state vector members to types ReadVector/WriteVect…
Nashatyrev Apr 10, 2019
570c24e
Fix NPE when trying to check isSupported() on strange containers
Nashatyrev Apr 10, 2019
35c9aff
Fiz SSZSerializer for DepositContract
Nashatyrev Apr 10, 2019
ad5b85b
Move type dump method to SSZType interface
Nashatyrev Apr 11, 2019
4507d31
Move type dump method to SSZType interface
Nashatyrev Apr 11, 2019
c84e0b8
Make SSZField.resolveFromValue support ReadList to simplify hashing o…
Nashatyrev Apr 11, 2019
0fa6690
Add @SSZ.order attribute to order SSZ fields declared by methods (cla…
Nashatyrev Apr 11, 2019
2a581f7
Fix merkle trie resizing
Nashatyrev Apr 11, 2019
e90e973
Add ability to fork update listener so two copies of the same source …
Nashatyrev Apr 11, 2019
0174942
Add observable Read/WriteList implementation. Add ObservableHelper fo…
Nashatyrev Apr 11, 2019
56682f2
Add check @SSZ.orders are not duplicated
Nashatyrev Apr 11, 2019
b057951
Update test
Nashatyrev Apr 11, 2019
2e098b4
BeaconState becomes ObservableComposite. Add SSZ fields order
Nashatyrev Apr 11, 2019
aa6c69c
Add ObservableListImpl.equals
Nashatyrev Apr 11, 2019
60d440d
Make BeaconChainImpl observable for incremental hashing
Nashatyrev Apr 11, 2019
c564d7e
Fix the bug
Nashatyrev Apr 11, 2019
917660e
Remove useless SSZContainerType.getChildNames() method
Nashatyrev Apr 12, 2019
d7802f1
Cache info inside SSZType classes
Nashatyrev Apr 12, 2019
f870d2a
Instantiate BC Digest directly for performance reason
Nashatyrev Apr 12, 2019
f32f0d5
Optimize Digest update for BytesValue.wrap() instance
Nashatyrev Apr 12, 2019
5ffd377
Extract MerkleTrie class
Nashatyrev Apr 12, 2019
64f2e6c
Use optimized SimpleHasher
Nashatyrev Apr 12, 2019
2fdfb23
Rename the method
Nashatyrev Apr 12, 2019
05a78fe
Use encode2() to get BytesValue
Nashatyrev Apr 12, 2019
e5c7564
Remove empty files
Nashatyrev Apr 12, 2019
a372df9
Resolve transitive dependency of BeaconState on SSZ
Nashatyrev Apr 12, 2019
f424056
Add some SSZ JavaDoc
Nashatyrev Apr 12, 2019
7089f81
Rename SSZCode to SSZBasicAccessor
Nashatyrev Apr 12, 2019
24aad88
Make AccessorResolver.resolve* methods look uniformly
Nashatyrev Apr 12, 2019
8937b57
Segregate @SSZ annotation static int vector size and variable resolve…
Nashatyrev Apr 12, 2019
8fb6121
Add some more JavaDoc
Nashatyrev Apr 12, 2019
e1d8bc8
Split @SSZSerializable.accessor to 3 different accessor types
Nashatyrev Apr 15, 2019
6c3a1f2
Merge branch 'feature/incremental-ssz' of https://github.com/harmony-…
Nashatyrev Apr 15, 2019
8c4a28d
Resolve merge conflicts
Nashatyrev Apr 15, 2019
2c68ce2
Rename remaining Codec mentions to BasicAccessor
Nashatyrev Apr 15, 2019
b0a12cc
Remove commented code
Nashatyrev Apr 15, 2019
935a73c
Fix the test
Nashatyrev Apr 15, 2019
9d7ba00
Fix overriding SpecConstants class case from a different module
Nashatyrev Apr 15, 2019
61a48ff
Fix Path calculation on Windows
Nashatyrev Apr 15, 2019
c66ae65
BeaconState.empty() should be created with respect to constants to co…
Nashatyrev Apr 15, 2019
e98e06a
Throw exception if supplied ssz data is bigger than required
Nashatyrev Apr 15, 2019
e05e960
Temporary fix for incremental hash case with removed list elements
Nashatyrev Apr 15, 2019
a811d29
Fix the test
Nashatyrev Apr 15, 2019
4e6eef6
Increase CircleCI heap size
Nashatyrev Apr 15, 2019
79cb073
Support list elements removal in IncrementalHasher
Nashatyrev Apr 15, 2019
5ea33a6
Minor JavaDoc fix
Nashatyrev Apr 15, 2019
8f077ed
Add ssz.access javadocs
Nashatyrev Apr 15, 2019
abb8a33
Add ssz.incremental javadocs
Nashatyrev Apr 15, 2019
db04a59
Add ssz.type javadocs
Nashatyrev Apr 15, 2019
540f2c3
Remove obsolete methods. Add ssz.visitor javadocs
Nashatyrev Apr 15, 2019
c438aac
Get rid of DefaultSSZ class
Nashatyrev Apr 16, 2019
cfaf11b
Fix test regression
Nashatyrev Apr 16, 2019
f847d7e
Use optimized version of SimpleHasher by default. Delete old class
Nashatyrev Apr 16, 2019
1a7ab12
Rename vectorSize to vectorLength attribute to avoid clashing with '…
Nashatyrev Apr 16, 2019
9dfd725
Fix minor bug in IncrementalHasher
Nashatyrev Apr 16, 2019
51aa0f5
Fix the test
Nashatyrev Apr 16, 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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
working_directory: ~/beacon-chain

environment:
JAVA_TOOL_OPTIONS: -Xmx768m
JAVA_TOOL_OPTIONS: -Xmx2G
GRADLE_OPTS: -Dorg.gradle.daemon=false -Dorg.gradle.workers.max=2
GRADLE_MAX_TEST_FORKS: 2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ private BeaconTuple fetchRecentTuple() {

private void initializeStorage() {
BeaconBlock initialGenesis = spec.get_empty_block();
BeaconStateEx initialState = initialTransition.apply(BeaconStateEx.getEmpty(), initialGenesis);
BeaconStateEx initialState =
initialTransition.apply(BeaconStateEx.getEmpty(spec.getConstants()), initialGenesis);

Hash32 initialStateRoot = spec.hash_tree_root(initialState);
BeaconBlock genesis = initialGenesis.withStateRoot(initialStateRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@
public interface BeaconChainStorageFactory {

BeaconChainStorage create(Database database);

static BeaconChainStorageFactory get() {
return new SSZBeaconChainStorageFactory();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
import tech.pegasys.artemis.ethereum.core.Hash32;

public class MemBeaconChainStorageFactory implements BeaconChainStorageFactory {
private final ObjectHasher<Hash32> objectHasher;

public MemBeaconChainStorageFactory(ObjectHasher<Hash32> objectHasher) {
this.objectHasher = objectHasher;
}

@Override
public BeaconChainStorage create(Database database) {
ObjectHasher<Hash32> objectHasher = ObjectHasher.createSSZOverKeccak256();

BeaconBlockStorage blockStorage =
new BeaconBlockStorageImpl(objectHasher, new HashMapDataSource<>(), new HashMapHoleyList<>());
BeaconStateStorage stateStorage =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@
* BeaconChainStorage} instance.
*/
public class SSZBeaconChainStorageFactory implements BeaconChainStorageFactory {
private final ObjectHasher<Hash32> objectHasher;
private final SerializerFactory serializerFactory;

public SSZBeaconChainStorageFactory(
ObjectHasher<Hash32> objectHasher,
SerializerFactory serializerFactory) {
this.objectHasher = objectHasher;
this.serializerFactory = serializerFactory;
}

@Override
public BeaconChainStorage create(Database database) {
ObjectHasher<Hash32> objectHasher = ObjectHasher.createSSZOverKeccak256();
SerializerFactory serializerFactory = SerializerFactory.createSSZ();

BeaconBlockStorage blockStorage =
BeaconBlockStorageImpl.create(database, objectHasher, serializerFactory);
BeaconStateStorage stateStorage =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.ethereum.beacon.chain.storage.impl;

import java.util.function.Function;
import org.ethereum.beacon.ssz.Serializer;
import org.ethereum.beacon.ssz.SSZSerializer;
import tech.pegasys.artemis.util.bytes.BytesValue;

public class SSZSerializerFactory implements SerializerFactory {

private final Serializer serializer;
private final SSZSerializer serializer;

public SSZSerializerFactory(Serializer serializer) {
public SSZSerializerFactory(SSZSerializer serializer) {
this.serializer = serializer;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.ethereum.beacon.chain.storage.impl;

import java.util.function.Function;
import org.ethereum.beacon.ssz.Serializer;
import org.ethereum.beacon.core.spec.SpecConstants;
import org.ethereum.beacon.core.spec.SpecConstantsResolver;
import org.ethereum.beacon.ssz.SSZBuilder;
import tech.pegasys.artemis.util.bytes.BytesValue;

public interface SerializerFactory {
Expand All @@ -10,7 +12,10 @@ public interface SerializerFactory {

<T> Function<T, BytesValue> getSerializer(Class<T> objectClass);

static SerializerFactory createSSZ() {
return new SSZSerializerFactory(Serializer.annotationSerializer());
static SerializerFactory createSSZ(SpecConstants specConstants) {
return new SSZSerializerFactory(
new SSZBuilder()
.withExternalVarResolver(new SpecConstantsResolver(specConstants))
.buildSerializer());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.stream.IntStream;
import org.ethereum.beacon.chain.storage.BeaconChainStorage;
import org.ethereum.beacon.chain.storage.BeaconChainStorageFactory;
import org.ethereum.beacon.chain.storage.impl.SSZBeaconChainStorageFactory;
import org.ethereum.beacon.chain.storage.impl.SerializerFactory;
import org.ethereum.beacon.consensus.BeaconChainSpec;
import org.ethereum.beacon.consensus.BeaconStateEx;
import org.ethereum.beacon.consensus.BlockTransition;
Expand Down Expand Up @@ -95,7 +97,9 @@ private MutableBeaconChain createBeaconChain(
BeaconBlockVerifier blockVerifier = (block, state) -> VerificationResult.PASSED;
BeaconStateVerifier stateVerifier = (block, state) -> VerificationResult.PASSED;
Database database = Database.inMemoryDB();
BeaconChainStorage chainStorage = BeaconChainStorageFactory.get().create(database);
BeaconChainStorage chainStorage = new SSZBeaconChainStorageFactory(
spec.getObjectHasher(), SerializerFactory.createSSZ(spec.getConstants()))
.create(database);

return new DefaultBeaconChain(
spec,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private BeaconBlockStorage create(BeaconChainSpec spec) {
return BeaconBlockStorageImpl.create(
Database.inMemoryDB(),
ObjectHasher.createSSZOverKeccak256(),
SerializerFactory.createSSZ());
SerializerFactory.createSSZ(spec.getConstants()));
}

private BeaconBlock createBlock(long slot, BeaconBlock parent, Hash32 parentHash) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import org.ethereum.beacon.chain.observer.ObservableStateProcessor;
import org.ethereum.beacon.chain.observer.ObservableStateProcessorImpl;
import org.ethereum.beacon.chain.storage.BeaconChainStorage;
import org.ethereum.beacon.chain.storage.BeaconChainStorageFactory;
import org.ethereum.beacon.chain.storage.impl.SSZBeaconChainStorageFactory;
import org.ethereum.beacon.chain.storage.impl.SerializerFactory;
import org.ethereum.beacon.consensus.BeaconChainSpec;
import org.ethereum.beacon.consensus.StateTransitions;
import org.ethereum.beacon.consensus.TestUtils;
Expand Down Expand Up @@ -92,7 +93,10 @@ public SlotNumber getGenesisSlot() {
PerBlockTransition blockTransition = StateTransitions.blockTransition(spec);

db = new InMemoryDatabase();
beaconChainStorage = BeaconChainStorageFactory.get().create(db);
beaconChainStorage =
new SSZBeaconChainStorageFactory(
spec.getObjectHasher(), SerializerFactory.createSSZ(specConstants))
.create(db);

// TODO
BeaconBlockVerifier blockVerifier = (block, state) -> VerificationResult.PASSED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static BeaconChainSpec createWithSSZHasher(@Nonnull SpecConstants constants) {
Objects.requireNonNull(constants);

Function<BytesValue, Hash32> hashFunction = Hashes::keccak256;
ObjectHasher<Hash32> sszHasher = SSZObjectHasher.create(hashFunction);
ObjectHasher<Hash32> sszHasher = SSZObjectHasher.create(constants, hashFunction);
return new BeaconChainSpecImpl(constants, hashFunction, sszHasher);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ static BeaconStateEx getEmpty() {
return new BeaconStateExImpl(BeaconState.getEmpty(), Hash32.ZERO, TransitionType.UNKNOWN);
}

Hash32 getHeadBlockHash();
static BeaconStateEx getEmpty(SpecConstants specConst) {
return new BeaconStateExImpl(BeaconState.getEmpty(specConst), Hash32.ZERO, TransitionType.UNKNOWN);
}


Hash32 getHeadBlockHash();

TransitionType getTransition();

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

import org.ethereum.beacon.core.spec.SpecConstants;
import org.ethereum.beacon.crypto.Hashes;
import tech.pegasys.artemis.ethereum.core.Hash32;
import tech.pegasys.artemis.util.bytes.BytesValue;
Expand All @@ -16,6 +17,10 @@ static ObjectHasher<Hash32> createSSZOverKeccak256() {
return SSZObjectHasher.create(Hashes::keccak256);
}

static ObjectHasher<Hash32> createSSZOverKeccak256(SpecConstants specConstants) {
return SSZObjectHasher.create(specConstants, Hashes::keccak256);
}

/**
* Calculates hash of given object.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package org.ethereum.beacon.consensus.hasher;

import java.util.function.Consumer;
import java.util.List;
import java.util.function.Function;
import org.ethereum.beacon.core.spec.SpecConstants;
import org.ethereum.beacon.core.spec.SpecConstantsResolver;
import org.ethereum.beacon.core.types.Hashable;
import org.ethereum.beacon.ssz.SSZHashSerializer;
import org.ethereum.beacon.ssz.SSZHashSerializers;
import org.ethereum.beacon.ssz.SSZBuilder;
import org.ethereum.beacon.ssz.SSZHasher;
import tech.pegasys.artemis.ethereum.core.Hash32;
import tech.pegasys.artemis.util.bytes.Bytes32;
import tech.pegasys.artemis.util.bytes.BytesValue;

import java.util.List;
import java.util.Optional;
import java.util.function.Function;

/**
* An object hasher implementation using Tree Hash algorithm described in the spec.
*
Expand All @@ -21,22 +20,35 @@
*/
public class SSZObjectHasher implements ObjectHasher<Hash32> {

private static final int SSZ_SCHEMES_CACHE_CAPACITY = 128;
private final SSZHashSerializer sszHashSerializer;
private final SSZHasher sszHasher;

SSZObjectHasher(SSZHashSerializer sszHashSerializer) {
this.sszHashSerializer = sszHashSerializer;
SSZObjectHasher(SSZHasher sszHasher) {
this.sszHasher = sszHasher;
}

public static SSZObjectHasher create(
SpecConstants constants, Function<BytesValue, Hash32> hashFunction) {

SSZHasher sszHasher =
new SSZBuilder()
.withExternalVarResolver(new SpecConstantsResolver(constants))
.withIncrementalHasher(true)
.buildHasher(hashFunction);
return new SSZObjectHasher(sszHasher);
}

public static SSZObjectHasher create(Function<BytesValue, Hash32> hashFunction) {
SSZHashSerializer sszHashSerializer =
SSZHashSerializers.createWithBeaconChainTypes(hashFunction, true, SSZ_SCHEMES_CACHE_CAPACITY);
return new SSZObjectHasher(sszHashSerializer);

SSZHasher sszHasher =
new SSZBuilder()
.withIncrementalHasher(true)
.buildHasher(hashFunction);
return new SSZObjectHasher(sszHasher);
}

@Override
public Hash32 getHash(Object input) {
Function<Object, Hash32> hasher = o -> Hash32.wrap(Bytes32.wrap(sszHashSerializer.hash(o)));
Function<Object, Hash32> hasher = o -> Hash32.wrap(Bytes32.wrap(sszHasher.hash(o)));
if (input instanceof Hashable) {
return ((Hashable<Hash32>) input).getHash(hasher);
} else {
Expand All @@ -49,7 +61,7 @@ public Hash32 getHashTruncateLast(Object input) {
if (input instanceof List) {
throw new RuntimeException("Lists are not supported in truncated hash");
} else {
return Hash32.wrap(Bytes32.wrap(sszHashSerializer.hashTruncateLast(input, input.getClass())));
return Hash32.wrap(Bytes32.wrap(sszHasher.hashTruncateLast(input, input.getClass())));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ default BeaconBlock get_empty_block() {
*/
default BeaconState get_genesis_beacon_state(
List<Deposit> genesisValidatorDeposits, Time genesisTime, Eth1Data genesisEth1Data) {
MutableBeaconState state = BeaconState.getEmpty().createMutableCopy();
MutableBeaconState state = BeaconState.getEmpty(getConstants()).createMutableCopy();

// Misc
state.setSlot(getConstants().getGenesisSlot());
Expand All @@ -72,8 +72,7 @@ default BeaconState get_genesis_beacon_state(
state.setValidatorRegistryUpdateEpoch(getConstants().getGenesisEpoch());

// Randomness and committees
state.getLatestRandaoMixes().addAll(
nCopies(getConstants().getLatestRandaoMixesLength().getIntValue(), Hash32.ZERO));
state.getLatestRandaoMixes().setAll(Hash32.ZERO);
state.setPreviousShufflingStartShard(getConstants().getGenesisStartShard());
state.setCurrentShufflingStartShard(getConstants().getGenesisStartShard());
state.setPreviousShufflingEpoch(getConstants().getGenesisEpoch());
Expand All @@ -99,14 +98,10 @@ default BeaconState get_genesis_beacon_state(
state.getCurrentCrosslinks().addAll(
nCopies(getConstants().getShardCount().getIntValue(),
new Crosslink(getConstants().getGenesisEpoch(), Hash32.ZERO)));
state.getLatestBlockRoots().addAll(
nCopies(getConstants().getSlotsPerHistoricalRoot().getIntValue(), Hash32.ZERO));
state.getLatestStateRoots().addAll(
nCopies(getConstants().getSlotsPerHistoricalRoot().getIntValue(), Hash32.ZERO));
state.getLatestActiveIndexRoots().addAll(
nCopies(getConstants().getLatestActiveIndexRootsLength().getIntValue(), Hash32.ZERO));
state.getLatestSlashedBalances().addAll(
nCopies(getConstants().getLatestSlashedExitLength().getIntValue(), Gwei.ZERO));
state.getLatestBlockRoots().setAll(Hash32.ZERO);
state.getLatestStateRoots().setAll(Hash32.ZERO);
state.getLatestActiveIndexRoots().setAll(Hash32.ZERO);
state.getLatestSlashedBalances().setAll(Gwei.ZERO);
state.setLatestBlockHeader(get_temporary_block_header(get_empty_block()));
state.getHistoricalRoots().clear();

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

import java.util.Map;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import org.ethereum.beacon.core.BeaconBlockHeader;
import org.ethereum.beacon.core.BeaconState;
Expand All @@ -18,8 +20,10 @@
import org.ethereum.beacon.core.types.SlotNumber;
import org.ethereum.beacon.core.types.Time;
import org.ethereum.beacon.core.types.ValidatorIndex;
import org.ethereum.beacon.ssz.incremental.UpdateListener;
import tech.pegasys.artemis.ethereum.core.Hash32;
import tech.pegasys.artemis.util.collections.ReadList;
import tech.pegasys.artemis.util.collections.ReadVector;
import tech.pegasys.artemis.util.uint.UInt64;

public class DelegateBeaconState implements BeaconState {
Expand All @@ -29,14 +33,21 @@ public DelegateBeaconState(BeaconState delegate) {
this.delegate = delegate;
}

public static BeaconState getEmpty() {
return BeaconState.getEmpty();
}

public BeaconState getDelegate() {
return delegate;
}

@Override
public UpdateListener getUpdateListener(String observerId,
Supplier<UpdateListener> listenerFactory) {
return delegate.getUpdateListener(observerId, listenerFactory);
}

@Override
public Map<String, UpdateListener> getAllUpdateListeners() {
return delegate.getAllUpdateListeners();
}

@Override
public SlotNumber getSlot() {
return delegate.getSlot();
Expand Down Expand Up @@ -68,7 +79,7 @@ public EpochNumber getValidatorRegistryUpdateEpoch() {
}

@Override
public ReadList<EpochNumber, Hash32> getLatestRandaoMixes() {
public ReadVector<EpochNumber, Hash32> getLatestRandaoMixes() {
return delegate.getLatestRandaoMixes();
}

Expand Down Expand Up @@ -158,22 +169,22 @@ public ReadList<ShardNumber, Crosslink> getCurrentCrosslinks() {
}

@Override
public ReadList<SlotNumber, Hash32> getLatestBlockRoots() {
public ReadVector<SlotNumber, Hash32> getLatestBlockRoots() {
return delegate.getLatestBlockRoots();
}

@Override
public ReadList<SlotNumber, Hash32> getLatestStateRoots() {
public ReadVector<SlotNumber, Hash32> getLatestStateRoots() {
return delegate.getLatestStateRoots();
}

@Override
public ReadList<EpochNumber, Hash32> getLatestActiveIndexRoots() {
public ReadVector<EpochNumber, Hash32> getLatestActiveIndexRoots() {
return delegate.getLatestActiveIndexRoots();
}

@Override
public ReadList<EpochNumber, Gwei> getLatestSlashedBalances() {
public ReadVector<EpochNumber, Gwei> getLatestSlashedBalances() {
return delegate.getLatestSlashedBalances();
}

Expand Down
Loading