Skip to content

Commit 3dcff60

Browse files
committed
feat: refactor discovery to use effect
1 parent 4997440 commit 3dcff60

38 files changed

+6261
-134
lines changed

package-lock.json

Lines changed: 430 additions & 125 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/discovery/.eslintignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Ignore all test and example files in Effect directory
2+
src/effect/**/*.spec.ts
3+
src/effect/**/*.test.ts
4+
src/effect/**/test-*.ts
5+
src/effect/**/*-test.ts
6+
src/effect/**/*-example.ts
7+
src/effect/test-utils.ts
8+
src/effect/discovery-test.ts
9+
src/effect/minimal-test.ts
10+
src/effect/simple-test.ts
11+
src/effect/standalone-test.ts
12+
src/effect/working-example.ts
13+
src/effect/basic.spec.ts
14+
src/effect/cache.spec.ts
15+
src/effect/dns-discovery.spec.ts
16+
src/effect/integration.spec.ts
17+
src/effect/peer-exchange.spec.ts

packages/discovery/.mocharc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const config = {
22
extension: ['ts'],
33
spec: 'src/**/*.spec.ts',
4+
ignore: 'src/effect/**/*.spec.ts',
45
require: ['ts-node/register', 'isomorphic-fetch'],
56
loader: 'ts-node/esm',
67
'node-option': [

packages/discovery/package.json

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,34 +51,44 @@
5151
"node": ">=20"
5252
},
5353
"dependencies": {
54-
"@waku/core": "0.0.35",
55-
"@waku/enr": "0.0.29",
56-
"@waku/interfaces": "0.0.30",
54+
"@effect/platform": "^0.84.9",
55+
"@effect/schema": "^0.75.5",
56+
"@waku/core": "^0.0.35",
57+
"@waku/enr": "^0.0.29",
58+
"@waku/interfaces": "^0.0.30",
5759
"@waku/proto": "^0.0.10",
58-
"@waku/utils": "0.0.23",
60+
"@waku/utils": "^0.0.23",
5961
"debug": "^4.3.4",
6062
"dns-over-http-resolver": "^3.0.8",
63+
"effect": "^3.16.5",
6164
"hi-base32": "^0.5.1",
6265
"uint8arrays": "^5.0.1"
6366
},
6467
"devDependencies": {
6568
"@libp2p/interface": "^2.1.3",
6669
"@libp2p/peer-id": "5.0.1",
70+
"@libp2p/peer-id-factory": "^4.2.4",
71+
"@libp2p/peer-store": "^11.2.3",
6772
"@multiformats/multiaddr": "^12.3.0",
6873
"@rollup/plugin-commonjs": "^25.0.7",
6974
"@rollup/plugin-json": "^6.0.0",
7075
"@rollup/plugin-node-resolve": "^15.2.3",
71-
"@types/chai": "^4.3.11",
76+
"@types/chai": "^4.3.20",
77+
"@types/mocha": "^10.0.10",
7278
"@types/node-localstorage": "^1.3.3",
79+
"@types/sinon": "^17.0.4",
7380
"@waku/build-utils": "*",
7481
"chai": "^4.3.10",
7582
"chai-as-promised": "^7.1.1",
7683
"cspell": "^8.6.1",
77-
"mocha": "^10.3.0",
84+
"datastore-core": "^10.0.4",
85+
"mocha": "^10.8.2",
7886
"node-localstorage": "^3.0.5",
7987
"npm-run-all": "^4.1.5",
8088
"rollup": "^4.12.0",
81-
"sinon": "^18.0.0"
89+
"sinon": "^18.0.1",
90+
"ts-node": "^10.9.2",
91+
"tsx": "^4.20.2"
8292
},
8393
"files": [
8494
"dist",
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import type { PeerDiscovery } from "@libp2p/interface";
2+
import type {
3+
DnsDiscoveryComponents,
4+
NodeCapabilityCount
5+
} from "@waku/interfaces";
6+
7+
import { wakuDnsDiscoveryEffect } from "../effect/index.js";
8+
9+
import { DEFAULT_NODE_REQUIREMENTS } from "./constants.js";
10+
import { wakuDnsDiscovery as wakuDnsDiscoveryPromise } from "./dns_discovery.js";
11+
12+
/**
13+
* Creates a DNS discovery instance with optional Effect support
14+
*
15+
* By default, uses the promise-based implementation for backward compatibility.
16+
* Set WAKU_USE_EFFECT_DISCOVERY=true to use the Effect-based implementation.
17+
*
18+
* @param enrUrls - ENR tree URLs for discovery
19+
* @param wantedNodeCapabilityCount - Required node capabilities
20+
* @returns Factory function for creating discovery instance
21+
*/
22+
export function wakuDnsDiscoveryWithEffect(
23+
enrUrls: string[],
24+
wantedNodeCapabilityCount: Partial<NodeCapabilityCount> = DEFAULT_NODE_REQUIREMENTS
25+
): (components: DnsDiscoveryComponents) => PeerDiscovery {
26+
// Check for feature flag
27+
const useEffect = process.env.WAKU_USE_EFFECT_DISCOVERY === "true";
28+
29+
if (useEffect) {
30+
// Using Effect-based implementation when WAKU_USE_EFFECT_DISCOVERY=true
31+
return wakuDnsDiscoveryEffect(enrUrls, wantedNodeCapabilityCount);
32+
}
33+
34+
return wakuDnsDiscoveryPromise(enrUrls, wantedNodeCapabilityCount);
35+
}

0 commit comments

Comments
 (0)