diff --git a/src/blockchain/txpool.ts b/src/blockchain/txpool.ts index 6b9250db..542693d3 100644 --- a/src/blockchain/txpool.ts +++ b/src/blockchain/txpool.ts @@ -8,7 +8,7 @@ import { Blockchain } from '.' import { InherentProvider } from './inherents' import { ResponseError } from '../rpc/shared' import { compactHex } from '../utils' -import { defaultLogger } from '../logger' +import { defaultLogger, truncateStorageDiff } from '../logger' const logger = defaultLogger.child({ name: 'txpool' }) @@ -112,7 +112,7 @@ export class TxPool { ) const resp = await newBlock.call('Core_initialize_block', header.toHex()) - logger.trace(resp.storageDiff, 'Initialize block') + logger.trace(truncateStorageDiff(resp.storageDiff), 'Initialize block') newBlock.pushStorageLayer().setAll(resp.storageDiff) @@ -128,7 +128,7 @@ export class TxPool { try { const resp = await newBlock.call('BlockBuilder_apply_extrinsic', extrinsic) newBlock.pushStorageLayer().setAll(resp.storageDiff) - logger.trace(resp.storageDiff, 'Applied inherent') + logger.trace(truncateStorageDiff(resp.storageDiff), 'Applied inherent') } catch (e) { logger.warn('Failed to apply inherents %o %s', e, e) throw new ResponseError(1, 'Failed to apply inherents') @@ -139,7 +139,7 @@ export class TxPool { try { const resp = await newBlock.call('BlockBuilder_apply_extrinsic', extrinsic) newBlock.pushStorageLayer().setAll(resp.storageDiff) - logger.trace(resp.storageDiff, 'Applied extrinsic') + logger.trace(truncateStorageDiff(resp.storageDiff), 'Applied extrinsic') } catch (e) { logger.info('Failed to apply extrinsic %o %s', e, e) this.#pool.push(extrinsic) diff --git a/src/executor.ts b/src/executor.ts index 358ddb79..7aa6954b 100644 --- a/src/executor.ts +++ b/src/executor.ts @@ -12,7 +12,7 @@ import { global.WebSocket = WebSocket import { calculate_state_root, create_proof, decode_proof, get_runtime_version, run_task } from '../executor/pkg' -import { defaultLogger } from './logger' +import { defaultLogger, truncate, truncateStorageDiff } from './logger' const logger = defaultLogger.child({ name: 'executor' }) @@ -65,8 +65,15 @@ export const runTask = async (task: { mockSignatureHost: boolean allowUnresolvedImports: boolean }) => { - logger.trace({ task }, 'taskRun') + logger.trace({ task: { ...task, wasm: truncate(task.wasm) } }, 'taskRun') const response = await run_task(task) - logger.trace({ response }, 'taskResponse') + if (response.Call) { + logger.trace( + { result: truncate(response.Call.result), storageDiff: truncateStorageDiff(response.Call.storageDiff) }, + 'taskResponse' + ) + } else { + logger.trace({ response }, 'taskResponse') + } return response } diff --git a/src/logger.ts b/src/logger.ts index 2fdf232e..2c1b995d 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -1,4 +1,6 @@ +import { HexString } from '@polkadot/util/types' import pino from 'pino' + export const defaultLogger = pino({ level: process.env.LOG_LEVEL || 'info', transport: { @@ -6,7 +8,7 @@ export const defaultLogger = pino({ }, }) -export const truncate = (str?: string) => { +export const truncate = (str: string | null) => { if (str == null) { return str } @@ -16,3 +18,7 @@ export const truncate = (str?: string) => { return str } } + +export const truncateStorageDiff = (diff: [HexString, HexString | null][]): [HexString, string | null][] => { + return diff.map(([key, value]) => [key, truncate(value)]) +}