From 0e803d038b7cdaac0fe24015e5e51aa131659f77 Mon Sep 17 00:00:00 2001 From: dapplion <35266934+dapplion@users.noreply.github.com> Date: Wed, 1 Mar 2023 10:21:13 +0800 Subject: [PATCH] Pass test gossipHandlers --- packages/beacon-node/src/network/network.ts | 3 ++- packages/beacon-node/src/network/processor/worker.ts | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/beacon-node/src/network/network.ts b/packages/beacon-node/src/network/network.ts index 4911bcdee40a..cef0090ae669 100644 --- a/packages/beacon-node/src/network/network.ts +++ b/packages/beacon-node/src/network/network.ts @@ -151,6 +151,7 @@ export class Network implements INetwork { chain, reqRespHandlers, signal, + gossipHandlers, }: NetworkInitModules): Promise { const clock = chain.clock; const peersData = new PeersData(); @@ -229,7 +230,7 @@ export class Network implements INetwork { ); const networkProcessor = new NetworkProcessor( - {attnetsService, chain, config, logger, metrics, peerRpcScores, events: networkEventBus}, + {attnetsService, chain, config, logger, metrics, peerRpcScores, events: networkEventBus, gossipHandlers}, opts ); diff --git a/packages/beacon-node/src/network/processor/worker.ts b/packages/beacon-node/src/network/processor/worker.ts index 3506acd09bb6..64edfbf37077 100644 --- a/packages/beacon-node/src/network/processor/worker.ts +++ b/packages/beacon-node/src/network/processor/worker.ts @@ -1,7 +1,7 @@ import {IBeaconChain} from "../../chain/interface.js"; import {Metrics} from "../../metrics/metrics.js"; import {NetworkEvent, NetworkEventBus} from "../events.js"; -import {GossipValidatorFn} from "../gossip/interface.js"; +import {GossipHandlers, GossipValidatorFn} from "../gossip/interface.js"; import {getGossipHandlers, GossipHandlerOpts, ValidatorFnsModules} from "./gossipHandlers.js"; import {getGossipValidatorFn, ValidatorFnModules} from "./gossipValidatorFn.js"; import {PendingGossipsubMessage} from "./types.js"; @@ -11,6 +11,8 @@ export type NetworkWorkerModules = ValidatorFnsModules & chain: IBeaconChain; events: NetworkEventBus; metrics: Metrics | null; + // Optionally pass custom GossipHandlers, for testing + gossipHandlers?: GossipHandlers; }; export class NetworkWorker { @@ -21,7 +23,7 @@ export class NetworkWorker { constructor(modules: NetworkWorkerModules, opts: GossipHandlerOpts) { this.events = modules.events; this.metrics = modules.metrics; - this.gossipValidatorFn = getGossipValidatorFn(getGossipHandlers(modules, opts), modules); + this.gossipValidatorFn = getGossipValidatorFn(modules.gossipHandlers ?? getGossipHandlers(modules, opts), modules); } async processPendingGossipsubMessage(message: PendingGossipsubMessage): Promise {