Skip to content

Commit

Permalink
add shouldRefresh flag (#675)
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 authored Dec 3, 2024
1 parent df027ce commit be3c0d2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/portalnetwork/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class PortalNetwork extends (EventEmitter as { new (): PortalNetworkEvent
private refreshListeners: Map<NetworkId, ReturnType<typeof setInterval>>
private supportsRendezvous: boolean
private unverifiedSessionCache: LRUCache<NodeId, Multiaddr>
shouldRefresh: boolean = true

public static create = async (opts: Partial<PortalNetworkOpts>) => {
const defaultConfig: IDiscv5CreateOptions = {
Expand Down Expand Up @@ -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)
}

/**
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions packages/portalnetwork/src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface PortalNetworkOpts {
trustedBlockRoot?: string
eventLog?: boolean
utpTimeout?: number
shouldRefresh?: boolean
}

export type PortalNetworkEventEmitter = StrictEventEmitter<EventEmitter, PortalNetworkEvents>
Expand Down
2 changes: 0 additions & 2 deletions packages/portalnetwork/test/integration/state.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit be3c0d2

Please sign in to comment.