Skip to content

Commit 651d651

Browse files
authored
fix metadata on init when its value is u32 max (#6043)
* fix metadata on init when its value is u32 max * Fix comment
1 parent 42b9735 commit 651d651

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

packages/api/src/base/Init.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
412412
: await firstValueFrom(this._rpcCore.state.call('Metadata_metadata_versions', '0x'));
413413
const versions = typeRegistry.createType('Vec<u32>', metadataVersionsAsBytes);
414414

415-
metadataVersion = versions.reduce((largest, current) => current.gt(largest) ? current : largest);
415+
// For unstable versions of the metadata the last value is set to u32 MAX in the runtime. This ensures only supported stable versions are used.
416+
metadataVersion = versions.filter((ver) => SUPPORTED_METADATA_VERSIONS.includes(ver.toNumber())).reduce((largest, current) => current.gt(largest) ? current : largest);
416417
} catch (e) {
417418
l.debug((e as Error).message);
418419
l.warn('error with state_call::Metadata_metadata_versions, rpc::state::get_metadata will be used');

0 commit comments

Comments
 (0)