Skip to content

Commit 3004a66

Browse files
authored
Genesis reftests (Consensys#8287)
Signed-off-by: Paul Harris <[email protected]>
1 parent 9e7c10e commit 3004a66

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

ethereum/spec/src/main/java/tech/pegasys/teku/spec/genesis/GenesisGenerator.java

+13-9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package tech.pegasys.teku.spec.genesis;
1515

1616
import static tech.pegasys.teku.spec.config.SpecConfig.GENESIS_EPOCH;
17+
import static tech.pegasys.teku.spec.config.SpecConfigElectra.UNSET_DEPOSIT_RECEIPTS_START_INDEX;
1718

1819
import it.unimi.dsi.fastutil.objects.Object2IntMap;
1920
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
@@ -29,7 +30,6 @@
2930
import tech.pegasys.teku.spec.SpecMilestone;
3031
import tech.pegasys.teku.spec.SpecVersion;
3132
import tech.pegasys.teku.spec.config.SpecConfig;
32-
import tech.pegasys.teku.spec.config.SpecConfigElectra;
3333
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockHeader;
3434
import tech.pegasys.teku.spec.datastructures.blocks.Eth1Data;
3535
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
@@ -95,7 +95,7 @@ public void updateCandidateState(
9595
// Process deposits
9696
deposits.forEach(
9797
deposit -> {
98-
LOG.trace("About to process deposit: {}", depositDataList::size);
98+
LOG.trace("About to process deposit: {}", depositDataList.size());
9999
depositDataList.append(deposit.getData());
100100

101101
// Skip verifying the merkle proof as these deposits come directly from an Eth1 event.
@@ -123,17 +123,19 @@ private void consumePendingBalance(
123123
genesisSpec.beaconStateAccessors(),
124124
schemaDefinitionsElectra);
125125
final List<PendingBalanceDeposit> pendingBalanceDeposits =
126-
stateElectra.getPendingBalanceDeposits().stream().toList();
126+
stateElectra.getPendingBalanceDeposits().asList();
127127

128128
final UInt64 depositAmount =
129129
pendingBalanceDeposits.stream()
130130
.filter(z -> z.getIndex() == validatorIndex)
131-
.map(z -> z.getAmount())
131+
.map(PendingBalanceDeposit::getAmount)
132132
.reduce(UInt64::plus)
133-
.get();
134-
if (depositAmount.isGreaterThanOrEqualTo(
135-
SpecConfigElectra.required(specConfig).getMinActivationBalance())) {
136-
mutatorsElectra.increaseBalance(state, validatorIndex, depositAmount);
133+
.orElse(UInt64.ZERO);
134+
mutatorsElectra.increaseBalance(state, validatorIndex, depositAmount);
135+
if (pendingBalanceDeposits.isEmpty()) {
136+
stateElectra.setPendingBalanceDeposits(
137+
schemaDefinitionsElectra.getPendingBalanceDepositsSchema().createFromElements(List.of()));
138+
} else {
137139
stateElectra.setPendingBalanceDeposits(
138140
schemaDefinitionsElectra
139141
.getPendingBalanceDepositsSchema()
@@ -150,7 +152,7 @@ private void processActivation(final Deposit deposit) {
150152
// Could be absent if the deposit was invalid
151153
return;
152154
}
153-
Validator validator = state.getValidators().get(index);
155+
final Validator validator = state.getValidators().get(index);
154156
if (validator.getActivationEpoch().equals(GENESIS_EPOCH)) {
155157
// Validator is already activated (and thus already has the max effective balance)
156158
return;
@@ -159,6 +161,8 @@ private void processActivation(final Deposit deposit) {
159161
if (genesisSpec.getMilestone().equals(SpecMilestone.ELECTRA)) {
160162
consumePendingBalance(
161163
MutableBeaconStateElectra.required(state), specConfig, genesisSpec, index);
164+
MutableBeaconStateElectra.required(state)
165+
.setDepositReceiptsStartIndex(UNSET_DEPOSIT_RECEIPTS_START_INDEX);
162166
}
163167
final UInt64 balance = state.getBalances().getElement(index);
164168
final UInt64 effectiveBalance =

0 commit comments

Comments
 (0)