Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to nodejs v18 #465

Merged
merged 10 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .changeset/neat-lobsters-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
"@rpch/ethereum-provider": minor
"@rpch/availability-monitor": minor
"@rpch/discovery-platform": minor
"@rpch/funding-service": minor
"@types/fetch": minor
"@rpch/configs-typescript": minor
"@rpch/rpc-server": minor
"@rpch/common": minor
"@rpch/ethers": minor
"@rpch/exit-node": minor
"@rpch/manager": minor
"@rpch/sandbox": minor
"@rpch/sdk": minor
---

Updates to support nodejs v18 and native fetch
2 changes: 1 addition & 1 deletion .github/actions/build-rpch/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ runs:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
cache: "yarn"
cache-dependency-path: ./yarn.lock
registry-url: "https://registry.npmjs.org/"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ We have four main project folders:

### Getting started

1. Install nodejs `v16`
1. Install nodejs `v18`
2. Download dependencies with `yarn`
3. Build everything with `yarn build`

Expand Down
6 changes: 3 additions & 3 deletions apps/availability-monitor/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Create availability monitor

# use slim version of node on Debian bullseye for smaller image sizes
FROM node:16-bullseye-slim as builder
FROM node:18-bullseye-slim as builder

# use bash to have source command and persistent environment.
SHELL ["/bin/bash", "-lc"]
Expand All @@ -18,7 +18,7 @@ COPY . .
RUN turbo prune --scope="@rpch/availability-monitor" --docker

