Skip to content

Commit efc47fa

Browse files
authored
fix: remove redundant filter (#663)
Swaps BloomFilter for the ScalableCuckooFilter from `@libp2p/utils`
1 parent 23ebae1 commit efc47fa

File tree

5 files changed

+5
-349
lines changed

5 files changed

+5
-349
lines changed

packages/utils/package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,10 @@
5858
"@ipld/dag-cbor": "^9.2.0",
5959
"@ipld/dag-json": "^10.2.0",
6060
"@ipld/dag-pb": "^4.1.0",
61-
"@libp2p/crypto": "^5.0.0",
6261
"@libp2p/interface": "^2.0.0",
6362
"@libp2p/logger": "^5.0.0",
6463
"@libp2p/utils": "^6.0.0",
6564
"@multiformats/dns": "^1.0.1",
66-
"@types/murmurhash3js-revisited": "^3.0.3",
6765
"any-signal": "^4.1.1",
6866
"blockstore-core": "^5.0.0",
6967
"cborg": "^4.0.9",
@@ -76,13 +74,12 @@
7674
"it-merge": "^3.0.3",
7775
"mortice": "^3.0.4",
7876
"multiformats": "^13.1.0",
79-
"murmurhash3js-revisited": "^3.0.0",
8077
"p-defer": "^4.0.1",
8178
"progress-events": "^1.0.0",
82-
"uint8arraylist": "^2.4.8",
8379
"uint8arrays": "^5.0.2"
8480
},
8581
"devDependencies": {
82+
"@libp2p/crypto": "^5.0.0",
8683
"@libp2p/peer-id": "^5.0.0",
8784
"@types/sinon": "^17.0.3",
8885
"aegir": "^44.0.1",

packages/utils/src/abstract-session.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { DEFAULT_SESSION_MIN_PROVIDERS, DEFAULT_SESSION_MAX_PROVIDERS, InsufficientProvidersError } from '@helia/interface'
22
import { TypedEventEmitter, setMaxListeners } from '@libp2p/interface'
3+
import { createScalableCuckooFilter } from '@libp2p/utils/filters'
34
import { Queue } from '@libp2p/utils/queue'
45
import { base64 } from 'multiformats/bases/base64'
56
import pDefer from 'p-defer'
6-
import { BloomFilter } from './bloom-filter.js'
77
import type { BlockBroker, BlockRetrievalOptions, CreateSessionOptions } from '@helia/interface'
88
import type { AbortOptions, ComponentLogger, Logger } from '@libp2p/interface'
9+
import type { Filter } from '@libp2p/utils/filters'
910
import type { CID } from 'multiformats/cid'
1011
import type { DeferredPromise } from 'p-defer'
1112
import type { ProgressEvent } from 'progress-events'
@@ -31,7 +32,7 @@ export abstract class AbstractSession<Provider, RetrieveBlockProgressEvents exte
3132
private readonly minProviders: number
3233
private readonly maxProviders: number
3334
public readonly providers: Provider[]
34-
private readonly evictionFilter: BloomFilter
35+
private readonly evictionFilter: Filter
3536

3637
constructor (components: AbstractSessionComponents, init: AbstractCreateSessionOptions) {
3738
super()
@@ -44,7 +45,7 @@ export abstract class AbstractSession<Provider, RetrieveBlockProgressEvents exte
4445
this.minProviders = init.minProviders ?? DEFAULT_SESSION_MIN_PROVIDERS
4546
this.maxProviders = init.maxProviders ?? DEFAULT_SESSION_MAX_PROVIDERS
4647
this.providers = []
47-
this.evictionFilter = BloomFilter.create(this.maxProviders)
48+
this.evictionFilter = createScalableCuckooFilter(this.maxProviders)
4849
}
4950

5051
async retrieve (cid: CID, options: BlockRetrievalOptions<RetrieveBlockProgressEvents> = {}): Promise<Uint8Array> {

packages/utils/src/bloom-filter.ts

-141
This file was deleted.

packages/utils/src/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ import type { MultihashHasher } from 'multiformats/hashes/interface'
4444

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

5048
export type { BlockStorage, BlockStorageInit }
5149

0 commit comments

Comments
 (0)