From 051ee3345303f46fe2789e77f327caaa93b19822 Mon Sep 17 00:00:00 2001 From: Alastair Holmes Date: Mon, 16 Oct 2023 16:29:56 +0200 Subject: [PATCH] wip --- .../client/base_rpc_api.rs | 14 +--------- .../signed/submission_watcher.rs | 6 ++++- engine/src/state_chain_observer/client/mod.rs | 16 ++++++++--- state-chain/custom-rpc/src/lib.rs | 27 ++++--------------- state-chain/runtime/src/lib.rs | 3 --- state-chain/runtime/src/runtime_apis.rs | 3 +-- 6 files changed, 24 insertions(+), 45 deletions(-) diff --git a/engine/src/state_chain_observer/client/base_rpc_api.rs b/engine/src/state_chain_observer/client/base_rpc_api.rs index d8386f3643a..8589f88df58 100644 --- a/engine/src/state_chain_observer/client/base_rpc_api.rs +++ b/engine/src/state_chain_observer/client/base_rpc_api.rs @@ -1,7 +1,7 @@ use async_trait::async_trait; use cf_amm::{common::Tick, range_orders::Liquidity}; -use cf_primitives::{Asset, SemVer}; +use cf_primitives::Asset; use jsonrpsee::core::{ client::{ClientT, Subscription, SubscriptionClientT}, RpcResult, @@ -128,8 +128,6 @@ pub trait BaseRpcApi { &self, ) -> RpcResult>>; - async fn release_version(&self, block_hash: state_chain_runtime::Hash) -> RpcResult; - async fn runtime_version(&self) -> RpcResult; async fn pool_minted_positions( @@ -238,16 +236,6 @@ impl BaseRpcApi for BaseRpcClient RpcResult { - let (version, _success_fut) = futures::future::select_ok([ - self.raw_rpc_client.cf_current_release_version(Some(block_hash)), - #[allow(deprecated)] - self.raw_rpc_client.cf_current_compatibility_version(Some(block_hash)), - ]) - .await?; - Ok(version) - } - async fn runtime_version(&self) -> RpcResult { self.raw_rpc_client.runtime_version(None).await } diff --git a/engine/src/state_chain_observer/client/extrinsic_api/signed/submission_watcher.rs b/engine/src/state_chain_observer/client/extrinsic_api/signed/submission_watcher.rs index 5af60d2a5bc..37854c74fe5 100644 --- a/engine/src/state_chain_observer/client/extrinsic_api/signed/submission_watcher.rs +++ b/engine/src/state_chain_observer/client/extrinsic_api/signed/submission_watcher.rs @@ -364,7 +364,11 @@ impl<'a, 'env, BaseRpcClient: base_rpc_api::BaseRpcApi + Send + Sync + 'static> { if if let Some(check_unfinalized_version) = self.check_unfinalized_version { check_unfinalized_version.is_compatible_with( - self.base_rpc_client.release_version(block_hash).await?, + self.base_rpc_client + .storage_value::>(block_hash) + .await?, ) } else { true diff --git a/engine/src/state_chain_observer/client/mod.rs b/engine/src/state_chain_observer/client/mod.rs index 727e11d990b..3b83f2bfc2a 100644 --- a/engine/src/state_chain_observer/client/mod.rs +++ b/engine/src/state_chain_observer/client/mod.rs @@ -25,6 +25,7 @@ use self::{ base_rpc_api::BaseRpcClient, chain_api::ChainApi, extrinsic_api::signed::{signer, SignedExtrinsicApi}, + storage_api::StorageApi, }; /// For expressing an expectation regarding substrate's behaviour (Not our chain though) @@ -339,7 +340,11 @@ impl(( block_hash, - base_rpc_client.release_version(block_hash).await?, + base_rpc_client + .storage_value::>(block_hash) + .await?, )) } }) @@ -357,8 +362,11 @@ impl(()) })).await?; } else { - let current_release_version = - base_rpc_client.release_version(latest_block_hash).await?; + let current_release_version = base_rpc_client + .storage_value::>( + latest_block_hash, + ) + .await?; if !required_version.is_compatible_with(current_release_version) { bail!( "This version '{}' is incompatible with the current release '{}' at block: {}.", @@ -399,7 +407,7 @@ impl>(block_hash).await?; if !required_version.is_compatible_with(current_release_version) { break Err(anyhow!("This version '{}' is no longer compatible with the release version '{}' at block: {}", required_version, current_release_version, block_hash)) } diff --git a/state-chain/custom-rpc/src/lib.rs b/state-chain/custom-rpc/src/lib.rs index b4ecc303ddd..b1303c4f16c 100644 --- a/state-chain/custom-rpc/src/lib.rs +++ b/state-chain/custom-rpc/src/lib.rs @@ -254,17 +254,9 @@ pub trait CustomApi { ) -> RpcResult>>; #[method(name = "environment")] fn cf_environment(&self, at: Option) -> RpcResult; - #[method(name = "current_release_version")] - fn cf_current_release_version( - &self, - at: Option, - ) -> RpcResult; - #[deprecated(note = "Use `cf_current_release_version` instead.")] + #[deprecated(note = "Use direct storage access of `CurrentReleaseVersion` instead.")] #[method(name = "current_compatibility_version")] - fn cf_current_compatibility_version( - &self, - at: Option, - ) -> RpcResult; + fn cf_current_compatibility_version(&self) -> RpcResult; #[method(name = "min_swap_amount")] fn cf_min_swap_amount(&self, asset: Asset) -> RpcResult; #[subscription(name = "subscribe_pool_price", item = Price)] @@ -683,23 +675,14 @@ where .map(RpcEnvironment::from) } - fn cf_current_release_version( - &self, - at: Option, - ) -> RpcResult { + fn cf_current_compatibility_version(&self) -> RpcResult { + #[allow(deprecated)] self.client .runtime_api() - .cf_current_release_version(self.unwrap_or_best(at)) + .cf_current_compatibility_version(self.unwrap_or_best(None)) .map_err(to_rpc_error) } - fn cf_current_compatibility_version( - &self, - at: Option, - ) -> RpcResult { - self.cf_current_release_version(at) - } - fn cf_min_swap_amount(&self, asset: Asset) -> RpcResult { self.client .runtime_api() diff --git a/state-chain/runtime/src/lib.rs b/state-chain/runtime/src/lib.rs index 7ad98e3c115..7516effb376 100644 --- a/state-chain/runtime/src/lib.rs +++ b/state-chain/runtime/src/lib.rs @@ -887,9 +887,6 @@ impl_runtime_apis! { fn cf_current_compatibility_version() -> SemVer { Environment::current_release_version() } - fn cf_current_release_version() -> SemVer { - Environment::current_release_version() - } fn cf_epoch_duration() -> u32 { Validator::blocks_per_epoch() } diff --git a/state-chain/runtime/src/runtime_apis.rs b/state-chain/runtime/src/runtime_apis.rs index 55ac22784a7..5a2bd786320 100644 --- a/state-chain/runtime/src/runtime_apis.rs +++ b/state-chain/runtime/src/runtime_apis.rs @@ -96,9 +96,8 @@ decl_runtime_apis!( fn cf_auction_parameters() -> (u32, u32); fn cf_min_funding() -> u128; fn cf_current_epoch() -> u32; - #[deprecated(note = "Use cf_current_release_version instead")] + #[deprecated(note = "Use direct storage access of `CurrentReleaseVersion` instead.")] fn cf_current_compatibility_version() -> SemVer; - fn cf_current_release_version() -> SemVer; fn cf_epoch_duration() -> u32; fn cf_current_epoch_started_at() -> u32; fn cf_authority_emission_per_block() -> u128;