polkadot-js / api

Promise and RxJS APIs around Polkadot and Substrate based chains via RPC calls. It is dynamically generated based on what the Substrate runtime provides in terms of metadata.
Apache License 2.0
1.07k stars 350 forks source link

Unable to decode storage when use .entriesAt() #4020

Closed jiqiang90 closed 3 years ago

jiqiang90 commented 3 years ago

Hi, I got problem when use api.query.staking.erasStakers.entriesAt() with historical era and blocks.

Tested with Kusama.

Working with recent block and era

const blockHash9516297 = "0xbcc72eeb49d384216ddacfe0f416c97e7d08e619e52a766857c3b784e6a1e769";
const recentEntries = await api.query.staking.erasStakers.entriesAt(blockHash9516297, 2822)
console.log(recentEntries)

Throw error with history era

const blockHash6851189 = "0xe973b4fa7aae6177fc84af5a4649c7356aef056a861d5489926f7ddd4d3b6c44";
const historyEntries = await api.query.staking.erasStakers.entriesAt(blockHash6851189, 2038)
console.log(historyEntries)

Error: Unable to decode storage staking.erasStakers: entry 0:: createType((EraIndex,AccountId)):: (EraIndex,AccountId):: Decoded input doesn't match input, received 0x0f5ae3b2135ce71807bc1a40b2630c4e7e2ef3ef3a1fc5805b40b01e10096b88…b81ae04010e998c32864d3fe045e533991dd24355d72a1050f593d2b4cc7e618 (130 bytes), created 0x0f5ae3b2135ce71807bc1a40b2630c4e7e2ef3ef3a1fc5805b40b01e10096b88e769c862 (36 bytes)
    at RpcCore._newType (/Users/jiatwork/polkadot/api/packages/rpc-core/src/bundle.ts:445:13)
    at RpcCore._formatStorageSetEntry (/Users/jiatwork/polkadot/api/packages/rpc-core/src/bundle.ts:422:17)
    at reduce (/Users/jiatwork/polkadot/api/packages/rpc-core/src/bundle.ts:395:25)
    at Array.reduce (<anonymous>)
    at RpcCore._formatStorageSet (/Users/jiatwork/polkadot/api/packages/rpc-core/src/bundle.ts:394:17)
    at map (/Users/jiatwork/polkadot/api/packages/rpc-core/src/bundle.ts:360:14)
    at Array.map (<anonymous>)
    at RpcCore._formatOutput (/Users/jiatwork/polkadot/api/packages/rpc-core/src/bundle.ts:358:57)
    at callWithRegistry (/Users/jiatwork/polkadot/api/packages/rpc-core/src/bundle.ts:215:16)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
jacogr commented 3 years ago

I actually wanted to deprecate api.query.<section>.<method>.{at, sizeAt, entriesAt, keysAt} in 6.x because of these types of issues. The api.at(<blockHash>) always does the sane/correct thing.

It will probably go in in the next major version (it is not simple since the raw .at is also used, incorrectly now, internally to stuff like derives)

polkadot-js-bot commented 3 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.