From 031214e4a84f5d9bf6f8067f2110d1cf03eaa776 Mon Sep 17 00:00:00 2001 From: NC <17676176+ensi321@users.noreply.github.com> Date: Fri, 13 Dec 2024 16:18:11 -0800 Subject: [PATCH] feat: implement partial spec changes for v1.5.0-alpha.10 (#7288) * Rename PartialPendingWithdrawal field * do not change creds type on consolidation * Use validator EB to process pending consolidation * lint --- packages/params/src/presets/mainnet.ts | 2 +- packages/params/src/presets/minimal.ts | 2 +- .../src/block/processConsolidationRequest.ts | 14 +++----------- .../src/block/processWithdrawalRequest.ts | 2 +- .../src/block/processWithdrawals.ts | 10 ++++++---- .../src/epoch/processPendingConsolidations.ts | 6 ++++-- packages/state-transition/src/util/validator.ts | 2 +- packages/types/src/electra/sszTypes.ts | 2 +- .../validator/test/unit/utils/interopConfigs.ts | 8 ++++---- 9 files changed, 22 insertions(+), 26 deletions(-) diff --git a/packages/params/src/presets/mainnet.ts b/packages/params/src/presets/mainnet.ts index afbfd78eba95..b4136f83da29 100644 --- a/packages/params/src/presets/mainnet.ts +++ b/packages/params/src/presets/mainnet.ts @@ -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, }; diff --git a/packages/params/src/presets/minimal.ts b/packages/params/src/presets/minimal.ts index d9be1b1468ab..4c2a56a11d82 100644 --- a/packages/params/src/presets/minimal.ts +++ b/packages/params/src/presets/minimal.ts @@ -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, }; diff --git a/packages/state-transition/src/block/processConsolidationRequest.ts b/packages/state-transition/src/block/processConsolidationRequest.ts index ade22c7454db..8d3cfdc062c9 100644 --- a/packages/state-transition/src/block/processConsolidationRequest.ts +++ b/packages/state-transition/src/block/processConsolidationRequest.ts @@ -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"; @@ -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; } @@ -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); - } } /** diff --git a/packages/state-transition/src/block/processWithdrawalRequest.ts b/packages/state-transition/src/block/processWithdrawalRequest.ts index 573c0a49dfc8..7dab10dbb32b 100644 --- a/packages/state-transition/src/block/processWithdrawalRequest.ts +++ b/packages/state-transition/src/block/processWithdrawalRequest.ts @@ -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, }); diff --git a/packages/state-transition/src/block/processWithdrawals.ts b/packages/state-transition/src/block/processWithdrawals.ts index 7f9ab6aa53f1..d3d3a5d58d9e 100644 --- a/packages/state-transition/src/block/processWithdrawals.ts +++ b/packages/state-transition/src/block/processWithdrawals.ts @@ -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, }); diff --git a/packages/state-transition/src/epoch/processPendingConsolidations.ts b/packages/state-transition/src/epoch/processPendingConsolidations.ts index 0ec39409f8a7..f9afc7fb122b 100644 --- a/packages/state-transition/src/epoch/processPendingConsolidations.ts +++ b/packages/state-transition/src/epoch/processPendingConsolidations.ts @@ -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) { diff --git a/packages/state-transition/src/util/validator.ts b/packages/state-transition/src/util/validator.ts index 555b8a09b614..071d936ead23 100644 --- a/packages/state-transition/src/util/validator.ts +++ b/packages/state-transition/src/util/validator.ts @@ -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); } diff --git a/packages/types/src/electra/sszTypes.ts b/packages/types/src/electra/sszTypes.ts index 238e6cc29c76..081853b26ade 100644 --- a/packages/types/src/electra/sszTypes.ts +++ b/packages/types/src/electra/sszTypes.ts @@ -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, }, diff --git a/packages/validator/test/unit/utils/interopConfigs.ts b/packages/validator/test/unit/utils/interopConfigs.ts index 4805154b4b64..a575b796e095 100644 --- a/packages/validator/test/unit/utils/interopConfigs.ts +++ b/packages/validator/test/unit/utils/interopConfigs.ts @@ -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 = { @@ -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 = { @@ -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 = { @@ -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", };