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 staking.ledger with runtime 1050 #5170

Closed wpank closed 2 years ago

wpank commented 2 years ago

This might be a duplicate of #4854, so feel free to close this if the issue is actually fixed.

I'm working on some indexing things for kusama with this repo:

https://github.com/wpank/subql/blob/dev/src/mappings/Nominate.ts#L32

Specifically this line with cause an error when trying to query storage at the past Kusama block height of #1387571 (blockhash 0xfb0cc3948aa7e2c7a32482c1da931d07209c808c764b7222276a41840f94d979) throwing:

2022-08-17T10:33:33.841Z <BlockDispatcherService> ERROR failed to index block at height 1387571  
Error: Unable to decode storage staking.ledger: entry 0:: createType(StakingLedger):: {"stash":"AccountId","total":"Compact<Balance>","active":"Compact<Balance>","unlocking":"Vec<UnlockChunk>"}:: Decoded input doesn't match input, received 0x7e8b419c60e88c55bce7525e697f90b1746746bf78a59707c3dbee339dd67c680bdfc3a796081e0bdfc3a796081e000108020000 (52 bytes), created 0x7e8b419c60e88c55bce7525e697f90b1746746bf78a59707c3dbee339dd67c680bdfc3a796081e0bdfc3a796081e00 (47 bytes)
    at RpcCore._newType (/usr/local/lib/node_modules/@subql/node/node_modules/@polkadot/rpc-core/cjs/bundle.js:504:13)
    at RpcCore._formatStorageSetEntry (/usr/local/lib/node_modules/@subql/node/node_modules/@polkadot/rpc-core/cjs/bundle.js:476:24)
    at /usr/local/lib/node_modules/@subql/node/node_modules/@polkadot/rpc-core/cjs/bundle.js:448:25
    at Type.reduce (<anonymous>)
    at RpcCore._formatStorageSet (/usr/local/lib/node_modules/@subql/node/node_modules/@polkadot/rpc-core/cjs/bundle.js:447:17)
    at /usr/local/lib/node_modules/@subql/node/node_modules/@polkadot/rpc-core/cjs/bundle.js:421:58
    at Array.map (<anonymous>)
    at RpcCore._formatOutput (/usr/local/lib/node_modules/@subql/node/node_modules/@polkadot/rpc-core/cjs/bundle.js:416:29)
    at RpcCore._formatResult (/usr/local/lib/node_modules/@subql/node/node_modules/@polkadot/rpc-core/cjs/bundle.js:232:27)
    at callWithRegistry (/usr/local/lib/node_modules/@subql/node/node_modules/@polkadot/rpc-core/cjs/bundle.js:260:19)
node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

Error: Unable to decode storage staking.ledger: entry 0:: createType(StakingLedger):: {"stash":"AccountId","total":"Compact<Balance>","active":"Compact<Balance>","unlocking":"Vec<UnlockChunk>"}:: Decoded input doesn't match input, received 0x7e8b419c60e88c55bce7525e697f90b1746746bf78a59707c3dbee339dd67c680bdfc3a796081e0bdfc3a796081e000108020000 (52 bytes), created 0x7e8b419c60e88c55bce7525e697f90b1746746bf78a59707c3dbee339dd67c680bdfc3a796081e0bdfc3a796081e00 (47 bytes)
    at RpcCore._newType (/usr/local/lib/node_modules/@subql/node/node_modules/@polkadot/rpc-core/cjs/bundle.js:504:13)
    at RpcCore._formatStorageSetEntry (/usr/local/lib/node_modules/@subql/node/node_modules/@polkadot/rpc-core/cjs/bundle.js:476:24)
    at /usr/local/lib/node_modules/@subql/node/node_modules/@polkadot/rpc-core/cjs/bundle.js:448:25
    at Type.reduce (<anonymous>)
    at RpcCore._formatStorageSet (/usr/local/lib/node_modules/@subql/node/node_modules/@polkadot/rpc-core/cjs/bundle.js:447:17)
    at /usr/local/lib/node_modules/@subql/node/node_modules/@polkadot/rpc-core/cjs/bundle.js:421:58
    at Array.map (<anonymous>)
    at RpcCore._formatOutput (/usr/local/lib/node_modules/@subql/node/node_modules/@polkadot/rpc-core/cjs/bundle.js:416:29)
    at RpcCore._formatResult (/usr/local/lib/node_modules/@subql/node/node_modules/@polkadot/rpc-core/cjs/bundle.js:232:27)
    at callWithRegistry (/usr/local/lib/node_modules/@subql/node/node_modules/@polkadot/rpc-core/cjs/bundle.js:260:19)

