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

Rename eip4844 fork as Deneb #5082

Merged
merged 6 commits into from
Jan 31, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/test-sim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ jobs:
run: yarn test:sim:endpoints
working-directory: packages/cli

- name: Sim tests eip4844
run: yarn test:sim:eip4844
- name: Sim tests deneb
run: yarn test:sim:deneb
working-directory: packages/cli

- name: Sim tests backup eth provider
Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/beacon/routes/beacon/block.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ContainerType} from "@chainsafe/ssz";
import {ForkName} from "@lodestar/params";
import {IChainForkConfig} from "@lodestar/config";
import {phase0, allForks, Slot, Root, ssz, RootHex, eip4844} from "@lodestar/types";
import {phase0, allForks, Slot, Root, ssz, RootHex, deneb} from "@lodestar/types";

import {
RoutesData,
Expand Down Expand Up @@ -196,7 +196,7 @@ export type Api = {
blockId: BlockId
): Promise<
ApiClientResponse<{
[HttpStatusCode.OK]: {executionOptimistic: ExecutionOptimistic; data: eip4844.BlobsSidecar};
[HttpStatusCode.OK]: {executionOptimistic: ExecutionOptimistic; data: deneb.BlobsSidecar};
}>
>;
};
Expand Down Expand Up @@ -294,6 +294,6 @@ export function getReturnTypes(): ReturnTypes<Api> {
getBlockHeader: ContainerDataExecutionOptimistic(BeaconHeaderResType),
getBlockHeaders: ContainerDataExecutionOptimistic(ArrayOf(BeaconHeaderResType)),
getBlockRoot: ContainerDataExecutionOptimistic(RootContainer),
getBlobsSidecar: ContainerDataExecutionOptimistic(ssz.eip4844.BlobsSidecar),
getBlobsSidecar: ContainerDataExecutionOptimistic(ssz.deneb.BlobsSidecar),
};
}
2 changes: 1 addition & 1 deletion packages/api/src/builder/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function getReturnTypes(): ReturnTypes<Api> {
submitBlindedBlockV2: WithVersion((fork: ForkName) =>
isForkBlobs(fork)
? ssz.allForksBlobs[fork].SignedBeaconBlockAndBlobsSidecar
: ssz.eip4844.SignedBeaconBlockAndBlobsSidecar
: ssz.deneb.SignedBeaconBlockAndBlobsSidecar
),
};
}
2 changes: 1 addition & 1 deletion packages/api/test/unit/beacon/testData/beacon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const testData: GenericServerTestCases<Api> = {
},
getBlobsSidecar: {
args: ["head"],
res: {executionOptimistic: true, data: ssz.eip4844.BlobsSidecar.defaultValue()},
res: {executionOptimistic: true, data: ssz.deneb.BlobsSidecar.defaultValue()},
},

