Skip to content

Commit

Permalink
fix: remove redundant filter (#663)
Browse files Browse the repository at this point in the history
Swaps BloomFilter for the ScalableCuckooFilter from `@libp2p/utils`
  • Loading branch information
achingbrain authored Oct 23, 2024
1 parent 23ebae1 commit efc47fa
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 349 deletions.
5 changes: 1 addition & 4 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,10 @@
"@ipld/dag-cbor": "^9.2.0",
"@ipld/dag-json": "^10.2.0",
"@ipld/dag-pb": "^4.1.0",
"@libp2p/crypto": "^5.0.0",
"@libp2p/interface": "^2.0.0",
"@libp2p/logger": "^5.0.0",
"@libp2p/utils": "^6.0.0",
"@multiformats/dns": "^1.0.1",
"@types/murmurhash3js-revisited": "^3.0.3",
"any-signal": "^4.1.1",
"blockstore-core": "^5.0.0",
"cborg": "^4.0.9",
Expand All @@ -76,13 +74,12 @@
"it-merge": "^3.0.3",
"mortice": "^3.0.4",
"multiformats": "^13.1.0",
"murmurhash3js-revisited": "^3.0.0",
"p-defer": "^4.0.1",
"progress-events": "^1.0.0",
"uint8arraylist": "^2.4.8",
"uint8arrays": "^5.0.2"
},
"devDependencies": {
"@libp2p/crypto": "^5.0.0",
"@libp2p/peer-id": "^5.0.0",
"@types/sinon": "^17.0.3",
"aegir": "^44.0.1",
Expand Down
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
Loading

0 comments on commit efc47fa

Please sign in to comment.