diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/execution/versions/electra/ExecutionPayloadElectraImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/execution/versions/electra/ExecutionPayloadElectraImpl.java index 84086836783..cfec479c768 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/execution/versions/electra/ExecutionPayloadElectraImpl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/execution/versions/electra/ExecutionPayloadElectraImpl.java @@ -103,7 +103,7 @@ public ExecutionPayloadElectraImpl( final SszUInt64 blobGasUsed, final SszUInt64 excessBlobGas, final SszList depositReceipts, - final SszList exits) { + final SszList withdrawalRequests) { super( schema, parentHash, @@ -124,7 +124,7 @@ public ExecutionPayloadElectraImpl( blobGasUsed, excessBlobGas, depositReceipts, - exits); + withdrawalRequests); } @Override diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/forktransition/ElectraStateUpgrade.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/forktransition/ElectraStateUpgrade.java index 5bafc9cc726..df3232852f9 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/forktransition/ElectraStateUpgrade.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/forktransition/ElectraStateUpgrade.java @@ -18,7 +18,6 @@ import java.util.Comparator; import java.util.stream.IntStream; import org.apache.tuweni.bytes.Bytes32; -import tech.pegasys.teku.infrastructure.ssz.SszList; import tech.pegasys.teku.infrastructure.ssz.SszMutableList; import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.config.SpecConfigElectra; @@ -120,7 +119,7 @@ public BeaconStateElectra upgrade(final BeaconState preState) { state.setDepositBalanceToConsume(UInt64.ZERO); state.setExitBalanceToConsume( beaconStateAccessors.getActivationExitChurnLimit(state)); - state.setEarliestExitEpoch(findEarliestExitEpoch(state)); + state.setEarliestExitEpoch(findEarliestExitEpoch(state, epoch)); state.setConsolidationBalanceToConsume( beaconStateAccessors.getConsolidationChurnLimit(state)); state.setEarliestConsolidationEpoch( @@ -152,15 +151,12 @@ public BeaconStateElectra upgrade(final BeaconState preState) { }); } - private UInt64 findEarliestExitEpoch(final BeaconState state) { - final SszList validators = state.getValidators(); - UInt64 lastExitEpoch = UInt64.ZERO; - for (int i = 0; i < validators.size(); i++) { - final UInt64 exitEpoch = validators.get(i).getExitEpoch(); - if (exitEpoch.isLessThan(UInt64.MAX_VALUE)) { - lastExitEpoch = lastExitEpoch.max(exitEpoch); - } - } - return lastExitEpoch.increment(); + private UInt64 findEarliestExitEpoch(final BeaconState state, final UInt64 currentEpoch) { + return state.getValidators().stream() + .map(Validator::getExitEpoch) + .filter(exitEpoch -> !exitEpoch.equals(FAR_FUTURE_EPOCH)) + .max(UInt64::compareTo) + .orElse(currentEpoch) + .increment(); } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/helpers/BeaconStateAccessorsElectra.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/helpers/BeaconStateAccessorsElectra.java index 6374c6a2931..7b77b070ff8 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/helpers/BeaconStateAccessorsElectra.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/helpers/BeaconStateAccessorsElectra.java @@ -79,7 +79,7 @@ public UInt64 getPendingBalanceToWithdraw( state.getPendingPartialWithdrawals().asList(); return partialWithdrawals.stream() .filter(z -> z.getIndex() == validatorIndex) - .map(z -> z.getAmount()) + .map(PendingPartialWithdrawal::getAmount) .reduce(UInt64.ZERO, UInt64::plus); } diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/logic/versions/electra/forktransition/ElectraStateUpgradeTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/logic/versions/electra/forktransition/ElectraStateUpgradeTest.java index 0114bd20262..8900228df8f 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/logic/versions/electra/forktransition/ElectraStateUpgradeTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/logic/versions/electra/forktransition/ElectraStateUpgradeTest.java @@ -57,12 +57,10 @@ class ElectraStateUpgradeTest { @Test void canUpgradeFromDeneb() { + final UInt64 slot = UInt64.valueOf(80_000L); final BeaconStateDeneb pre = BeaconStateDeneb.required( - dataStructureUtil - .stateBuilder(SpecMilestone.DENEB, 0, 0) - .slot(UInt64.valueOf(80_000L)) - .build()); + dataStructureUtil.stateBuilder(SpecMilestone.DENEB, 0, 0).slot(slot).build()); final ElectraStateUpgrade upgrade = new ElectraStateUpgrade( @@ -78,7 +76,7 @@ void canUpgradeFromDeneb() { // = (64 *10^9) - (64 *10^9) MOD 10^9 // = (64 *10^9) - 0 assertThat(post.getExitBalanceToConsume()).isEqualTo(UInt64.valueOf(64_000_000_000L)); - assertThat(post.getEarliestExitEpoch()).isEqualTo(UInt64.ONE); + assertThat(post.getEarliestExitEpoch()).isEqualTo(slot.dividedBy(8).increment()); assertThat(post.getConsolidationBalanceToConsume()).isEqualTo(UInt64.ZERO); // 80_000/8 (slots -> epochs) + max_seed_lookahead + 1 assertThat(post.getEarliestConsolidationEpoch()).isEqualTo(UInt64.valueOf(10005)); @@ -168,6 +166,7 @@ public void shouldAddValidatorsWithCompoundingCredentialsExcessBalanceToPendingB BeaconStateDeneb.required( dataStructureUtil .stateBuilder(SpecMilestone.DENEB, 4, 0) + .slot(UInt64.valueOf(100_000)) .validators(validator1, validator2) // All validators have their balance = maxEffectiveBalance .balances(