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

Storage Decoding error when querying system.account.at() from a historic block #3871

Closed
TarikGul opened this issue Aug 12, 2021 · 3 comments
Closed

Comments

@TarikGul
Copy link
Member

TarikGul commented Aug 12, 2021

Resproducible Example:

const { ApiPromise, WsProvider } = require('@polkadot/api');

const main = async () => {
    const api = await ApiPromise.create({
        provider: new WsProvider('wss://kusama-rpc.polkadot.io'),
    });
    
    const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
    
    // Block Height 467568
    const historicBlockHash = '0x3361f6446c72aaa6679aa40a03e493a851161fd08cb53237968a9967902691c0'
    const { data: { free } } = await api.query.system.account.at(historicBlockHash, ALICE);

    console.log('Alice has a free balance of ', free.toHuman());
}

Resulting error:

RPC-CORE: getStorage(key: StorageKey, at?: BlockHash): StorageData:: Unable to decode storage system.account:: createType(AccountInfo):: {"nonce":"Index","refcount":"RefCount","data":"AccountData"}:: Decoded input doesn't match input, received 0x0000000000000000000000000000000000000000000000000000000000000000…0000000000000000000000000000000000000000000000000000000000000000 (80 bytes), created 0x0000000000000000000000000000000000000000000000000000000000000000…0000000000000000000000000000000000000000000000000000000000000000 (69 bytes)
Error: Unable to decode storage system.account:: createType(AccountInfo):: {"nonce":"Index","refcount":"RefCount","data":"AccountData"}:: Decoded input doesn't match input, received 0x0000000000000000000000000000000000000000000000000000000000000000…0000000000000000000000000000000000000000000000000000000000000000 (80 bytes), created 0x0000000000000000000000000000000000000000000000000000000000000000…0000000000000000000000000000000000000000000000000000000000000000 (69 bytes)
    at RpcCore._newType (/Users/tarik/Desktop/parity/sanity-checks/polka-test/node_modules/@polkadot/rpc-core/bundle.cjs:450:13)
    at RpcCore._formatStorageData (/Users/tarik/Desktop/parity/sanity-checks/polka-test/node_modules/@polkadot/rpc-core/bundle.cjs:399:17)
    at RpcCore._formatOutput (/Users/tarik/Desktop/parity/sanity-checks/polka-test/node_modules/@polkadot/rpc-core/bundle.cjs:376:19)
    at callWithRegistry (/Users/tarik/Desktop/parity/sanity-checks/polka-test/node_modules/@polkadot/rpc-core/bundle.cjs:255:42)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

Using @polkadot/api 5.4.1

Rel: #634

Per the related issue:

this breakage may have something to do with a change of the storage key location for balances or account info.

@jacogr
Copy link
Member

jacogr commented Aug 13, 2021

There is pre introduction of system.account - so whatever it returns won't be decodable.

// get API instance with metadata at a specific hash
const a = await api.at('0x3361f6446c72aaa6679aa40a03e493a851161fd08cb53237968a9967902691c0');

// [accountNonce, extrinsicCount, allExtrinsicsWeight, allExtrinsicsLen, blockHash, extrinsicData, number, parentHash, extrinsicsRoot, digest, events, eventCount, eventTopics]
console.log(Object.keys(a.query.system));

Rather at this point of the chain evolution it is a balances.freeBalance query` -

const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';

const a = await api.at('0x3361f6446c72aaa6679aa40a03e493a851161fd08cb53237968a9967902691c0');

// [totalIssuance, vesting, freeBalance, reservedBalance, locks]
console.log(Object.keys(a.query.balances));
console.log((await a.query.balances.freeBalance(ALICE)).toHuman())

// for extra benefit, the nonce (at this point stored in system)
console.log((await a.query.system.accountNonce(ALICE)).toHuman())

@TarikGul
Copy link
Member Author

Thanks for the response on this! Will close due to this giving enough context to find a work around for our problem!

Thanks again.

@polkadot-js-bot
Copy link

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.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Aug 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants