@lodestar/state-transition 1.52.0-dev.269cf1aa5b → 1.52.0-dev.31011e1c39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/block/index.d.ts.map +1 -1
- package/lib/block/index.js +1 -1
- package/lib/block/index.js.map +1 -1
- package/lib/block/processExecutionPayloadBid.d.ts +1 -1
- package/lib/block/processExecutionPayloadBid.d.ts.map +1 -1
- package/lib/block/processExecutionPayloadBid.js +2 -2
- package/lib/block/processExecutionPayloadBid.js.map +1 -1
- package/lib/rewards/blockRewards.d.ts.map +1 -1
- package/lib/rewards/blockRewards.js +7 -1
- package/lib/rewards/blockRewards.js.map +1 -1
- package/lib/signatureSets/index.d.ts.map +1 -1
- package/lib/signatureSets/index.js +13 -4
- package/lib/signatureSets/index.js.map +1 -1
- package/lib/slot/upgradeStateToGloas.d.ts.map +1 -1
- package/lib/slot/upgradeStateToGloas.js +22 -27
- package/lib/slot/upgradeStateToGloas.js.map +1 -1
- package/lib/slot/upgradeStateToHeze.d.ts.map +1 -1
- package/lib/slot/upgradeStateToHeze.js +0 -4
- package/lib/slot/upgradeStateToHeze.js.map +1 -1
- package/lib/stateView/beaconStateView.d.ts +1 -0
- package/lib/stateView/beaconStateView.d.ts.map +1 -1
- package/lib/stateView/beaconStateView.js +9 -1
- package/lib/stateView/beaconStateView.js.map +1 -1
- package/lib/stateView/interface.d.ts +1 -0
- package/lib/stateView/interface.d.ts.map +1 -1
- package/lib/stateView/interface.js.map +1 -1
- package/lib/stateView/nativeBeaconStateView.d.ts +1 -0
- package/lib/stateView/nativeBeaconStateView.d.ts.map +1 -1
- package/lib/stateView/nativeBeaconStateView.js +3 -0
- package/lib/stateView/nativeBeaconStateView.js.map +1 -1
- package/lib/util/gloas.d.ts +5 -0
- package/lib/util/gloas.d.ts.map +1 -1
- package/lib/util/gloas.js +10 -0
- package/lib/util/gloas.js.map +1 -1
- package/lib/util/slot.d.ts.map +1 -1
- package/lib/util/slot.js +3 -7
- package/lib/util/slot.js.map +1 -1
- package/package.json +9 -9
- package/src/block/index.ts +2 -1
- package/src/block/processExecutionPayloadBid.ts +3 -2
- package/src/rewards/blockRewards.ts +8 -2
- package/src/signatureSets/index.ts +26 -4
- package/src/slot/upgradeStateToGloas.ts +23 -31
- package/src/slot/upgradeStateToHeze.ts +0 -6
- package/src/stateView/beaconStateView.ts +11 -1
- package/src/stateView/interface.ts +1 -0
- package/src/stateView/nativeBeaconStateView.ts +4 -0
- package/src/util/gloas.ts +11 -0
- package/src/util/slot.ts +3 -7
|
@@ -115,6 +115,8 @@ export function upgradeStateToGloas(
|
|
|
115
115
|
for (let i = 0; i < SLOTS_PER_HISTORICAL_ROOT; i++) {
|
|
116
116
|
stateGloasView.executionPayloadAvailability.set(i, true);
|
|
117
117
|
}
|
|
118
|
+
// process_slot of the last pre-fork slot ran with Fulu rules and did not unset the fork slot
|
|
119
|
+
stateGloasView.executionPayloadAvailability.set(stateFulu.slot % SLOTS_PER_HISTORICAL_ROOT, false);
|
|
118
120
|
stateGloasView.latestBlockHash = stateFulu.latestExecutionPayloadHeader.blockHash;
|
|
119
121
|
|
|
120
122
|
const stateGloas = getCachedBeaconState(stateGloasView, stateFulu);
|
|
@@ -176,7 +178,7 @@ function migrateBasicListToGloas<ElementType extends BasicType<unknown>>(
|
|
|
176
178
|
|
|
177
179
|
/**
|
|
178
180
|
* Applies any pending deposits for builders to onboard builders during the fork transition
|
|
179
|
-
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-
|
|
181
|
+
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-beta.5/specs/gloas/fork.md#new-onboard_builders_from_pending_deposits
|
|
180
182
|
*/
|
|
181
183
|
function onboardBuildersFromPendingDeposits(
|
|
182
184
|
state: CachedBeaconStateGloas,
|
|
@@ -188,8 +190,8 @@ function onboardBuildersFromPendingDeposits(
|
|
|
188
190
|
// deposit queue, and its cost is dominated by whichever branch the queue happens to
|
|
189
191
|
// hit. `verified` signature checks are the ones the pre-verify cache missed, i.e. BLS
|
|
190
192
|
// running inline on the fork transition's critical path. The signature totals include
|
|
191
|
-
// the checks hasPendingValidator() does internally
|
|
192
|
-
//
|
|
193
|
+
// the checks hasPendingValidator() does internally for invalid builder deposits that are
|
|
194
|
+
// preceded by same-pubkey validator deposits.
|
|
193
195
|
let onboarded = 0;
|
|
194
196
|
let topups = 0;
|
|
195
197
|
let kept = 0;
|
|
@@ -207,12 +209,11 @@ function onboardBuildersFromPendingDeposits(
|
|
|
207
209
|
|
|
208
210
|
for (const deposit of state.pendingDeposits.getAllReadonly()) {
|
|
209
211
|
const depositValue = deposit.toValue();
|
|
210
|
-
|
|
211
|
-
const validatorIndex = state.epochCtx.getValidatorIndex(deposit.pubkey);
|
|
212
212
|
const pubkeyHex = toPubkeyHex(deposit.pubkey);
|
|
213
213
|
|
|
214
|
-
//
|
|
215
|
-
if
|
|
214
|
+
// Only builder-credential deposits can fund builders at the fork, everything else stays in
|
|
215
|
+
// the pending queue even if a builder uses the same pubkey
|
|
216
|
+
if (!isBuilderWithdrawalCredential(deposit.withdrawalCredentials)) {
|
|
216
217
|
pendingDeposits.push(deposit);
|
|
217
218
|
pendingDepositsLookup.add(depositValue, pubkeyHex);
|
|
218
219
|
kept++;
|
|
@@ -227,29 +228,9 @@ function onboardBuildersFromPendingDeposits(
|
|
|
227
228
|
continue;
|
|
228
229
|
}
|
|
229
230
|
|
|
230
|
-
//
|
|
231
|
-
//
|
|
232
|
-
//
|
|
233
|
-
if (!isBuilderWithdrawalCredential(deposit.withdrawalCredentials)) {
|
|
234
|
-
pendingDeposits.push(deposit);
|
|
235
|
-
pendingDepositsLookup.add(depositValue, pubkeyHex);
|
|
236
|
-
kept++;
|
|
237
|
-
continue;
|
|
238
|
-
}
|
|
239
|
-
if (
|
|
240
|
-
pendingDepositsLookup.hasPendingValidator(state.config, pubkeyHex, state.epochCtx.builderDepositSignatureCache)
|
|
241
|
-
) {
|
|
242
|
-
pendingDeposits.push(deposit);
|
|
243
|
-
pendingDepositsLookup.add(depositValue, pubkeyHex);
|
|
244
|
-
kept++;
|
|
245
|
-
continue;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// Verify the deposit signature (proof of possession). If invalid the deposit is silently
|
|
249
|
-
// dropped — stake is forfeited, matching the validator deposit contract behavior.
|
|
250
|
-
//
|
|
251
|
-
// The prepareNextSlot scheduler pre-verifies these signatures in the epochs before the fork
|
|
252
|
-
// A cache miss falls back to verifying this one deposit — no worse than pre-cache.
|
|
231
|
+
// Verify the deposit signature (proof of possession). The prepareNextSlot scheduler
|
|
232
|
+
// pre-verifies these signatures in the epochs before the fork, a cache miss falls back to
|
|
233
|
+
// verifying this one deposit
|
|
253
234
|
const cached = state.epochCtx.builderDepositSignatureCache.getSignatureValidity(depositValue);
|
|
254
235
|
if (cached === null) {
|
|
255
236
|
sigVerified++;
|
|
@@ -266,7 +247,18 @@ function onboardBuildersFromPendingDeposits(
|
|
|
266
247
|
deposit.signature
|
|
267
248
|
);
|
|
268
249
|
if (!isValid) {
|
|
269
|
-
|
|
250
|
+
// Keep the deposit as a validator top-up if a validator with this pubkey exists or a valid
|
|
251
|
+
// pending deposit will create one, otherwise it is dropped and the stake is forfeited
|
|
252
|
+
if (
|
|
253
|
+
isValidatorKnown(state, state.epochCtx.getValidatorIndex(deposit.pubkey)) ||
|
|
254
|
+
pendingDepositsLookup.hasPendingValidator(state.config, pubkeyHex, state.epochCtx.builderDepositSignatureCache)
|
|
255
|
+
) {
|
|
256
|
+
pendingDeposits.push(deposit);
|
|
257
|
+
pendingDepositsLookup.add(depositValue, pubkeyHex);
|
|
258
|
+
kept++;
|
|
259
|
+
} else {
|
|
260
|
+
dropped++;
|
|
261
|
+
}
|
|
270
262
|
continue;
|
|
271
263
|
}
|
|
272
264
|
|
|
@@ -7,12 +7,6 @@ import {CachedBeaconStateGloas, CachedBeaconStateHeze} from "../types.js";
|
|
|
7
7
|
* Spec: heze/fork.md `upgrade_to_heze`.
|
|
8
8
|
*/
|
|
9
9
|
export function upgradeStateToHeze(stateGloas: CachedBeaconStateGloas): CachedBeaconStateHeze {
|
|
10
|
-
// In Heze, the old deposit mechanism must be fully drained before the fork
|
|
11
|
-
if (BigInt(stateGloas.eth1DepositIndex) !== stateGloas.depositRequestsStartIndex) {
|
|
12
|
-
throw new Error(
|
|
13
|
-
`Cannot upgrade to Heze: legacy deposit mechanism still active eth1DepositIndex=${stateGloas.eth1DepositIndex} depositRequestsStartIndex=${stateGloas.depositRequestsStartIndex}`
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
10
|
const {config} = stateGloas;
|
|
17
11
|
|
|
18
12
|
ssz.gloas.BeaconState.commitViewDU(stateGloas);
|
|
@@ -63,7 +63,7 @@ import {
|
|
|
63
63
|
isGloasStateType,
|
|
64
64
|
isMergeTransitionComplete,
|
|
65
65
|
} from "../util/execution.js";
|
|
66
|
-
import {canBuilderCoverBid} from "../util/gloas.js";
|
|
66
|
+
import {canBuilderCoverBid, getBuilderBidLimit} from "../util/gloas.js";
|
|
67
67
|
import {loadState} from "../util/loadState/loadState.js";
|
|
68
68
|
import {PreVerifyBuilderDepositsResult, preVerifyBuilderDepositsPreGloas} from "../util/preVerifyBuilderDeposits.js";
|
|
69
69
|
import {getRandaoMix} from "../util/seed.js";
|
|
@@ -469,6 +469,14 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
469
469
|
return canBuilderCoverBid(this.cachedState as CachedBeaconStateGloas, builderIndex, bidAmount);
|
|
470
470
|
}
|
|
471
471
|
|
|
472
|
+
getBuilderBidLimit(builderIndex: BuilderIndex): number {
|
|
473
|
+
if (this.config.getForkSeq(this.cachedState.slot) < ForkSeq.gloas) {
|
|
474
|
+
throw new Error("Builders are not supported before Gloas");
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
return getBuilderBidLimit(this.cachedState as CachedBeaconStateGloas, builderIndex);
|
|
478
|
+
}
|
|
479
|
+
|
|
472
480
|
/**
|
|
473
481
|
* Return the PTCs for an epoch
|
|
474
482
|
*/
|
|
@@ -914,6 +922,8 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
914
922
|
const stateCopy = this.cachedState.clone(true) as CachedBeaconStateGloas;
|
|
915
923
|
|
|
916
924
|
applyParentExecutionPayload(stateCopy, executionRequests);
|
|
925
|
+
// Getters such as executionPayloadAvailability read committed nodes
|
|
926
|
+
stateCopy.commit();
|
|
917
927
|
|
|
918
928
|
const stateView = new BeaconStateView(stateCopy);
|
|
919
929
|
if (!isStatePostGloas(stateView)) {
|
|
@@ -293,6 +293,7 @@ export interface IBeaconStateViewGloas extends IBeaconStateViewFulu {
|
|
|
293
293
|
getBuilder(index: BuilderIndex): gloas.Builder;
|
|
294
294
|
getBuildersLength(): number;
|
|
295
295
|
canBuilderCoverBid(builderIndex: BuilderIndex, bidAmount: number): boolean;
|
|
296
|
+
getBuilderBidLimit(builderIndex: BuilderIndex): number;
|
|
296
297
|
getEpochPTCs(epoch: Epoch): Uint32Array[];
|
|
297
298
|
getPayloadTimelinessCommittee(slot: Slot): Uint32Array;
|
|
298
299
|
getIndicesInPayloadTimelinessCommittee(validatorIndex: ValidatorIndex, slot: Slot): number[];
|
|
@@ -958,6 +958,10 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
958
958
|
return this.binding.canBuilderCoverBid(builderIndex, bidAmount);
|
|
959
959
|
}
|
|
960
960
|
|
|
961
|
+
getBuilderBidLimit(builderIndex: BuilderIndex): number {
|
|
962
|
+
return this.binding.getBuilderBidLimit(builderIndex);
|
|
963
|
+
}
|
|
964
|
+
|
|
961
965
|
getEpochPTCs(epoch: Epoch): Uint32Array[] {
|
|
962
966
|
return this.binding.getEpochPTCs(epoch);
|
|
963
967
|
}
|
package/src/util/gloas.ts
CHANGED
|
@@ -25,6 +25,7 @@ import {computePayloadTimelinessCommitteesForEpoch} from "./seed.js";
|
|
|
25
25
|
import {createSingleSignatureSetFromComponents, verifySignatureSet} from "./signatureSets.js";
|
|
26
26
|
import {computeSigningRoot} from "./signingRoot.js";
|
|
27
27
|
import {getActiveValidatorIndices} from "./validator.js";
|
|
28
|
+
import {ETH_TO_GWEI} from "./weakSubjectivity.js";
|
|
28
29
|
|
|
29
30
|
export function isBuilderWithdrawalCredential(withdrawalCredentials: Uint8Array): boolean {
|
|
30
31
|
return withdrawalCredentials[0] === BUILDER_WITHDRAWAL_PREFIX;
|
|
@@ -161,6 +162,16 @@ export function canBuilderCoverBid(
|
|
|
161
162
|
return builder.balance - minBalance >= bidAmount;
|
|
162
163
|
}
|
|
163
164
|
|
|
165
|
+
/**
|
|
166
|
+
* Return the number of bids the builder may submit for each slot and parent.
|
|
167
|
+
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-beta.5/specs/gloas/p2p-interface.md#new-get_builder_bid_limit
|
|
168
|
+
*/
|
|
169
|
+
export function getBuilderBidLimit(state: CachedBeaconStateGloas, builderIndex: BuilderIndex): number {
|
|
170
|
+
const builder = state.builders.getReadonly(builderIndex);
|
|
171
|
+
const pendingBalance = getPendingBalanceToWithdrawForBuilder(state, builderIndex);
|
|
172
|
+
return Math.floor(Math.max(builder.balance - pendingBalance, 0) / ETH_TO_GWEI);
|
|
173
|
+
}
|
|
174
|
+
|
|
164
175
|
/**
|
|
165
176
|
* Initiate a builder exit by setting their withdrawable epoch.
|
|
166
177
|
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#new-initiate_builder_exit
|
package/src/util/slot.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {ChainConfig, ChainForkConfig} from "@lodestar/config";
|
|
2
|
-
import {GENESIS_EPOCH, GENESIS_SLOT} from "@lodestar/params";
|
|
2
|
+
import {GENESIS_EPOCH, GENESIS_SLOT, SLOTS_PER_EPOCH} from "@lodestar/params";
|
|
3
3
|
import {Epoch, Slot, TimeSeconds} from "@lodestar/types";
|
|
4
4
|
import {computeEpochAtSlot, computeStartSlotAtEpoch} from "./epoch.js";
|
|
5
5
|
|
|
@@ -8,11 +8,7 @@ import {computeEpochAtSlot, computeStartSlotAtEpoch} from "./epoch.js";
|
|
|
8
8
|
* A fork that changes the slot duration must add an entry here and in `ForkConfig.getSlotDurationMs`.
|
|
9
9
|
*/
|
|
10
10
|
export function getSlotDurations(config: ChainConfig): [Epoch, number][] {
|
|
11
|
-
|
|
12
|
-
if (config.HEZE_FORK_EPOCH !== Infinity) {
|
|
13
|
-
durations.push([config.HEZE_FORK_EPOCH, config.SLOT_DURATION_MS_HEZE]);
|
|
14
|
-
}
|
|
15
|
-
return durations;
|
|
11
|
+
return [[GENESIS_EPOCH, config.SLOT_DURATION_MS]];
|
|
16
12
|
}
|
|
17
13
|
|
|
18
14
|
/** Slot duration in ms in effect at a given epoch */
|
|
@@ -78,7 +74,7 @@ export function getCurrentSlot(config: ChainConfig, genesisTime: TimeSeconds): S
|
|
|
78
74
|
* across slot duration changes
|
|
79
75
|
*/
|
|
80
76
|
export function getBlobDataRetentionStartEpoch(config: ChainConfig, epoch: Epoch): Epoch {
|
|
81
|
-
const windowMs = config.
|
|
77
|
+
const windowMs = config.MIN_EPOCHS_FOR_DATA_COLUMN_SIDECARS_REQUESTS * SLOTS_PER_EPOCH * config.SLOT_DURATION_MS;
|
|
82
78
|
const currentStartMs = computeTimeAtSlotMs(config, computeStartSlotAtEpoch(epoch), 0);
|
|
83
79
|
if (currentStartMs < windowMs) {
|
|
84
80
|
return GENESIS_EPOCH;
|