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

feat: placeholder PR for verge #5805

Closed
wants to merge 6 commits into from
Closed
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
14 changes: 7 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

# --platform=$BUILDPLATFORM is used build javascript source with host arch
# Otherwise TS builds on emulated archs and can be extremely slow (+1h)
FROM --platform=${BUILDPLATFORM:-amd64} node:20-alpine as build_src
FROM --platform=${BUILDPLATFORM:-amd64} node:20-slim AS build_src
ARG COMMIT
WORKDIR /usr/app
RUN apk update && apk add --no-cache g++ make python3 && rm -rf /var/cache/apk/*
RUN apt-get update && apt-get install -y g++ make python3 python3-setuptools && apt-get clean && rm -rf /var/lib/apt/lists/*

COPY . .

Expand All @@ -21,21 +21,21 @@ RUN cd packages/cli && GIT_COMMIT=${COMMIT} yarn write-git-data

# Copy built src + node_modules to build native packages for archs different than host.
# Note: This step is redundant for the host arch
FROM node:20-alpine as build_deps
FROM node:20-slim AS build_deps
WORKDIR /usr/app
RUN apk update && apk add --no-cache g++ make python3 && rm -rf /var/cache/apk/*
RUN apt-get update && apt-get install -y g++ make python3 python3-setuptools && apt-get clean && rm -rf /var/lib/apt/lists/*

COPY --from=build_src /usr/app .

# Do yarn --force to trigger a rebuild of the native packages
# Emmulates `yarn rebuild` which is not available in v1 https://yarnpkg.com/cli/rebuild
# Emmulates `yarn rebuild` which is not available in v1 https://yarnpkg.com/cli/rebuild
RUN yarn install --non-interactive --frozen-lockfile --production --force
# Rebuild leveldb bindings (required for arm64 build)
RUN cd node_modules/classic-level && yarn rebuild

# Copy built src + node_modules to a new layer to prune unnecessary fs
# Previous layer weights 7.25GB, while this final 488MB (as of Oct 2020)
FROM node:20-alpine
FROM node:20-slim
WORKDIR /usr/app
COPY --from=build_deps /usr/app .

Expand All @@ -44,4 +44,4 @@ COPY --from=build_deps /usr/app .
# since memory may spike during certain network conditions.
ENV NODE_OPTIONS=--max-old-space-size=8192

ENTRYPOINT ["node", "./packages/cli/bin/lodestar"]
ENTRYPOINT ["node", "./packages/cli/bin/lodestar"]
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {BlockInput, ImportBlockOpts, BlockInputType} 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 @@ -152,6 +153,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
32 changes: 31 additions & 1 deletion packages/beacon-node/src/execution/engine/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {allForks, capella, deneb, Wei, bellatrix, Root} from "@lodestar/types";
import * as util from "node:util";
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 @@ -134,6 +135,7 @@ export type ExecutionPayloadRpc = {
blobGasUsed?: QUANTITY; // DENEB
excessBlobGas?: QUANTITY; // DENEB
parentBeaconBlockRoot?: QUANTITY; // DENEB
executionWitness?: Record<string, unknown>; // DENEB
};

export type WithdrawalRpc = {
Expand Down Expand Up @@ -194,6 +196,20 @@ export function serializeExecutionPayload(fork: ForkName, data: allForks.Executi
payload.excessBlobGas = numToQuantity(excessBlobGas);
}

// 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.electra.ExecutionWitness.toJson(executionWitness);
// serialization with ssz serialize suffix diff's suffix to a string while geth expects num
(payload.executionWitness as electra.ExecutionWitness).stateDiff.forEach((sDiff) => {
sDiff.suffixDiffs.forEach((sfDiff) => {
sfDiff.suffix = Number(sfDiff.suffix);
});
});
}

return payload;
}

Expand Down Expand Up @@ -279,6 +295,20 @@ export function parseExecutionPayload(
(executionPayload as deneb.ExecutionPayload).excessBlobGas = quantityToBigint(excessBlobGas);
}

// 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;
console.log(
"parse executionWitness from EL",
util.inspect(executionWitness, false, null, true /* enable colors */),
{blockNumber: data.blockNumber}
);
(executionPayload as electra.ExecutionPayload).executionWitness =
ssz.electra.ExecutionWitness.fromJson(executionWitness);
}

return {executionPayload, executionPayloadValue, blobsBundle, shouldOverrideBuilder};
}

Expand Down
3 changes: 3 additions & 0 deletions packages/beacon-node/test/spec/presets/fork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
CachedBeaconStateAltair,
CachedBeaconStatePhase0,
CachedBeaconStateCapella,
CachedBeaconStateDeneb,
} from "@lodestar/state-transition";
import * as slotFns from "@lodestar/state-transition/slot";
import {phase0, ssz} from "@lodestar/types";
Expand Down Expand Up @@ -35,6 +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.electra:
return slotFns.upgradeStateToElectra(preState as CachedBeaconStateDeneb);
}
},
options: {
Expand Down
6 changes: 3 additions & 3 deletions packages/beacon-node/test/spec/presets/genesis.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from "node:path";
import {expect} from "vitest";
import {phase0, Root, ssz, TimeSeconds, allForks, deneb} from "@lodestar/types";
import {phase0, Root, ssz, TimeSeconds, allForks} from "@lodestar/types";
import {InputType} from "@lodestar/spec-test-util";
import {
BeaconStateAllForks,
Expand Down Expand Up @@ -47,7 +47,7 @@ const genesisInitialization: TestRunnerFn<GenesisInitSpecTest, BeaconStateAllFor
genesisValidatorsRoot: Buffer.alloc(32, 0),
});

