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
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,19 @@ default BeaconState initialize_beacon_state_from_eth1(
state.setLatestBlockHeader(get_block_header(get_empty_block()));

// Process deposits
for (int index = 0; index < deposits.size(); index++) {
Deposit deposit = deposits.get(index);
ReadList<Integer, DepositData> deposit_data_list =
ReadList.wrap(
deposits.stream().map(Deposit::getData).limit(index + 1).collect(Collectors.toList()),
Integer::new,
1L << getConstants().getDepositContractTreeDepth().getIntValue());
state.setEth1Data(new Eth1Data(
hash_tree_root(deposit_data_list), UInt64.valueOf(deposits.size()), eth1_block_hash));
verify_deposit(state, deposit);
process_deposit(state, deposit);
}
ReadList<Integer, DepositData> deposit_data_list =
ReadList.wrap(
deposits.stream().map(Deposit::getData).collect(Collectors.toList()),
Integer::new,
1L << getConstants().getDepositContractTreeDepth().getIntValue());
state.setEth1Data(new Eth1Data(
hash_tree_root(deposit_data_list), UInt64.valueOf(deposits.size()), eth1_block_hash));

// according to the spec deposits are verified before processing
// but this is redundant for genesis initialisation
// since passed deposits are created by our own code
// hence, we are able to avoid verification which saves us some computational resources
deposits.forEach(deposit -> process_deposit(state, deposit));
Comment thread
mkalinin marked this conversation as resolved.

// Process activations
for (ValidatorIndex index : state.getValidators().size().iterateFromZero()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ public void handleChainStartCorrectly() {
.plus(spec.getConstants().getSecondsPerDay().times(2));

assertThat(initialState.getGenesisTime()).isEqualTo(expectedTime);
assertThat(initialState.getEth1Data()).isEqualTo(Eth1Data.EMPTY);
assertThat(initialState.getEth1Data()).isEqualTo(eth1Data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,16 @@ protected synchronized void newDeposits(List<DepositEventData> eventDataList, by
}

private void tryChainStart(byte[] blockHash, long blockTimestamp) {
// use fake proof for initial deposits to avoid of unnecessary merklizing
List<Hash32> fakeProof =
Collections.nCopies(
spec.getConstants().getDepositContractTreeDepthPlusOne().getIntValue(), Hash32.ZERO);
// instantiate initial deposits
List<Deposit> genesisDeposits = new ArrayList<>();
for (int i = 0; i < initialDeposits.size(); i++) {
genesisDeposits.add(
Deposit.create(tree.getProof(i, initialDeposits.size()), initialDeposits.get(i)));
}
List<Deposit> genesisDeposits =
initialDeposits.stream()
.map(data -> Deposit.create(fakeProof, data))
.collect(Collectors.toList());

try {
// check if genesis conditions met
Eth1Data genesisEth1Data =
Expand Down