Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
AlastairHolmes committed Oct 16, 2023
1 parent 86663fb commit 051ee33
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 45 deletions.
14 changes: 1 addition & 13 deletions engine/src/state_chain_observer/client/base_rpc_api.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -128,8 +128,6 @@ pub trait BaseRpcApi {
&self,
) -> RpcResult<Subscription<sp_runtime::generic::Header<u32, BlakeTwo256>>>;

async fn release_version(&self, block_hash: state_chain_runtime::Hash) -> RpcResult<SemVer>;

async fn runtime_version(&self) -> RpcResult<RuntimeVersion>;

async fn pool_minted_positions(
Expand Down Expand Up @@ -238,16 +236,6 @@ impl<RawRpcClient: RawRpcApi + Send + Sync> BaseRpcApi for BaseRpcClient<RawRpcC
self.raw_rpc_client.subscribe_finalized_heads().await
}

async fn release_version(&self, block_hash: state_chain_runtime::Hash) -> RpcResult<SemVer> {
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<RuntimeVersion> {
self.raw_rpc_client.runtime_version(None).await
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::<pallet_cf_environment::CurrentReleaseVersion<
state_chain_runtime::Runtime,
>>(block_hash)
.await?,
)
} else {
true
Expand Down
16 changes: 12 additions & 4 deletions engine/src/state_chain_observer/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -339,7 +340,11 @@ impl<BaseRpcClient: base_rpc_api::BaseRpcApi + Send + Sync + 'static, SignedExtr
async move {
Ok::<_, anyhow::Error>((
block_hash,
base_rpc_client.release_version(block_hash).await?,
base_rpc_client
.storage_value::<pallet_cf_environment::CurrentReleaseVersion<
state_chain_runtime::Runtime,
>>(block_hash)
.await?,
))
}
})
Expand All @@ -357,8 +362,11 @@ impl<BaseRpcClient: base_rpc_api::BaseRpcApi + Send + Sync + 'static, SignedExtr
Ok::<_, anyhow::Error>(())
})).await?;
} else {
let current_release_version =
base_rpc_client.release_version(latest_block_hash).await?;
let current_release_version = base_rpc_client
.storage_value::<pallet_cf_environment::CurrentReleaseVersion<state_chain_runtime::Runtime>>(
latest_block_hash,
)
.await?;
if !required_version.is_compatible_with(current_release_version) {
bail!(
"This version '{}' is incompatible with the current release '{}' at block: {}.",
Expand Down Expand Up @@ -399,7 +407,7 @@ impl<BaseRpcClient: base_rpc_api::BaseRpcApi + Send + Sync + 'static, SignedExtr
finalized_block_header_stream.next().await.unwrap()?;
let block_hash = block_header.hash();
if let Some(required_version) = required_version {
let current_release_version = base_rpc_client.release_version(block_hash).await?;
let current_release_version = base_rpc_client.storage_value::<pallet_cf_environment::CurrentReleaseVersion<state_chain_runtime::Runtime>>(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))
}
Expand Down
27 changes: 5 additions & 22 deletions state-chain/custom-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,9 @@ pub trait CustomApi {
) -> RpcResult<Option<AssetsMap<Amount>>>;
#[method(name = "environment")]
fn cf_environment(&self, at: Option<state_chain_runtime::Hash>) -> RpcResult<RpcEnvironment>;
#[method(name = "current_release_version")]
fn cf_current_release_version(
&self,
at: Option<state_chain_runtime::Hash>,
) -> RpcResult<SemVer>;
#[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<state_chain_runtime::Hash>,
) -> RpcResult<SemVer>;
fn cf_current_compatibility_version(&self) -> RpcResult<SemVer>;
#[method(name = "min_swap_amount")]
fn cf_min_swap_amount(&self, asset: Asset) -> RpcResult<AssetAmount>;
#[subscription(name = "subscribe_pool_price", item = Price)]
Expand Down Expand Up @@ -683,23 +675,14 @@ where
.map(RpcEnvironment::from)
}

fn cf_current_release_version(
&self,
at: Option<state_chain_runtime::Hash>,
) -> RpcResult<SemVer> {
fn cf_current_compatibility_version(&self) -> RpcResult<SemVer> {
#[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<state_chain_runtime::Hash>,
) -> RpcResult<SemVer> {
self.cf_current_release_version(at)
}

fn cf_min_swap_amount(&self, asset: Asset) -> RpcResult<AssetAmount> {
self.client
.runtime_api()
Expand Down
3 changes: 0 additions & 3 deletions state-chain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
3 changes: 1 addition & 2 deletions state-chain/runtime/src/runtime_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 051ee33

Please sign in to comment.