const executionPayloadHeaderType =
const executionPayloadHeaderType: allForks.AllForksExecutionSSZTypes["ExecutionPayloadHeader"] =
fork !== ForkName.phase0 && fork !== ForkName.altair
? ssz.allForksExecution[fork as ExecutionFork].ExecutionPayloadHeader
: ssz.bellatrix.ExecutionPayloadHeader;
Expand All @@ -60,7 +60,7 @@ const genesisInitialization: TestRunnerFn<GenesisInitSpecTest, BeaconStateAllFor
deposits,
undefined,
testcase["execution_payload_header"] &&
executionPayloadHeaderType.toViewDU(testcase["execution_payload_header"] as deneb.ExecutionPayloadHeader)
executionPayloadHeaderType.toViewDU(testcase["execution_payload_header"])
);
},
// eth1.yaml
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 @@ -27,6 +27,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,6 +36,7 @@ describe("UpgradeLightClientHeader", function () {
bellatrix: 17,
capella: 25,
deneb: 33,
electra: 41,
};
});

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, 4]),
prevVersion: Buffer.from([0, 0, 0, 3]),
prevForkName: ForkName.capella,
},
};
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
3 changes: 3 additions & 0 deletions packages/config/src/chainConfig/configs/minimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export const chainConfig: ChainConfig = {
// Deneb
DENEB_FORK_VERSION: b("0x04000001"),
DENEB_FORK_EPOCH: Infinity,
// Electra
ELECTRA_FORK_VERSION: b("0x05000001"),
ELECTRA_FORK_EPOCH: Infinity,

// Time parameters
// ---------------------------------------------------------------
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.CAPELLA_FORK_VERSION,
prevForkName: ForkName.capella,
};

/** 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, electra, deneb};

// Prevents allocating an array on every getForkInfo() call
const forksAscendingEpochOrder = Object.values(forks);
Expand Down
15 changes: 12 additions & 3 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 @@ -17,7 +18,9 @@ export enum ForkSeq {
altair = 1,
bellatrix = 2,
capella = 3,
deneb = 4,
// Electra is scheduled after capella for now
electra = 4,
deneb = 5,
}

export type ForkPreLightClient = ForkName.phase0;
Expand All @@ -38,8 +41,14 @@ export function isForkWithdrawals(fork: ForkName): fork is ForkWithdrawals {
return isForkExecution(fork) && fork !== ForkName.bellatrix;
}

export type ForkPreBlobs = ForkPreWithdrawals | ForkName.capella;
export type ForkPreVerge = ForkPreWithdrawals | ForkName.capella;
export type ForkVerge = Exclude<ForkName, ForkPreVerge>;
export function isForkVerge(fork: ForkName): fork is ForkVerge {
return isForkWithdrawals(fork) && fork !== ForkName.capella;
}

export type ForkPreBlobs = ForkPreVerge | ForkName.electra;
export type ForkBlobs = Exclude<ForkName, ForkPreBlobs>;
export function isForkBlobs(fork: ForkName): fork is ForkBlobs {
return isForkWithdrawals(fork) && fork !== ForkName.capella;
return isForkVerge(fork) && fork !== ForkName.electra;
}
7 changes: 7 additions & 0 deletions packages/params/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,10 @@ export const KZG_COMMITMENT_SUBTREE_INDEX0 = KZG_COMMITMENT_GINDEX0 - 2 ** KZG_C

// ssz.deneb.BlobSidecars.elementType.fixedSize
export const BLOBSIDECAR_FIXED_SIZE = ACTIVE_PRESET === PresetName.minimal ? 131672 : 131928;

// 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;
export const VERKLE_WIDTH = 256;
export const IPA_PROOF_DEPTH = 8;
2 changes: 2 additions & 0 deletions packages/state-transition/src/cache/stateCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
BeaconStateBellatrix,
BeaconStateCapella,
BeaconStateDeneb,
BeaconStateElectra,
} from "./types.js";
import {RewardCache, createEmptyRewardCache} from "./rewardCache.js";

Expand Down Expand Up @@ -131,6 +132,7 @@ export type CachedBeaconStateAltair = CachedBeaconState<BeaconStateAltair>;
export type CachedBeaconStateBellatrix = CachedBeaconState<BeaconStateBellatrix>;
export type CachedBeaconStateCapella = CachedBeaconState<BeaconStateCapella>;
export type CachedBeaconStateDeneb = CachedBeaconState<BeaconStateDeneb>;
export type CachedBeaconStateElectra = CachedBeaconState<BeaconStateElectra>;

export type CachedBeaconStateAllForks = CachedBeaconState<BeaconStateAllForks>;
export type CachedBeaconStateExecutions = CachedBeaconState<BeaconStateExecutions>;
Expand Down
Loading