Skip to content

Commit

Permalink
handle empty value (#99)
Browse files Browse the repository at this point in the history
* handle empty value

* fix log

* truncate storage diff
  • Loading branch information
ermalkaleci authored Dec 19, 2022
1 parent 14313c3 commit 1123889
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
12 changes: 8 additions & 4 deletions executor/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,14 @@ pub async fn run_task(task: TaskCall) -> Result<TaskResponse, String> {
let key = HexString(req.key().as_ref().to_vec());
let key = serde_wasm_bindgen::to_value(&key).map_err(|e| e.to_string())?;
let value = get_storage(hash.clone(), key).await;
let value = serde_wasm_bindgen::from_value::<HexString>(value)
.map(|x| x.0)
.map_err(|e| e.to_string())?;
let value = if value.is_empty() { None } else { Some(value) };
let value = if value.is_string() {
let encoded = serde_wasm_bindgen::from_value::<HexString>(value)
.map(|x| x.0)
.map_err(|e| e.to_string())?;
Some(encoded)
} else {
None
};
req.inject_value(value.map(iter::once))
}
RuntimeHostVm::PrefixKeys(req) => {
Expand Down
4 changes: 2 additions & 2 deletions src/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export const setupBindings = (chain: Blockchain) => {
getStorage: async function (blockHash: HexString, key: HexString) {
const block = await chain.getBlock(blockHash)
if (!block) throw Error(`Block not found ${blockHash}`)
const value = await block.get(key).then((x) => (x ? x : '0x'))
logger.trace({ blockHash, key, value: truncate(value) }, 'exec_storageGet')
const value = await block.get(key)
logger.trace({ blockHash, key, value: value && truncate(value) }, 'exec_storageGet')
return value
},
getPrefixKeys: async function (blockHash: HexString, key: HexString) {
Expand Down
9 changes: 6 additions & 3 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, truncateStorageDiff } from '../logger'
import { defaultLogger, truncate, truncateStorageDiff } from '../logger'

const logger = defaultLogger.child({ name: 'txpool' })

Expand Down Expand Up @@ -157,7 +157,7 @@ export class TxPool {
const resp2 = await newBlock.call('BlockBuilder_finalize_block', '0x')

newBlock.pushStorageLayer().setAll(resp2.storageDiff)
logger.trace(resp2.storageDiff, 'Finalize block')
logger.trace(truncateStorageDiff(resp2.storageDiff), 'Finalize block')

const blockData = registry.createType('Block', {
header,
Expand All @@ -171,7 +171,10 @@ export class TxPool {
})

const diff = await newBlock.storageDiff()
logger.trace(diff, 'Final block')
logger.trace(
Object.entries(diff).map(([key, value]) => [key, truncate(value)]),
'Final block'
)
finalBlock.pushStorageLayer().setAll(diff)

this.#chain.unregisterBlock(newBlock)
Expand Down

0 comments on commit 1123889

Please sign in to comment.