Skip to content

Commit

Permalink
feat: implement partial spec changes for v1.5.0-alpha.10 (#7288)
Browse files Browse the repository at this point in the history
* Rename PartialPendingWithdrawal field

* do not change creds type on consolidation

* Use validator EB to process pending consolidation

* lint
  • Loading branch information
ensi321 committed Dec 17, 2024
1 parent 76ee6b3 commit 031214e
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion packages/params/src/presets/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,6 @@ export const mainnetPreset: BeaconPreset = {
PENDING_DEPOSITS_LIMIT: 134217728,
PENDING_PARTIAL_WITHDRAWALS_LIMIT: 134217728,
PENDING_CONSOLIDATIONS_LIMIT: 262144,
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: 1,
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: 2,
WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA: 4096,
};
2 changes: 1 addition & 1 deletion packages/params/src/presets/minimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,6 @@ export const minimalPreset: BeaconPreset = {
PENDING_DEPOSITS_LIMIT: 134217728,
PENDING_PARTIAL_WITHDRAWALS_LIMIT: 64,
PENDING_CONSOLIDATIONS_LIMIT: 64,
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: 1,
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: 2,
WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA: 4096,
};
14 changes: 3 additions & 11 deletions packages/state-transition/src/block/processConsolidationRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {electra, ssz} from "@lodestar/types";

import {CachedBeaconStateElectra} from "../types.js";
import {hasEth1WithdrawalCredential} from "../util/capella.js";
import {hasExecutionWithdrawalCredential, isPubkeyKnown, switchToCompoundingValidator} from "../util/electra.js";
import {hasCompoundingWithdrawalCredential, isPubkeyKnown, switchToCompoundingValidator} from "../util/electra.js";
import {computeConsolidationEpochAndUpdateChurn} from "../util/epoch.js";
import {getConsolidationChurnLimit, getPendingBalanceToWithdraw, isActiveValidator} from "../util/validator.js";

Expand Down Expand Up @@ -49,11 +49,8 @@ export function processConsolidationRequest(
const sourceWithdrawalAddress = sourceValidator.withdrawalCredentials.subarray(12);
const currentEpoch = state.epochCtx.epoch;

// Verify withdrawal credentials
if (
!hasExecutionWithdrawalCredential(sourceValidator.withdrawalCredentials) ||
!hasExecutionWithdrawalCredential(targetValidator.withdrawalCredentials)
) {
// Verify that target has compounding withdrawal credentials
if (!hasCompoundingWithdrawalCredential(targetValidator.withdrawalCredentials)) {
return;
}

Expand Down Expand Up @@ -91,11 +88,6 @@ export function processConsolidationRequest(
targetIndex,
});
state.pendingConsolidations.push(pendingConsolidation);

// Churn any target excess active balance of target and raise its max
if (hasEth1WithdrawalCredential(targetValidator.withdrawalCredentials)) {
switchToCompoundingValidator(state, targetIndex);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function processWithdrawalRequest(
const withdrawableEpoch = exitQueueEpoch + config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY;

const pendingPartialWithdrawal = ssz.electra.PendingPartialWithdrawal.toViewDU({
index: validatorIndex,
validatorIndex,
amount: amountToWithdraw,
withdrawableEpoch,
});
Expand Down
10 changes: 6 additions & 4 deletions packages/state-transition/src/block/processWithdrawals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,21 @@ export function getExpectedWithdrawals(
break;
}

const validator = validators.getReadonly(withdrawal.index);
const validator = validators.getReadonly(withdrawal.validatorIndex);

if (
validator.exitEpoch === FAR_FUTURE_EPOCH &&
validator.effectiveBalance >= MIN_ACTIVATION_BALANCE &&
balances.get(withdrawal.index) > MIN_ACTIVATION_BALANCE
balances.get(withdrawal.validatorIndex) > MIN_ACTIVATION_BALANCE
) {
const balanceOverMinActivationBalance = BigInt(balances.get(withdrawal.index) - MIN_ACTIVATION_BALANCE);
const balanceOverMinActivationBalance = BigInt(
balances.get(withdrawal.validatorIndex) - MIN_ACTIVATION_BALANCE
);
const withdrawableBalance =
balanceOverMinActivationBalance < withdrawal.amount ? balanceOverMinActivationBalance : withdrawal.amount;
withdrawals.push({
index: withdrawalIndex,
validatorIndex: withdrawal.index,
validatorIndex: withdrawal.validatorIndex,
address: validator.withdrawalCredentials.subarray(12),
amount: withdrawableBalance,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ export function processPendingConsolidations(state: CachedBeaconStateElectra, ca
break;
}
// Move active balance to target. Excess balance is withdrawable.
const maxEffectiveBalance = getMaxEffectiveBalance(state.validators.getReadonly(sourceIndex).withdrawalCredentials);
const sourceEffectiveBalance = Math.min(state.balances.get(sourceIndex), maxEffectiveBalance);
const sourceEffectiveBalance = Math.min(
state.balances.get(sourceIndex),
state.validators.getReadonly(sourceIndex).effectiveBalance
);
decreaseBalance(state, sourceIndex, sourceEffectiveBalance);
increaseBalance(state, targetIndex, sourceEffectiveBalance);
if (cachedBalances) {
Expand Down
2 changes: 1 addition & 1 deletion packages/state-transition/src/util/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ export function getMaxEffectiveBalance(withdrawalCredentials: Uint8Array): numbe
export function getPendingBalanceToWithdraw(state: CachedBeaconStateElectra, validatorIndex: ValidatorIndex): number {
return state.pendingPartialWithdrawals
.getAllReadonly()
.filter((item) => item.index === validatorIndex)
.filter((item) => item.validatorIndex === validatorIndex)
.reduce((total, item) => total + Number(item.amount), 0);
}
2 changes: 1 addition & 1 deletion packages/types/src/electra/sszTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export const PendingDeposits = new ListCompositeType(PendingDeposit, PENDING_DEP

export const PendingPartialWithdrawal = new ContainerType(
{
index: ValidatorIndex,
validatorIndex: ValidatorIndex,
amount: Gwei,
withdrawableEpoch: Epoch,
},
Expand Down
8 changes: 4 additions & 4 deletions packages/validator/test/unit/utils/interopConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const lighthouseHoleskyConfig = {
PENDING_DEPOSITS_LIMIT: "134217728",
PENDING_PARTIAL_WITHDRAWALS_LIMIT: "134217728",
PENDING_CONSOLIDATIONS_LIMIT: "262144",
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: "1",
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: "2",
};

export const prysmHoleskyConfig = {
Expand Down Expand Up @@ -266,7 +266,7 @@ export const prysmHoleskyConfig = {
PENDING_DEPOSITS_LIMIT: "134217728",
PENDING_PARTIAL_WITHDRAWALS_LIMIT: "134217728",
PENDING_CONSOLIDATIONS_LIMIT: "262144",
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: "1",
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: "2",
};

export const tekuHoleskyConfig = {
Expand Down Expand Up @@ -406,7 +406,7 @@ export const tekuHoleskyConfig = {
PENDING_DEPOSITS_LIMIT: "134217728",
PENDING_PARTIAL_WITHDRAWALS_LIMIT: "134217728",
PENDING_CONSOLIDATIONS_LIMIT: "262144",
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: "1",
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: "2",
};

export const nimbusHoleskyConfig = {
Expand Down Expand Up @@ -549,5 +549,5 @@ export const nimbusHoleskyConfig = {
PENDING_DEPOSITS_LIMIT: "134217728",
PENDING_PARTIAL_WITHDRAWALS_LIMIT: "134217728",
PENDING_CONSOLIDATIONS_LIMIT: "262144",
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: "1",
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: "2",
};

0 comments on commit 031214e

Please sign in to comment.