Skip to content

Commit

Permalink
minor cleanup/improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ecioppettini committed Feb 14, 2024
1 parent 90bd2c5 commit 8a9d340
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/engine/paima-funnel/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ChainData, ChainDataExtensionDatum, PresyncChainData } from '@paima/sm';
import { ConfigNetworkType } from '@paima/utils';
import type { ConfigNetworkType } from '@paima/utils';

export function groupCdeData(
network: string,
Expand Down
11 changes: 4 additions & 7 deletions packages/engine/paima-runtime/src/runtime-loops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import {
} from './utils.js';
import { cleanNoncesIfTime } from './nonce-gc.js';
import type { PoolClient } from 'pg';
import { FUNNEL_PRESYNC_FINISHED } from '@paima/utils';
import type { CardanoConfig } from '@paima/utils/src/config/loading.js';
import { ConfigNetworkType } from '@paima/utils/src/config/loading.js';
import { FUNNEL_PRESYNC_FINISHED, ConfigNetworkType } from '@paima/utils';
import type { CardanoConfig } from '@paima/utils';

// The core logic of paima runtime which polls the funnel and processes the resulting chain data using the game's state machine.
// Of note, the runtime is designed to continue running/attempting to process the next required block no matter what errors propagate upwards.
Expand Down Expand Up @@ -81,11 +80,9 @@ async function runPresync(

for (const network of Object.keys(networks)) {
if (upper[network] > presyncBlockHeight[network]) {
doLog(
`${network}: ${JSON.stringify(presyncBlockHeight[network])}-${JSON.stringify(upper[network])}`
);
doLog(`[presync-round] ${network}: ${presyncBlockHeight[network]}-${upper[network]}`);
} else {
doLog(`${network}: ${JSON.stringify(presyncBlockHeight[network])}`);
doLog(`[presync-round] ${network}: ${presyncBlockHeight[network]}`);
}
}

Expand Down
8 changes: 6 additions & 2 deletions packages/engine/paima-sm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ const SM: GameStateMachineInitializer = {
dbTx
);
if (cdeDataLength > 0) {
doLog(`Processed ${cdeDataLength} CDE events in block #${latestCdeData.blockNumber}`);
doLog(
`[${latestCdeData.network}] Processed ${cdeDataLength} CDE events in block #${latestCdeData.blockNumber}`
);
}
} else if (latestCdeData.networkType === ConfigNetworkType.CARDANO) {
const cdeDataLength = await processCardanoCdeData(
Expand All @@ -128,7 +130,9 @@ const SM: GameStateMachineInitializer = {
dbTx
);
if (cdeDataLength > 0) {
doLog(`Processed ${cdeDataLength} CDE events in slot #${latestCdeData.blockNumber}`);
doLog(
`[${latestCdeData.network}] Processed ${cdeDataLength} CDE events in slot #${latestCdeData.blockNumber}`
);
}
}
},
Expand Down
6 changes: 1 addition & 5 deletions packages/paima-sdk/paima-utils/src/config/loading.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as fs from 'fs/promises';
import YAML from 'yaml';
import type { Static, TSchema } from '@sinclair/typebox';
import type { ValueErrorType } from '@sinclair/typebox/value';
import { Value } from '@sinclair/typebox/value';
import { Type } from '@sinclair/typebox';
import { ENV, doLog } from '../index.js';
Expand Down Expand Up @@ -124,19 +123,16 @@ export function parseConfigFile(configFileData: string): Static<typeof BaseConfi
return baseConfig;
}

// TODO: copy pasted code
function checkOrError<T extends TSchema>(
name: undefined | string,
structure: T,
config: unknown
): Static<T> {
// 1) Check if there are any errors since Value.Decode doesn't give error messages
{
const skippableErrors: ValueErrorType[] = [];

const errors = Array.from(Value.Errors(structure, config));
for (const error of errors) {
if (errors.length !== 1 && skippableErrors.find(val => val === error.type) != null) continue;
if (errors.length !== 1) continue;
console.error({
name: name ?? 'Configuration root',
path: error.path,
Expand Down

0 comments on commit 8a9d340

Please sign in to comment.