From df4ecf5961d6d37a8c4997fe7d187f569b9dbd08 Mon Sep 17 00:00:00 2001 From: acolytec3 <17355484+acolytec3@users.noreply.github.com> Date: Wed, 20 Nov 2024 12:23:16 -0500 Subject: [PATCH] add shouldRefresh flag --- packages/portalnetwork/src/client/client.ts | 5 ++++- packages/portalnetwork/src/client/types.ts | 1 + packages/portalnetwork/test/integration/state.spec.ts | 2 -- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/portalnetwork/src/client/client.ts b/packages/portalnetwork/src/client/client.ts index d06a5300d..649b4194d 100644 --- a/packages/portalnetwork/src/client/client.ts +++ b/packages/portalnetwork/src/client/client.ts @@ -45,6 +45,7 @@ export class PortalNetwork extends (EventEmitter as { new (): PortalNetworkEvent private refreshListeners: Map> private supportsRendezvous: boolean private unverifiedSessionCache: LRUCache + shouldRefresh: boolean = true public static create = async (opts: Partial) => { const defaultConfig: IDiscv5CreateOptions = { @@ -268,6 +269,8 @@ export class PortalNetwork extends (EventEmitter as { new (): PortalNetworkEvent this.metrics?.currentDBSize.set(await this.db.currentSize()) } } + // Should refresh by default but can be disabled (e.g. in tests) + opts.shouldRefresh === false && (this.shouldRefresh = false) } /** @@ -288,7 +291,7 @@ export class PortalNetwork extends (EventEmitter as { new (): PortalNetworkEvent if (network instanceof HistoryNetwork) { network.blockHashIndex = storedIndex } - network.startRefresh() + this.shouldRefresh && network.startRefresh() await network.prune() } void this.bootstrap() diff --git a/packages/portalnetwork/src/client/types.ts b/packages/portalnetwork/src/client/types.ts index 1b19ed115..3a97380ac 100644 --- a/packages/portalnetwork/src/client/types.ts +++ b/packages/portalnetwork/src/client/types.ts @@ -45,6 +45,7 @@ export interface PortalNetworkOpts { trustedBlockRoot?: string eventLog?: boolean utpTimeout?: number + shouldRefresh?: boolean } export type PortalNetworkEventEmitter = StrictEventEmitter diff --git a/packages/portalnetwork/test/integration/state.spec.ts b/packages/portalnetwork/test/integration/state.spec.ts index ae3b7eedd..c5a785852 100644 --- a/packages/portalnetwork/test/integration/state.spec.ts +++ b/packages/portalnetwork/test/integration/state.spec.ts @@ -63,8 +63,6 @@ describe('AccountTrieNode Gossip / Request', async () => { const network1 = node1.networks.get(NetworkId.StateNetwork) as StateNetwork const network2 = node2.networks.get(NetworkId.StateNetwork) as StateNetwork - network1.startRefresh = () => {} // Disable for test since causes occasional timeouts - network2.startRefresh = () => {} // Disable for test since causes occasional timeouts await node1.start() await node2.start() network1.nodeRadius = 2n ** 254n - 1n