From 3cd2f1603f5ca7e4af4ad4ebf5c2f6e4531bf405 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Mon, 28 Oct 2024 18:27:43 +0000 Subject: [PATCH] refactor: move WithBytes to types package (#7201) --- packages/beacon-node/src/network/interface.ts | 3 +-- packages/beacon-node/src/network/network.ts | 3 ++- .../src/network/reqresp/beaconBlocksMaybeBlobsByRange.ts | 4 ++-- packages/beacon-node/src/network/reqresp/utils/collect.ts | 2 +- .../network/reqresp/utils/collectSequentialBlocksInRange.ts | 3 +-- packages/beacon-node/src/sync/backfill/verify.ts | 3 +-- packages/beacon-node/test/unit/sync/backfill/verify.test.ts | 3 +-- packages/types/src/types.ts | 6 ++++++ 8 files changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/beacon-node/src/network/interface.ts b/packages/beacon-node/src/network/interface.ts index 8d73379af221..0d48df42b31e 100644 --- a/packages/beacon-node/src/network/interface.ts +++ b/packages/beacon-node/src/network/interface.ts @@ -27,6 +27,7 @@ import { deneb, phase0, SignedAggregateAndProof, + WithBytes, } from "@lodestar/types"; import {PeerIdStr} from "../util/peerId.js"; import {INetworkEventBus} from "./events.js"; @@ -35,8 +36,6 @@ import {GossipType} from "./gossip/interface.js"; import {PendingGossipsubMessage} from "./processor/types.js"; import {PeerAction} from "./peers/index.js"; -export type WithBytes = {data: T; bytes: Uint8Array}; - /** * The architecture of the network looks like so: * - core: diff --git a/packages/beacon-node/src/network/network.ts b/packages/beacon-node/src/network/network.ts index 1b3ccaaaf75a..15414fcf9138 100644 --- a/packages/beacon-node/src/network/network.ts +++ b/packages/beacon-node/src/network/network.ts @@ -18,6 +18,7 @@ import { LightClientOptimisticUpdate, LightClientUpdate, SignedAggregateAndProof, + WithBytes, } from "@lodestar/types"; import {routes} from "@lodestar/api"; import {ResponseIncoming} from "@lodestar/reqresp"; @@ -28,7 +29,7 @@ import {IBeaconDb} from "../db/interface.js"; import {PeerIdStr, peerIdToString} from "../util/peerId.js"; import {IClock} from "../util/clock.js"; import {NetworkOptions} from "./options.js"; -import {WithBytes, INetwork} from "./interface.js"; +import {INetwork} from "./interface.js"; import {ReqRespMethod} from "./reqresp/index.js"; import {GossipHandlers, GossipTopicMap, GossipType, GossipTypeMap} from "./gossip/index.js"; import {PeerAction, PeerScoreStats} from "./peers/index.js"; diff --git a/packages/beacon-node/src/network/reqresp/beaconBlocksMaybeBlobsByRange.ts b/packages/beacon-node/src/network/reqresp/beaconBlocksMaybeBlobsByRange.ts index 8c69c21679ba..3d71087c8fd8 100644 --- a/packages/beacon-node/src/network/reqresp/beaconBlocksMaybeBlobsByRange.ts +++ b/packages/beacon-node/src/network/reqresp/beaconBlocksMaybeBlobsByRange.ts @@ -1,11 +1,11 @@ import {ChainForkConfig} from "@lodestar/config"; -import {deneb, Epoch, phase0, SignedBeaconBlock, Slot} from "@lodestar/types"; +import {deneb, Epoch, phase0, SignedBeaconBlock, Slot, WithBytes} from "@lodestar/types"; import {ForkSeq} from "@lodestar/params"; import {computeEpochAtSlot} from "@lodestar/state-transition"; import {BlobsSource, BlockInput, BlockSource, getBlockInput, BlockInputDataBlobs} from "../../chain/blocks/types.js"; import {PeerIdStr} from "../../util/peerId.js"; -import {INetwork, WithBytes} from "../interface.js"; +import {INetwork} from "../interface.js"; export async function beaconBlocksMaybeBlobsByRange( config: ChainForkConfig, diff --git a/packages/beacon-node/src/network/reqresp/utils/collect.ts b/packages/beacon-node/src/network/reqresp/utils/collect.ts index 06f3cfc36806..9818b1921f8e 100644 --- a/packages/beacon-node/src/network/reqresp/utils/collect.ts +++ b/packages/beacon-node/src/network/reqresp/utils/collect.ts @@ -1,7 +1,7 @@ import {Type} from "@chainsafe/ssz"; import {ResponseIncoming, RequestErrorCode, RequestError} from "@lodestar/reqresp"; +import {WithBytes} from "@lodestar/types"; import {ResponseTypeGetter} from "../types.js"; -import {WithBytes} from "../../interface.js"; /** * Sink for `*`, from diff --git a/packages/beacon-node/src/network/reqresp/utils/collectSequentialBlocksInRange.ts b/packages/beacon-node/src/network/reqresp/utils/collectSequentialBlocksInRange.ts index c2cf0ad16ea0..2709cb3f64a9 100644 --- a/packages/beacon-node/src/network/reqresp/utils/collectSequentialBlocksInRange.ts +++ b/packages/beacon-node/src/network/reqresp/utils/collectSequentialBlocksInRange.ts @@ -1,7 +1,6 @@ import {ResponseIncoming} from "@lodestar/reqresp"; import {LodestarError} from "@lodestar/utils"; -import {phase0, SignedBeaconBlock} from "@lodestar/types"; -import {WithBytes} from "../../interface.js"; +import {phase0, SignedBeaconBlock, WithBytes} from "@lodestar/types"; import {ReqRespMethod, responseSszTypeByMethod} from "../types.js"; import {sszDeserializeResponse} from "./collect.js"; diff --git a/packages/beacon-node/src/sync/backfill/verify.ts b/packages/beacon-node/src/sync/backfill/verify.ts index 462762a5576f..715cc6621253 100644 --- a/packages/beacon-node/src/sync/backfill/verify.ts +++ b/packages/beacon-node/src/sync/backfill/verify.ts @@ -1,9 +1,8 @@ import {CachedBeaconStateAllForks, ISignatureSet, getBlockProposerSignatureSet} from "@lodestar/state-transition"; import {BeaconConfig} from "@lodestar/config"; -import {Root, ssz, Slot, SignedBeaconBlock} from "@lodestar/types"; +import {Root, ssz, Slot, SignedBeaconBlock, WithBytes} from "@lodestar/types"; import {GENESIS_SLOT} from "@lodestar/params"; import {IBlsVerifier} from "../../chain/bls/index.js"; -import {WithBytes} from "../../network/interface.js"; import {BackfillSyncError, BackfillSyncErrorCode} from "./errors.js"; export type BackfillBlockHeader = { diff --git a/packages/beacon-node/test/unit/sync/backfill/verify.test.ts b/packages/beacon-node/test/unit/sync/backfill/verify.test.ts index bba1f7c93f19..3197013455e3 100644 --- a/packages/beacon-node/test/unit/sync/backfill/verify.test.ts +++ b/packages/beacon-node/test/unit/sync/backfill/verify.test.ts @@ -4,9 +4,8 @@ import {fileURLToPath} from "node:url"; import {describe, it, expect} from "vitest"; import {createBeaconConfig} from "@lodestar/config"; import {config} from "@lodestar/config/default"; -import {phase0, ssz} from "@lodestar/types"; +import {phase0, ssz, WithBytes} from "@lodestar/types"; import {verifyBlockSequence} from "../../../../src/sync/backfill/verify.js"; -import {WithBytes} from "../../../../src/network/interface.js"; import {ZERO_HASH} from "../../../../src/constants/constants.js"; import {BackfillSyncErrorCode, BackfillSyncError} from "./../../../../src/sync/backfill/errors.js"; diff --git a/packages/types/src/types.ts b/packages/types/src/types.ts index 51fa2b12a28e..b1919c2f0842 100644 --- a/packages/types/src/types.ts +++ b/packages/types/src/types.ts @@ -32,6 +32,12 @@ export enum ProducedBlockSource { engine = "engine", } +export type WithBytes = { + data: T; + /** SSZ serialized `data` bytes */ + bytes: Uint8Array; +}; + export type WithOptionalBytes = { data: T; /** SSZ serialized `data` bytes */