Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

truncate storageDiff and wasm #98

Merged
merged 1 commit into from
Dec 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/blockchain/txpool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })

Expand Down Expand Up @@ -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)

Expand All @@ -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')
Expand All @@ -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)
Expand Down
13 changes: 10 additions & 3 deletions src/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })

Expand Down Expand Up @@ -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
}
8 changes: 7 additions & 1 deletion src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { HexString } from '@polkadot/util/types'
import pino from 'pino'

export const defaultLogger = pino({
level: process.env.LOG_LEVEL || 'info',
transport: {
target: 'pino-pretty',
},
})

export const truncate = (str?: string) => {
export const truncate = (str: string | null) => {
if (str == null) {
return str
}
Expand All @@ -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)])
}