Skip to content

Commit

Permalink
Default to currentEpoch in findEarliestExitEpoch (#8273)
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Harris <[email protected]>
Co-authored-by: Paul Harris <[email protected]>
  • Loading branch information
jtraglia and rolfyone authored May 1, 2024
1 parent 80687ba commit 7463355
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public ExecutionPayloadElectraImpl(
final SszUInt64 blobGasUsed,
final SszUInt64 excessBlobGas,
final SszList<DepositReceipt> depositReceipts,
final SszList<ExecutionLayerWithdrawalRequest> exits) {
final SszList<ExecutionLayerWithdrawalRequest> withdrawalRequests) {
super(
schema,
parentHash,
Expand All @@ -124,7 +124,7 @@ public ExecutionPayloadElectraImpl(
blobGasUsed,
excessBlobGas,
depositReceipts,
exits);
withdrawalRequests);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -152,15 +151,12 @@ public BeaconStateElectra upgrade(final BeaconState preState) {
});
}

private UInt64 findEarliestExitEpoch(final BeaconState state) {
final SszList<Validator> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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));
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 7463355

Please sign in to comment.