Skip to content

Commit

Permalink
refactor: move WithBytes to types package (#7201)
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig authored Oct 28, 2024
1 parent 4c757cb commit 3cd2f16
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 12 deletions.
3 changes: 1 addition & 2 deletions packages/beacon-node/src/network/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
deneb,
phase0,
SignedAggregateAndProof,
WithBytes,
} from "@lodestar/types";
import {PeerIdStr} from "../util/peerId.js";
import {INetworkEventBus} from "./events.js";
Expand All @@ -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<T> = {data: T; bytes: Uint8Array};

/**
* The architecture of the network looks like so:
* - core:
Expand Down
3 changes: 2 additions & 1 deletion packages/beacon-node/src/network/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
LightClientOptimisticUpdate,
LightClientUpdate,
SignedAggregateAndProof,
WithBytes,
} from "@lodestar/types";
import {routes} from "@lodestar/api";
import {ResponseIncoming} from "@lodestar/reqresp";
Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/network/reqresp/utils/collect.ts
Original file line number Diff line number Diff line change
@@ -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 `<response_chunk>*`, from
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
3 changes: 1 addition & 2 deletions packages/beacon-node/src/sync/backfill/verify.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
3 changes: 1 addition & 2 deletions packages/beacon-node/test/unit/sync/backfill/verify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
6 changes: 6 additions & 0 deletions packages/types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export enum ProducedBlockSource {
engine = "engine",
}

export type WithBytes<T> = {
data: T;
/** SSZ serialized `data` bytes */
bytes: Uint8Array;
};

export type WithOptionalBytes<T> = {
data: T;
/** SSZ serialized `data` bytes */
Expand Down

0 comments on commit 3cd2f16

Please sign in to comment.