Skip to content
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

feat: API Bins check SC compatibility #4342

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion api/lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chainflip-api"
version = "0.1.0"
version = "1.1.0"
edition = "2021"

[dependencies]
Expand All @@ -20,6 +20,7 @@ tokio = "1.28"
tracing = "0.1"
zeroize = "1.5.4"
libp2p-identity = { version = "0.2", features = ["ed25519", "peerid"] }
lazy_static = "1.4"

# Local
chainflip-engine = { path = "../../engine/" }
Expand Down
12 changes: 10 additions & 2 deletions api/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cf_chains::{
address::EncodedAddress, dot::PolkadotAccountId, evm::to_evm_address, AnyChain,
CcmChannelMetadata, ForeignChain,
};
use cf_primitives::{AccountRole, Asset, BasisPoints, ChannelId};
use cf_primitives::{AccountRole, Asset, BasisPoints, ChannelId, SemVer};
use futures::FutureExt;
use pallet_cf_governance::ExecutionMode;
use pallet_cf_validator::MAX_LENGTH_FOR_VANITY_NAME;
Expand Down Expand Up @@ -48,6 +48,14 @@ use chainflip_engine::state_chain_observer::client::{
};
use utilities::{clean_hex_address, task_scope::Scope};

lazy_static::lazy_static! {
static ref API_VERSION: SemVer = SemVer {
major: env!("CARGO_PKG_VERSION_MAJOR").parse::<u8>().unwrap(),
minor: env!("CARGO_PKG_VERSION_MINOR").parse::<u8>().unwrap(),
patch: env!("CARGO_PKG_VERSION_PATCH").parse::<u8>().unwrap(),
};
}

#[async_trait]
pub trait AuctionPhaseApi {
async fn is_auction_phase(&self) -> Result<bool>;
Expand Down Expand Up @@ -112,7 +120,7 @@ impl StateChainApi {
&state_chain_settings.signing_key_file,
AccountRole::Unregistered,
false,
None,
Some((*API_VERSION, false)),
)
.await?;

Expand Down
20 changes: 12 additions & 8 deletions engine/src/state_chain_observer/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ async fn create_finalized_block_subscription<
let base_rpc_client = &base_rpc_client;
async move {
Ok::<_, anyhow::Error>((
block.number,
block.hash,
base_rpc_client
.storage_value::<pallet_cf_environment::CurrentReleaseVersion<
Expand All @@ -269,7 +270,7 @@ async fn create_finalized_block_subscription<
))
}
})
.try_take_while(|(_block_hash, current_release_version)| {
.try_take_while(|(_block_number, _block_hash, current_release_version)| {
futures::future::ready({
Ok::<_, anyhow::Error>(
!required_version.is_compatible_with(*current_release_version),
Expand All @@ -278,8 +279,8 @@ async fn create_finalized_block_subscription<
})
.boxed();

incompatible_blocks.try_for_each(move |(block_hash, current_release_version)| futures::future::ready({
info!("This version '{}' is incompatible with the current release '{}' at block: {}. WAITING for a compatible release version.", required_version, current_release_version, block_hash);
incompatible_blocks.try_for_each(move |(block_number, block_hash, current_release_version)| futures::future::ready({
info!("This version '{required_version}' is incompatible with the current release '{current_release_version}' at block {block_number}: {block_hash:?}. WAITING for a compatible release version.");
Ok::<_, anyhow::Error>(())
})).await?;
} else {
Expand All @@ -290,9 +291,8 @@ async fn create_finalized_block_subscription<
.await?;
if !required_version.is_compatible_with(current_release_version) {
bail!(
"This version '{}' is incompatible with the current release '{}' at block: {}.",
required_version,
current_release_version,
"This version '{required_version}' is incompatible with the current release '{current_release_version}' at block {}: {:?}.",
latest_block.number,
latest_block.hash,
);
}
Expand Down Expand Up @@ -321,9 +321,13 @@ async fn create_finalized_block_subscription<
let block = result_block?;
latest_block = block;
if let Some((required_version, _)) = required_version_and_wait {
let current_release_version = base_rpc_client.storage_value::<pallet_cf_environment::CurrentReleaseVersion<state_chain_runtime::Runtime>>(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))
break Err(anyhow!("This version '{required_version}' is no longer compatible with the release version '{current_release_version}' at block {}: {:?}", block.number, block.hash))
}
}

Expand Down