Skip to content

Commit

Permalink
feat: speedy scc (PRO-777 PRO-593) (#3986)
Browse files Browse the repository at this point in the history
* disable gap filling

* resubmit_window

* next_account_nonce rpc

squash

* use next_account_nonce

* New InBlock interface changes only

* submission ids

* submit with watch stream

* check if submission in block

* Cache blocks inside SubmissionWatcher

* comments

* use until_in_block inside api code

* fix

* fix test

* fix for real

* logs
  • Loading branch information
AlastairHolmes authored and dandanlen committed Sep 26, 2023
1 parent a8ffe7c commit 3909df0
Show file tree
Hide file tree
Showing 11 changed files with 543 additions and 349 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

21 changes: 11 additions & 10 deletions api/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ pub use chainflip_engine::settings;
pub use chainflip_node::chain_spec::use_chainflip_account_id_encoding;

use chainflip_engine::state_chain_observer::client::{
base_rpc_api::BaseRpcClient, DefaultRpcClient, StateChainClient,
base_rpc_api::BaseRpcClient, extrinsic_api::signed::UntilInBlock, DefaultRpcClient,
StateChainClient,
};
use utilities::{clean_hex_address, task_scope::Scope};

Expand Down Expand Up @@ -178,7 +179,7 @@ pub trait OperatorApi: SignedExtrinsicApi + RotateSessionKeysApi + AuctionPhaseA
let (tx_hash, ..) = self
.submit_signed_extrinsic(pallet_cf_funding::Call::redeem { amount, address, executor })
.await
.until_finalized()
.until_in_block()
.await?;

Ok(tx_hash)
Expand All @@ -188,7 +189,7 @@ pub trait OperatorApi: SignedExtrinsicApi + RotateSessionKeysApi + AuctionPhaseA
let (tx_hash, ..) = self
.submit_signed_extrinsic(pallet_cf_funding::Call::bind_redeem_address { address })
.await
.until_finalized()
.until_in_block()
.await?;

Ok(tx_hash)
Expand All @@ -210,7 +211,7 @@ pub trait OperatorApi: SignedExtrinsicApi + RotateSessionKeysApi + AuctionPhaseA
let (tx_hash, ..) = self
.submit_signed_extrinsic(call)
.await
.until_finalized()
.until_in_block()
.await
.context("Could not register account role for account")?;
Ok(tx_hash)
Expand All @@ -233,7 +234,7 @@ pub trait OperatorApi: SignedExtrinsicApi + RotateSessionKeysApi + AuctionPhaseA
proof: [0; 1].to_vec(),
})
.await
.until_finalized()
.until_in_block()
.await?;

Ok(tx_hash)
Expand All @@ -243,7 +244,7 @@ pub trait OperatorApi: SignedExtrinsicApi + RotateSessionKeysApi + AuctionPhaseA
let (tx_hash, ..) = self
.submit_signed_extrinsic(pallet_cf_funding::Call::stop_bidding {})
.await
.until_finalized()
.until_in_block()
.await
.context("Could not stop bidding")?;
println!("Account stopped bidding, in tx {tx_hash:#x}.");
Expand All @@ -254,7 +255,7 @@ pub trait OperatorApi: SignedExtrinsicApi + RotateSessionKeysApi + AuctionPhaseA
let (tx_hash, ..) = self
.submit_signed_extrinsic(pallet_cf_funding::Call::start_bidding {})
.await
.until_finalized()
.until_in_block()
.await
.context("Could not start bidding")?;
println!("Account started bidding at tx {tx_hash:#x}.");
Expand All @@ -272,7 +273,7 @@ pub trait OperatorApi: SignedExtrinsicApi + RotateSessionKeysApi + AuctionPhaseA
name: name.as_bytes().to_vec(),
})
.await
.until_finalized()
.until_in_block()
.await
.context("Could not set vanity name for your account")?;
println!("Vanity name set at tx {tx_hash:#x}.");
Expand All @@ -295,7 +296,7 @@ pub trait GovernanceApi: SignedExtrinsicApi {
execution: ExecutionMode::Automatic,
})
.await
.until_finalized()
.until_in_block()
.await
.context("Failed to submit rotation governance proposal")?;

Expand Down Expand Up @@ -331,7 +332,7 @@ pub trait BrokerApi: SignedExtrinsicApi {
channel_metadata,
})
.await
.until_finalized()
.until_in_block()
.await?;

if let Some(state_chain_runtime::RuntimeEvent::Swapping(
Expand Down
16 changes: 8 additions & 8 deletions api/lib/src/lp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub use cf_amm::{
use cf_chains::address::EncodedAddress;
use cf_primitives::{Asset, AssetAmount, EgressId};
use chainflip_engine::state_chain_observer::client::{
extrinsic_api::signed::{SignedExtrinsicApi, UntilFinalized},
extrinsic_api::signed::{SignedExtrinsicApi, UntilInBlock},
StateChainClient,
};
use pallet_cf_pools::{AssetAmounts, IncreaseOrDecrease, OrderId, RangeOrderSize};
Expand Down Expand Up @@ -105,7 +105,7 @@ pub trait LpApi: SignedExtrinsicApi {
pallet_cf_lp::Call::register_liquidity_refund_address { address },
))
.await
.until_finalized()
.until_in_block()
.await
.context("Registration for Liquidity Refund Address failed.")?;
Ok(tx_hash)
Expand All @@ -117,7 +117,7 @@ pub trait LpApi: SignedExtrinsicApi {
asset,
})
.await
.until_finalized()
.until_in_block()
.await?;

Ok(events
Expand All @@ -144,7 +144,7 @@ pub trait LpApi: SignedExtrinsicApi {
destination_address,
})
.await
.until_finalized()
.until_in_block()
.await?;

Ok(events
Expand Down Expand Up @@ -178,7 +178,7 @@ pub trait LpApi: SignedExtrinsicApi {
size,
})
.await
.until_finalized()
.until_in_block()
.await?;

Ok(collect_range_order_returns(events))
Expand All @@ -202,7 +202,7 @@ pub trait LpApi: SignedExtrinsicApi {
size,
})
.await
.until_finalized()
.until_in_block()
.await?;

