Skip to content

Commit

Permalink
Fix the types
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarhussain committed Jul 1, 2024
1 parent d4e8b9f commit d5a07e6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
4 changes: 2 additions & 2 deletions packages/beacon-node/src/db/repositories/blockArchive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class BlockArchiveRepository extends Repository<Slot, FullOrBlindedSigned
async remove(value: FullOrBlindedSignedBeaconBlock): Promise<void> {
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),
]);
}
Expand All @@ -100,7 +100,7 @@ export class BlockArchiveRepository extends Repository<Slot, FullOrBlindedSigned
await Promise.all([
super.batchRemove(values),
Array.from(values).map((value) =>
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)),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function deleteRootIndex(
signedBeaconBlockType: SSZTypesFor<ForkAll, "SignedBeaconBlock">,
block: FullOrBlindedSignedBeaconBlock
): Promise<void> {
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<void> {
Expand Down
12 changes: 5 additions & 7 deletions packages/beacon-node/src/util/fullOrBlindedBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}

Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 3 additions & 7 deletions packages/types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,9 @@ export type BlindedBeaconBlock<F extends ForkExecution = ForkExecution> = TypesB
export type SignedBeaconBlock<F extends ForkAll = ForkAll> = TypesByFork[F]["SignedBeaconBlock"];
export type SignedBlindedBeaconBlock<F extends ForkExecution = ForkExecution> =
TypesByFork[F]["SignedBlindedBeaconBlock"];
export type FullOrBlindedSignedBeaconBlockPreExecution<F extends ForkPreExecution = ForkPreExecution> =
TypesByFork[F]["SignedBeaconBlock"];
export type FullOrBlindedSignedBeaconBlockExecution<F extends ForkExecution = ForkExecution> =
TypesByFork[F]["FullOrBlindedSignedBeaconBlock"];
export type FullOrBlindedSignedBeaconBlock =
| FullOrBlindedSignedBeaconBlockPreExecution
| FullOrBlindedSignedBeaconBlockExecution;
export type FullOrBlindedSignedBeaconBlock<F extends ForkAll = ForkAll, E extends ForkExecution = ForkExecution> =
| SignedBeaconBlock<F>
| SignedBlindedBeaconBlock<E>;

export type BeaconBlockBody<F extends ForkAll = ForkAll> = TypesByFork[F]["BeaconBlockBody"];
export type BlindedBeaconBlockBody<F extends ForkExecution = ForkExecution> = TypesByFork[F]["BlindedBeaconBlockBody"];
Expand Down

0 comments on commit d5a07e6

Please sign in to comment.