Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: review electra branch - part 2 #7019

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/state-transition/src/block/processOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function processOperations(
}

for (const elWithdrawalRequest of bodyElectra.executionPayload.withdrawalRequests) {
processWithdrawalRequest(fork, state as CachedBeaconStateElectra, elWithdrawalRequest);
processWithdrawalRequest(fork, stateElectra, elWithdrawalRequest);
}

for (const elConsolidationRequest of bodyElectra.executionPayload.consolidationRequests) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function getAttestationsSignatureSets(
return signedBlock.message.body.attestations.map((attestation) =>
getIndexedAttestationSignatureSet(
state,
state.epochCtx.getIndexedAttestation(state.epochCtx.config.getForkSeq(signedBlock.message.slot), attestation)
state.epochCtx.getIndexedAttestation(state.config.getForkSeq(signedBlock.message.slot), attestation)
)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {computeActivationExitEpoch} from "../util/epoch.js";
import {getActivationExitChurnLimit, getConsolidationChurnLimit} from "../util/validator.js";

/**
* Upgrade a state from Capella to Deneb.
* Upgrade a state from Deneb to Electra.
*/
export function upgradeStateToElectra(stateDeneb: CachedBeaconStateDeneb): CachedBeaconStateElectra {
const {config} = stateDeneb;
Expand Down
12 changes: 6 additions & 6 deletions packages/state-transition/src/stateTransition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,20 @@ function processSlotsWithTransientCache(
epochTransitionTimer?.();

// Upgrade state if exactly at epoch boundary
const stateSlot = computeEpochAtSlot(postState.slot);
if (stateSlot === config.ALTAIR_FORK_EPOCH) {
const stateEpoch = computeEpochAtSlot(postState.slot);
if (stateEpoch === config.ALTAIR_FORK_EPOCH) {
postState = upgradeStateToAltair(postState as CachedBeaconStatePhase0) as CachedBeaconStateAllForks;
}
if (stateSlot === config.BELLATRIX_FORK_EPOCH) {
if (stateEpoch === config.BELLATRIX_FORK_EPOCH) {
postState = upgradeStateToBellatrix(postState as CachedBeaconStateAltair) as CachedBeaconStateAllForks;
}
if (stateSlot === config.CAPELLA_FORK_EPOCH) {
if (stateEpoch === config.CAPELLA_FORK_EPOCH) {
postState = upgradeStateToCapella(postState as CachedBeaconStateBellatrix) as CachedBeaconStateAllForks;
}
if (stateSlot === config.DENEB_FORK_EPOCH) {
if (stateEpoch === config.DENEB_FORK_EPOCH) {
postState = upgradeStateToDeneb(postState as CachedBeaconStateCapella) as CachedBeaconStateAllForks;
}
if (stateSlot === config.ELECTRA_FORK_EPOCH) {
if (stateEpoch === config.ELECTRA_FORK_EPOCH) {
postState = upgradeStateToElectra(postState as CachedBeaconStateDeneb) as CachedBeaconStateAllForks;
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions packages/state-transition/test/unit/util/deposit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {describe, it, expect} from "vitest";
import {ssz} from "@lodestar/types";
import {createChainForkConfig} from "@lodestar/config";
import {MAX_DEPOSITS} from "@lodestar/params";
import {CachedBeaconStateElectra, getEth1DepositCount} from "../../../src/index.js";
import {getEth1DepositCount} from "../../../src/index.js";
import {createCachedBeaconStateTest} from "../../utils/state.js";

describe("getEth1DepositCount", () => {
Expand Down Expand Up @@ -37,7 +37,7 @@ describe("getEth1DepositCount", () => {
ELECTRA_FORK_EPOCH: 0,
}),
{skipSyncCommitteeCache: true, skipSyncPubkeys: true}
) as CachedBeaconStateElectra;
);

if (!postElectraState.epochCtx.isPostElectra()) {
throw Error("Not a post-Electra state");
Expand Down Expand Up @@ -71,7 +71,7 @@ describe("getEth1DepositCount", () => {
ELECTRA_FORK_EPOCH: 0,
}),
{skipSyncCommitteeCache: true, skipSyncPubkeys: true}
) as CachedBeaconStateElectra;
);

if (!postElectraState.epochCtx.isPostElectra()) {
throw Error("Not a post-Electra state");
Expand Down
18 changes: 9 additions & 9 deletions packages/types/src/electra/sszTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export const ExecutionPayload = new ContainerType(
...denebSsz.ExecutionPayload.fields,
depositRequests: DepositRequests, // New in ELECTRA
withdrawalRequests: WithdrawalRequests, // New in ELECTRA
consolidationRequests: ConsolidationRequests, // [New in Electra]
consolidationRequests: ConsolidationRequests, // New in ELECTRA
},
{typeName: "ExecutionPayload", jsonCase: "eth2"}
);
Expand Down Expand Up @@ -333,14 +333,14 @@ export const BeaconState = new ContainerType(
// Deep history valid from Capella onwards
historicalSummaries: capellaSsz.BeaconState.fields.historicalSummaries,
depositRequestsStartIndex: UintBn64, // New in ELECTRA:EIP6110
depositBalanceToConsume: Gwei, // New in Electra:EIP7251
exitBalanceToConsume: Gwei, // New in Electra:EIP7251
earliestExitEpoch: Epoch, // New in Electra:EIP7251
consolidationBalanceToConsume: Gwei, // New in Electra:EIP7251
earliestConsolidationEpoch: Epoch, // New in Electra:EIP7251
pendingBalanceDeposits: PendingBalanceDeposits, // New in Electra:EIP7251
pendingPartialWithdrawals: new ListCompositeType(PendingPartialWithdrawal, PENDING_PARTIAL_WITHDRAWALS_LIMIT), // New in Electra:EIP7251
pendingConsolidations: new ListCompositeType(PendingConsolidation, PENDING_CONSOLIDATIONS_LIMIT), // New in Electra:EIP7251
depositBalanceToConsume: Gwei, // New in ELECTRA:EIP7251
exitBalanceToConsume: Gwei, // New in ELECTRA:EIP7251
earliestExitEpoch: Epoch, // New in ELECTRA:EIP7251
consolidationBalanceToConsume: Gwei, // New in ELECTRA:EIP7251
earliestConsolidationEpoch: Epoch, // New in ELECTRA:EIP7251
pendingBalanceDeposits: PendingBalanceDeposits, // New in ELECTRA:EIP7251
pendingPartialWithdrawals: new ListCompositeType(PendingPartialWithdrawal, PENDING_PARTIAL_WITHDRAWALS_LIMIT), // New in ELECTRA:EIP7251
pendingConsolidations: new ListCompositeType(PendingConsolidation, PENDING_CONSOLIDATIONS_LIMIT), // New in ELECTRA:EIP7251
},
{typeName: "BeaconState", jsonCase: "eth2"}
);
Expand Down
3 changes: 2 additions & 1 deletion packages/validator/src/services/attestation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {toHexString} from "@chainsafe/ssz";
import {BLSSignature, phase0, Slot, ssz, Attestation, SignedAggregateAndProof} from "@lodestar/types";
import {ForkSeq} from "@lodestar/params";
import {computeEpochAtSlot, isAggregatorFromCommitteeLength} from "@lodestar/state-transition";
import {sleep} from "@lodestar/utils";
import {ApiClient, routes} from "@lodestar/api";
Expand Down Expand Up @@ -159,7 +160,7 @@ export class AttestationService {
this.metrics?.attesterStepCallProduceAggregate.observe(this.clock.secFromSlot(slot + 2 / 3));

const dutiesByCommitteeIndex = groupAttDutiesByCommitteeIndex(dutiesAll);
const isPostElectra = computeEpochAtSlot(slot) >= this.config.ELECTRA_FORK_EPOCH;
const isPostElectra = this.config.getForkSeq(slot) >= ForkSeq.electra;

// Then download, sign and publish a `SignedAggregateAndProof` for each
// validator that is elected to aggregate for this `slot` and `committeeIndex`.
Expand Down
7 changes: 2 additions & 5 deletions packages/validator/src/services/validatorStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,8 @@ export class ValidatorStore {
return {
aggregationBits: BitArray.fromSingleBit(duty.committeeLength, duty.validatorCommitteeIndex),
data: attestationData,
committeeBits: BitArray.fromSingleBit(MAX_COMMITTEES_PER_SLOT, duty.committeeIndex),
signature: await this.getSignature(duty.pubkey, signingRoot, signingSlot, signableMessage),
committeeBits: BitArray.fromSingleBit(MAX_COMMITTEES_PER_SLOT, duty.committeeIndex),
};
} else {
return {
Expand Down Expand Up @@ -801,7 +801,7 @@ export class ValidatorStore {
throw Error(`Inconsistent duties during signing: duty.slot ${duty.slot} != att.slot ${data.slot}`);
}

const isPostElectra = computeEpochAtSlot(duty.slot) >= this.config.ELECTRA_FORK_EPOCH;
const isPostElectra = this.config.getForkSeq(duty.slot) >= ForkSeq.electra;
if (!isPostElectra && duty.committeeIndex != data.index) {
throw Error(
`Inconsistent duties during signing: duty.committeeIndex ${duty.committeeIndex} != att.committeeIndex ${data.index}`
Expand All @@ -810,9 +810,6 @@ export class ValidatorStore {
if (isPostElectra && data.index !== 0) {
throw Error(`Non-zero committee index post-electra during signing: att.committeeIndex ${data.index}`);
}
if (this.config.getForkSeq(duty.slot) >= ForkSeq.electra && data.index !== 0) {
throw Error(`Attestataion data index must be 0 post electra: index ${data.index}`);
}
}

private assertDoppelgangerSafe(pubKey: PubkeyHex | BLSPubkey): void {
Expand Down
Loading