Ok(collect_range_order_returns(events))
Expand All @@ -228,7 +228,7 @@ pub trait LpApi: SignedExtrinsicApi {
amount,
})
.await
.until_finalized()
.until_in_block()
.await?;

Ok(collect_limit_order_returns(events))
Expand All @@ -252,7 +252,7 @@ pub trait LpApi: SignedExtrinsicApi {
sell_amount,
})
.await
.until_finalized()
.until_in_block()
.await?;

Ok(collect_limit_order_returns(events))
Expand Down
1 change: 1 addition & 0 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ codec = { package = "parity-scale-codec", version = "3.6.1", features = [
frame-support = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainflip-monthly-2023-08+2" }
frame-system = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainflip-monthly-2023-08+2" }
sc-rpc-api = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainflip-monthly-2023-08+2" }
sc-transaction-pool-api = { git = "https://github.com/chainflip-io/substrate.git", tag = 'chainflip-monthly-2023-08+2' }
scale-info = { version = "2.5.0", features = ["derive"] }
sp-core = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainflip-monthly-2023-08+2" }
sp-rpc = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainflip-monthly-2023-08+2" }
Expand Down
39 changes: 32 additions & 7 deletions engine/src/state_chain_observer/client/base_rpc_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ use async_trait::async_trait;
use cf_amm::{common::Tick, range_orders::Liquidity};
use cf_primitives::Asset;
use jsonrpsee::core::{
client::{ClientT, SubscriptionClientT},
client::{ClientT, Subscription, SubscriptionClientT},
RpcResult,
};
use sc_transaction_pool_api::TransactionStatus;
use sp_core::{
storage::{StorageData, StorageKey},
Bytes,
Expand Down Expand Up @@ -62,6 +63,10 @@ impl<
state_chain_runtime::Hash,
state_chain_runtime::Header,
state_chain_runtime::SignedBlock,
> + substrate_frame_rpc_system::SystemApiClient<
state_chain_runtime::Block,
state_chain_runtime::AccountId,
state_chain_runtime::Nonce,
>,
> RawRpcApi for T
{
Expand All @@ -78,11 +83,21 @@ impl<
pub trait BaseRpcApi {
async fn health(&self) -> RpcResult<Health>;

async fn next_account_nonce(
&self,
account_id: state_chain_runtime::AccountId,
) -> RpcResult<state_chain_runtime::Nonce>;

async fn submit_extrinsic(
&self,
extrinsic: state_chain_runtime::UncheckedExtrinsic,
) -> RpcResult<sp_core::H256>;

async fn submit_and_watch_extrinsic(
&self,
extrinsic: state_chain_runtime::UncheckedExtrinsic,
) -> RpcResult<Subscription<TransactionStatus<sp_core::H256, sp_core::H256>>>;

async fn storage(
&self,
block_hash: state_chain_runtime::Hash,
Expand Down Expand Up @@ -111,9 +126,7 @@ pub trait BaseRpcApi {

async fn subscribe_finalized_block_headers(
&self,
) -> RpcResult<
jsonrpsee::core::client::Subscription<sp_runtime::generic::Header<u32, BlakeTwo256>>,
>;
) -> RpcResult<Subscription<sp_runtime::generic::Header<u32, BlakeTwo256>>>;

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

Expand Down Expand Up @@ -154,13 +167,27 @@ impl<RawRpcClient: RawRpcApi + Send + Sync> BaseRpcApi for BaseRpcClient<RawRpcC
self.raw_rpc_client.system_health().await
}

async fn next_account_nonce(
&self,
account_id: state_chain_runtime::AccountId,
) -> RpcResult<state_chain_runtime::Nonce> {
self.raw_rpc_client.nonce(account_id).await
}

async fn submit_extrinsic(
&self,
extrinsic: state_chain_runtime::UncheckedExtrinsic,
) -> RpcResult<sp_core::H256> {
self.raw_rpc_client.submit_extrinsic(Bytes::from(extrinsic.encode())).await
}

async fn submit_and_watch_extrinsic(
&self,
extrinsic: state_chain_runtime::UncheckedExtrinsic,
) -> RpcResult<Subscription<TransactionStatus<sp_core::H256, sp_core::H256>>> {
self.raw_rpc_client.watch_extrinsic(Bytes::from(extrinsic.encode())).await
}

async fn storage(
&self,
block_hash: state_chain_runtime::Hash,
Expand Down Expand Up @@ -205,9 +232,7 @@ impl<RawRpcClient: RawRpcApi + Send + Sync> BaseRpcApi for BaseRpcClient<RawRpcC

async fn subscribe_finalized_block_headers(
&self,
) -> RpcResult<
jsonrpsee::core::client::Subscription<sp_runtime::generic::Header<u32, BlakeTwo256>>,
> {
) -> RpcResult<Subscription<sp_runtime::generic::Header<u32, BlakeTwo256>>> {
self.raw_rpc_client.subscribe_finalized_heads().await
}

Expand Down
2 changes: 1 addition & 1 deletion engine/src/state_chain_observer/client/error_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl ErrorDecoder {
}
}

#[derive(Error, Debug)]
#[derive(Error, Debug, Clone)]
pub enum DispatchError {
#[error("{0:?}")]
DispatchError(sp_runtime::DispatchError),
Expand Down
Loading

0 comments on commit 3909df0

Please sign in to comment.