Skip to content

Commit

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

fix types

fixes

rename

cleanup types

fix types
  • Loading branch information
g11tech committed Sep 9, 2024
1 parent b05c93e commit 3e779a6
Show file tree
Hide file tree
Showing 24 changed files with 474 additions and 12 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 @@ -38,6 +38,8 @@ const fork: TestRunnerFn<ForkStateCase, BeaconStateAllForks> = (forkNext) => {
return slotFns.upgradeStateToDeneb(preState as CachedBeaconStateCapella);
case ForkName.electra:
return slotFns.upgradeStateToElectra(preState as CachedBeaconStateDeneb);
case ForkName.ebps:
throw Error("not Implemented");
}
},
options: {
Expand Down
9 changes: 9 additions & 0 deletions packages/beacon-node/test/spec/presets/transition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ function getTransitionConfig(fork: ForkName, forkEpoch: number): Partial<ChainCo
DENEB_FORK_EPOCH: 0,
ELECTRA_FORK_EPOCH: forkEpoch,
};
case ForkName.ebps:
return {
ALTAIR_FORK_EPOCH: 0,
BELLATRIX_FORK_EPOCH: 0,
CAPELLA_FORK_EPOCH: 0,
DENEB_FORK_EPOCH: 0,
ELECTRA_FORK_EPOCH: 0,
EBPS_FORK_EPOCH: forkEpoch,
};
}
}

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

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

testSlots = {
Expand All @@ -38,11 +40,18 @@ describe("UpgradeLightClientHeader", function () {
capella: 25,
deneb: 33,
electra: 41,
ebps: 0,
};
});

