Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shouldRefresh flag #675

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading