Skip to content

Commit

Permalink
upgrade the blocktype on lightclient server import block
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed Jan 20, 2023
1 parent 4319343 commit 74af4da
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/beacon-node/src/chain/blocks/importBlock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {altair, capella, ssz} from "@lodestar/types";
import {capella, ssz, allForks} from "@lodestar/types";
import {MAX_SEED_LOOKAHEAD, SLOTS_PER_EPOCH} from "@lodestar/params";
import {toHexString} from "@chainsafe/ssz";
import {
Expand Down Expand Up @@ -275,7 +275,7 @@ export async function importBlock(
if (blockEpoch >= this.config.ALTAIR_FORK_EPOCH) {
try {
this.lightClientServer.onImportBlockHead(
block.message as altair.BeaconBlock,
block.message as allForks.AllForksLightClient["BeaconBlock"],
postState as CachedBeaconStateAltair,
parentBlockSlot
);
Expand Down
8 changes: 6 additions & 2 deletions packages/beacon-node/src/chain/lightClient/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {altair, phase0, Root, RootHex, Slot, ssz, SyncPeriod} from "@lodestar/types";
import {altair, phase0, Root, RootHex, Slot, ssz, SyncPeriod, allForks} from "@lodestar/types";
import {IChainForkConfig} from "@lodestar/config";
import {
CachedBeaconStateAltair,
Expand Down Expand Up @@ -212,7 +212,11 @@ export class LightClientServer {
* - Persist state witness
* - Use block's syncAggregate
*/
onImportBlockHead(block: altair.BeaconBlock, postState: CachedBeaconStateAltair, parentBlockSlot: Slot): void {
onImportBlockHead(
block: allForks.AllForksLightClient["BeaconBlock"],
postState: CachedBeaconStateAltair,
parentBlockSlot: Slot
): void {
// TEMP: To disable this functionality for fork_choice spec tests.
// Since the tests have deep-reorgs attested data is not available often printing lots of error logs.
// While this function is only called for head blocks, best to disable.
Expand Down
4 changes: 4 additions & 0 deletions packages/types/src/allForks/sszTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export const allForksBlinded = {

export const allForksLightClient = {
altair: {
BeaconBlock: altair.BeaconBlock,
LightClientHeader: altair.LightClientHeader,
LightClientBootstrap: altair.LightClientBootstrap,
LightClientUpdate: altair.LightClientUpdate,
Expand All @@ -116,6 +117,7 @@ export const allForksLightClient = {
LightClientStore: altair.LightClientStore,
},
bellatrix: {
BeaconBlock: bellatrix.BeaconBlock,
LightClientHeader: altair.LightClientHeader,
LightClientBootstrap: altair.LightClientBootstrap,
LightClientUpdate: altair.LightClientUpdate,
Expand All @@ -124,6 +126,7 @@ export const allForksLightClient = {
LightClientStore: altair.LightClientStore,
},
capella: {
BeaconBlock: capella.BeaconBlock,
LightClientHeader: capella.LightClientHeader,
LightClientBootstrap: capella.LightClientBootstrap,
LightClientUpdate: capella.LightClientUpdate,
Expand All @@ -132,6 +135,7 @@ export const allForksLightClient = {
LightClientStore: capella.LightClientStore,
},
eip4844: {
BeaconBlock: eip4844.BeaconBlock,
LightClientHeader: eip4844.LightClientHeader,
LightClientBootstrap: eip4844.LightClientBootstrap,
LightClientUpdate: eip4844.LightClientUpdate,
Expand Down
9 changes: 9 additions & 0 deletions packages/types/src/allForks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,13 @@ export type AllForksBlindedTypes = {
};

export type AllForksLightClient = {
BeaconBlock: altair.BeaconBlock | bellatrix.BeaconBlock | capella.BeaconBlock | eip4844.BeaconBlock;
LightClientHeader: LightClientHeader;
LightClientBootstrap: LightClientBootstrap;
LightClientUpdate: LightClientUpdate;
LightClientFinalityUpdate: LightClientFinalityUpdate;
LightClientOptimisticUpdate: LightClientOptimisticUpdate;
LightClientStore: LightClientStore;
};

/**
Expand Down Expand Up @@ -222,6 +228,9 @@ export type AllForksBlindedSSZTypes = {
};

export type AllForksLightClientSSZTypes = {
BeaconBlock: AllForksTypeOf<
typeof altairSsz.BeaconBlock | typeof capellaSsz.BeaconBlock | typeof eip4844Ssz.BeaconBlock
>;
LightClientHeader: AllForksTypeOf<
typeof altairSsz.LightClientHeader | typeof capellaSsz.LightClientHeader | typeof eip4844Ssz.LightClientHeader
>;
Expand Down

0 comments on commit 74af4da

Please sign in to comment.