From d5a07e6afa2221a8c3dc06f0d1280d86d1c2fca7 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Mon, 1 Jul 2024 15:19:29 +0500 Subject: [PATCH] Fix the types --- .../beacon-node/src/db/repositories/blockArchive.ts | 4 ++-- .../src/db/repositories/blockArchiveIndex.ts | 2 +- packages/beacon-node/src/util/fullOrBlindedBlock.ts | 12 +++++------- packages/types/src/types.ts | 10 +++------- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/packages/beacon-node/src/db/repositories/blockArchive.ts b/packages/beacon-node/src/db/repositories/blockArchive.ts index b8e8bb4bd568..17e23f75b478 100644 --- a/packages/beacon-node/src/db/repositories/blockArchive.ts +++ b/packages/beacon-node/src/db/repositories/blockArchive.ts @@ -91,7 +91,7 @@ export class BlockArchiveRepository extends Repository { await Promise.all([ super.remove(value), - deleteRootIndex(this.db, this.config.getForkTypes(value.message.slot).BeaconBlock, value), + deleteRootIndex(this.db, this.config.getForkTypes(value.message.slot).SignedBeaconBlock, value), deleteParentRootIndex(this.db, value), ]); } @@ -100,7 +100,7 @@ export class BlockArchiveRepository extends Repository - deleteRootIndex(this.db, this.config.getForkTypes(value.message.slot).BeaconBlock, value) + deleteRootIndex(this.db, this.config.getForkTypes(value.message.slot).SignedBeaconBlock, value) ), Array.from(values).map((value) => deleteParentRootIndex(this.db, value)), ]); diff --git a/packages/beacon-node/src/db/repositories/blockArchiveIndex.ts b/packages/beacon-node/src/db/repositories/blockArchiveIndex.ts index e8069befb569..8bc22b9795af 100644 --- a/packages/beacon-node/src/db/repositories/blockArchiveIndex.ts +++ b/packages/beacon-node/src/db/repositories/blockArchiveIndex.ts @@ -17,7 +17,7 @@ export async function deleteRootIndex( signedBeaconBlockType: SSZTypesFor, block: FullOrBlindedSignedBeaconBlock ): Promise { - return db.delete(getRootIndexKey(beaconBlockType.hashTreeRoot(block.message))); + return db.delete(getRootIndexKey(signedBeaconBlockType.hashTreeRoot(block.message))); } export async function deleteParentRootIndex(db: Db, block: FullOrBlindedSignedBeaconBlock): Promise { diff --git a/packages/beacon-node/src/util/fullOrBlindedBlock.ts b/packages/beacon-node/src/util/fullOrBlindedBlock.ts index 9aa6aa216e67..045cd851d418 100644 --- a/packages/beacon-node/src/util/fullOrBlindedBlock.ts +++ b/packages/beacon-node/src/util/fullOrBlindedBlock.ts @@ -8,8 +8,6 @@ import { SignedBeaconBlock, SignedBlindedBeaconBlock, FullOrBlindedSignedBeaconBlock, - FullOrBlindedSignedBeaconBlockExecution, - FullOrBlindedSignedBeaconBlockPreExecution, } from "@lodestar/types"; import {BYTES_PER_LOGS_BLOOM, ForkSeq, SYNC_COMMITTEE_SIZE} from "@lodestar/params"; import {executionPayloadToPayloadHeader} from "@lodestar/state-transition"; @@ -129,7 +127,7 @@ export function isBlindedBytes(forkSeq: ForkSeq, blockBytes: Uint8Array): boolea } // same as isBlindedSignedBeaconBlock but without type narrowing -export function isBlinded(block: FullOrBlindedSignedBeaconBlock): boolean { +export function isBlinded(block: FullOrBlindedSignedBeaconBlock): block is SignedBlindedBeaconBlock { return (block as bellatrix.SignedBlindedBeaconBlock).message.body.executionPayloadHeader !== undefined; } @@ -138,11 +136,11 @@ export function serializeFullOrBlindedSignedBeaconBlock( value: FullOrBlindedSignedBeaconBlock ): Uint8Array { if (isBlinded(value)) { - const type = config.getExecutionForkTypes(value.message.slot).SignedBeaconBlock; - return type.serialize(value as SignedBeaconBlock); + const type = config.getExecutionForkTypes(value.message.slot).SignedBlindedBeaconBlock; + return type.serialize(value); } const type = config.getForkTypes(value.message.slot).SignedBeaconBlock; - return type.serialize(value as FullOrBlindedSignedBeaconBlockPreExecution); + return type.serialize(value); } export function deserializeFullOrBlindedSignedBeaconBlock( @@ -263,7 +261,7 @@ export function blindedOrFullBlockToFull( message: { ...block.message, body: { - ...(block.message.body as bellatrix.BeaconBlockBody), + ...block.message.body, executionPayload: executionPayloadHeaderToPayload( forkSeq, (block.message.body as bellatrix.BlindedBeaconBlockBody).executionPayloadHeader, diff --git a/packages/types/src/types.ts b/packages/types/src/types.ts index 2a34d69d7ce0..2f32339ae12c 100644 --- a/packages/types/src/types.ts +++ b/packages/types/src/types.ts @@ -162,13 +162,9 @@ export type BlindedBeaconBlock = TypesB export type SignedBeaconBlock = TypesByFork[F]["SignedBeaconBlock"]; export type SignedBlindedBeaconBlock = TypesByFork[F]["SignedBlindedBeaconBlock"]; -export type FullOrBlindedSignedBeaconBlockPreExecution = - TypesByFork[F]["SignedBeaconBlock"]; -export type FullOrBlindedSignedBeaconBlockExecution = - TypesByFork[F]["FullOrBlindedSignedBeaconBlock"]; -export type FullOrBlindedSignedBeaconBlock = - | FullOrBlindedSignedBeaconBlockPreExecution - | FullOrBlindedSignedBeaconBlockExecution; +export type FullOrBlindedSignedBeaconBlock = + | SignedBeaconBlock + | SignedBlindedBeaconBlock; export type BeaconBlockBody = TypesByFork[F]["BeaconBlockBody"]; export type BlindedBeaconBlockBody = TypesByFork[F]["BlindedBeaconBlockBody"];