// pool
Expand Down
6 changes: 3 additions & 3 deletions packages/api/test/unit/builder/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export const testData: GenericServerTestCases<Api> = {
res: {version: ForkName.bellatrix, data: ssz.bellatrix.SignedBuilderBid.defaultValue()},
},
submitBlindedBlock: {
args: [ssz.eip4844.SignedBlindedBeaconBlock.defaultValue()],
args: [ssz.deneb.SignedBlindedBeaconBlock.defaultValue()],
res: {version: ForkName.bellatrix, data: ssz.bellatrix.ExecutionPayload.defaultValue()},
},
submitBlindedBlockV2: {
args: [ssz.eip4844.SignedBlindedBeaconBlock.defaultValue()],
res: {version: ForkName.eip4844, data: ssz.eip4844.SignedBeaconBlockAndBlobsSidecar.defaultValue()},
args: [ssz.deneb.SignedBlindedBeaconBlock.defaultValue()],
res: {version: ForkName.deneb, data: ssz.deneb.SignedBeaconBlockAndBlobsSidecar.defaultValue()},
},
};
16 changes: 8 additions & 8 deletions packages/beacon-node/src/api/impl/beacon/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {routes, ServerApi} from "@lodestar/api";
import {computeTimeAtSlot} from "@lodestar/state-transition";
import {ForkSeq, SLOTS_PER_HISTORICAL_ROOT} from "@lodestar/params";
import {sleep} from "@lodestar/utils";
import {eip4844, allForks} from "@lodestar/types";
import {deneb, allForks} from "@lodestar/types";
import {fromHexString, toHexString} from "@chainsafe/ssz";
import {getBlockInput} from "../../../../chain/blocks/types.js";
import {promiseAllMaybeAsync} from "../../../../util/promises.js";
Expand Down Expand Up @@ -183,7 +183,7 @@ export function getBeaconBlockApi({
const executionBuilder = chain.executionBuilder;
if (!executionBuilder) throw Error("exeutionBuilder required to publish SignedBlindedBeaconBlock");
let signedBlock: allForks.SignedBeaconBlock;
if (config.getForkSeq(signedBlindedBlock.message.slot) >= ForkSeq.eip4844) {
if (config.getForkSeq(signedBlindedBlock.message.slot) >= ForkSeq.deneb) {
const {beaconBlock, blobsSidecar} = await executionBuilder.submitBlindedBlockV2(signedBlindedBlock);
signedBlock = beaconBlock;
// add this blobs to the map for access & broadcasting in publishBlock
Expand Down Expand Up @@ -215,15 +215,15 @@ export function getBeaconBlockApi({

metrics?.registerBeaconBlock(OpSource.api, seenTimestampSec, signedBlock.message);

// TODO EIP-4844: Open question if broadcast to both block topic + block_and_blobs topic
// TODO Deneb: Open question if broadcast to both block topic + block_and_blobs topic
const blockForImport =
config.getForkSeq(signedBlock.message.slot) >= ForkSeq.eip4844
? getBlockInput.postEIP4844(
config.getForkSeq(signedBlock.message.slot) >= ForkSeq.deneb
? getBlockInput.postDeneb(
config,
signedBlock,
chain.getBlobsSidecar(signedBlock.message as eip4844.BeaconBlock)
chain.getBlobsSidecar(signedBlock.message as deneb.BeaconBlock)
)
: getBlockInput.preEIP4844(config, signedBlock);
: getBlockInput.preDeneb(config, signedBlock);

await promiseAllMaybeAsync([
// Send the block, regardless of whether or not it is valid. The API
Expand Down Expand Up @@ -252,7 +252,7 @@ export function getBeaconBlockApi({
blobsSidecar = {
beaconBlockRoot: blockRoot,
beaconBlockSlot: block.message.slot,
blobs: [] as eip4844.Blobs,
blobs: [] as deneb.Blobs,
kzgAggregatedProof: ckzg.computeAggregateKzgProof([]),
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/api/impl/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const specConstants = {
// ## Capella domain types
DOMAIN_BLS_TO_EXECUTION_CHANGE,

// EIP4844 types
// Deneb types
BLOB_TX_TYPE,
VERSIONED_HASH_VERSION_KZG,
};
10 changes: 5 additions & 5 deletions packages/beacon-node/src/chain/archiver/archiveBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function archiveBlocks(
const finalizedNonCanonicalBlocks = forkChoice.getAllNonAncestorBlocks(finalizedCheckpoint.rootHex);

// NOTE: The finalized block will be exactly the first block of `epoch` or previous
const finalizedPostEIP4844 = finalizedCheckpoint.epoch >= config.EIP4844_FORK_EPOCH;
const finalizedPostDeneb = finalizedCheckpoint.epoch >= config.EIP4844_FORK_EPOCH;

const finalizedCanonicalBlockRoots: BlockRootSlot[] = finalizedCanonicalBlocks.map((block) => ({
slot: block.slot,
Expand All @@ -56,7 +56,7 @@ export async function archiveBlocks(
size: finalizedCanonicalBlockRoots.length,
});

if (finalizedPostEIP4844) {
if (finalizedPostDeneb) {
await migrateBlobsSidecarFromHotToColdDb(config, db, finalizedCanonicalBlockRoots);
logger.verbose("Migrated blobsSidecar from hot DB to cold DB");
}
Expand All @@ -72,15 +72,15 @@ export async function archiveBlocks(
slots: finalizedNonCanonicalBlocks.map((summary) => summary.slot).join(","),
});

if (finalizedPostEIP4844) {
if (finalizedPostDeneb) {
await db.blobsSidecar.batchDelete(nonCanonicalBlockRoots);
logger.verbose("Deleted non canonical blobsSider from hot DB");
}
}

// Delete expired blobs
// Keep only `[max(GENESIS_EPOCH, current_epoch - MIN_EPOCHS_FOR_BLOBS_SIDECARS_REQUESTS), current_epoch]`
if (finalizedPostEIP4844) {
if (finalizedPostDeneb) {
const blobsSidecarMinEpoch = currentEpoch - config.MIN_EPOCHS_FOR_BLOBS_SIDECARS_REQUESTS;
if (blobsSidecarMinEpoch >= config.EIP4844_FORK_EPOCH) {
const slotsToDelete = await db.blobsSidecarArchive.keys({lt: computeStartSlotAtEpoch(blobsSidecarMinEpoch)});
Expand Down Expand Up @@ -162,7 +162,7 @@ async function migrateBlobsSidecarFromHotToColdDb(
// load Buffer instead of ssz deserialized to improve performance
const canonicalBlobsSidecarEntries: IKeyValue<Slot, Uint8Array>[] = await Promise.all(
canonicalBlocks
.filter((block) => config.getForkSeq(block.slot) >= ForkSeq.eip4844)
.filter((block) => config.getForkSeq(block.slot) >= ForkSeq.deneb)
.map(async (block) => {
const bytes = await db.blobsSidecar.getBinary(block.root);
if (!bytes) {
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/chain/blocks/importBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export async function importBlock(
root: blockRootHex,
});

if (blockInput.type === BlockInputType.postEIP4844) {
if (blockInput.type === BlockInputType.postDeneb) {
const {blobs} = blockInput;
// NOTE: Old blobs are pruned on archive
await this.db.blobsSidecar.add(blobs);
Expand Down
40 changes: 20 additions & 20 deletions packages/beacon-node/src/chain/blocks/types.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
import {CachedBeaconStateAllForks, computeEpochAtSlot} from "@lodestar/state-transition";
import {MaybeValidExecutionStatus} from "@lodestar/fork-choice";
import {allForks, eip4844, Slot} from "@lodestar/types";
import {allForks, deneb, Slot} from "@lodestar/types";
import {ForkSeq} from "@lodestar/params";
import {IChainForkConfig} from "@lodestar/config";

export enum BlockInputType {
preEIP4844 = "preEIP4844",
postEIP4844 = "postEIP4844",
postEIP4844OldBlobs = "postEIP4844OldBlobs",
preDeneb = "preDeneb",
postDeneb = "postDeneb",
postDenebOldBlobs = "postDenebOldBlobs",
}

export type BlockInput =
| {type: BlockInputType.preEIP4844; block: allForks.SignedBeaconBlock}
| {type: BlockInputType.postEIP4844; block: allForks.SignedBeaconBlock; blobs: eip4844.BlobsSidecar}
| {type: BlockInputType.postEIP4844OldBlobs; block: allForks.SignedBeaconBlock};
| {type: BlockInputType.preDeneb; block: allForks.SignedBeaconBlock}
| {type: BlockInputType.postDeneb; block: allForks.SignedBeaconBlock; blobs: deneb.BlobsSidecar}
| {type: BlockInputType.postDenebOldBlobs; block: allForks.SignedBeaconBlock};

export function blockRequiresBlobs(config: IChainForkConfig, blockSlot: Slot, clockSlot: Slot): boolean {
return (
config.getForkSeq(blockSlot) >= ForkSeq.eip4844 &&
config.getForkSeq(blockSlot) >= ForkSeq.deneb &&
// Only request blobs if they are recent enough
computeEpochAtSlot(blockSlot) >= computeEpochAtSlot(clockSlot) - config.MIN_EPOCHS_FOR_BLOBS_SIDECARS_REQUESTS
);
}

export const getBlockInput = {
preEIP4844(config: IChainForkConfig, block: allForks.SignedBeaconBlock): BlockInput {
if (config.getForkSeq(block.message.slot) >= ForkSeq.eip4844) {
throw Error(`Post EIP4844 block slot ${block.message.slot}`);
preDeneb(config: IChainForkConfig, block: allForks.SignedBeaconBlock): BlockInput {
if (config.getForkSeq(block.message.slot) >= ForkSeq.deneb) {
throw Error(`Post Deneb block slot ${block.message.slot}`);
}
return {
type: BlockInputType.preEIP4844,
type: BlockInputType.preDeneb,
block,
};
},

postEIP4844(config: IChainForkConfig, block: allForks.SignedBeaconBlock, blobs: eip4844.BlobsSidecar): BlockInput {
if (config.getForkSeq(block.message.slot) < ForkSeq.eip4844) {
throw Error(`Pre EIP4844 block slot ${block.message.slot}`);
postDeneb(config: IChainForkConfig, block: allForks.SignedBeaconBlock, blobs: deneb.BlobsSidecar): BlockInput {
if (config.getForkSeq(block.message.slot) < ForkSeq.deneb) {
throw Error(`Pre Deneb block slot ${block.message.slot}`);
}
return {
type: BlockInputType.postEIP4844,
type: BlockInputType.postDeneb,
block,
blobs,
};
},

postEIP4844OldBlobs(config: IChainForkConfig, block: allForks.SignedBeaconBlock): BlockInput {
if (config.getForkSeq(block.message.slot) < ForkSeq.eip4844) {
throw Error(`Pre EIP4844 block slot ${block.message.slot}`);
postDenebOldBlobs(config: IChainForkConfig, block: allForks.SignedBeaconBlock): BlockInput {
if (config.getForkSeq(block.message.slot) < ForkSeq.deneb) {
throw Error(`Pre Deneb block slot ${block.message.slot}`);
}
return {
type: BlockInputType.postEIP4844OldBlobs,
type: BlockInputType.postDenebOldBlobs,
block,
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ExecutionPayloadStatus,
DataAvailableStatus,
} from "@lodestar/state-transition";
import {eip4844} from "@lodestar/types";
import {deneb} from "@lodestar/types";
import {ErrorAborted, ILogger, sleep} from "@lodestar/utils";
import {IChainForkConfig} from "@lodestar/config";
import {IMetrics} from "../../metrics/index.js";
Expand Down Expand Up @@ -39,9 +39,9 @@ export async function verifyBlocksStateTransitionOnly(
const {block} = blocks[i];
const preState = i === 0 ? preState0 : postStates[i - 1];

// TODO EIP-4844: Is the best place here to call validateBlobsSidecar()?
// TODO EIP-4844: Gossip may already call validateBlobsSidecar, add some flag to de-dup from here
// TODO EIP-4844: For sync if this function is expensive, consider adding sleep(0) if metrics show it
// TODO Deneb: Is the best place here to call validateBlobsSidecar()?
// TODO Deneb: Gossip may already call validateBlobsSidecar, add some flag to de-dup from here
// TODO Deneb: For sync if this function is expensive, consider adding sleep(0) if metrics show it
const dataAvailableStatus = maybeValidateBlobs(config, blocks[i], opts);

// STFN - per_slot_processing() + per_block_processing()
Expand All @@ -54,7 +54,7 @@ export async function verifyBlocksStateTransitionOnly(
// NOTE: Assume valid for now while sending payload to execution engine in parallel
// Latter verifyBlocksInEpoch() will make sure that payload is indeed valid
executionPayloadStatus: ExecutionPayloadStatus.valid,
// TODO EIP-4844: Data is validated above for
// TODO Deneb: Data is validated above for
dataAvailableStatus,
// false because it's verified below with better error typing
verifyStateRoot: false,
Expand Down Expand Up @@ -109,28 +109,28 @@ function maybeValidateBlobs(
blockInput: BlockInput,
opts: ImportBlockOpts
): DataAvailableStatus {
// TODO EIP4844: Make switch verify it's exhaustive
// TODO Deneb: Make switch verify it's exhaustive
switch (blockInput.type) {
case BlockInputType.postEIP4844: {
case BlockInputType.postDeneb: {
if (opts.validBlobsSidecar) {
return DataAvailableStatus.available;
}

const {block, blobs} = blockInput;
const blockSlot = block.message.slot;
const {blobKzgCommitments} = (block as eip4844.SignedBeaconBlock).message.body;
const {blobKzgCommitments} = (block as deneb.SignedBeaconBlock).message.body;
const beaconBlockRoot = config.getForkTypes(blockSlot).BeaconBlock.hashTreeRoot(block.message);
// TODO EIP-4844: This function throws un-typed errors
// TODO Deneb: This function throws un-typed errors
validateBlobsSidecar(blockSlot, beaconBlockRoot, blobKzgCommitments, blobs);

return DataAvailableStatus.available;
}

case BlockInputType.preEIP4844:
return DataAvailableStatus.preEIP4844;
case BlockInputType.preDeneb:
return DataAvailableStatus.preDeneb;

// TODO: Ok to assume old data available?
case BlockInputType.postEIP4844OldBlobs:
case BlockInputType.postDenebOldBlobs:
return DataAvailableStatus.available;
}
}
14 changes: 7 additions & 7 deletions packages/beacon-node/src/chain/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
PubkeyIndexMap,
} from "@lodestar/state-transition";
import {IBeaconConfig} from "@lodestar/config";
import {allForks, UintNum64, Root, phase0, Slot, RootHex, Epoch, ValidatorIndex, eip4844, Wei} from "@lodestar/types";
import {allForks, UintNum64, Root, phase0, Slot, RootHex, Epoch, ValidatorIndex, deneb, Wei} from "@lodestar/types";
import {CheckpointWithHex, ExecutionStatus, IForkChoice, ProtoBlock} from "@lodestar/fork-choice";
import {ProcessShutdownCallback} from "@lodestar/validator";
import {ILogger, pruneSetToMax, toHex} from "@lodestar/utils";
Expand Down Expand Up @@ -118,9 +118,9 @@ export class BeaconChain implements IBeaconChain {

readonly beaconProposerCache: BeaconProposerCache;
readonly checkpointBalancesCache: CheckpointBalancesCache;
// TODO EIP-4844: Prune data structure every time period, for both old entries
// TODO DENEB: Prune data structure every time period, for both old entries
/** Map keyed by executionPayload.blockHash of the block for those blobs */
readonly producedBlobsSidecarCache = new Map<RootHex, eip4844.BlobsSidecar>();
readonly producedBlobsSidecarCache = new Map<RootHex, deneb.BlobsSidecar>();
readonly opts: IChainOptions;

protected readonly blockProcessor: BlockProcessor;
Expand Down Expand Up @@ -398,9 +398,9 @@ export class BeaconChain implements IBeaconChain {
// blinded blobs will be fetched and added to this cache later before finally
// publishing the blinded block's full version
if (blobs.type === BlobsResultType.produced) {
// TODO EIP-4844: Prune data structure for max entries
// TODO DENEB: Prune data structure for max entries
this.producedBlobsSidecarCache.set(blobs.blockHash, {
// TODO EIP-4844: Optimize, hashing the full block is not free.
// TODO DENEB: Optimize, hashing the full block is not free.
beaconBlockRoot: this.config.getForkTypes(block.slot).BeaconBlock.hashTreeRoot(block),
beaconBlockSlot: block.slot,
blobs: blobs.blobs,
Expand All @@ -425,7 +425,7 @@ export class BeaconChain implements IBeaconChain {
* kzg_aggregated_proof=compute_proof_from_blobs(blobs),
* )
*/
getBlobsSidecar(beaconBlock: eip4844.BeaconBlock): eip4844.BlobsSidecar {
getBlobsSidecar(beaconBlock: deneb.BeaconBlock): deneb.BlobsSidecar {
const blockHash = toHex(beaconBlock.body.executionPayload.blockHash);
const blobsSidecar = this.producedBlobsSidecarCache.get(blockHash);
if (!blobsSidecar) {
Expand Down Expand Up @@ -649,7 +649,7 @@ export class BeaconChain implements IBeaconChain {
}

// Prune old blobsSidecar for block production, those are only useful on their slot
if (this.config.getForkSeq(slot) >= ForkSeq.eip4844 && this.producedBlobsSidecarCache.size > 0) {
if (this.config.getForkSeq(slot) >= ForkSeq.deneb && this.producedBlobsSidecarCache.size > 0) {
for (const [key, blobsSidecar] of this.producedBlobsSidecarCache) {
if (slot > blobsSidecar.beaconBlockSlot + MAX_RETAINED_SLOTS_CACHED_BLOBS_SIDECAR) {
this.producedBlobsSidecarCache.delete(key);
Expand Down
6 changes: 3 additions & 3 deletions packages/beacon-node/src/chain/interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {allForks, UintNum64, Root, phase0, Slot, RootHex, Epoch, ValidatorIndex, eip4844, Wei} from "@lodestar/types";
import {allForks, UintNum64, Root, phase0, Slot, RootHex, Epoch, ValidatorIndex, deneb, Wei} from "@lodestar/types";
import {CachedBeaconStateAllForks} from "@lodestar/state-transition";
import {IBeaconConfig} from "@lodestar/config";
import {CompositeTypeAny, TreeView, Type} from "@chainsafe/ssz";
Expand Down Expand Up @@ -88,7 +88,7 @@ export interface IBeaconChain {

readonly beaconProposerCache: BeaconProposerCache;
readonly checkpointBalancesCache: CheckpointBalancesCache;
readonly producedBlobsSidecarCache: Map<RootHex, eip4844.BlobsSidecar>;
readonly producedBlobsSidecarCache: Map<RootHex, deneb.BlobsSidecar>;
readonly opts: IChainOptions;

/** Stop beacon chain processing */
Expand All @@ -111,7 +111,7 @@ export interface IBeaconChain {
*/
getCanonicalBlockAtSlot(slot: Slot): Promise<allForks.SignedBeaconBlock | null>;

getBlobsSidecar(beaconBlock: eip4844.BeaconBlock): eip4844.BlobsSidecar;
getBlobsSidecar(beaconBlock: deneb.BeaconBlock): deneb.BlobsSidecar;

produceBlock(blockAttributes: BlockAttributes): Promise<{block: allForks.BeaconBlock; blockValue: Wei}>;
produceBlindedBlock(blockAttributes: BlockAttributes): Promise<{block: allForks.BlindedBeaconBlock; blockValue: Wei}>;
Expand Down
Loading