Skip to content

Commit

Permalink
feat: implement maxEB EIP-7251 (#6539)
Browse files Browse the repository at this point in the history
* feat: implement EIP-6110 (#6042)

* Add immutable in the dependencies

* Initial change to pubkeyCache

* Added todos

* Moved unfinalized cache to epochCache

* Move populating finalized cache to afterProcessEpoch

* Specify unfinalized cache during state cloning

* Move from unfinalized to finalized cache in afterProcessEpoch

* Confused myself

* Clean up

* Change logic

* Fix cloning issue

* Clean up redundant code

* Add CarryoverData in epochCtx.createFromState

* Fix typo

* Update usage of pubkeyCache

* Update pubkeyCache usage

* Fix lint

* Fix lint

* Add 6110 to ChainConfig

* Add 6110 to BeaconPreset

* Define 6110 fork and container

* Add V6110 api to execution engine

* Update test

* Add depositReceiptsRoot to process_execution_payload

* State transitioning to EIP6110

* State transitioning to EIP6110

* Light client change in EIP-6110

* Update tests

* produceBlock

* Refactor processDeposit to match the spec

* Implement processDepositReceipt

* Implement 6110 fork guard for pubkeyCache

* Handle changes in eth1 deposit

* Update eth1 deposit test

* Fix typo

* Lint

* Remove embarassing comments

* Address comments

* Modify applyDeposit signature

* Update packages/state-transition/src/cache/epochCache.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Update packages/state-transition/src/cache/epochCache.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Update packages/state-transition/src/cache/pubkeyCache.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Remove old code

* Rename fields in epochCache and immutableData

* Remove CarryoverData

* Move isAfter6110 from var to method

* Fix cyclic import

* Fix operations spec runner

* Fix for spec test

* Fix spec test

* state.depositReceiptsStartIndex to BigInt

* getDeposit requires cached state

* default depositReceiptsStartIndex value in genesis

* Fix pubkeyCache bug

* newUnfinalizedPubkeyIndexMap in createCachedBeaconState

* Lint

* Pass epochCache instead of pubkey2IndexFn in apis

* Address comments

* Add unit test on pubkey cache cloning

* Add unfinalizedPubkeyCacheSize to metrics

* Add unfinalizedPubkeyCacheSize to metrics

* Clean up code

* Add besu to el-interop

* Add 6110 genesis file

* Template for sim test

* Add unit test for getEth1DepositCount

* Update sim test

* Update besudocker

* Finish beacon api calls in sim test

* Update epochCache.createFromState()

* Fix bug unfinalized validators are not finalized

* Add sim test to run a few blocks

* Lint

* Merge branch 'unstable' into 611

* Add more check to sim test

* Update besu docker image instruction

* Update sim test with correct tx

* Address comment + cleanup

* Clean up code

* Properly handle promise rejection

* Lint

* Update packages/beacon-node/src/execution/engine/types.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Update comments

* Accept type undefined in ExecutionPayloadBodyRpc

* Update comment and semantic

* Remove if statement when adding finalized validator

* Comment on repeated insert on finalized cache

* rename createFromState

* Add comment on getPubkey()

* Stash change to reduce diffs

* Stash change to reduce diffs

* Lint

* addFinalizedPubkey on finalized checkpoint

* Update comment

* Use OrderedMap for unfinalized cache

* Pull out logic of deleting pubkeys for batch op

* Add updateUnfinalizedPubkeys in regen

* Update updateUnfinalizedPubkeys logic

* Add comment

* Add metrics for state context caches

* Address comment

* Address comment

* Deprecate eth1Data polling when condition is reached

* Fix conflicts

* Fix sim test

* Lint

* Fix type

* Fix test

* Fix test

* Lint

* Update packages/light-client/src/spec/utils.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Fix spec test

* Address comments

* Improve cache logic on checkpoint finalized

* Update sim test according to new cache logic

* Update comment

* Lint

* Finalized pubkey cache only update once per checkpoint

* Add perf test for updateUnfinalizedPubkeys

* Add perf test for updateUnfinalizedPubkeys

* Tweak params for perf test

* Freeze besu docker image version for 6110

* Add benchmark result

* Use Map instead of OrderedMap. Update benchmark

* Minor optimization

* Minor optimization

* Add memory test for immutable.js

* Update test

* Reduce code duplication

* Lint

* Remove try/catch in updateUnfinalizedPubkeys

* Introduce EpochCache metric

* Add historicalValidatorLengths

* Polish code

* Migrate state-transition unit tests to vitest

* Fix calculation of pivot index

* `historicalValidatorLengths` only activate post 6110

* Update sim test

* Lint

* Update packages/state-transition/src/cache/epochCache.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Improve readability on historicalValidatorLengths

* Update types

* Fix calculation

* Add eth1data poll todo

* Add epochCache.getValidatorCountAtEpoch

* Add todo

* Add getStateIterator for state cache

* Partial commit

* Update perf test

* updateUnfinalizedPubkeys directly modify states from regen

* Update sim test. Lint

* Add todo

* some improvements and a fix for effectiveBalanceIncrements fork safeness

* rename eip6110 to elctra

* fix electra-interop.test.ts

---------

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>
Co-authored-by: gajinder <develop@g11tech.io>

lint and tsc

small cleanup

fix rebase issue

* feat: implement EIP-6110 (#6042)

* Add immutable in the dependencies

* Initial change to pubkeyCache

* Added todos

* Moved unfinalized cache to epochCache

* Move populating finalized cache to afterProcessEpoch

* Specify unfinalized cache during state cloning

* Move from unfinalized to finalized cache in afterProcessEpoch

* Confused myself

* Clean up

* Change logic

* Fix cloning issue

* Clean up redundant code

* Add CarryoverData in epochCtx.createFromState

* Fix typo

* Update usage of pubkeyCache

* Update pubkeyCache usage

* Fix lint

* Fix lint

* Add 6110 to ChainConfig

* Add 6110 to BeaconPreset

* Define 6110 fork and container

* Add V6110 api to execution engine

* Update test

* Add depositReceiptsRoot to process_execution_payload

* State transitioning to EIP6110

* State transitioning to EIP6110

* Light client change in EIP-6110

* Update tests

* produceBlock

* Refactor processDeposit to match the spec

* Implement processDepositReceipt

* Implement 6110 fork guard for pubkeyCache

* Handle changes in eth1 deposit

* Update eth1 deposit test

* Fix typo

* Lint

* Remove embarassing comments

* Address comments

* Modify applyDeposit signature

* Update packages/state-transition/src/cache/epochCache.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Update packages/state-transition/src/cache/epochCache.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Update packages/state-transition/src/cache/pubkeyCache.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Remove old code

* Rename fields in epochCache and immutableData

* Remove CarryoverData

* Move isAfter6110 from var to method

* Fix cyclic import

* Fix operations spec runner

* Fix for spec test

* Fix spec test

* state.depositReceiptsStartIndex to BigInt

* getDeposit requires cached state

* default depositReceiptsStartIndex value in genesis

* Fix pubkeyCache bug

* newUnfinalizedPubkeyIndexMap in createCachedBeaconState

* Lint

* Pass epochCache instead of pubkey2IndexFn in apis

* Address comments

* Add unit test on pubkey cache cloning

* Add unfinalizedPubkeyCacheSize to metrics

* Add unfinalizedPubkeyCacheSize to metrics

* Clean up code

* Add besu to el-interop

* Add 6110 genesis file

* Template for sim test

* Add unit test for getEth1DepositCount

* Update sim test

* Update besudocker

* Finish beacon api calls in sim test

* Update epochCache.createFromState()

* Fix bug unfinalized validators are not finalized

* Add sim test to run a few blocks

* Lint

* Merge branch 'unstable' into 611

* Add more check to sim test

* Update besu docker image instruction

* Update sim test with correct tx

* Address comment + cleanup

* Clean up code

* Properly handle promise rejection

* Lint

* Update packages/beacon-node/src/execution/engine/types.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Update comments

* Accept type undefined in ExecutionPayloadBodyRpc

* Update comment and semantic

* Remove if statement when adding finalized validator

* Comment on repeated insert on finalized cache

* rename createFromState

* Add comment on getPubkey()

* Stash change to reduce diffs

* Stash change to reduce diffs

* Lint

* addFinalizedPubkey on finalized checkpoint

* Update comment

* Use OrderedMap for unfinalized cache

* Pull out logic of deleting pubkeys for batch op

* Add updateUnfinalizedPubkeys in regen

* Update updateUnfinalizedPubkeys logic

* Add comment

* Add metrics for state context caches

* Address comment

* Address comment

* Deprecate eth1Data polling when condition is reached

* Fix conflicts

* Fix sim test

* Lint

* Fix type

* Fix test

* Fix test

* Lint

* Update packages/light-client/src/spec/utils.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Fix spec test

* Address comments

* Improve cache logic on checkpoint finalized

* Update sim test according to new cache logic

* Update comment

* Lint

* Finalized pubkey cache only update once per checkpoint

* Add perf test for updateUnfinalizedPubkeys

* Add perf test for updateUnfinalizedPubkeys

* Tweak params for perf test

* Freeze besu docker image version for 6110

* Add benchmark result

* Use Map instead of OrderedMap. Update benchmark

* Minor optimization

* Minor optimization

* Add memory test for immutable.js

* Update test

* Reduce code duplication

* Lint

* Remove try/catch in updateUnfinalizedPubkeys

* Introduce EpochCache metric

* Add historicalValidatorLengths

* Polish code

* Migrate state-transition unit tests to vitest

* Fix calculation of pivot index

* `historicalValidatorLengths` only activate post 6110

* Update sim test

* Lint

* Update packages/state-transition/src/cache/epochCache.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Improve readability on historicalValidatorLengths

* Update types

* Fix calculation

* Add eth1data poll todo

* Add epochCache.getValidatorCountAtEpoch

* Add todo

* Add getStateIterator for state cache

* Partial commit

* Update perf test

* updateUnfinalizedPubkeys directly modify states from regen

* Update sim test. Lint

* Add todo

* some improvements and a fix for effectiveBalanceIncrements fork safeness

* rename eip6110 to elctra

* fix electra-interop.test.ts

---------

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>
Co-authored-by: gajinder <develop@g11tech.io>

lint and tsc

small cleanup

* Add presets

* Update config

* Add necessary containers

* Update presets

* Update config

* Add todo comments

* Update constants and params

* Impl new process withdrawal

* Add withdrawaRequests to payload

* Add processConsolidation

* Add process withdraw request

* Update deposit and withdrawal flow

* epoch processing

* Implement churn limits

* Lint

* lint

* Update state-transition utils

* processExecutionLayerWithdrawRequest

* processConsolidation

* queueExcessActiveBalance

* isValidDepositSignature

* Add jsdoc and timer for new processEpoch functions

* Lint

* Update maxEB

* update voluntary exit

* Fix config

* Update initiateValidatorExit

* Remove churn limit in processRegistryUpdates

* Fix conflict

* Add MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD

* Reflect latest spec changes

* rebase fixes, fixes, improvements and cleanup

lint

* Upgrade ssz version

* Use sliceFrom()

* cleanup as per specs feedback

subarry

* simplify

* fix withdrawals

* remove slice

* fix the slashing quotient determination in slashvalidator

---------

Co-authored-by: harkamal <gajinder@g11.in>
  • Loading branch information
ensi321 and g11tech committed Aug 27, 2024
1 parent 8db4ada commit 244dc88
Show file tree
Hide file tree
Showing 43 changed files with 1,056 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,9 @@ function preparePayloadAttributes(
};

if (ForkSeq[fork] >= ForkSeq.capella) {
// withdrawals logic is now fork aware as it changes on electra fork post capella
(payloadAttributes as capella.SSEPayloadAttributes["payloadAttributes"]).withdrawals = getExpectedWithdrawals(
ForkSeq[fork],
prepareState as CachedBeaconStateCapella
).withdrawals;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/test/sim/electra-interop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ describe("executionEngine / ExecutionEngineHttp", function () {
blockHash: dataToBytes(newPayloadBlockHash, 32),
receiptsRoot: dataToBytes("0x79ee3424eb720a3ad4b1c5a372bb8160580cbe4d893778660f34213c685627a9", 32),
blobGasUsed: 0n,
exits: [],
withdrawalRequests: [],
};
const parentBeaconBlockRoot = dataToBytes("0x0000000000000000000000000000000000000000000000000000000000000000", 32);
const payloadResult = await executionEngine.notifyNewPayload(
Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-node/test/spec/presets/operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import * as blockFns from "@lodestar/state-transition/block";
import {ssz, phase0, altair, bellatrix, capella, electra, sszTypesFor} from "@lodestar/types";
import {InputType} from "@lodestar/spec-test-util";
import {ACTIVE_PRESET, ForkName} from "@lodestar/params";
import {ACTIVE_PRESET, ForkName, ForkSeq} from "@lodestar/params";

import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js";
import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js";
Expand Down Expand Up @@ -88,7 +88,7 @@ const operationFns: Record<string, BlockProcessFn<CachedBeaconStateAllForks>> =
},

withdrawals: (state, testCase: {execution_payload: capella.ExecutionPayload}) => {
blockFns.processWithdrawals(state as CachedBeaconStateCapella, testCase.execution_payload);
blockFns.processWithdrawals(ForkSeq.capella, state as CachedBeaconStateCapella, testCase.execution_payload);
},
};

Expand Down
8 changes: 4 additions & 4 deletions packages/beacon-node/test/unit/executionEngine/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ describe("ExecutionEngine / http", () => {
},
],
depositReceipts: null, // depositReceipts is null pre-electra
exits: null,
withdrawalRequests: null,
},
null, // null returned for missing blocks
{
Expand All @@ -204,7 +204,7 @@ describe("ExecutionEngine / http", () => {
],
withdrawals: null, // withdrawals is null pre-capella
depositReceipts: null, // depositReceipts is null pre-electra
exits: null,
withdrawalRequests: null,
},
],
};
Expand Down Expand Up @@ -253,7 +253,7 @@ describe("ExecutionEngine / http", () => {
},
],
depositReceipts: null, // depositReceipts is null pre-electra
exits: null,
withdrawalRequests: null,
},
null, // null returned for missing blocks
{
Expand All @@ -263,7 +263,7 @@ describe("ExecutionEngine / http", () => {
],
withdrawals: null, // withdrawals is null pre-capella
depositReceipts: null, // depositReceipts is null pre-electra
exits: null,
withdrawalRequests: null,
},
],
};
Expand Down
6 changes: 6 additions & 0 deletions packages/config/src/chainConfig/configs/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,10 @@ export const chainConfig: ChainConfig = {
// Deneb
// `2**12` (= 4096 epochs, ~18 days)
MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: 4096,

// Electra
// 2**8 * 10**9 (= 256,000,000,000)
MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT: 256000000000,
// 2*7 * 10**9 (= 128,000,000,000)
MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA: 128000000000,
};
6 changes: 6 additions & 0 deletions packages/config/src/chainConfig/configs/minimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,10 @@ export const chainConfig: ChainConfig = {
// Deneb
// `2**12` (= 4096 epochs, ~18 days)
MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: 4096,

// Electra
// 2**7 * 10**9 (= 128,000,000,000)
MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT: 128000000000,
// 2**6 * 10**9 (= 64,000,000,000)
MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA: 64000000000,
};
4 changes: 4 additions & 0 deletions packages/config/src/chainConfig/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export type ChainConfig = {
MIN_PER_EPOCH_CHURN_LIMIT: number;
MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: number;
CHURN_LIMIT_QUOTIENT: number;
MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT: number;
MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA: number;

// Fork choice
PROPOSER_SCORE_BOOST: number;
Expand Down Expand Up @@ -120,6 +122,8 @@ export const chainConfigTypes: SpecTypes<ChainConfig> = {
MIN_PER_EPOCH_CHURN_LIMIT: "number",
MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: "number",
CHURN_LIMIT_QUOTIENT: "number",
MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT: "number",
MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA: "number",

// Fork choice
PROPOSER_SCORE_BOOST: "number",
Expand Down
14 changes: 13 additions & 1 deletion packages/params/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,20 @@ export const {
MAX_BLOBS_PER_BLOCK,
KZG_COMMITMENT_INCLUSION_PROOF_DEPTH,

MAX_EFFECTIVE_BALANCE_ELECTRA,
MIN_ACTIVATION_BALANCE,
PENDING_BALANCE_DEPOSITS_LIMIT,
PENDING_PARTIAL_WITHDRAWALS_LIMIT,
PENDING_CONSOLIDATIONS_LIMIT,
MIN_SLASHING_PENALTY_QUOTIENT_ELECTRA,
MAX_CONSOLIDATIONS,

MAX_DEPOSIT_RECEIPTS_PER_PAYLOAD,
MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD,
MAX_ATTESTER_SLASHINGS_ELECTRA,
MAX_ATTESTATIONS_ELECTRA,
MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP,
WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA,
} = activePreset;

////////////
Expand All @@ -119,6 +129,7 @@ export const JUSTIFICATION_BITS_LENGTH = 4;
// Since the prefixes are just 1 byte, we define and use them as number
export const BLS_WITHDRAWAL_PREFIX = 0;
export const ETH1_ADDRESS_WITHDRAWAL_PREFIX = 1;
export const COMPOUNDING_WITHDRAWAL_PREFIX = 2;

// Domain types

Expand All @@ -133,7 +144,7 @@ export const DOMAIN_SYNC_COMMITTEE = Uint8Array.from([7, 0, 0, 0]);
export const DOMAIN_SYNC_COMMITTEE_SELECTION_PROOF = Uint8Array.from([8, 0, 0, 0]);
export const DOMAIN_CONTRIBUTION_AND_PROOF = Uint8Array.from([9, 0, 0, 0]);
export const DOMAIN_BLS_TO_EXECUTION_CHANGE = Uint8Array.from([10, 0, 0, 0]);
export const DOMAIN_BLOB_SIDECAR = Uint8Array.from([11, 0, 0, 0]);
export const DOMAIN_CONSOLIDATION = Uint8Array.from([11, 0, 0, 0]);

// Application specific domains

Expand Down Expand Up @@ -252,3 +263,4 @@ export const BLOBSIDECAR_FIXED_SIZE = ACTIVE_PRESET === PresetName.minimal ? 131

// Electra Misc
export const UNSET_DEPOSIT_RECEIPTS_START_INDEX = 2n ** 64n - 1n;
export const FULL_EXIT_REQUEST_AMOUNT = 0;
11 changes: 11 additions & 0 deletions packages/params/src/presets/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,15 @@ export const mainnetPreset: BeaconPreset = {
MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD: 16,
MAX_ATTESTER_SLASHINGS_ELECTRA: 1,
MAX_ATTESTATIONS_ELECTRA: 8,
MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP: 8,
// 2**11 * 10**9 (= 2,048,000,000,000) Gwei
MAX_EFFECTIVE_BALANCE_ELECTRA: 2048000000000,
// 2**16 (= 65536)
MIN_SLASHING_PENALTY_QUOTIENT_ELECTRA: 4096,
MIN_ACTIVATION_BALANCE: 32000000000,
PENDING_BALANCE_DEPOSITS_LIMIT: 134217728,
PENDING_PARTIAL_WITHDRAWALS_LIMIT: 134217728,
PENDING_CONSOLIDATIONS_LIMIT: 262144,
MAX_CONSOLIDATIONS: 1,
WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA: 4096,
};
13 changes: 12 additions & 1 deletion packages/params/src/presets/minimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,18 @@ export const minimalPreset: BeaconPreset = {

// ELECTRA
MAX_DEPOSIT_RECEIPTS_PER_PAYLOAD: 4,
MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD: 16,
MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD: 2,
MAX_ATTESTER_SLASHINGS_ELECTRA: 1,
MAX_ATTESTATIONS_ELECTRA: 8,
MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP: 1,
// 2**11 * 10**9 (= 2,048,000,000,000) Gwei
MAX_EFFECTIVE_BALANCE_ELECTRA: 2048000000000,
// 2**16 (= 65536)
MIN_SLASHING_PENALTY_QUOTIENT_ELECTRA: 4096,
MIN_ACTIVATION_BALANCE: 32000000000,
PENDING_BALANCE_DEPOSITS_LIMIT: 134217728,
PENDING_PARTIAL_WITHDRAWALS_LIMIT: 64,
PENDING_CONSOLIDATIONS_LIMIT: 64,
MAX_CONSOLIDATIONS: 1,
WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA: 4096,
};
18 changes: 18 additions & 0 deletions packages/params/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ export type BeaconPreset = {
MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD: number;
MAX_ATTESTER_SLASHINGS_ELECTRA: number;
MAX_ATTESTATIONS_ELECTRA: number;
MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP: number;
MAX_EFFECTIVE_BALANCE_ELECTRA: number;
MIN_SLASHING_PENALTY_QUOTIENT_ELECTRA: number;
MIN_ACTIVATION_BALANCE: number;
PENDING_BALANCE_DEPOSITS_LIMIT: number;
PENDING_PARTIAL_WITHDRAWALS_LIMIT: number;
PENDING_CONSOLIDATIONS_LIMIT: number;
MAX_CONSOLIDATIONS: number;
WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA: number;
};

/**
Expand Down Expand Up @@ -179,6 +188,15 @@ export const beaconPresetTypes: BeaconPresetTypes = {
MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD: "number",
MAX_ATTESTER_SLASHINGS_ELECTRA: "number",
MAX_ATTESTATIONS_ELECTRA: "number",
MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP: "number",
MAX_EFFECTIVE_BALANCE_ELECTRA: "number",
MIN_SLASHING_PENALTY_QUOTIENT_ELECTRA: "number",
MIN_ACTIVATION_BALANCE: "number",
PENDING_BALANCE_DEPOSITS_LIMIT: "number",
PENDING_PARTIAL_WITHDRAWALS_LIMIT: "number",
PENDING_CONSOLIDATIONS_LIMIT: "number",
MAX_CONSOLIDATIONS: "number",
WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA: "number",
};

type BeaconPresetTypes = {
Expand Down
2 changes: 2 additions & 0 deletions packages/state-transition/src/block/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ export function processBlock(
// https://github.com/ethereum/consensus-specs/blob/b62c9e877990242d63aa17a2a59a49bc649a2f2e/specs/eip4844/beacon-chain.md#disabling-withdrawals
if (fork >= ForkSeq.capella) {
processWithdrawals(
fork,
state as CachedBeaconStateCapella,
fullOrBlindedPayload as capella.FullOrBlindedExecutionPayload
);
}

processExecutionPayload(fork, state as CachedBeaconStateBellatrix, block.body, externalData);
}

Expand Down
39 changes: 25 additions & 14 deletions packages/state-transition/src/block/initiateValidatorExit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {CompositeViewDU} from "@chainsafe/ssz";
import {FAR_FUTURE_EPOCH} from "@lodestar/params";
import {FAR_FUTURE_EPOCH, ForkSeq} from "@lodestar/params";
import {ssz} from "@lodestar/types";
import {CachedBeaconStateAllForks} from "../types.js";
import {CachedBeaconStateAllForks, CachedBeaconStateElectra} from "../types.js";
import {computeExitEpochAndUpdateChurn} from "../util/epoch.js";

/**
* Initiate the exit of the validator with index ``index``.
Expand All @@ -24,6 +25,7 @@ import {CachedBeaconStateAllForks} from "../types.js";
* Forcing consumers to pass the SubTree of `validator` directly mitigates this issue.
*/
export function initiateValidatorExit(
fork: ForkSeq,
state: CachedBeaconStateAllForks,
validator: CompositeViewDU<typeof ssz.phase0.Validator>
): void {
Expand All @@ -34,18 +36,27 @@ export function initiateValidatorExit(
return;
}

// Limits the number of validators that can exit on each epoch.
// Expects all state.validators to follow this rule, i.e. no validator.exitEpoch is greater than exitQueueEpoch.
// If there the churnLimit is reached at this current exitQueueEpoch, advance epoch and reset churn.
if (epochCtx.exitQueueChurn >= epochCtx.churnLimit) {
epochCtx.exitQueueEpoch += 1;
epochCtx.exitQueueChurn = 1; // = 1 to account for this validator with exitQueueEpoch
if (fork < ForkSeq.electra) {
// Limits the number of validators that can exit on each epoch.
// Expects all state.validators to follow this rule, i.e. no validator.exitEpoch is greater than exitQueueEpoch.
// If there the churnLimit is reached at this current exitQueueEpoch, advance epoch and reset churn.
if (epochCtx.exitQueueChurn >= epochCtx.churnLimit) {
epochCtx.exitQueueEpoch += 1;
epochCtx.exitQueueChurn = 1; // = 1 to account for this validator with exitQueueEpoch
} else {
// Add this validator to the current exitQueueEpoch churn
epochCtx.exitQueueChurn += 1;
}

// set validator exit epoch
validator.exitEpoch = epochCtx.exitQueueEpoch;
} else {
// Add this validator to the current exitQueueEpoch churn
epochCtx.exitQueueChurn += 1;
// set validator exit epoch
// Note we don't use epochCtx.exitQueueChurn and exitQueueEpoch anymore
validator.exitEpoch = computeExitEpochAndUpdateChurn(
state as CachedBeaconStateElectra,
BigInt(validator.effectiveBalance)
);
}

// set validator exit epoch and withdrawable epoch
validator.exitEpoch = epochCtx.exitQueueEpoch;
validator.withdrawableEpoch = epochCtx.exitQueueEpoch + config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY;
validator.withdrawableEpoch = validator.exitEpoch + config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY;
}
Loading

0 comments on commit 244dc88

Please sign in to comment.