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

Feature: Add dry run CLI and use it in register_account_role #3992

Merged
merged 4 commits into from
Sep 19, 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
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions api/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ cf-amm = { path = "../../state-chain/amm" }
sp-consensus-aura = { git = 'https://github.com/chainflip-io/substrate.git', tag = 'chainflip-monthly-2023-08+2' }
sp-core = { git = 'https://github.com/chainflip-io/substrate.git', tag = 'chainflip-monthly-2023-08+2' }
sp-consensus-grandpa = { git = 'https://github.com/chainflip-io/substrate.git', tag = 'chainflip-monthly-2023-08+2' }
codec = { package = "parity-scale-codec", version = "3.6.1" }
28 changes: 27 additions & 1 deletion api/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use cf_chains::{
CcmChannelMetadata, ForeignChain,
};
use cf_primitives::{AccountRole, Asset, BasisPoints, ChannelId};
use codec::Encode;
use futures::FutureExt;
use pallet_cf_governance::ExecutionMode;
use pallet_cf_validator::MAX_LENGTH_FOR_VANITY_NAME;
Expand Down Expand Up @@ -138,7 +139,24 @@ impl StateChainApi {
}

#[async_trait]
impl OperatorApi for StateChainClient {}
impl<
SignedExtrinsicClient: Send + Sync + 'static + SignedExtrinsicApi,
RawRpcClient: Send + Sync + 'static + RawRpcApi,
> OperatorApi for StateChainClient<SignedExtrinsicClient, BaseRpcClient<RawRpcClient>>
{
async fn dry_run(
&self,
call: RuntimeCall,
at: Option<state_chain_runtime::Hash>,
) -> Result<Bytes> {
Ok(self
.base_rpc_client
.raw_rpc_client
.dry_run(Encode::encode(&call).into(), at)
.await?)
}
}

#[async_trait]
impl GovernanceApi for StateChainClient {}
#[async_trait]
Expand Down Expand Up @@ -187,6 +205,8 @@ pub trait OperatorApi: SignedExtrinsicApi + RotateSessionKeysApi + AuctionPhaseA
AccountRole::None => bail!("Cannot register account role None"),
};

let _ = self.dry_run(call.clone(), None).await?;

let (tx_hash, ..) = self
.submit_signed_extrinsic(call)
.await
Expand Down Expand Up @@ -258,6 +278,12 @@ pub trait OperatorApi: SignedExtrinsicApi + RotateSessionKeysApi + AuctionPhaseA
println!("Vanity name set at tx {tx_hash:#x}.");
Ok(())
}

async fn dry_run(
&self,
call: RuntimeCall,
at: Option<state_chain_runtime::Hash>,
) -> Result<Bytes>;
}

#[async_trait]
Expand Down
1 change: 1 addition & 0 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ sp-core = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainf
sp-rpc = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainflip-monthly-2023-08+2" }
sp-runtime = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainflip-monthly-2023-08+2" }
sp-version = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainflip-monthly-2023-08+2" }
substrate-frame-rpc-system = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainflip-monthly-2023-08+2" }

[dependencies.rocksdb]
version = "0.21.0"
Expand Down
18 changes: 18 additions & 0 deletions engine/src/state_chain_observer/client/base_rpc_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ pub trait RawRpcApi:
state_chain_runtime::Hash,
state_chain_runtime::Header,
state_chain_runtime::SignedBlock,
> + substrate_frame_rpc_system::SystemApiClient<
state_chain_runtime::Hash,
state_chain_runtime::AccountId,
state_chain_runtime::Nonce,
>
{
}
Expand Down Expand Up @@ -119,6 +123,12 @@ pub trait BaseRpcApi {
asset: Asset,
at: state_chain_runtime::Hash,
) -> RpcResult<Vec<(Tick, Tick, Liquidity)>>;

async fn dry_run(
&self,
extrinsic: Bytes,
at: Option<state_chain_runtime::Hash>,
) -> RpcResult<Bytes>;
}

pub struct BaseRpcClient<RawRpcClient> {
Expand Down Expand Up @@ -215,4 +225,12 @@ impl<RawRpcClient: RawRpcApi + Send + Sync> BaseRpcApi for BaseRpcClient<RawRpcC
//self.raw_rpc_client.cf_pool_minted_positions(lp, asset, Some(at)).await
Err(jsonrpsee::core::Error::Custom("Not implemented".to_string()))
}

async fn dry_run(
&self,
extrinsic: Bytes,
at: Option<state_chain_runtime::Hash>,
) -> RpcResult<Bytes> {
self.raw_rpc_client.dry_run(extrinsic, at).await
}
}