Skip to content

Commit

Permalink
Fix batcher middleware configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienGllmt committed Mar 14, 2024
1 parent efeffed commit 83b1a58
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fi
if [ ! -x $executable ]; then chmod +x $executable; fi

export ENV_FILE="../.env.${NETWORK:-localhost}";
echo \"ENV FILE: $ENV_FILE\";
echo ENV FILE: $ENV_FILE;
docker compose --env-file $ENV_FILE build

# running a localhost node on your machine isn't exposed to docker which runs in a container
Expand Down
1 change: 0 additions & 1 deletion packages/batcher/batcher-transaction-poster/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class BatchedTransactionPoster {
}
await wait(periodMs);
}
console.log('[BatchedTransactionPoster::run] run end');
}

while (true) {
Expand Down
29 changes: 17 additions & 12 deletions packages/batcher/runtime/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
import type { Pool } from 'pg';

import BatchedTransactionPoster from '@paima/batcher-transaction-poster';
import { server, startServer } from '@paima/batcher-webserver';
import GameInputValidator, {
DefaultInputValidatorCoreInitializator,
EmptyInputValidatorCoreInitializator,
getErrors,
} from '@paima/batcher-game-input-validator';

import type { EthersEvmProvider } from '@paima/providers';
import {
ENV,
getWalletWeb3AndAddress,
Expand All @@ -20,14 +9,26 @@ import {
VERSION_STRING,
getAndConfirmWeb3,
getInvalidEnvVars,
} from '@paima/batcher-utils';
} from '@paima/batcher-utils'; // load first to load ENV variables
import type { Pool } from 'pg';

import BatchedTransactionPoster from '@paima/batcher-transaction-poster';
import { server, startServer } from '@paima/batcher-webserver';
import GameInputValidator, {
DefaultInputValidatorCoreInitializator,
EmptyInputValidatorCoreInitializator,
getErrors,
} from '@paima/batcher-game-input-validator';

import type { EthersEvmProvider } from '@paima/providers';
import type { ErrorCode, ErrorMessageFxn, GameInputValidatorCore } from '@paima/batcher-utils';

import { initializePool } from './pg/pgPool.js';
import type { BatcherRuntimeInitializer } from './types.js';
import { setLogger } from '@paima/utils';
import * as fs from 'fs';
import { parseSecurityYaml } from '@paima/utils-backend';
import { getRemoteBackendVersion, initMiddlewareCore } from '@paima/mw-core';

setLogger(s => {
try {
Expand Down Expand Up @@ -160,6 +161,10 @@ async function main(): Promise<void> {
}

const pool = initializePool();
await initMiddlewareCore(
'Game Batcher', // TODO: it doesn't matter now, but there is no way for the batcher to get the name of the game
await getRemoteBackendVersion()
);
const provider = await getWalletWeb3AndAddress(ENV.CHAIN_URI, privateKey);

console.log('Chain URI: ', ENV.CHAIN_URI);
Expand Down
1 change: 1 addition & 0 deletions packages/batcher/runtime/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
{ "path": "../../paima-sdk/paima-providers/tsconfig.build.json" },
{ "path": "../../paima-sdk/paima-utils/tsconfig.build.json" },
{ "path": "../../node-sdk/paima-utils-backend" },
{ "path": "../../paima-sdk/paima-mw-core/tsconfig.json" },
]
}
1 change: 1 addition & 0 deletions packages/batcher/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './config.js'; // place at the top to load ENV variables
import type { EthersEvmProvider } from '@paima/providers';
import { EthersConnector, WalletMode } from '@paima/providers';
import { paimaEndpoints } from '@paima/mw-core';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function getRawLatestProcessedBlockHeight(): Promise<Result<number>
}

// TODO: reworking this to use serverEndpointCall requires the endpoint to return a JSON
export async function getRemoteBackendVersion(): Promise<string> {
export async function getRemoteBackendVersion(): Promise<`${number}.${number}.${number}`> {
const errorFxn = buildEndpointErrorFxn('getRemoteBackendVersion');

let res: Response;
Expand All @@ -51,7 +51,7 @@ export async function getRemoteBackendVersion(): Promise<string> {
if (versionString[0] !== '"' || versionString[versionString.length - 1] !== '"') {
throw new Error('Invalid version string: ' + versionString);
}
return versionString.slice(1, versionString.length - 1);
return versionString.slice(1, versionString.length - 1) as `${number}.${number}.${number}`;
} catch (err) {
errorFxn(PaimaMiddlewareErrorCode.INVALID_RESPONSE_FROM_BACKEND, err);
throw err;
Expand Down
2 changes: 1 addition & 1 deletion packages/paima-sdk/paima-mw-core/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const getFee = (): undefined | FeeCache => fee;

export const getWeb3 = async (): Promise<Web3> => {
if (typeof web3 === 'undefined') {
web3 = await initWeb3(chainUri);
web3 = await initWeb3(getChainUri());
}
return web3;
};
Expand Down

0 comments on commit 83b1a58

Please sign in to comment.