diff --git a/Cargo.lock b/Cargo.lock index 10048cde63c..8124c2cfd2d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10052,6 +10052,7 @@ dependencies = [ "sc-rpc-api", "sc-transaction-pool-api", "scale-info", + "sp-consensus-grandpa", "sp-core", "sp-rpc", "sp-runtime", diff --git a/relays/client-substrate/Cargo.toml b/relays/client-substrate/Cargo.toml index 8c9f2f58048..a0f53a5ffef 100644 --- a/relays/client-substrate/Cargo.toml +++ b/relays/client-substrate/Cargo.toml @@ -40,6 +40,7 @@ pallet-utility = { git = "https://github.com/paritytech/substrate", branch = "ma sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-rpc-api = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-consensus-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/relays/client-substrate/src/client/caching.rs b/relays/client-substrate/src/client/caching.rs index a67d669c278..dfe738264b8 100644 --- a/relays/client-substrate/src/client/caching.rs +++ b/relays/client-substrate/src/client/caching.rs @@ -219,6 +219,17 @@ impl> Client for CachingClient { .await } + async fn generate_grandpa_key_ownership_proof( + &self, + at: HashOf, + set_id: sp_consensus_grandpa::SetId, + authority_id: sp_consensus_grandpa::AuthorityId, + ) -> Result> { + self.backend + .generate_grandpa_key_ownership_proof(at, set_id, authority_id) + .await + } + async fn subscribe_beefy_finality_justifications(&self) -> Result> { self.subscribe_finality_justifications( &self.data.beefy_justifications, diff --git a/relays/client-substrate/src/client/client.rs b/relays/client-substrate/src/client/client.rs index ec2fd075d67..e1d8dfd667d 100644 --- a/relays/client-substrate/src/client/client.rs +++ b/relays/client-substrate/src/client/client.rs @@ -78,6 +78,14 @@ pub trait Client: 'static + Send + Sync + Clone + Debug { async fn subscribe_grandpa_finality_justifications(&self) -> Result> where C: ChainWithGrandpa; + /// Generates a proof of key ownership for the given authority in the given set. + async fn generate_grandpa_key_ownership_proof( + &self, + at: HashOf, + set_id: sp_consensus_grandpa::SetId, + authority_id: sp_consensus_grandpa::AuthorityId, + ) -> Result>; + /// Subscribe to BEEFY finality justifications. async fn subscribe_beefy_finality_justifications(&self) -> Result>; diff --git a/relays/client-substrate/src/client/rpc.rs b/relays/client-substrate/src/client/rpc.rs index b82e3c1a37b..d647249d8b1 100644 --- a/relays/client-substrate/src/client/rpc.rs +++ b/relays/client-substrate/src/client/rpc.rs @@ -60,6 +60,8 @@ const MAX_SUBSCRIPTION_CAPACITY: usize = 4096; const SUB_API_TXPOOL_VALIDATE_TRANSACTION: &str = "TaggedTransactionQueue_validate_transaction"; const SUB_API_TX_PAYMENT_QUERY_INFO: &str = "TransactionPaymentApi_query_info"; +const SUB_API_GRANDPA_GENERATE_KEY_OWNERSHIP_PROOF: &str = + "GrandpaApi_generate_key_ownership_proof"; /// Client implementation that connects to the Substrate node over `ws`/`wss` connection /// and is using RPC methods to get required data and submit transactions. @@ -310,6 +312,20 @@ impl Client for RpcClient { .await } + async fn generate_grandpa_key_ownership_proof( + &self, + at: HashOf, + set_id: sp_consensus_grandpa::SetId, + authority_id: sp_consensus_grandpa::AuthorityId, + ) -> Result> { + self.state_call( + at, + SUB_API_GRANDPA_GENERATE_KEY_OWNERSHIP_PROOF.into(), + (set_id, authority_id), + ) + .await + } + async fn subscribe_beefy_finality_justifications(&self) -> Result> { self.subscribe_finality_justifications("BEEFY", move |client| async move { SubstrateBeefyClient::::subscribe_justifications(&*client).await