-
Notifications
You must be signed in to change notification settings - Fork 354
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
Ensure correct metadata for parsing (archive nodes, historical queries) #845
Comments
It must be the runtime upgrade blocks. (Sudo + setCode) Cannot think off hand where the error originates, but def. an issue and it should just work. (Strangely I have pulled a number of the upgrade blocks before without issues on multiple chains, so it feels like something new - or maybe I just got lucky earlier on and it just hit some limit lately) |
To add a little more information, the most recent instance of this happening is just prior to block 580,000. However, prior to that, there are perhaps another 100 or so errors of this type. If you need a larger sample of block hashes that can reproduce this issue I am happy to grab those for you. |
I am currently sync-ing with archive mode, so will be looking at this one as well as #846 ASAP. (They have been hanging for way too long) |
Ok, this one is problematic... basically the staking interfaces has changed radically. It seems to fail on this extrinsic -
The issue at this point in time is that there was no actual extrinsic of type Basically, the API gets the latest metadata, tries to use that to decode... and fails. All is not lost, at this point the support is just lacking - for these cases you need to use the metadata available at this specific block to decode. Which is all fine and well, however doing this automatically is problematic since you effectively need to query the block, query for metadata at blockNumber - 1 (the query result is the data at the end of the block), inject it and use it. TL;DR As it stands there is no "quick" API fix, however can be done to work around when using it as a trawler, something along the lines of Line 390 in 4e83a7f
parentHash is passed into the getMetadata, or rather the last known good block)
Related to #449 (which goes the other way) |
Related to #449 (in reverse) |
This is an attempt to find out if the version is causing the metadata issue in the frontend. polkadot-js/api#845
I wrote a function to switch to metadata and types to the runtime version of a given block. Unfortunately it works only for switching from newer version to older version (eg. from 1058 to 1055). When switching from older to newer (eg. from 1055 to 1058), event decoding returns bad deserialization error. let apiSpecVersion = undefined;
export async function updateMetadataAndTypes(api, hash) {
const runtimeVersion = await api.rpc.state.getRuntimeVersion(hash);
const targetVersion = runtimeVersion.specVersion;
if (apiSpecVersion && targetVersion.gt(apiSpecVersion)) {
// FIXME: when injecting metadata and types with a newer runtime spec
// version, event decoding does not work any more. For workaround, use
// a supervisor to restart the process.
process.exit(1);
}
if (targetVersion.eq(apiSpecVersion)) {
return;
}
console.log(
`Updating spec version from ${apiSpecVersion} to ${targetVersion}`
);
apiSpecVersion = targetVersion;
const rpcMeta = await api.rpc.state.getMetadata(hash);
api.registerTypes(
getSpecTypes(
api.registry,
api._runtimeChain,
runtimeVersion.specName,
runtimeVersion.specVersion
)
);
api.injectMetadata(rpcMeta, false);
api._runtimeMetadata = rpcMeta;
api._runtimeVersion = runtimeVersion;
api._rx.runtimeVersion = runtimeVersion;
const version = api.runtimeVersion.specVersion;
console.log(`Metadata and types updated to version ${version}`);
} For example: const hash1055 = "0xe0d2fd5baf79aac0780bf706c1e22464a6f9190ba3cdd3295d10b5ec21b77160"
const hash1058 = "0x937d98e4bbd3908b9147db7798462f8cb0453593598754eb2225b118f0b83161"
updateMetadataAndTypes(api, hash1058)
await api.query.system.events.at(hash1058) // ok
updateMetadataAndTypes(api, hash1055)
await api.query.system.events.at(hash1055) // ok
updateMetadataAndTypes(api, hash1058)
await api.query.system.events.at(hash1058) // uncaught decoding error Any idea on how to make this also works for switching back to metadata / types with newer versions? |
We also have some code dealing with different metadata versions https://github.com/open-web3-stack/open-web3.js/blob/02c9a1f0fd02cb5bc86a48a1037492c800e2f493/packages/scanner/src/Scanner.ts#L201 |
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. |
There are several blocks throughout the chain that produce the following error when you try to fetch them:
This code will recreate the problem:
Also, you will notice there is no
then
orcatch
on thegetBlock
promise. That is because the above error does not actually land in the catch block. It gets handled and logged by the library itself, which makes it more difficult for me to handle the error in my code.The text was updated successfully, but these errors were encountered: