Skip to content

Commit

Permalink
Merge pull request #42 from NillionNetwork/timhm/release-tweaks-and-f…
Browse files Browse the repository at this point in the history
…ixes-0-2-0
  • Loading branch information
tim-hm authored Nov 21, 2024
2 parents 8ddf291 + 79a3fe5 commit 5ac2c1e
Show file tree
Hide file tree
Showing 31 changed files with 642 additions and 916 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
aws-region: "eu-west-1"
- uses: NillionNetwork/nillion-setup-action@main
with:
version: "v0.7.0-rc.42"
version: "v0.7.0-rc.55"
- uses: actions/setup-python@v5
with:
python-version: "3.12"
Expand Down
6 changes: 3 additions & 3 deletions client-react-hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@nillion/client-react-hooks",
"license": "MIT",
"author": "[email protected]",
"version": "0.2.0-rc.3",
"version": "0.2.0",
"homepage": "https://nillion.pub/client-ts",
"repository": {
"type": "git",
Expand All @@ -23,14 +23,14 @@
"dependencies": {
"@nillion/client-vms": "workspace:^",
"@tanstack/react-query": "^5.59.20",
"pino": "^9.5.0",
"pino-pretty": "^13.0.0",
"debug": "^4.3.7",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"zod": "^3.23.8"
},
"devDependencies": {
"@tsconfig/vite-react": "^3.0.2",
"@types/debug": "^4.1.12",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"browserslist": "^4.24.2",
Expand Down
4 changes: 2 additions & 2 deletions client-react-hooks/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { createLogger } from "@nillion/client-vms/logger";
import debug from "debug";

export const Log = createLogger("@nillion/client-react-hooks");
export const Log = debug("@nillion/client-react-hooks");
10 changes: 5 additions & 5 deletions client-vms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@nillion/client-vms",
"license": "MIT",
"author": "[email protected]",
"version": "0.2.0-rc.3",
"version": "0.2.0",
"repository": "https://github.com/NillionNetwork/client-ts",
"type": "module",
"exports": {
Expand All @@ -20,25 +20,25 @@
},
"dependencies": {
"@bufbuild/protobuf": "^2.2.2",
"@connectrpc/connect": "2.0.0-rc.3",
"@connectrpc/connect-web": "2.0.0-rc.3",
"@connectrpc/connect": "^2.0.0",
"@connectrpc/connect-web": "^2.0.0",
"@cosmjs/proto-signing": "^0.32.4",
"@cosmjs/stargate": "^0.32.4",
"@nillion/client-wasm": "workspace:^",
"@noble/curves": "^1.6.0",
"@noble/hashes": "^1.5.0",
"@noble/secp256k1": "^2.1.0",
"bs58": "^6.0.0",
"debug": "^4.3.7",
"effect": "^3.10.14",
"pino": "^9.5.0",
"pino-pretty": "^13.0.0",
"uuid": "^11.0.3",
"zod": "^3.23.8"
},
"devDependencies": {
"@bufbuild/buf": "^1.46.0",
"@bufbuild/protoc-gen-es": "^2.2.2",
"@keplr-wallet/types": "^0.12.154",
"@types/debug": "^4.1.12",
"@types/node": "^22.9.0",
"@types/uuid": "^10.0.0",
"@vitest/coverage-v8": "^2.1.4",
Expand Down
85 changes: 2 additions & 83 deletions client-vms/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,84 +1,3 @@
import pino, { type Logger } from "pino";
import debug from "debug";

export const Log = createLogger("@nillion/client-vm");

type PinoWriteFnArgs = {
time: number;
level: string;
module: string;
msg: string | object;
[index: string]: unknown;
};

const levelColors: Record<string, string> = {
debug: "#808080",
info: "#0099ff",
warn: "#ffa500",
error: "#ff0000",
fatal: "#800000",
trace: "#a0a0a0",
};

export function createLogger(module: string): Logger<never, boolean> {
const isBrowser = Boolean(globalThis.window);

try {
if (isBrowser) {
return createBrowserLogger(module);
}

return pino({
level: "debug",
transport: {
target: "pino-pretty",
},
}).child({ module });
} catch (_e) {
return pino({
level: "debug",
}).child({ module });
}
}

function createBrowserLogger(module: string): Logger<never, boolean> {
return pino({
level: "debug",
browser: {
asObject: true,
formatters: {
level(label, _numerical) {
return { level: label };
},
},
// @ts-expect-error args type is customised through `child` and `formatters` which pino doesn't recognize
write: (args: PinoWriteFnArgs) => {
if (!localStorage.debug?.includes("@nillion")) {
return;
}

const time = new Date(args.time).toLocaleTimeString();
const { level, module, msg, time: _, ...rest } = args;
const color = levelColors[level.toLowerCase()] || "#000000";
const style = `color: ${color}; font-weight: bold`;
const baseMsg = `${time} %c${level.toUpperCase().padEnd(5)}%c ${module}:`;

const logArgs: unknown[] = [baseMsg, style, ""];

if (typeof msg === "object") {
logArgs[0] += " %O";
logArgs.push({ ...msg, ...rest });
} else {
if (msg) {
logArgs[0] += ` ${msg}`;
}
if (Object.keys(rest).length > 0) {
logArgs[0] += " %O";
logArgs.push(rest);
}
}

console.log(...logArgs);
},
},
}).child({ module });
}
export const Log = debug("@nillion/vms");
6 changes: 3 additions & 3 deletions client-vms/src/payment/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class PaymentClient {
{ ...quotePb, request, signed },
{ path: ["client.quote"] },
);
Log.info(
Log(
"Quoted %s unil for %s",
quote.fees.total.toString(),
request.operation.case,
Expand All @@ -80,7 +80,7 @@ export class PaymentClient {
"auto",
);
const hash = TxHash.parse(result.transactionHash);
Log.info("Paid %d unil hash: %s", amount, hash);
Log("Paid %d unil hash: %s", amount, hash);
return hash;
}

Expand All @@ -90,7 +90,7 @@ export class PaymentClient {
txHash,
});
const receipt = await this.leader.paymentReceipt(request);
Log.info("Validated payment with cluster");
Log("Validated payment with cluster");
return receipt;
}
}
2 changes: 1 addition & 1 deletion client-vms/src/vm/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class VmClientBuilder {
nodes,
});

