Skip to content

Commit

Permalink
rename verge to electra and fix upgrade issues and transition banner
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed Nov 23, 2023
1 parent de9d20d commit 815364b
Show file tree
Hide file tree
Showing 31 changed files with 182 additions and 156 deletions.
20 changes: 20 additions & 0 deletions packages/beacon-node/src/chain/blocks/utils/elephantWithWings.ts
@@ -0,0 +1,20 @@
export const ELECTRA_ELEPHANTWITHWINGS_BANNER = String.raw`
:~~.
:!:^::^^!!^
:!^^ !:J.
.!!:! .^7^
.?7~: ^#! !!!^!~.
:!^ GP~..^^?^ ^!:
!^ Y5 #7:
.:^^~7~. ! ~~6800~~^ ^6800^ ~~6800 68 00 68~~ 00~ ||
.~! 55J ~~6800~~ :! !^ .YP :JP 7B. ^7#
^7 :: 5 #:::^::~~6800~~^^?!?.~:: :! !^ 6800 .^PJ JG ~!B
:G ^7 ^ !^68 00^ ~~6800~~ :! !: .&~ ^#! ^!55~~~6800~~7G~ !7B
7G ~!5J ^? !.----. ~! ~~6800~~ .7#: 6800 ~
?G :^?G. ...... ^?^.!G. ?G :^?G. ...... ^?^.!G. !
~! ~~6800~~ .7#: 6800 G~ 7G ~!5J ^? !.----. ::
:! !: .&~ ^#! ^!55~~~6800~~7G~ !7B :G ^7 ^ !^68 00^ ~~6800~~ ::
:! !^ 6800 .^PJ JG ~!B ^7 :: 5 ^^ !!!! #:::^::~~6800~~^^?!?.~
:! !^ .YP :JP 7B. ^7# .~!~ ~~6800 ^6800^ ~~6800~~
6800 68 00 68~~ 00~ 6800
`;
6 changes: 6 additions & 0 deletions packages/beacon-node/src/chain/blocks/verifyBlock.ts
Expand Up @@ -18,6 +18,7 @@ import {BlockInput, ImportBlockOpts} from "./types.js";
import {POS_PANDA_MERGE_TRANSITION_BANNER} from "./utils/pandaMergeTransitionBanner.js";
import {CAPELLA_OWL_BANNER} from "./utils/ownBanner.js";
import {DENEB_BLOWFISH_BANNER} from "./utils/blowfishBanner.js";
import {ELECTRA_ELEPHANTWITHWINGS_BANNER} from "./utils/elephantWithWings.js";
import {verifyBlocksStateTransitionOnly} from "./verifyBlocksStateTransitionOnly.js";
import {verifyBlocksSignatures} from "./verifyBlocksSignatures.js";
import {verifyBlocksExecutionPayload, SegmentExecStatus} from "./verifyBlocksExecutionPayloads.js";
Expand Down Expand Up @@ -129,6 +130,11 @@ export async function verifyBlocksInEpoch(
this.logger.info("Activating withdrawals", {epoch: this.config.CAPELLA_FORK_EPOCH});
break;

case ForkName.electra:
this.logger.info(ELECTRA_ELEPHANTWITHWINGS_BANNER);
this.logger.info("Activating verkle", {epoch: this.config.ELECTRA_FORK_EPOCH});
break;

case ForkName.deneb:
this.logger.info(DENEB_BLOWFISH_BANNER);
this.logger.info("Activating blobs", {epoch: this.config.DENEB_FORK_EPOCH});
Expand Down
20 changes: 10 additions & 10 deletions packages/beacon-node/src/execution/engine/types.ts
@@ -1,5 +1,5 @@
import * as util from "node:util";
import {allForks, capella, deneb, Wei, bellatrix, Root, verge, ssz} from "@lodestar/types";
import {allForks, capella, deneb, Wei, bellatrix, Root, electra, ssz} from "@lodestar/types";
import {
BYTES_PER_LOGS_BLOOM,
FIELD_ELEMENTS_PER_BLOB,
Expand Down Expand Up @@ -195,14 +195,14 @@ export function serializeExecutionPayload(fork: ForkName, data: allForks.Executi
payload.excessBlobGas = numToQuantity(excessBlobGas);
}

// VERGE adds executionWitness to the ExecutionPayload
if (ForkSeq[fork] >= ForkSeq.verge) {
const {executionWitness} = data as verge.ExecutionPayload;
// ELECTRA adds executionWitness to the ExecutionPayload
if (ForkSeq[fork] >= ForkSeq.electra) {
const {executionWitness} = data as electra.ExecutionPayload;
// right now the caseMap of ssz ExecutionWitness is camel cased and can
// directly be used to serialize tojson
payload.executionWitness = ssz.verge.ExecutionWitness.toJson(executionWitness);
payload.executionWitness = ssz.electra.ExecutionWitness.toJson(executionWitness);
// serialization with ssz serialize suffix diff's suffix to a string while geth expects num
(payload.executionWitness as verge.ExecutionWitness).stateDiff.forEach((sDiff) => {
(payload.executionWitness as electra.ExecutionWitness).stateDiff.forEach((sDiff) => {
sDiff.suffixDiffs.forEach((sfDiff) => {
sfDiff.suffix = Number(sfDiff.suffix);
});
Expand Down Expand Up @@ -285,8 +285,8 @@ export function parseExecutionPayload(
(executionPayload as deneb.ExecutionPayload).excessBlobGas = quantityToBigint(excessBlobGas);
}

// VERGE adds execution witness to the payload
if (ForkSeq[fork] >= ForkSeq.verge) {
// ELECTRA adds execution witness to the payload
if (ForkSeq[fork] >= ForkSeq.electra) {
// right now the casing of executionWitness is camel case in the ssz caseMap
// we can directly use fromJson to read the serialized data from payload
const {executionWitness} = data;
Expand All @@ -295,8 +295,8 @@ export function parseExecutionPayload(
util.inspect(executionWitness, false, null, true /* enable colors */),
{blockNumber: data.blockNumber}
);
(executionPayload as verge.ExecutionPayload).executionWitness =
ssz.verge.ExecutionWitness.fromJson(executionWitness);
(executionPayload as electra.ExecutionPayload).executionWitness =
ssz.electra.ExecutionWitness.fromJson(executionWitness);
}

return {executionPayload, executionPayloadValue, blobsBundle};
Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-node/test/spec/presets/fork.test.ts
Expand Up @@ -36,8 +36,8 @@ const fork: TestRunnerFn<ForkStateCase, BeaconStateAllForks> = (forkNext) => {
return slotFns.upgradeStateToCapella(preState as CachedBeaconStateBellatrix);
case ForkName.deneb:
return slotFns.upgradeStateToDeneb(preState as CachedBeaconStateCapella);
case ForkName.verge:
return slotFns.upgradeStateToVerge(preState as CachedBeaconStateDeneb);
case ForkName.electra:
return slotFns.upgradeStateToElectra(preState as CachedBeaconStateDeneb);
}
},
options: {
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/test/spec/presets/transition.test.ts
Expand Up @@ -102,7 +102,7 @@ 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.verge:
case ForkName.electra:
return {
ALTAIR_FORK_EPOCH: 0,
BELLATRIX_FORK_EPOCH: 0,
Expand Down
Expand Up @@ -27,7 +27,7 @@ describe("UpgradeLightClientHeader", function () {
capella: ssz.capella.LightClientHeader.defaultValue(),
bellatrix: ssz.altair.LightClientHeader.defaultValue(),
deneb: ssz.deneb.LightClientHeader.defaultValue(),
verge: ssz.verge.LightClientHeader.defaultValue(),
electra: ssz.electra.LightClientHeader.defaultValue(),
};

testSlots = {
Expand All @@ -36,7 +36,7 @@ describe("UpgradeLightClientHeader", function () {
bellatrix: 17,
capella: 25,
deneb: 33,
verge: 41,
electra: 41,
};
});

Expand Down
16 changes: 8 additions & 8 deletions packages/beacon-node/test/unit/network/fork.test.ts
Expand Up @@ -9,14 +9,14 @@ function getForkConfig({
bellatrix,
capella,
deneb,
verge,
electra,
}: {
phase0: number;
altair: number;
bellatrix: number;
capella: number;
deneb: number;
verge: number;
electra: number;
}): BeaconConfig {
const forks: Record<ForkName, ForkInfo> = {
phase0: {
Expand Down Expand Up @@ -59,10 +59,10 @@ function getForkConfig({
prevVersion: Buffer.from([0, 0, 0, 3]),
prevForkName: ForkName.capella,
},
verge: {
name: ForkName.verge,
seq: ForkSeq.verge,
epoch: verge,
electra: {
name: ForkName.electra,
seq: ForkSeq.electra,
epoch: electra,
version: Buffer.from([0, 0, 0, 4]),
prevVersion: Buffer.from([0, 0, 0, 3]),
prevForkName: ForkName.capella,
Expand Down Expand Up @@ -143,10 +143,10 @@ const testScenarios = [
for (const testScenario of testScenarios) {
const {phase0, altair, bellatrix, capella, testCases} = testScenario;
const deneb = Infinity;
const verge = Infinity;
const electra = Infinity;

describe(`network / fork: phase0: ${phase0}, altair: ${altair}, bellatrix: ${bellatrix} capella: ${capella}`, () => {
const forkConfig = getForkConfig({phase0, altair, bellatrix, capella, deneb, verge});
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
2 changes: 1 addition & 1 deletion packages/beacon-node/test/utils/config.ts
Expand Up @@ -31,7 +31,7 @@ export function getConfig(fork: ForkName, forkEpoch = 0): ChainForkConfig {
CAPELLA_FORK_EPOCH: 0,
DENEB_FORK_EPOCH: forkEpoch,
});
case ForkName.verge:
case ForkName.electra:
return createChainForkConfig({
ALTAIR_FORK_EPOCH: 0,
BELLATRIX_FORK_EPOCH: 0,
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/chainConfig/presets/mainnet.ts
Expand Up @@ -45,7 +45,7 @@ export const chainConfig: ChainConfig = {
DENEB_FORK_VERSION: b("0x04000000"),
DENEB_FORK_EPOCH: Infinity,

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

Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/chainConfig/presets/minimal.ts
Expand Up @@ -42,7 +42,7 @@ export const chainConfig: ChainConfig = {
// Deneb
DENEB_FORK_VERSION: b("0x04000001"),
DENEB_FORK_EPOCH: Infinity,
// Verge
// Electra
ELECTRA_FORK_VERSION: b("0x05000001"),
ELECTRA_FORK_EPOCH: Infinity,

Expand Down
4 changes: 2 additions & 2 deletions packages/config/src/chainConfig/types.ts
Expand Up @@ -40,7 +40,7 @@ export type ChainConfig = {
// DENEB
DENEB_FORK_VERSION: Uint8Array;
DENEB_FORK_EPOCH: number;
// VERGE
// ELECTRA
ELECTRA_FORK_VERSION: Uint8Array;
ELECTRA_FORK_EPOCH: number;

Expand Down Expand Up @@ -96,7 +96,7 @@ export const chainConfigTypes: SpecTypes<ChainConfig> = {
// DENEB
DENEB_FORK_VERSION: "bytes",
DENEB_FORK_EPOCH: "number",
// VERGE
// ELECTRA
ELECTRA_FORK_VERSION: "bytes",
ELECTRA_FORK_EPOCH: "number",

Expand Down
8 changes: 4 additions & 4 deletions packages/config/src/forkConfig/index.ts
Expand Up @@ -55,9 +55,9 @@ export function createForkConfig(config: ChainConfig): ForkConfig {
prevVersion: config.CAPELLA_FORK_VERSION,
prevForkName: ForkName.capella,
};
const verge: ForkInfo = {
name: ForkName.verge,
seq: ForkSeq.verge,
const electra: ForkInfo = {
name: ForkName.electra,
seq: ForkSeq.electra,
epoch: config.ELECTRA_FORK_EPOCH,
version: config.ELECTRA_FORK_VERSION,
prevVersion: config.CAPELLA_FORK_VERSION,
Expand All @@ -66,7 +66,7 @@ export function createForkConfig(config: ChainConfig): ForkConfig {

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

// Prevents allocating an array on every getForkInfo() call
const forksAscendingEpochOrder = Object.values(forks);
Expand Down
10 changes: 5 additions & 5 deletions packages/params/src/forkName.ts
Expand Up @@ -7,7 +7,7 @@ export enum ForkName {
bellatrix = "bellatrix",
capella = "capella",
deneb = "deneb",
verge = "verge",
electra = "electra",
}

/**
Expand All @@ -18,8 +18,8 @@ export enum ForkSeq {
altair = 1,
bellatrix = 2,
capella = 3,
// Verge is scheduled after capella for now
verge = 4,
// Electra is scheduled after capella for now
electra = 4,
deneb = 5,
}

Expand Down Expand Up @@ -47,8 +47,8 @@ export function isForkVerge(fork: ForkName): fork is ForkVerge {
return isForkWithdrawals(fork) && fork !== ForkName.capella;
}

export type ForkPreBlobs = ForkPreVerge | ForkName.verge;
export type ForkPreBlobs = ForkPreVerge | ForkName.electra;
export type ForkBlobs = Exclude<ForkName, ForkPreBlobs>;
export function isForkBlobs(fork: ForkName): fork is ForkBlobs {
return isForkVerge(fork) && fork !== ForkName.verge;
return isForkVerge(fork) && fork !== ForkName.electra;
}
2 changes: 1 addition & 1 deletion packages/params/src/index.ts
Expand Up @@ -236,7 +236,7 @@ export const BYTES_PER_FIELD_ELEMENT = 32;
export const BLOB_TX_TYPE = 0x03;
export const VERSIONED_HASH_VERSION_KZG = 0x01;

// TODO: Verge spec notes these as preset but there's only one value
// TODO: Electra spec notes these as preset but there's only one value
// https://github.com/ethereum/consensus-specs/blob/db74090c1e8dc1fb2c052bae268e22dc63061e32/specs/verge/beacon-chain.md#preset
export const MAX_STEMS = 2 ** 16;
export const MAX_COMMITMENTS_PER_STEM = 33;
Expand Down
4 changes: 2 additions & 2 deletions packages/state-transition/src/cache/stateCache.ts
Expand Up @@ -11,7 +11,7 @@ import {
BeaconStateBellatrix,
BeaconStateCapella,
BeaconStateDeneb,
BeaconStateVerge,
BeaconStateElectra,
} from "./types.js";

export type BeaconStateCache = {
Expand Down Expand Up @@ -130,7 +130,7 @@ export type CachedBeaconStateAltair = CachedBeaconState<BeaconStateAltair>;
export type CachedBeaconStateBellatrix = CachedBeaconState<BeaconStateBellatrix>;
export type CachedBeaconStateCapella = CachedBeaconState<BeaconStateCapella>;
export type CachedBeaconStateDeneb = CachedBeaconState<BeaconStateDeneb>;
export type CachedBeaconStateVerge = CachedBeaconState<BeaconStateVerge>;
export type CachedBeaconStateElectra = CachedBeaconState<BeaconStateElectra>;

export type CachedBeaconStateAllForks = CachedBeaconState<BeaconStateAllForks>;
export type CachedBeaconStateExecutions = CachedBeaconState<BeaconStateExecutions>;
Expand Down
6 changes: 3 additions & 3 deletions packages/state-transition/src/cache/types.ts
Expand Up @@ -7,7 +7,7 @@ export type BeaconStateAltair = CompositeViewDU<typeof ssz.altair.BeaconState>;
export type BeaconStateBellatrix = CompositeViewDU<typeof ssz.bellatrix.BeaconState>;
export type BeaconStateCapella = CompositeViewDU<typeof ssz.capella.BeaconState>;
export type BeaconStateDeneb = CompositeViewDU<typeof ssz.deneb.BeaconState>;
export type BeaconStateVerge = CompositeViewDU<typeof ssz.verge.BeaconState>;
export type BeaconStateElectra = CompositeViewDU<typeof ssz.electra.BeaconState>;

// Union at the TreeViewDU level
// - Works well as function argument and as generic type for allForks functions
Expand All @@ -20,8 +20,8 @@ export type BeaconStateAllForks =
| BeaconStateBellatrix
| BeaconStateCapella
| BeaconStateDeneb
| BeaconStateVerge;
| BeaconStateElectra;

export type BeaconStateExecutions = BeaconStateBellatrix | BeaconStateCapella | BeaconStateDeneb | BeaconStateVerge;
export type BeaconStateExecutions = BeaconStateBellatrix | BeaconStateCapella | BeaconStateDeneb | BeaconStateElectra;

export type ShufflingGetter = (shufflingEpoch: Epoch, dependentRoot: RootHex) => EpochShuffling | null;
2 changes: 1 addition & 1 deletion packages/state-transition/src/slot/index.ts
Expand Up @@ -7,7 +7,7 @@ export {upgradeStateToAltair} from "./upgradeStateToAltair.js";
export {upgradeStateToBellatrix} from "./upgradeStateToBellatrix.js";
export {upgradeStateToCapella} from "./upgradeStateToCapella.js";
export {upgradeStateToDeneb} from "./upgradeStateToDeneb.js";
export {upgradeStateToVerge} from "./upgradeStateToVerge.js";
export {upgradeStateToElectra} from "./upgradeStateToElectra.js";

/**
* Dial state to next slot. Common for all forks
Expand Down
26 changes: 26 additions & 0 deletions packages/state-transition/src/slot/upgradeStateToElectra.ts
@@ -0,0 +1,26 @@
import {ssz} from "@lodestar/types";
import {CachedBeaconStateCapella, CachedBeaconStateElectra} from "../types.js";
import {getCachedBeaconState} from "../cache/stateCache.js";

/**
* Upgrade a state from Capella (Eventualy DENEB) to Electra.
*/
export function upgradeStateToElectra(stateCapella: CachedBeaconStateCapella): CachedBeaconStateElectra {
const {config} = stateCapella;

const stateCapellaNode = ssz.capella.BeaconState.commitViewDU(stateCapella);
const stateElectraView = ssz.electra.BeaconState.getViewDU(stateCapellaNode);

const stateElectra = getCachedBeaconState(stateElectraView, stateCapella);

stateElectra.fork = ssz.phase0.Fork.toViewDU({
previousVersion: stateCapella.fork.currentVersion,
currentVersion: config.ELECTRA_FORK_VERSION,
epoch: stateCapella.epochCtx.epoch,
});

// latestExecutionPayloadHeader's executionWitnessRoot will have default zero root

stateElectra.commit();
return stateElectra;
}
26 changes: 0 additions & 26 deletions packages/state-transition/src/slot/upgradeStateToVerge.ts

This file was deleted.

0 comments on commit 815364b

Please sign in to comment.