Skip to content

Commit

Permalink
fix: remove redundant filter
Browse files Browse the repository at this point in the history
Swaps BloomFilter for the ScalableCuckooFilter from `@libp2p/utils`
  • Loading branch information
achingbrain committed Oct 23, 2024
1 parent 8364296 commit 0be2f87
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 345 deletions.
7 changes: 4 additions & 3 deletions packages/utils/src/abstract-session.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { DEFAULT_SESSION_MIN_PROVIDERS, DEFAULT_SESSION_MAX_PROVIDERS, InsufficientProvidersError } from '@helia/interface'
import { TypedEventEmitter, setMaxListeners } from '@libp2p/interface'
import { createScalableCuckooFilter } from '@libp2p/utils/filters'
import { Queue } from '@libp2p/utils/queue'
import { base64 } from 'multiformats/bases/base64'
import pDefer from 'p-defer'
import { BloomFilter } from './bloom-filter.js'
import type { BlockBroker, BlockRetrievalOptions, CreateSessionOptions } from '@helia/interface'
import type { AbortOptions, ComponentLogger, Logger } from '@libp2p/interface'
import type { Filter } from '@libp2p/utils/filters'
import type { CID } from 'multiformats/cid'
import type { DeferredPromise } from 'p-defer'
import type { ProgressEvent } from 'progress-events'
Expand All @@ -31,7 +32,7 @@ export abstract class AbstractSession<Provider, RetrieveBlockProgressEvents exte
private readonly minProviders: number
private readonly maxProviders: number
public readonly providers: Provider[]
private readonly evictionFilter: BloomFilter
private readonly evictionFilter: Filter

constructor (components: AbstractSessionComponents, init: AbstractCreateSessionOptions) {
super()
Expand All @@ -44,7 +45,7 @@ export abstract class AbstractSession<Provider, RetrieveBlockProgressEvents exte
this.minProviders = init.minProviders ?? DEFAULT_SESSION_MIN_PROVIDERS
this.maxProviders = init.maxProviders ?? DEFAULT_SESSION_MAX_PROVIDERS
this.providers = []
this.evictionFilter = BloomFilter.create(this.maxProviders)
this.evictionFilter = createScalableCuckooFilter(this.maxProviders)
}

async retrieve (cid: CID, options: BlockRetrievalOptions<RetrieveBlockProgressEvents> = {}): Promise<Uint8Array> {
Expand Down
141 changes: 0 additions & 141 deletions packages/utils/src/bloom-filter.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ import type { MultihashHasher } from 'multiformats/hashes/interface'

export { AbstractSession } from './abstract-session.js'
export type { AbstractCreateSessionOptions, BlockstoreSessionEvents, AbstractSessionComponents } from './abstract-session.js'
export { BloomFilter } from './bloom-filter.js'
export type { BloomFilterOptions } from './bloom-filter.js'

export type { BlockStorage, BlockStorageInit }

Expand Down
199 changes: 0 additions & 199 deletions packages/utils/test/bloom-filter.spec.ts

This file was deleted.

0 comments on commit 0be2f87

Please sign in to comment.