Skip to content

Commit f78495a

Browse files
authored
Merge pull request #1997 from waku-org/feat/docker-sepolia-rpc
feat: add rpc url to nwaku, persist rln tree in docker and ci
2 parents 4eb06c6 + aad819b commit f78495a

File tree

7 files changed

+135
-2
lines changed

7 files changed

+135
-2
lines changed

.github/workflows/ci.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,53 @@ jobs:
6868
- run: npm run build:esm
6969
- run: npm run test:browser
7070

71+
build_rln_tree:
72+
if: false # This condition disables the job
73+
runs-on: ubuntu-latest
74+
steps:
75+
- uses: actions/checkout@v3
76+
with:
77+
repository: waku-org/js-waku
78+
- uses: actions/setup-node@v3
79+
with:
80+
node-version: ${{ env.NODE_JS }}
81+
- name: Check for existing RLN tree artifact
82+
id: check-artifact
83+
uses: actions/github-script@v6
84+
with:
85+
script: |
86+
const artifact = await github.rest.actions.listWorkflowRunArtifacts({
87+
owner: context.repo.owner,
88+
repo: context.repo.repo,
89+
run_id: context.runId
90+
});
91+
console.log(artifact);
92+
const foundArtifact = artifact.data.artifacts.find(art => art.name === 'rln_tree.tar.gz');
93+
if (foundArtifact) {
94+
core.setOutput('artifact_id', foundArtifact.id);
95+
core.setOutput('artifact_found', 'true');
96+
} else {
97+
core.setOutput('artifact_found', 'false');
98+
}
99+
- name: Download RLN tree artifact
100+
if: steps.check-artifact.outputs.artifact_found == 'true'
101+
uses: actions/download-artifact@v4
102+
with:
103+
name: rln_tree.tar.gz
104+
path: /tmp
105+
- uses: ./.github/actions/npm
106+
- name: Sync rln tree and save artifact
107+
run: |
108+
mkdir -p /tmp/rln_tree.db
109+
npm run build:esm
110+
npm run sync-rln-tree
111+
tar -czf rln_tree.tar.gz -C /tmp/rln_tree.db .
112+
- name: Upload artifact
113+
uses: actions/upload-artifact@v4
114+
with:
115+
name: rln_tree.tar.gz
116+
path: rln_tree.tar.gz
117+
71118
node:
72119
uses: ./.github/workflows/test-node.yml
73120
secrets: inherit

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"doc": "run-s doc:*",
3737
"doc:html": "typedoc --options typedoc.cjs",
3838
"doc:cname": "echo 'js.waku.org' > docs/CNAME",
39-
"publish": "node ./ci/publish.js"
39+
"publish": "node ./ci/publish.js",
40+
"sync-rln-tree": "node ./packages/tests/src/sync-rln-tree.js"
4041
},
4142
"devDependencies": {
4243
"@size-limit/preset-big-lib": "^11.0.2",

packages/tests/src/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,6 @@ export const TEST_TIMESTAMPS = [
6262
];
6363

6464
export const MOCHA_HOOK_MAX_TIMEOUT = 50_000;
65+
66+
export const SEPOLIA_RPC_URL =
67+
process.env.SEPOLIA_RPC_URL || "https://sepolia.gateway.tenderly.co";

packages/tests/src/lib/dockerode.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,17 @@ export default class Dockerode {
115115
...(args?.peerExchange && {
116116
[`${discv5UdpPort}/udp`]: [{ HostPort: discv5UdpPort.toString() }]
117117
})
118-
}
118+
},
119+
Mounts: args.rlnRelayEthClientAddress
120+
? [
121+
{
122+
Type: "bind",
123+
ReadOnly: false,
124+
Source: "/tmp/rln_tree.db",
125+
Target: "/rln_tree.db"
126+
}
127+
]
128+
: []
119129
},
120130
ExposedPorts: {
121131
[`${restPort}/tcp`]: {},

packages/tests/src/lib/service_node.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ export class ServiceNode {
8787
return isGoWaku ? "go-waku" : "nwaku";
8888
}
8989

90+
get containerName(): string | undefined {
91+
return this.docker?.container?.id;
92+
}
93+
9094
async start(
9195
args: Args = {},
9296
options: {
@@ -229,6 +233,17 @@ export class ServiceNode {
229233
);
230234
}
231235

236+
async healthy(): Promise<boolean> {
237+
this.checkProcess();
238+
239+
return this.restCall<boolean>(
240+
"/health",
241+
"GET",
242+
undefined,
243+
async (response) => response.status === 200
244+
);
245+
}
246+
232247
async ensureSubscriptions(
233248
pubsubTopics: string[] = [DefaultPubsubTopic]
234249
): Promise<boolean> {

packages/tests/src/sync-rln-tree.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { exec } from "child_process";
2+
import { setTimeout } from "timers";
3+
import { promisify } from "util";
4+
5+
import { SEPOLIA_RPC_URL } from "../dist/constants.js";
6+
import { ServiceNode } from "../dist/lib/service_node.js";
7+
8+
const execAsync = promisify(exec);
9+
10+
const WAKUNODE_IMAGE = process.env.WAKUNODE_IMAGE || "wakuorg/nwaku:v0.27.0";
11+
const containerName = "rln_tree";
12+
13+
async function syncRlnTree() {
14+
try {
15+
await execAsync(`docker inspect ${WAKUNODE_IMAGE}`);
16+
console.log(`Using local image ${WAKUNODE_IMAGE}`);
17+
} catch (error) {
18+
console.log(`Pulling image ${WAKUNODE_IMAGE}`);
19+
await execAsync(`docker pull ${WAKUNODE_IMAGE}`);
20+
console.log("Image pulled");
21+
}
22+
23+
const nwaku = new ServiceNode(containerName);
24+
await nwaku.start(
25+
{
26+
store: false,
27+
lightpush: false,
28+
relay: true,
29+
filter: false,
30+
rest: true,
31+
clusterId: 1,
32+
rlnRelayEthClientAddress: SEPOLIA_RPC_URL
33+
},
34+
{ retries: 3 }
35+
);
36+
let healthy = false;
37+
while (!healthy) {
38+
healthy = await nwaku.healthy();
39+
await new Promise((resolve) => setTimeout(resolve, 500));
40+
}
41+
42+
await execAsync(
43+
`docker cp ${nwaku.containerName}:/rln_tree.db /tmp/rln_tree.db`
44+
);
45+
await nwaku.stop();
46+
}
47+
48+
syncRlnTree()
49+
.then(() => {
50+
console.log("Synced RLN tree");
51+
process.exit(0);
52+
})
53+
.catch((err) => {
54+
console.error(`Error syncing RLN tree: ${err}`);
55+
process.exit(1);
56+
});

packages/tests/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface Args {
2626
legacyFilter?: boolean;
2727
clusterId?: number;
2828
shard?: Array<number>;
29+
rlnRelayEthClientAddress?: string;
2930
}
3031

3132
export interface Ports {

0 commit comments

Comments
 (0)