Skip to content

Commit

Permalink
feat: add rpc url to nwaku, persist rln tree in docker and ci
Browse files Browse the repository at this point in the history
  • Loading branch information
adklempner committed May 7, 2024
1 parent 3d92f19 commit e7bef35
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 2 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,53 @@ jobs:
- run: npm run build:esm
- run: npm run test:browser

build_rln_tree:
if: false # This condition disables the job
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
repository: waku-org/js-waku
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_JS }}
- name: Check for existing RLN tree artifact
id: check-artifact
uses: actions/github-script@v6
with:
script: |
const artifact = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.runId
});
console.log(artifact);
const foundArtifact = artifact.data.artifacts.find(art => art.name === 'rln_tree.tar.gz');
if (foundArtifact) {
core.setOutput('artifact_id', foundArtifact.id);
core.setOutput('artifact_found', 'true');
} else {
core.setOutput('artifact_found', 'false');
}
- name: Download RLN tree artifact
if: steps.check-artifact.outputs.artifact_found == 'true'
uses: actions/download-artifact@v3
with:
name: rln_tree.tar.gz
path: /tmp
- uses: ./.github/actions/npm
- name: Sync rln tree and save artifact
run: |
mkdir -p /tmp/rln_tree.db
npm run build:esm
npm run sync-rln-tree
tar -czf rln_tree.tar.gz -C /tmp/rln_tree.db .
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: rln_tree.tar.gz
path: rln_tree.tar.gz

node:
uses: ./.github/workflows/test-node.yml
secrets: inherit
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"doc": "run-s doc:*",
"doc:html": "typedoc --options typedoc.cjs",
"doc:cname": "echo 'js.waku.org' > docs/CNAME",
"publish": "node ./ci/publish.js"
"publish": "node ./ci/publish.js",
"sync-rln-tree": "node ./packages/tests/src/sync-rln-tree.js"
},
"devDependencies": {
"@size-limit/preset-big-lib": "^11.0.2",
Expand Down
3 changes: 3 additions & 0 deletions packages/tests/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ export const TEST_TIMESTAMPS = [
];

export const MOCHA_HOOK_MAX_TIMEOUT = 50_000;

export const SEPOLIA_RPC_URL =
process.env.SEPOLIA_RPC_URL || "https://sepolia.gateway.tenderly.co";
12 changes: 11 additions & 1 deletion packages/tests/src/lib/dockerode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,17 @@ export default class Dockerode {
...(args?.peerExchange && {
[`${discv5UdpPort}/udp`]: [{ HostPort: discv5UdpPort.toString() }]
})
}
},
Mounts: args.rlnRelayEthClientAddress
? [
{
Type: "bind",
ReadOnly: false,
Source: "/tmp/rln_tree.db",
Target: "/rln_tree.db"
}
]
: []
},
ExposedPorts: {
[`${restPort}/tcp`]: {},
Expand Down
15 changes: 15 additions & 0 deletions packages/tests/src/lib/service_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ export class ServiceNode {
return isGoWaku ? "go-waku" : "nwaku";
}

get containerName(): string | undefined {
return this.docker?.container?.id;
}

async start(
args: Args = {},
options: {
Expand Down Expand Up @@ -229,6 +233,17 @@ export class ServiceNode {
);
}

async healthy(): Promise<boolean> {
this.checkProcess();

return this.restCall<boolean>(
"/health",
"GET",
undefined,
async (response) => response.status === 200
);
}

async ensureSubscriptions(
pubsubTopics: string[] = [DefaultPubsubTopic]
): Promise<boolean> {
Expand Down
56 changes: 56 additions & 0 deletions packages/tests/src/sync-rln-tree.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { exec } from "child_process";
import { setTimeout } from "timers";
import { promisify } from "util";

import { SEPOLIA_RPC_URL } from "../dist/constants.js";
import { ServiceNode } from "../dist/lib/service_node.js";

const execAsync = promisify(exec);

const WAKUNODE_IMAGE = process.env.WAKUNODE_IMAGE || "wakuorg/nwaku:v0.27.0";
const containerName = "rln_tree";

async function syncRlnTree() {
try {
await execAsync(`docker inspect ${WAKUNODE_IMAGE}`);
console.log(`Using local image ${WAKUNODE_IMAGE}`);
} catch (error) {
console.log(`Pulling image ${WAKUNODE_IMAGE}`);
await execAsync(`docker pull ${WAKUNODE_IMAGE}`);
console.log("Image pulled");
}

const nwaku = new ServiceNode(containerName);
await nwaku.start(
{
store: false,
lightpush: false,
relay: true,
filter: false,
rest: true,
clusterId: 1,
rlnRelayEthClientAddress: SEPOLIA_RPC_URL
},
{ retries: 3 }
);
let healthy = false;
while (!healthy) {
healthy = await nwaku.healthy();
await new Promise((resolve) => setTimeout(resolve, 500));
}

await execAsync(
`docker cp ${nwaku.containerName}:/rln_tree.db /tmp/rln_tree.db`
);
await nwaku.stop();
}

syncRlnTree()
.then(() => {
console.log("Synced RLN tree");
process.exit(0);
})
.catch((err) => {
console.error(`Error syncing RLN tree: ${err}`);
process.exit(1);
});
1 change: 1 addition & 0 deletions packages/tests/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface Args {
// `legacyFilter` is required to enable filter v1 with go-waku
legacyFilter?: boolean;
clusterId?: number;
rlnRelayEthClientAddress?: string;
}

export interface Ports {
Expand Down

0 comments on commit e7bef35

Please sign in to comment.