for (let i = ForkSeq.altair; i < Object.values(ForkName).length; i++) {
for (let j = i + 1; j < Object.values(ForkName).length; j++) {
// Since ebps is not implemented for loop is till deneb (Object.values(ForkName).length-1)
// Once ebps 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 @@ -56,7 +65,27 @@ describe("UpgradeLightClientHeader", function () {
}
}

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

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 ebps is not implemented for loop is till deneb (Object.values(ForkName).length-1)
// Once ebps 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 @@ -10,13 +10,15 @@ function getForkConfig({
capella,
deneb,
electra,
ebps,
}: {
phase0: number;
altair: number;
bellatrix: number;
capella: number;
deneb: number;
electra: number;
ebps: number;
}): BeaconConfig {
const forks: Record<ForkName, ForkInfo> = {
phase0: {
Expand Down Expand Up @@ -67,6 +69,14 @@ function getForkConfig({
prevVersion: Buffer.from([0, 0, 0, 4]),
prevForkName: ForkName.deneb,
},
ebps: {
name: ForkName.ebps,
seq: ForkSeq.ebps,
epoch: ebps,
version: Buffer.from([0, 0, 0, 9]),
prevVersion: Buffer.from([0, 0, 0, 5]),
prevForkName: ForkName.electra,
},
};
const forksAscendingEpochOrder = Object.values(forks);
const forksDescendingEpochOrder = Object.values(forks).reverse();
Expand Down Expand Up @@ -144,9 +154,10 @@ for (const testScenario of testScenarios) {
const {phase0, altair, bellatrix, capella, testCases} = testScenario;
const deneb = Infinity;
const electra = Infinity;
const ebps = Infinity;

describe(`network / fork: phase0: ${phase0}, altair: ${altair}, bellatrix: ${bellatrix} capella: ${capella}`, () => {
const forkConfig = getForkConfig({phase0, altair, bellatrix, capella, deneb, electra});
const forkConfig = getForkConfig({phase0, altair, bellatrix, capella, deneb, electra, ebps});
const forks = forkConfig.forks;
for (const testCase of testCases) {
const {epoch, currentFork, nextFork, activeForks} = testCase;
Expand Down
9 changes: 9 additions & 0 deletions packages/beacon-node/test/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,14 @@ export function getConfig(fork: ForkName, forkEpoch = 0): ChainForkConfig {
DENEB_FORK_EPOCH: 0,
ELECTRA_FORK_EPOCH: forkEpoch,
});
case ForkName.ebps:
return createChainForkConfig({
ALTAIR_FORK_EPOCH: 0,
BELLATRIX_FORK_EPOCH: 0,
CAPELLA_FORK_EPOCH: 0,
DENEB_FORK_EPOCH: 0,
ELECTRA_FORK_EPOCH: 0,
EBPS_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 @@ -53,6 +53,10 @@ export const chainConfig: ChainConfig = {
ELECTRA_FORK_VERSION: b("0x05000000"),
ELECTRA_FORK_EPOCH: Infinity,

// Ebps
EBPS_FORK_VERSION: b("0x09000000"),
EBPS_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 @@ -49,6 +49,10 @@ export const chainConfig: ChainConfig = {
ELECTRA_FORK_VERSION: b("0x05000001"),
ELECTRA_FORK_EPOCH: Infinity,

// Ebps
EBPS_FORK_VERSION: b("0x05000001"),
EBPS_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 @@ -43,6 +43,9 @@ export type ChainConfig = {
// ELECTRA
ELECTRA_FORK_VERSION: Uint8Array;
ELECTRA_FORK_EPOCH: number;
// EBPS
EBPS_FORK_VERSION: Uint8Array;
EBPS_FORK_EPOCH: number;

// Time parameters
SECONDS_PER_SLOT: number;
Expand Down Expand Up @@ -107,6 +110,9 @@ export const chainConfigTypes: SpecTypes<ChainConfig> = {
// ELECTRA
ELECTRA_FORK_VERSION: "bytes",
ELECTRA_FORK_EPOCH: "number",
// EBPS
EBPS_FORK_VERSION: "bytes",
EBPS_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 @@ -67,10 +67,18 @@ export function createForkConfig(config: ChainConfig): ForkConfig {
prevVersion: config.DENEB_FORK_VERSION,
prevForkName: ForkName.deneb,
};
const ebps: ForkInfo = {
name: ForkName.ebps,
seq: ForkSeq.ebps,
epoch: config.EBPS_FORK_EPOCH,
version: config.EBPS_FORK_VERSION,
prevVersion: config.ELECTRA_FORK_VERSION,
prevForkName: ForkName.electra,
};

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

// 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 @@ -124,6 +124,10 @@ export function upgradeLightClientHeader(

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

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

/**
Expand All @@ -20,6 +21,7 @@ export enum ForkSeq {
capella = 3,
deneb = 4,
electra = 5,
ebps = 6,
}

function exclude<T extends ForkName, U extends T>(coll: T[], val: U[]): Exclude<T, U>[] {
Expand Down Expand Up @@ -93,3 +95,20 @@ export const forkPostElectra = exclude(forkAll, [
export function isForkPostElectra(fork: ForkName): fork is ForkPostElectra {
return isForkBlobs(fork) && fork !== ForkName.deneb;
}

// TODO add electra type in ForkPreEpbs
export type ForkPreEpbs = ForkPreBlobs | ForkName.deneb | ForkName.electra;
export type ForkExecutionPreEpbs = Exclude<ForkPreEpbs, ForkPreExecution>;
export const forkExecutionPreEpbs = [ForkName.bellatrix, ForkName.capella, ForkName.deneb, ForkName.electra];
export type ForkEpbs = Exclude<ForkName, ForkPreBlobs>;
export const forkEpbs = exclude(forkAll, [
ForkName.phase0,
ForkName.altair,
ForkName.bellatrix,
ForkName.capella,
ForkName.deneb,
ForkName.electra,
]);
export function isForkEpbs(fork: ForkName): fork is ForkEpbs {
return isForkBlobs(fork) && fork !== ForkName.deneb && fork !== ForkName.electra;
}
11 changes: 11 additions & 0 deletions packages/params/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ export const {
MAX_ATTESTATIONS_ELECTRA,
MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP,
WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA,

PTC_SIZE,
MAX_PAYLOAD_ATTESTATIONS,
} = activePreset;

////////////
Expand Down Expand Up @@ -145,6 +148,8 @@ 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_CONSOLIDATION = Uint8Array.from([11, 0, 0, 0]);
export const DOMAIN_PTC_ATTESTER = Uint8Array.from([12, 0, 0, 0]); //DomainType('0x0C000000') # (New in EIP-7732)
export const DOMAIN_BEACON_BUILDER = Uint8Array.from([27, 0, 0, 0]); // DomainType('0x1B000000') # (New in EIP-7732)

// Application specific domains

Expand Down Expand Up @@ -268,3 +273,9 @@ export const NEXT_SYNC_COMMITTEE_GINDEX_ELECTRA = 87;
export const NEXT_SYNC_COMMITTEE_DEPTH_ELECTRA = 6;
export const FINALIZED_ROOT_DEPTH_ELECTRA = 7;
export const FINALIZED_ROOT_INDEX_ELECTRA = 169;

// ebps
export const PAYLOAD_ABSENT = 0;
export const PAYLOAD_PRESENT = 1;
export const PAYLOAD_WITHHELD = 2;
export const PAYLOAD_INVALID_STATUS = 3;
6 changes: 6 additions & 0 deletions packages/params/src/presets/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,10 @@ export const mainnetPreset: BeaconPreset = {
PENDING_CONSOLIDATIONS_LIMIT: 262144,
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: 1,
WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA: 4096,

// ebps - EIP-7732
// uint64(2**9) = 512
PTC_SIZE: 512,
// 2**2 = 4
MAX_PAYLOAD_ATTESTATIONS: 4,
};
6 changes: 6 additions & 0 deletions packages/params/src/presets/minimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,10 @@ export const minimalPreset: BeaconPreset = {
PENDING_CONSOLIDATIONS_LIMIT: 64,
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: 1,
WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA: 4096,

// ebps - EIP-7732
// uint64(2**9) = 512
PTC_SIZE: 512,
// 2**2 = 4
MAX_PAYLOAD_ATTESTATIONS: 4,
};
8 changes: 8 additions & 0 deletions packages/params/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ export type BeaconPreset = {
PENDING_CONSOLIDATIONS_LIMIT: number;
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: number;
WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA: number;

// EBPS
PTC_SIZE: number;
MAX_PAYLOAD_ATTESTATIONS: number;
};

/**
Expand Down Expand Up @@ -197,6 +201,10 @@ export const beaconPresetTypes: BeaconPresetTypes = {
PENDING_CONSOLIDATIONS_LIMIT: "number",
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: "number",
WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA: "number",

// EBPS
PTC_SIZE: "number",
MAX_PAYLOAD_ATTESTATIONS: "number",
};

type BeaconPresetTypes = {
Expand Down
9 changes: 9 additions & 0 deletions packages/state-transition/test/unit/upgradeState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,14 @@ function getConfig(fork: ForkName, forkEpoch = 0): ChainForkConfig {
DENEB_FORK_EPOCH: 0,
ELECTRA_FORK_EPOCH: forkEpoch,
});
case ForkName.ebps:
return createChainForkConfig({
ALTAIR_FORK_EPOCH: 0,
BELLATRIX_FORK_EPOCH: 0,
CAPELLA_FORK_EPOCH: 0,
DENEB_FORK_EPOCH: 0,
ELECTRA_FORK_EPOCH: 0,
EBPS_FORK_EPOCH: forkEpoch,
});
}
}
3 changes: 3 additions & 0 deletions packages/types/src/ebps/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 3e779a6

Please sign in to comment.