diff --git a/CHANGELOG.md b/CHANGELOG.md index f9805eb258..81b7cc1eb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.14.0-beta.x + +- Ensure metadata is only requested once upon startup + # 1.13.1 May 6, 2020 - Add support for ECDSA keypairs in extrinsic signers (Thanks to https://github.com/akru) @@ -7,6 +11,7 @@ - Remove static test-only metadata for Polkadot dev chains (not updated regularly, Substrate dev to remain) - Revert error swallow for wrong preimage data (temp. override for Kusama upgrade with no migration) - Fix `.encodedLength` calculation on `[Type; N]` types +- Add new `rpc.grandpa.roundState` RPC - Update types & metadata as per latest Substrate master - Adjust Centrifuge starting version diff --git a/packages/api/src/base/Init.ts b/packages/api/src/base/Init.ts index 93d77b9bec..68d0fba128 100644 --- a/packages/api/src/base/Init.ts +++ b/packages/api/src/base/Init.ts @@ -5,7 +5,7 @@ import { SignedBlock, RuntimeVersion } from '@polkadot/types/interfaces'; import { ApiBase, ApiOptions, ApiTypes, DecorateMethod } from '../types'; -import { Subscription, combineLatest, of } from 'rxjs'; +import { Observable, Subscription, of } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; import { Metadata, Text } from '@polkadot/types'; import { LATEST_EXTRINSIC_VERSION } from '@polkadot/types/extrinsic/Extrinsic'; @@ -124,28 +124,25 @@ export default abstract class Init extends Decorate - combineLatest( - of(version), - this._rpcCore.state.getMetadata() - ) - ), - map(([version, metadata]: [RuntimeVersion, Metadata]): boolean => { - if (this._runtimeVersion?.specVersion.eq(version.specVersion)) { - return false; - } + switchMap((version: RuntimeVersion): Observable => + // only retrieve the metadata when the on-chain version has been changed + this._runtimeVersion?.specVersion.eq(version.specVersion) + ? of(false) + : this._rpcCore.state.getMetadata().pipe( + map((metadata: Metadata): boolean => { + l.log(`Runtime version updated to ${version.specVersion}`); - l.log(`Runtime version updated to ${version.specVersion}`); + this._runtimeMetadata = metadata; + this._runtimeVersion = version; + this._rx.runtimeVersion = version; - this._runtimeMetadata = metadata; - this._runtimeVersion = version; - this._rx.runtimeVersion = version; + this.registerTypes(getSpecTypes(this.registry, this._runtimeChain as Text, version.specName, version.specVersion)); + this.injectMetadata(metadata, false); - this.registerTypes(getSpecTypes(this.registry, this._runtimeChain as Text, version.specName, version.specVersion)); - this.injectMetadata(metadata, false); - - return true; - }) + return true; + }) + ) + ) ).subscribe(); } @@ -159,6 +156,7 @@ export default abstract class Init extends Decorate