# Add lockfile and package.json's of isolated subworkspace.
FROM node:16-bullseye-slim AS installer
FROM node:18-bullseye-slim AS installer
RUN apt-get update && \
apt-get install -y libc6 && \
rm -rf /var/lib/apt/lists/*
Expand All @@ -36,7 +36,7 @@ COPY turbo.json turbo.json
RUN yarn run build --scope="@rpch/availability-monitor"

# Copy only the necesary files to run the app.
FROM node:16-bullseye-slim AS runner
FROM node:18-bullseye-slim AS runner
WORKDIR /app

# we use tini as process 1 to catch signals properly, which is also built into Docker by default
Expand Down
3 changes: 0 additions & 3 deletions apps/availability-monitor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
"@types/async-retry": "^1.4.5",
"@types/compression": "^1.7.2",
"@types/express": "^4.17.17",
"@types/node-fetch": "2.6.2",
"@types/supertest": "^2.0.12",
"nock": "^13.2.9",
"pg-mem": "^2.6.4",
"supertest": "^6.3.3"
},
Expand All @@ -35,7 +33,6 @@
"async-retry": "^1.3.3",
"express": "^4.18.2",
"express-validator": "^6.15.0",
"node-fetch": "^2.6.2",
"pg": "^8.9.0",
"pg-promise": "^11.0.0",
"prom-client": "^14.2.0"
Expand Down
280 changes: 207 additions & 73 deletions apps/availability-monitor/src/review/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,88 +1,222 @@
import assert from "assert";
import nock from "nock";
import review from ".";
import { NODE_A as NODE } from "../fixtures";
import { checks } from ".";

/** Mock HOPRd's API endpoints */
function mockHoprdApi(
hoprdApiEndpoint: string,
ops: {
failingVersion?: boolean;
badHealth?: boolean;
workingSSL?: boolean;
} = {
failingVersion: false,
badHealth: false,
workingSSL: false,
}
) {
if (ops.workingSSL) {
hoprdApiEndpoint = hoprdApiEndpoint.replace("http://", "https://");
}
describe("test hoprdVersion check", function () {
it("should pass", async function () {
const sdk: any = {
api: {
node: {
getVersion: () => Promise.resolve("1.0.0"),
},
},
};
const result = await checks.hoprdVersion.run(sdk);
assert(result.passed);
assert.equal(result.value, "1.0.0");
});

it("should not pass when SDK throws", async function () {
const sdk: any = {
api: {
node: {
getVersion: () => Promise.reject(Error("fake error")),
},
},
};
const result = await checks.hoprdVersion.run(sdk);
assert(!result.passed);
assert.equal(result.error, "fake error");
});
});

describe("test hoprdHealth check", function () {
it("should pass", async function () {
const sdk: any = {
api: {
node: {
getInfo: () => Promise.resolve({ connectivityStatus: "green" }),
},
},
};
const result = await checks.hoprdHealth.run(sdk);
assert(result.passed);
assert.equal(result.value, "green");
});

it("should not pass when status is red", async function () {
const sdk: any = {
api: {
node: {
getInfo: () => Promise.resolve({ connectivityStatus: "red" }),
},
},
};
const result = await checks.hoprdHealth.run(sdk);
assert(!result.passed);
assert.equal(result.value, "red");
});

it("should not pass when SDK throws", async function () {
const sdk: any = {
api: {
node: {
getInfo: () => Promise.reject(Error("fake error")),
},
},
};
const result = await checks.hoprdHealth.run(sdk);
assert(!result.passed);
assert.equal(result.error, "fake error");
});
});

if (ops.failingVersion) {
nock(hoprdApiEndpoint).get(`/api/v2/node/version`).reply(500);
} else {
nock(hoprdApiEndpoint).get(`/api/v2/node/version`).reply(200, "1.83.5");
}
describe("test hoprdSSL check", function () {
it("should pass", async function () {
const result = await checks.hoprdSSL.run(
"https://hoprd_api_endpoint",
"token"
);
assert(result.passed);
assert.equal(result.value, true);
});

it("should not pass", async function () {
const result = await checks.hoprdSSL.run(
"http://hoprd_api_endpoint",
"token"
);
assert(!result.passed);
assert(result.error!.includes("reason: getaddrinfo"));
});
});

nock(hoprdApiEndpoint)
.get(`/api/v2/node/info`)
.reply(200, {
environment: "anvil-localhost",
announcedAddress: [
"/ip4/128.0.215.32/tcp/9080/p2p/16Uiu2HAm91QFjPepnwjuZWzK5pb5ZS8z8qxQRfKZJNXjkgGNUAit",
"/p2p/16Uiu2HAmLpqczAGfgmJchVgVk233rmB2T3DSn2gPG6JMa5brEHZ1/p2p-circuit/p2p/16Uiu2HAm91QFjPepnwjuZWzK5pb5ZS8z8qxQRfKZJNXjkgGNUAit",
"/ip4/127.0.0.1/tcp/9080/p2p/16Uiu2HAm91QFjPepnwjuZWzK5pb5ZS8z8qxQRfKZJNXjkgGNUAit",
"/ip4/192.168.178.56/tcp/9080/p2p/16Uiu2HAm91QFjPepnwjuZWzK5pb5ZS8z8qxQRfKZJNXjkgGNUAit",
],
listeningAddress: [
"/ip4/0.0.0.0/tcp/9080/p2p/16Uiu2HAm91QFjPepnwjuZWzK5pb5ZS8z8qxQRfKZJNXjkgGNUAit",
],
network: "anvil",
hoprToken: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
hoprChannels: "0x2a54194c8fe0e3CdeAa39c49B95495aA3b44Db63",
hoprNetworkRegistryAddress: "0xBEE1F5d64b562715E749771408d06D57EE0892A7",
connectivityStatus: ops.badHealth ? "orange" : "green",
isEligible: true,
channelClosurePeriod: 1,
});
}
describe("test hoprdSendMessage check", function () {
it("should pass", async function () {
const sdk: any = {
api: {
node: {
getPeers: () =>
Promise.resolve({
connected: [
{
peerId: "peer_3",
quality: 0.85,
},
{
peerId: "peer_2",
quality: 0.9,
},
{
peerId: "peer_1",
quality: 1,
},
],
}),
},
messages: {
sendMessage: ({ recipient }: { recipient: string }) =>
Promise.resolve(recipient),
},
},
};
const result = await checks.hoprdSendMessage.run(sdk);
assert(result.passed);
assert.equal(result.value, "peer_1,peer_2,peer_3");
});

describe("test review", function () {
beforeEach(function () {
// reset nock before every test
nock.cleanAll();
it("should not pass when peers are too low", async function () {
const sdk: any = {
api: {
node: {
getPeers: () => Promise.resolve({ connected: [] }),
},
},
};
const result = await checks.hoprdSendMessage.run(sdk);
assert(!result.passed);
assert.equal(result.error, "Not enough peers found to send messages");
});
});

it("should review stable node as stable", async function () {
mockHoprdApi(NODE.hoprdApiEndpoint);
const result = await review({ node: NODE, exitNodes: [] });
assert(result.isStable);
describe("test hoprdPeers check", function () {
it("should pass", async function () {
const sdk: any = {
api: {
node: {
getPeers: () => Promise.resolve({ connected: ["peer_1"] }),
},
},
};
const result = await checks.hoprdPeers.run(sdk, 1);
assert(result.passed);
assert.equal(result.value, 1);
});

it("should review unstable node as unstable", async function () {
mockHoprdApi(NODE.hoprdApiEndpoint, { badHealth: true });
const result = await review({ node: NODE, exitNodes: [] });
assert(!result.isStable);
it("should not pass when peers are too low", async function () {
const sdk: any = {
api: {
node: {
getPeers: () => Promise.resolve({ connected: [] }),
},
},
};
const result = await checks.hoprdPeers.run(sdk, 1);
assert(!result.passed);
assert.equal(result.value, 0);
});

it("should not pass when SDK throws", async function () {
const sdk: any = {
api: {
node: {
getPeers: () => Promise.reject(Error("fake error")),
},
},
};
const result = await checks.hoprdPeers.run(sdk, 1);
assert(!result.passed);
assert.equal(result.error, "fake error");
});
});

describe("test hoprdOpenOutgoingChannels check", function () {
it("should pass", async function () {
const sdk: any = {
api: {
channels: {
getChannels: () =>
Promise.resolve({ outgoing: [{ status: "Open" }] }),
},
},
};
const result = await checks.hoprdOpenOutgoingChannels.run(sdk, 1);
assert(result.passed);
assert.deepEqual(result.value, [{ status: "Open" }]);
});

it("should correctly identify failing checks", async function () {
mockHoprdApi(NODE.hoprdApiEndpoint, {
failingVersion: true,
badHealth: true,
});
const result = await review({ node: NODE, exitNodes: [] });
assert(!result.stabilityReview.hoprdVersion.passed);
assert(!result.stabilityReview.hoprdHealth.passed);
assert(!result.stabilityReview.hoprdSSL.passed);
it("should not pass when peers are too low", async function () {
const sdk: any = {
api: {
channels: {
getChannels: () => Promise.resolve({ outgoing: [] }),
},
},
};
const result = await checks.hoprdOpenOutgoingChannels.run(sdk, 1);
assert(!result.passed);
assert.deepEqual(result.value, []);
});

it("should correctly identify working SSL", async function () {
mockHoprdApi(NODE.hoprdApiEndpoint, {
workingSSL: true,
});
const result = await review({ node: NODE, exitNodes: [] });
assert(result.stabilityReview.hoprdSSL.passed);
it("should not pass when SDK throws", async function () {
const sdk: any = {
api: {
channels: {
getChannels: () => Promise.reject(Error("fake error")),
},
},
};
const result = await checks.hoprdOpenOutgoingChannels.run(sdk, 1);
assert(!result.passed);
assert.equal(result.error, "fake error");
});
});
2 changes: 1 addition & 1 deletion apps/availability-monitor/src/review/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
const log = createLogger(["review"]);

/** Checks made by interacting with the HOPRd node */
const checks = {
export const checks = {
hoprdVersion: createCheck<string, [HoprSDK]>(
"hoprd-version",
async function checkHoprdVersion(sdk) {
Expand Down
Loading