Skip to content

Commit 9c86957

Browse files
nflaigg11tech
authored andcommitted
chore: review electra branch - part 2 (#7019)
1 parent 4b2f34b commit 9c86957

File tree

8 files changed

+25
-27
lines changed

8 files changed

+25
-27
lines changed

packages/state-transition/src/block/processOperations.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export function processOperations(
7272
}
7373

7474
for (const elWithdrawalRequest of bodyElectra.executionPayload.withdrawalRequests) {
75-
processWithdrawalRequest(fork, state as CachedBeaconStateElectra, elWithdrawalRequest);
75+
processWithdrawalRequest(fork, stateElectra, elWithdrawalRequest);
7676
}
7777

7878
for (const elConsolidationRequest of bodyElectra.executionPayload.consolidationRequests) {

packages/state-transition/src/signatureSets/indexedAttestation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function getAttestationsSignatureSets(
4545
return signedBlock.message.body.attestations.map((attestation) =>
4646
getIndexedAttestationSignatureSet(
4747
state,
48-
state.epochCtx.getIndexedAttestation(state.epochCtx.config.getForkSeq(signedBlock.message.slot), attestation)
48+
state.epochCtx.getIndexedAttestation(state.config.getForkSeq(signedBlock.message.slot), attestation)
4949
)
5050
);
5151
}

packages/state-transition/src/slot/upgradeStateToElectra.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {computeActivationExitEpoch} from "../util/epoch.js";
1111
import {getActivationExitChurnLimit, getConsolidationChurnLimit} from "../util/validator.js";
1212

1313
/**
14-
* Upgrade a state from Capella to Deneb.
14+
* Upgrade a state from Deneb to Electra.
1515
*/
1616
export function upgradeStateToElectra(stateDeneb: CachedBeaconStateDeneb): CachedBeaconStateElectra {
1717
const {config} = stateDeneb;

packages/state-transition/src/stateTransition.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -228,20 +228,20 @@ function processSlotsWithTransientCache(
228228
epochTransitionTimer?.();
229229

230230
// Upgrade state if exactly at epoch boundary
231-
const stateSlot = computeEpochAtSlot(postState.slot);
232-
if (stateSlot === config.ALTAIR_FORK_EPOCH) {
231+
const stateEpoch = computeEpochAtSlot(postState.slot);
232+
if (stateEpoch === config.ALTAIR_FORK_EPOCH) {
233233
postState = upgradeStateToAltair(postState as CachedBeaconStatePhase0) as CachedBeaconStateAllForks;
234234
}
235-
if (stateSlot === config.BELLATRIX_FORK_EPOCH) {
235+
if (stateEpoch === config.BELLATRIX_FORK_EPOCH) {
236236
postState = upgradeStateToBellatrix(postState as CachedBeaconStateAltair) as CachedBeaconStateAllForks;
237237
}
238-
if (stateSlot === config.CAPELLA_FORK_EPOCH) {
238+
if (stateEpoch === config.CAPELLA_FORK_EPOCH) {
239239
postState = upgradeStateToCapella(postState as CachedBeaconStateBellatrix) as CachedBeaconStateAllForks;
240240
}
241-
if (stateSlot === config.DENEB_FORK_EPOCH) {
241+
if (stateEpoch === config.DENEB_FORK_EPOCH) {
242242
postState = upgradeStateToDeneb(postState as CachedBeaconStateCapella) as CachedBeaconStateAllForks;
243243
}
244-
if (stateSlot === config.ELECTRA_FORK_EPOCH) {
244+
if (stateEpoch === config.ELECTRA_FORK_EPOCH) {
245245
postState = upgradeStateToElectra(postState as CachedBeaconStateDeneb) as CachedBeaconStateAllForks;
246246
}
247247
} else {

packages/state-transition/test/unit/util/deposit.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {describe, it, expect} from "vitest";
22
import {ssz} from "@lodestar/types";
33
import {createChainForkConfig} from "@lodestar/config";
44
import {MAX_DEPOSITS} from "@lodestar/params";
5-
import {CachedBeaconStateElectra, getEth1DepositCount} from "../../../src/index.js";
5+
import {getEth1DepositCount} from "../../../src/index.js";
66
import {createCachedBeaconStateTest} from "../../utils/state.js";
77

88
describe("getEth1DepositCount", () => {
@@ -37,7 +37,7 @@ describe("getEth1DepositCount", () => {
3737
ELECTRA_FORK_EPOCH: 0,
3838
}),
3939
{skipSyncCommitteeCache: true, skipSyncPubkeys: true}
40-
) as CachedBeaconStateElectra;
40+
);
4141

4242
if (!postElectraState.epochCtx.isPostElectra()) {
4343
throw Error("Not a post-Electra state");
@@ -71,7 +71,7 @@ describe("getEth1DepositCount", () => {
7171
ELECTRA_FORK_EPOCH: 0,
7272
}),
7373
{skipSyncCommitteeCache: true, skipSyncPubkeys: true}
74-
) as CachedBeaconStateElectra;
74+
);
7575

7676
if (!postElectraState.epochCtx.isPostElectra()) {
7777
throw Error("Not a post-Electra state");

packages/types/src/electra/sszTypes.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export const ExecutionPayload = new ContainerType(
152152
...denebSsz.ExecutionPayload.fields,
153153
depositRequests: DepositRequests, // New in ELECTRA
154154
withdrawalRequests: WithdrawalRequests, // New in ELECTRA
155-
consolidationRequests: ConsolidationRequests, // [New in Electra]
155+
consolidationRequests: ConsolidationRequests, // New in ELECTRA
156156
},
157157
{typeName: "ExecutionPayload", jsonCase: "eth2"}
158158
);
@@ -333,14 +333,14 @@ export const BeaconState = new ContainerType(
333333
// Deep history valid from Capella onwards
334334
historicalSummaries: capellaSsz.BeaconState.fields.historicalSummaries,
335335
depositRequestsStartIndex: UintBn64, // New in ELECTRA:EIP6110
336-
depositBalanceToConsume: Gwei, // New in Electra:EIP7251
337-
exitBalanceToConsume: Gwei, // New in Electra:EIP7251
338-
earliestExitEpoch: Epoch, // New in Electra:EIP7251
339-
consolidationBalanceToConsume: Gwei, // New in Electra:EIP7251
340-
earliestConsolidationEpoch: Epoch, // New in Electra:EIP7251
341-
pendingBalanceDeposits: PendingBalanceDeposits, // New in Electra:EIP7251
342-
pendingPartialWithdrawals: new ListCompositeType(PendingPartialWithdrawal, PENDING_PARTIAL_WITHDRAWALS_LIMIT), // New in Electra:EIP7251
343-
pendingConsolidations: new ListCompositeType(PendingConsolidation, PENDING_CONSOLIDATIONS_LIMIT), // New in Electra:EIP7251
336+
depositBalanceToConsume: Gwei, // New in ELECTRA:EIP7251
337+
exitBalanceToConsume: Gwei, // New in ELECTRA:EIP7251
338+
earliestExitEpoch: Epoch, // New in ELECTRA:EIP7251
339+
consolidationBalanceToConsume: Gwei, // New in ELECTRA:EIP7251
340+
earliestConsolidationEpoch: Epoch, // New in ELECTRA:EIP7251
341+
pendingBalanceDeposits: PendingBalanceDeposits, // New in ELECTRA:EIP7251
342+
pendingPartialWithdrawals: new ListCompositeType(PendingPartialWithdrawal, PENDING_PARTIAL_WITHDRAWALS_LIMIT), // New in ELECTRA:EIP7251
343+
pendingConsolidations: new ListCompositeType(PendingConsolidation, PENDING_CONSOLIDATIONS_LIMIT), // New in ELECTRA:EIP7251
344344
},
345345
{typeName: "BeaconState", jsonCase: "eth2"}
346346
);

packages/validator/src/services/attestation.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {toHexString} from "@chainsafe/ssz";
22
import {BLSSignature, phase0, Slot, ssz, Attestation, SignedAggregateAndProof} from "@lodestar/types";
3+
import {ForkSeq} from "@lodestar/params";
34
import {computeEpochAtSlot, isAggregatorFromCommitteeLength} from "@lodestar/state-transition";
45
import {sleep} from "@lodestar/utils";
56
import {ApiClient, routes} from "@lodestar/api";
@@ -159,7 +160,7 @@ export class AttestationService {
159160
this.metrics?.attesterStepCallProduceAggregate.observe(this.clock.secFromSlot(slot + 2 / 3));
160161

161162
const dutiesByCommitteeIndex = groupAttDutiesByCommitteeIndex(dutiesAll);
162-
const isPostElectra = computeEpochAtSlot(slot) >= this.config.ELECTRA_FORK_EPOCH;
163+
const isPostElectra = this.config.getForkSeq(slot) >= ForkSeq.electra;
163164

164165
// Then download, sign and publish a `SignedAggregateAndProof` for each
165166
// validator that is elected to aggregate for this `slot` and `committeeIndex`.

packages/validator/src/services/validatorStore.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,8 @@ export class ValidatorStore {
534534
return {
535535
aggregationBits: BitArray.fromSingleBit(duty.committeeLength, duty.validatorCommitteeIndex),
536536
data: attestationData,
537-
committeeBits: BitArray.fromSingleBit(MAX_COMMITTEES_PER_SLOT, duty.committeeIndex),
538537
signature: await this.getSignature(duty.pubkey, signingRoot, signingSlot, signableMessage),
538+
committeeBits: BitArray.fromSingleBit(MAX_COMMITTEES_PER_SLOT, duty.committeeIndex),
539539
};
540540
} else {
541541
return {
@@ -801,7 +801,7 @@ export class ValidatorStore {
801801
throw Error(`Inconsistent duties during signing: duty.slot ${duty.slot} != att.slot ${data.slot}`);
802802
}
803803

804-
const isPostElectra = computeEpochAtSlot(duty.slot) >= this.config.ELECTRA_FORK_EPOCH;
804+
const isPostElectra = this.config.getForkSeq(duty.slot) >= ForkSeq.electra;
805805
if (!isPostElectra && duty.committeeIndex != data.index) {
806806
throw Error(
807807
`Inconsistent duties during signing: duty.committeeIndex ${duty.committeeIndex} != att.committeeIndex ${data.index}`
@@ -810,9 +810,6 @@ export class ValidatorStore {
810810
if (isPostElectra && data.index !== 0) {
811811
throw Error(`Non-zero committee index post-electra during signing: att.committeeIndex ${data.index}`);
812812
}
813-
if (this.config.getForkSeq(duty.slot) >= ForkSeq.electra && data.index !== 0) {
814-
throw Error(`Attestataion data index must be 0 post electra: index ${data.index}`);
815-
}
816813
}
817814

818815
private assertDoppelgangerSafe(pubKey: PubkeyHex | BLSPubkey): void {

0 commit comments

Comments
 (0)