1

I understand that every so often the metadata version gets changed with runtime upgrades over time. What I'm not clear about is how does this affect trying to access the older blocks?

Today, will one version of the metadata decode all blocks from genesis to the head on a single parachain? Or do I need to have all the metadata versions that were used to be able to go back in time all the way to genesis? (If this is the case, is there a way to know at which blocks the metadata version transitions occur?)

1 Answer 1

2

You need to decode events/extrinsics/errors/etc. with the metadata at that point in the runtime. With different upgrades types change, indexes move around, pallets are added, etc. There is no one-size-fits-all.

So you would effectively need to query the runtime version for the point at which you would like the values and then, if you don't have metadata corresponding to this, retrieve it and use it for decoding. (On relays the system.CodeUpdated event also shows when an upgrade has been applied, in addition to the change in runtime version)

It is slightly more tricky to retrieve the specific metadata, since the version update already shows at the end of the block processing, but using the new update only kicks in at the start of the next.

So if an upgrade happens at block X, the extrinsics in that block is processed with the metadata from block X-1, however the new metadata will be used to process anything at X+1. So basically the metadata that is to be used for decoding (and what was used for block processing) is what is available on the block parent.

2
  • Seems inefficient to have to fetch the state for system.lastRuntimeUpgrade at each block to see if the metadata has changed before decoding. Is the runtime version or metadata version (or a hash of these) stored in the block header somewhere?
    – Squirrel
    Commented May 24, 2022 at 7:10
  • This would be nice to have as on chain state: github.com/polkadot-js/api/blob/master/packages/types-known/src/…
    – Squirrel
    Commented May 24, 2022 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.