Skip to content

Commit

Permalink
feat: placeholder PR for electra
Browse files Browse the repository at this point in the history
add types stub and epoch config

fix types
  • Loading branch information
g11tech committed Mar 13, 2024
1 parent 15974b5 commit b4ce652
Show file tree
Hide file tree
Showing 19 changed files with 323 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/beacon-node/test/spec/presets/fork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const fork: TestRunnerFn<ForkStateCase, BeaconStateAllForks> = (forkNext) => {
return slotFns.upgradeStateToCapella(preState as CachedBeaconStateBellatrix);
case ForkName.deneb:
return slotFns.upgradeStateToDeneb(preState as CachedBeaconStateCapella);
case ForkName.electra:
throw Error("not Implemented");
}
},
options: {
Expand Down
8 changes: 8 additions & 0 deletions packages/beacon-node/test/spec/presets/transition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ function getTransitionConfig(fork: ForkName, forkEpoch: number): Partial<ChainCo
return {ALTAIR_FORK_EPOCH: 0, BELLATRIX_FORK_EPOCH: 0, CAPELLA_FORK_EPOCH: forkEpoch};
case ForkName.deneb:
return {ALTAIR_FORK_EPOCH: 0, BELLATRIX_FORK_EPOCH: 0, CAPELLA_FORK_EPOCH: 0, DENEB_FORK_EPOCH: forkEpoch};
case ForkName.electra:
return {
ALTAIR_FORK_EPOCH: 0,
BELLATRIX_FORK_EPOCH: 0,
CAPELLA_FORK_EPOCH: 0,
DENEB_FORK_EPOCH: 0,
ELECTRA_FORK_EPOCH: forkEpoch,
};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe("UpgradeLightClientHeader", function () {
BELLATRIX_FORK_EPOCH: 2,
CAPELLA_FORK_EPOCH: 3,
DENEB_FORK_EPOCH: 4,
ELECTRA_FORK_EPOCH: Infinity,
});

const genesisValidatorsRoot = Buffer.alloc(32, 0xaa);
Expand All @@ -27,6 +28,7 @@ describe("UpgradeLightClientHeader", function () {
capella: ssz.capella.LightClientHeader.defaultValue(),
bellatrix: ssz.altair.LightClientHeader.defaultValue(),
deneb: ssz.deneb.LightClientHeader.defaultValue(),
electra: ssz.electra.LightClientHeader.defaultValue(),
};

testSlots = {
Expand All @@ -35,11 +37,18 @@ describe("UpgradeLightClientHeader", function () {
bellatrix: 17,
capella: 25,
deneb: 33,
electra: 0,
};
});

for (let i = ForkSeq.altair; i < Object.values(ForkName).length; i++) {
for (let j = i + 1; j < Object.values(ForkName).length; j++) {
// Since electra is not implemented for loop is till deneb (Object.values(ForkName).length-1)
// Once electra is implemnted run for loop till Object.values(ForkName).length

// for (let i = ForkSeq.altair; i < Object.values(ForkName).length; i++) {
// for (let j = i + 1; j < Object.values(ForkName).length; j++) {

for (let i = ForkSeq.altair; i < Object.values(ForkName).length - 1; i++) {
for (let j = i + 1; j < Object.values(ForkName).length - 1; j++) {
const fromFork = ForkName[ForkSeq[i] as ForkName];
const toFork = ForkName[ForkSeq[j] as ForkName];

Expand All @@ -53,7 +62,27 @@ describe("UpgradeLightClientHeader", function () {
}
}

// for electra not implemented
for (let i = ForkSeq.altair; i < Object.values(ForkName).length; i++) {
const fromFork = ForkName[ForkSeq[i] as ForkName];
const toFork = ForkName["electra"];

it(`Throw error ${fromFork}=>${toFork}`, function () {
lcHeaderByFork[fromFork].beacon.slot = testSlots[fromFork];
lcHeaderByFork[toFork].beacon.slot = testSlots[fromFork];

expect(() => {
upgradeLightClientHeader(config, toFork, lcHeaderByFork[fromFork]);
}).toThrow("Not Implemented");
});
}

// Since electra is not implemented for loop is till deneb (Object.values(ForkName).length-1)
// Once electra is implemnted run for loop till Object.values(ForkName).length

// for (let i = ForkSeq.altair; i < Object.values(ForkName).length; i++) {

for (let i = ForkSeq.altair; i < Object.values(ForkName).length - 1; i++) {
for (let j = i; j > 0; j--) {
const fromFork = ForkName[ForkSeq[i] as ForkName];
const toFork = ForkName[ForkSeq[j] as ForkName];
Expand Down
13 changes: 12 additions & 1 deletion packages/beacon-node/test/unit/network/fork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ function getForkConfig({
bellatrix,
capella,
deneb,
electra,
}: {
phase0: number;
altair: number;
bellatrix: number;
capella: number;
deneb: number;
electra: number;
}): BeaconConfig {
const forks: Record<ForkName, ForkInfo> = {
phase0: {
Expand Down Expand Up @@ -57,6 +59,14 @@ function getForkConfig({
prevVersion: Buffer.from([0, 0, 0, 3]),
prevForkName: ForkName.capella,
},
electra: {
name: ForkName.electra,
seq: ForkSeq.electra,
epoch: electra,
version: Buffer.from([0, 0, 0, 5]),
prevVersion: Buffer.from([0, 0, 0, 4]),
prevForkName: ForkName.deneb,
},
};
const forksAscendingEpochOrder = Object.values(forks);
const forksDescendingEpochOrder = Object.values(forks).reverse();
Expand Down Expand Up @@ -133,9 +143,10 @@ const testScenarios = [
for (const testScenario of testScenarios) {
const {phase0, altair, bellatrix, capella, testCases} = testScenario;
const deneb = Infinity;
const electra = Infinity;

describe(`network / fork: phase0: ${phase0}, altair: ${altair}, bellatrix: ${bellatrix} capella: ${capella}`, () => {
const forkConfig = getForkConfig({phase0, altair, bellatrix, capella, deneb});
const forkConfig = getForkConfig({phase0, altair, bellatrix, capella, deneb, electra});
const forks = forkConfig.forks;
for (const testCase of testCases) {
const {epoch, currentFork, nextFork, activeForks} = testCase;
Expand Down
8 changes: 8 additions & 0 deletions packages/beacon-node/test/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,13 @@ export function getConfig(fork: ForkName, forkEpoch = 0): ChainForkConfig {
CAPELLA_FORK_EPOCH: 0,
DENEB_FORK_EPOCH: forkEpoch,
});
case ForkName.electra:
return createChainForkConfig({
ALTAIR_FORK_EPOCH: 0,
BELLATRIX_FORK_EPOCH: 0,
CAPELLA_FORK_EPOCH: 0,
DENEB_FORK_EPOCH: 0,
ELECTRA_FORK_EPOCH: forkEpoch,
});
}
}
4 changes: 4 additions & 0 deletions packages/config/src/chainConfig/configs/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export const chainConfig: ChainConfig = {
DENEB_FORK_VERSION: b("0x04000000"),
DENEB_FORK_EPOCH: 269568, // March 13, 2024, 01:55:35pm UTC

// Electra
ELECTRA_FORK_VERSION: b("0x05000000"),
ELECTRA_FORK_EPOCH: Infinity,

// Time parameters
// ---------------------------------------------------------------
// 12 seconds
Expand Down
4 changes: 4 additions & 0 deletions packages/config/src/chainConfig/configs/minimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export const chainConfig: ChainConfig = {
DENEB_FORK_VERSION: b("0x04000001"),
DENEB_FORK_EPOCH: Infinity,

// Electra
ELECTRA_FORK_VERSION: b("0x05000001"),
ELECTRA_FORK_EPOCH: Infinity,

// Time parameters
// ---------------------------------------------------------------
// [customized] Faster for testing purposes
Expand Down
6 changes: 6 additions & 0 deletions packages/config/src/chainConfig/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export type ChainConfig = {
// DENEB
DENEB_FORK_VERSION: Uint8Array;
DENEB_FORK_EPOCH: number;
// ELECTRA
ELECTRA_FORK_VERSION: Uint8Array;
ELECTRA_FORK_EPOCH: number;

// Time parameters
SECONDS_PER_SLOT: number;
Expand Down Expand Up @@ -96,6 +99,9 @@ export const chainConfigTypes: SpecTypes<ChainConfig> = {
// DENEB
DENEB_FORK_VERSION: "bytes",
DENEB_FORK_EPOCH: "number",
// ELECTRA
ELECTRA_FORK_VERSION: "bytes",
ELECTRA_FORK_EPOCH: "number",

// Time parameters
SECONDS_PER_SLOT: "number",
Expand Down
10 changes: 9 additions & 1 deletion packages/config/src/forkConfig/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,18 @@ export function createForkConfig(config: ChainConfig): ForkConfig {
prevVersion: config.CAPELLA_FORK_VERSION,
prevForkName: ForkName.capella,
};
const electra: ForkInfo = {
name: ForkName.electra,
seq: ForkSeq.electra,
epoch: config.ELECTRA_FORK_EPOCH,
version: config.ELECTRA_FORK_VERSION,
prevVersion: config.DENEB_FORK_VERSION,
prevForkName: ForkName.deneb,
};

/** Forks in order order of occurence, `phase0` first */
// Note: Downstream code relies on proper ordering.
const forks = {phase0, altair, bellatrix, capella, deneb};
const forks = {phase0, altair, bellatrix, capella, deneb, electra};

// Prevents allocating an array on every getForkInfo() call
const forksAscendingEpochOrder = Object.values(forks);
Expand Down
4 changes: 4 additions & 0 deletions packages/light-client/src/spec/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ export function upgradeLightClientHeader(

// Break if no further upgradation is required else fall through
if (ForkSeq[targetFork] <= ForkSeq.deneb) break;

// eslint-disable-next-line no-fallthrough
case ForkName.electra:
throw Error("Not Implemented");
}
return upgradedHeader;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/params/src/forkName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum ForkName {
bellatrix = "bellatrix",
capella = "capella",
deneb = "deneb",
electra = "electra",
}

/**
Expand All @@ -18,6 +19,7 @@ export enum ForkSeq {
bellatrix = 2,
capella = 3,
deneb = 4,
electra = 5,
}

export type ForkPreLightClient = ForkName.phase0;
Expand Down
8 changes: 8 additions & 0 deletions packages/state-transition/test/unit/upgradeState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,13 @@ function getConfig(fork: ForkName, forkEpoch = 0): ChainForkConfig {
CAPELLA_FORK_EPOCH: 0,
DENEB_FORK_EPOCH: forkEpoch,
});
case ForkName.electra:
return createChainForkConfig({
ALTAIR_FORK_EPOCH: 0,
BELLATRIX_FORK_EPOCH: 0,
CAPELLA_FORK_EPOCH: 0,
DENEB_FORK_EPOCH: 0,
ELECTRA_FORK_EPOCH: forkEpoch,
});
}
}
38 changes: 38 additions & 0 deletions packages/types/src/allForks/sszTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {ssz as altair} from "../altair/index.js";
import {ssz as bellatrix} from "../bellatrix/index.js";
import {ssz as capella} from "../capella/index.js";
import {ssz as deneb} from "../deneb/index.js";
import {ssz as electra} from "../electra/index.js";

/**
* Index the ssz types that differ by fork
Expand Down Expand Up @@ -44,6 +45,13 @@ export const allForks = {
BeaconState: deneb.BeaconState,
Metadata: altair.Metadata,
},
electra: {
BeaconBlockBody: electra.BeaconBlockBody,
BeaconBlock: electra.BeaconBlock,
SignedBeaconBlock: electra.SignedBeaconBlock,
BeaconState: electra.BeaconState,
Metadata: altair.Metadata,
},
};

/**
Expand Down Expand Up @@ -85,6 +93,17 @@ export const allForksExecution = {
SignedBuilderBid: deneb.SignedBuilderBid,
SSEPayloadAttributes: deneb.SSEPayloadAttributes,
},
electra: {
BeaconBlockBody: electra.BeaconBlockBody,
BeaconBlock: electra.BeaconBlock,
SignedBeaconBlock: electra.SignedBeaconBlock,
BeaconState: electra.BeaconState,
ExecutionPayload: electra.ExecutionPayload,
ExecutionPayloadHeader: electra.ExecutionPayloadHeader,
BuilderBid: electra.BuilderBid,
SignedBuilderBid: electra.SignedBuilderBid,
SSEPayloadAttributes: electra.SSEPayloadAttributes,
},
};

/**
Expand All @@ -107,6 +126,11 @@ export const allForksBlinded = {
BeaconBlock: deneb.BlindedBeaconBlock,
SignedBeaconBlock: deneb.SignedBlindedBeaconBlock,
},
electra: {
BeaconBlockBody: electra.BlindedBeaconBlockBody,
BeaconBlock: electra.BlindedBeaconBlock,
SignedBeaconBlock: electra.SignedBlindedBeaconBlock,
},
};

export const allForksLightClient = {
Expand Down Expand Up @@ -150,11 +174,25 @@ export const allForksLightClient = {
LightClientOptimisticUpdate: deneb.LightClientOptimisticUpdate,
LightClientStore: deneb.LightClientStore,
},
electra: {
BeaconBlock: electra.BeaconBlock,
BeaconBlockBody: electra.BeaconBlockBody,
LightClientHeader: electra.LightClientHeader,
LightClientBootstrap: electra.LightClientBootstrap,
LightClientUpdate: electra.LightClientUpdate,
LightClientFinalityUpdate: electra.LightClientFinalityUpdate,
LightClientOptimisticUpdate: electra.LightClientOptimisticUpdate,
LightClientStore: electra.LightClientStore,
},
};

export const allForksBlobs = {
deneb: {
BlobSidecar: deneb.BlobSidecar,
ExecutionPayloadAndBlobsBundle: deneb.ExecutionPayloadAndBlobsBundle,
},
electra: {
BlobSidecar: electra.BlobSidecar,
ExecutionPayloadAndBlobsBundle: electra.ExecutionPayloadAndBlobsBundle,
},
};
3 changes: 3 additions & 0 deletions packages/types/src/electra/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./types.js";
export * as ts from "./types.js";
export * as ssz from "./sszTypes.js";
Loading

0 comments on commit b4ce652

Please sign in to comment.