Skip to content

Commit

Permalink
Merge pull request #224 from wormhole-foundation/fix/strict-typechecking
Browse files Browse the repository at this point in the history
Fix/strict typechecking
  • Loading branch information
solanoepalacio authored Dec 5, 2023
2 parents 6c56f6e + 2829174 commit cb4faeb
Show file tree
Hide file tree
Showing 40 changed files with 485 additions and 332 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,7 @@ jspm_packages/
.pnp.*

.idea
.vscode
.vscode

# Test typescript output
test-out
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
export default {
preset: "ts-jest/presets/default-esm", // or other ESM presets
preset: "ts-jest/presets/js-with-ts-esm", // or other ESM presets
testEnvironment: "node",
moduleNameMapper: {
"^(\\.\\.?\\/.+)\\.js$": "$1",
},
extensionsToTreatAsEsm: [".ts"],
transform: {
// '^.+\\.[tj]sx?$' to process js/ts with `ts-jest`
// '^.+\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest`
Expand Down
74 changes: 29 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"test-redis": "docker run --rm -p 6301:6379 --name relayer-engine-test -d redis; npm run test; docker kill relayer-engine-test",
"test": "jest --silent=false",
"test-watch": "jest --silent=false --watch",
"build": "tsc -b ./tsconfig.cjs.json && tsc -b ./tsconfig.esm.json && bin/create-package.json.sh",
"watch": "tsc --watch",
"typecheck": "tsc --noEmit --skipLibCheck",
"build": "tsc --build ./tsconfig.cjs.json ./tsconfig.esm.json && bin/create-package.json.sh",
"watch": "tsc --watch --project ./tsconfig.esm.json",
"typecheck": "tsc --build ./tsconfig.esm.json ./test/tsconfig.json",
"prettier": "prettier --write $(git diff main --name-only --diff-filter u | grep '.ts$' | xargs)",
"mainnet-spy": "docker run --platform=linux/amd64 -p 7073:7073 --entrypoint /guardiand ghcr.io/wormhole-foundation/guardiand:latest spy --nodeKey /node.key --spyRPC \"[::]:7073\" --network /wormhole/mainnet/2 --bootstrap /dns4/wormhole-mainnet-v2-bootstrap.certus.one/udp/8999/quic/p2p/12D3KooWQp644DK27fd3d4Km3jr7gHiuJJ5ZGmy8hH4py7fP4FP7",
"testnet-spy": "docker run --platform=linux/amd64 -p 7073:7073 --entrypoint /guardiand ghcr.io/wormhole-foundation/guardiand:latest spy --nodeKey /node.key --spyRPC \"[::]:7073\" --network /wormhole/testnet/2/1 --bootstrap /dns4/wormhole-testnet-v2-bootstrap.certus.one/udp/8999/quic/p2p/12D3KooWAkB9ynDur1Jtoa97LBUp8RXdhzS5uHgAfdTquJbrbN7i",
Expand Down Expand Up @@ -56,16 +56,15 @@
"devDependencies": {
"@certusone/wormhole-sdk-proto-node": "^0.0.6",
"@cloudnc/grpc-web-testing-toolbox": "^2.2.0",
"@jest/globals": "^29.6.4",
"@types/bluebird": "^3.5.38",
"@types/bs58": "^4.0.1",
"@types/jest": "^29.5.4",
"@jest/globals": "^29.7.0",
"@types/jest": "^29.5.10",
"@types/koa": "^2.13.8",
"@types/node": "^20.6.0",
"@types/winston": "^2.4.4",
"jest": "^29.6.4",
"jest": "^29.7.0",
"prettier": "^2.8.8",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
"typed-assert": "^1.0.9",
"typescript": "^5.3.2"
}
}
53 changes: 32 additions & 21 deletions relayer/application-standard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RelayerApp, RelayerAppOpts } from "./application.js";
import { RelayerApp, RelayerAppOpts, defaultOpts } from "./application.js";
import {
logging,
LoggingContext,
Expand All @@ -22,7 +22,7 @@ import {
} from "./storage/redis-storage.js";
import { ChainId } from "@certusone/wormhole-sdk";
import { ClusterNode, ClusterOptions, RedisOptions } from "ioredis";
import { mergeDeep } from "./utils.js";
import { MakeOptional, mergeDeep } from "./utils.js";
import { defaultLogger } from "./logging.js";
import { BullMQAdapter } from "@bull-board/api/bullMQAdapter.js";
import { KoaAdapter } from "@bull-board/koa";
Expand All @@ -44,7 +44,7 @@ export interface StandardMissedVaaOpts {

export interface StandardRelayerAppOpts extends RelayerAppOpts {
name: string;
spyEndpoint?: string;
spyEndpoint: string;
logger?: Logger;
privateKeys?: Partial<{
[k in ChainId]: any[];
Expand All @@ -64,14 +64,16 @@ export interface StandardRelayerAppOpts extends RelayerAppOpts {
maxFailedQueueSize?: number;
}

const defaultOpts: Partial<StandardRelayerAppOpts> = {
const defaultStdOpts = {
spyEndpoint: "localhost:7073",
workflows: {
retries: 3,
},
fetchSourceTxhash: true,
logger: defaultLogger,
};
} satisfies Partial<StandardRelayerAppOpts>;

type FullDefaultOpts = typeof defaultStdOpts & ReturnType<typeof defaultOpts>;

export type StandardRelayerContext = LoggingContext &
StorageContext &
Expand All @@ -86,12 +88,18 @@ export class StandardRelayerApp<
private readonly store: RedisStorage;
private readonly mergedRegistry: Registry;

constructor(env: Environment, opts: StandardRelayerAppOpts) {
constructor(
env: Environment,
opts: MakeOptional<StandardRelayerAppOpts, FullDefaultOpts>,
) {
// take logger out before merging because of recursive call stack
const logger = opts.logger ?? defaultLogger;
delete opts.logger;
// now we can merge
opts = mergeDeep({}, [defaultOpts, opts]);
const options = mergeDeep<StandardRelayerAppOpts>({}, [
defaultStdOpts,
opts,
]);

const {
privateKeys,
Expand All @@ -105,14 +113,14 @@ export class StandardRelayerApp<
retryBackoffOptions,
maxCompletedQueueSize,
maxFailedQueueSize,
} = opts;
super(env, opts);
} = options;
super(env, options);

this.store = new RedisStorage({
redis,
redisClusterEndpoints,
redisCluster,
attempts: opts.workflows.retries ?? 3,
attempts: options.workflows?.retries ?? 3,
namespace: name,
queueName: `${name}-relays`,
exponentialBackoff: retryBackoffOptions,
Expand All @@ -131,13 +139,14 @@ export class StandardRelayerApp<
redisCluster,
redisClusterEndpoints,
wormholeRpcs,
concurrency: opts.missedVaaOptions?.concurrency,
checkInterval: opts.missedVaaOptions?.checkInterval,
fetchVaaRetries: opts.missedVaaOptions?.fetchVaaRetries,
vaasFetchConcurrency: opts.missedVaaOptions?.vaasFetchConcurrency,
concurrency: options.missedVaaOptions?.concurrency,
checkInterval: options.missedVaaOptions?.checkInterval,
fetchVaaRetries: options.missedVaaOptions?.fetchVaaRetries,
vaasFetchConcurrency: options.missedVaaOptions?.vaasFetchConcurrency,
storagePrefix: this.store.getPrefix(),
startingSequenceConfig: opts.missedVaaOptions?.startingSequenceConfig,
forceSeenKeysReindex: opts.missedVaaOptions?.forceSeenKeysReindex,
startingSequenceConfig:
options.missedVaaOptions?.startingSequenceConfig,
forceSeenKeysReindex: options.missedVaaOptions?.forceSeenKeysReindex,
});
}

Expand All @@ -149,9 +158,11 @@ export class StandardRelayerApp<
this.spy(spyEndpoint);
this.useStorage(this.store);
this.logger(logger);
this.use(logging(logger)); // <-- logging middleware
this.use(providers(opts.providers, Object.keys(opts.privateKeys ?? {})));
if (opts.privateKeys && Object.keys(opts.privateKeys).length) {
this.use(logging(logger));
this.use(providers(options.providers, Object.keys(privateKeys ?? {})));

// You need valid private keys to turn on the wallet middleware
if (privateKeys !== undefined && Object.keys(privateKeys).length > 0) {
this.use(
wallets(env, {
logger,
Expand All @@ -160,7 +171,7 @@ export class StandardRelayerApp<
tokensByChain,
metrics: { enabled: true, registry: this.metricsRegistry },
}),
); // <-- you need valid private keys to turn on this middleware
);
}
this.use(tokenBridgeContracts());
this.use(
Expand All @@ -171,7 +182,7 @@ export class StandardRelayerApp<
redisClusterEndpoints,
}),
);
if (opts.fetchSourceTxhash) {
if (options.fetchSourceTxhash) {
this.use(sourceTx());
}
}
Expand Down
Loading

0 comments on commit cb4faeb

Please sign in to comment.