This is querying storage from runtime 1050. Based on reading the other issue it seems like the issue was fixed with #4856, so not sure if I'm doing something wrong or need to add some types or something.

Trying this also in the polkadot.js ui in querying the chainstate tab, it seems to not resolve and has the same error in the console.

For example, querying staking.ledger for the account Gk6v5CXUy2cPMtVxXtN7ZUn7K5y7UFEm78xp98Uatjt2yuV at blockhash: 0xfb0cc3948aa7e2c7a32482c1da931d07209c808c764b7222276a41840f94d979

jacogr commented 2 years ago

If I have one more types issue, I'm going to move to Antartica.

Anyway, linked the above issue does help, it at least gives another testcase. So somewhere between these for 1050 -

https://github.com/polkadot-js/api/blob/2bad0f479932ddac92a5583321a280e40e9cb8cf/packages/types-known/src/spec/kusama.ts#L111

and these for 1051+

https://github.com/polkadot-js/api/blob/2bad0f479932ddac92a5583321a280e40e9cb8cf/packages/types-known/src/spec/kusama.ts#L125

Maybe the PR above was too heavy handed, but either way both tests need to pass.

(PS: When you have time, would be good to index the whole of Polkadot in the same manner as well, would be interesting to see if that passes all the way though. These are really handled on a case-by-case basis, generally with the changes backdated some things do fall by the wayside)

jacogr commented 2 years ago

0xb645c7be25ab36bb1e70ebb5541fc238367c206124427b9c6871b2581a5a0f2e is 1,375,829 0xfb0cc3948aa7e2c7a32482c1da931d07209c808c764b7222276a41840f94d979 is 1,387,571

Both are on 1050, however -

// passes
const at1 = await api.at('0xb645c7be25ab36bb1e70ebb5541fc238367c206124427b9c6871b2581a5a0f2e')
await at.query.staking.ledger('F4qoxcCDNyYoMKiu4LNXkQQaJVnMDNhoABGtVVWwmsf4kdZ')

// fails
const at = await api.at('0xfb0cc3948aa7e2c7a32482c1da931d07209c808c764b7222276a41840f94d979')
await at.query.staking.ledger('F4qoxcCDNyYoMKiu4LNXkQQaJVnMDNhoABGtVVWwmsf4kdZ')

No idea why the same runtime, same definition is ok for one and not the other.

jacogr commented 2 years ago

Can you recall how lastReward: 'Option<EraIndex>' was introduced. Was it -

  1. one-time migration (which should not yield the above discrepancy - all types would be aligned immediately, so the above would indicate broken state)
  2. done on a per-reward-call basis, i.e. as the call was made (this would 100% explain the above where some structs have extra bytes and others do not - same runtime)
wpank commented 2 years ago

Can you recall how lastReward: 'Option<EraIndex>' was introduced. Was it -

  1. one-time migration (which should not yield the above discrepancy - all types would be aligned immediately, so the above would indicate broken state)
  2. done on a per-reward-call basis, i.e. as the call was made (this would 100% explain the above where some structs have extra bytes and others do not - same runtime)

https://github.com/paritytech/substrate/pull/5406

Based on this PR I think it's a mix of both

jacogr commented 2 years ago

It would be the change before this one - here there was already last_reward

polkadot-js-bot commented 2 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.