Log.info("Client connected");
Log("Client connected");

return new VmClient(config);
}
Expand Down
7 changes: 3 additions & 4 deletions client-vms/src/vm/operation/delete-values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ export class DeleteValues implements Operation<Uuid> {
),
E.flatMap(collapse),
E.tapBoth({
onFailure: (e) =>
E.sync(() => Log.error("Values delete failed: %O", e)),
onSuccess: (id) => E.sync(() => Log.info(`Values deleted: ${id}`)),
onFailure: (e) => E.sync(() => Log("Values delete failed: %O", e)),
onSuccess: (id) => E.sync(() => Log(`Values deleted: ${id}`)),
}),
E.runPromise,
);
Expand Down Expand Up @@ -79,7 +78,7 @@ export class DeleteValues implements Operation<Uuid> {
E.tryPromise(() => client.deleteValues(request)),
E.map((_response) => this.config.id),
E.tap((id) =>
Log.debug(`Values deleted: node=${nodeId.toBase64()} values=${id} `),
Log(`Values deleted: node=${nodeId.toBase64()} values=${id} `),
),
);
}
Expand Down
9 changes: 3 additions & 6 deletions client-vms/src/vm/operation/invoke-compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ export class InvokeCompute implements Operation<Uuid> {
),
E.flatMap(collapse),
E.tapBoth({
onFailure: (e) =>
E.sync(() => Log.error("Invoke compute failed: %O", e)),
onSuccess: (id) => E.sync(() => Log.info(`Invoke compute: ${id}`)),
onFailure: (e) => E.sync(() => Log("Invoke compute failed: %O", e)),
onSuccess: (id) => E.sync(() => Log(`Invoke compute: ${id}`)),
}),
E.runPromise,
);
Expand Down Expand Up @@ -134,9 +133,7 @@ export class InvokeCompute implements Operation<Uuid> {
return pipe(
E.tryPromise(() => client.invokeCompute(request)),
E.map((response) => stringify(response.computeId)),
E.tap((id) =>
Log.debug(`Invoked compute: node=${nodeId.toBase64()} id=${id}`),
),
E.tap((id) => Log(`Invoked compute: node=${nodeId.toBase64()} id=${id}`)),
);
}

Expand Down
6 changes: 3 additions & 3 deletions client-vms/src/vm/operation/overwrite-permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ export class OverwritePermissions implements Operation<ValuesPermissions> {
E.flatMap(collapse),
E.tapBoth({
onFailure: (e) =>
E.sync(() => Log.error("Overwrite permissions failed: %O", e)),
E.sync(() => Log("Overwrite permissions failed: %O", e)),
onSuccess: (permissions) =>
E.sync(() =>
Log.info("Overwrote permissions: %O", permissions.toObject()),
Log("Overwrote permissions: %O", permissions.toObject()),
),
}),
E.runPromise,
Expand Down Expand Up @@ -90,7 +90,7 @@ export class OverwritePermissions implements Operation<ValuesPermissions> {
E.tryPromise(() => client.overwritePermissions(request)),
E.map((_response) => this.config.permissions),
E.tap((_permissions) =>
Log.debug(
Log(
`Overwrote permissions: node=${nodeId.toBase64()} values=${this.config.id} `,
),
),
Expand Down
6 changes: 2 additions & 4 deletions client-vms/src/vm/operation/query-pool-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ export class QueryPoolStatus implements Operation<PoolStatus> {
),
E.flatMap((response) => E.try(() => PoolStatus.parse(response))),
E.tapBoth({
onFailure: (e) =>
E.sync(() => Log.error("Query pool status failed: %O", e)),
onSuccess: (status) =>
E.sync(() => Log.info("Pool status: %O", status)),
onFailure: (e) => E.sync(() => Log("Query pool status failed: %O", e)),
onSuccess: (status) => E.sync(() => Log("Pool status: %O", status)),
}),
E.runPromise,
);
Expand Down
8 changes: 4 additions & 4 deletions client-vms/src/vm/operation/retrieve-compute-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export class RetrieveComputeResult implements Operation<NadaValuesRecord> {
}),
E.tapBoth({
onFailure: (e) =>
E.sync(() => Log.error("Retrieve compute results failed: %O", e)),
E.sync(() => Log("Retrieve compute results failed: %O", e)),
onSuccess: (data) =>
E.sync(() => Log.info("Retrieved compute results: %O", data)),
E.sync(() => Log("Retrieved compute results: %O", data)),
}),
E.runPromise,
);
Expand Down Expand Up @@ -107,12 +107,12 @@ export class RetrieveComputeResult implements Operation<NadaValuesRecord> {
);
}

Log.debug(`Compute result waiting on: node=${nodeId.toBase64()}`);
Log(`Compute result waiting on: node=${nodeId.toBase64()}`);
}
}),
E.map((shares) => shares as PartyShares),
E.tap(() =>
Log.debug(`Compute result shares retrieved: node=${nodeId.toBase64()}`),
Log(`Compute result shares retrieved: node=${nodeId.toBase64()}`),
),
);
}
Expand Down
6 changes: 3 additions & 3 deletions client-vms/src/vm/operation/retrieve-permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ export class RetrievePermissions implements Operation<ValuesPermissions> {
E.flatMap(collapse),
E.tapBoth({
onFailure: (e) =>
E.sync(() => Log.error("Retrieve permissions failed: %O", e)),
E.sync(() => Log("Retrieve permissions failed: %O", e)),
onSuccess: (data) =>
E.sync(() => Log.info("Retrieved permissions: %O", data)),
E.sync(() => Log("Retrieved permissions: %O", data)),
}),
E.runPromise,
);
Expand Down Expand Up @@ -86,7 +86,7 @@ export class RetrievePermissions implements Operation<ValuesPermissions> {
E.tryPromise(() => client.retrievePermissions(request)),
E.map((response) => ValuesPermissions.from(response)),
E.tap((_permissions) =>
Log.debug(
Log(
`Retrieved permissions: node=${nodeId.toBase64()} values=${this.config.id} `,
),
),
Expand Down
10 changes: 3 additions & 7 deletions client-vms/src/vm/operation/retrieve-values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ export class RetrieveValues implements Operation<NadaValuesRecord> {
return NadaValuesRecord.parse(record);
}),
E.tapBoth({
onFailure: (e) =>
E.sync(() => Log.error("Retrieve values failed: %O", e)),
onSuccess: (data) =>
E.sync(() => Log.info("Retrieved values: %O", data)),
onFailure: (e) => E.sync(() => Log("Retrieve values failed: %O", e)),
onSuccess: (data) => E.sync(() => Log("Retrieved values: %O", data)),
}),
E.runPromise,
);
Expand Down Expand Up @@ -97,9 +95,7 @@ export class RetrieveValues implements Operation<NadaValuesRecord> {
),
),
E.tap((id) =>
Log.debug(
`Retrieved values shares: node=${nodeId.toBase64()} values=${id}`,
),
Log(`Retrieved values shares: node=${nodeId.toBase64()} values=${id}`),
),
);
}
Expand Down
9 changes: 3 additions & 6 deletions client-vms/src/vm/operation/retry-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@ function createRetryStrategy<E>(context: string) {
attempt += 1;

if (recoverable) {
Log.warn(
`${context} failed (attempt ${attempt}/${maxRetries}): %O`,
error,
);
Log(`${context} failed (attempt ${attempt}/${maxRetries}): %O`, error);
} else {
Log.error(`${context} irrecoverable failure: %O`, error);
Log(`${context} irrecoverable failure: %O`, error);
}

return recoverable;
Expand All @@ -66,7 +63,7 @@ export function retryGrpcRequestIfRecoverable<R>(
request,
createRetryStrategy(context),
E.tapError((error) =>
E.sync(() => Log.error("Retries exhausted. Final error:", error)),
E.sync(() => Log("Retries exhausted. Final error:", error)),
),
);
}
7 changes: 3 additions & 4 deletions client-vms/src/vm/operation/store-program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ export class StoreProgram implements Operation<ProgramId> {
),
E.flatMap(collapse),
E.tapBoth({
onFailure: (e) =>
E.sync(() => Log.error("Store program failed: %O", e)),
onSuccess: (id) => E.sync(() => Log.info(`Stored program: ${id}`)),
onFailure: (e) => E.sync(() => Log("Store program failed: %O", e)),
onSuccess: (id) => E.sync(() => Log(`Stored program: ${id}`)),
}),
E.runPromise,
);
Expand Down Expand Up @@ -98,7 +97,7 @@ export class StoreProgram implements Operation<ProgramId> {
E.tryPromise(() => client.storeProgram(request)),
E.map((response) => ProgramId.parse(response.programId)),
E.tap((id) =>
Log.debug(`Stored program: node=${nodeId.toBase64()} values=${id} `),
Log(`Stored program: node=${nodeId.toBase64()} values=${id} `),
),
);
}
Expand Down
Loading

0 comments on commit 5ac2c1e

Please sign in to comment.