Skip to content

Commit

Permalink
Define generate_grandpa_key_ownership_proof() (#2247)
Browse files Browse the repository at this point in the history
  • Loading branch information
serban300 authored Jul 7, 2023
1 parent 9ba800f commit 7f35621
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 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.

1 change: 1 addition & 0 deletions relays/client-substrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
11 changes: 11 additions & 0 deletions relays/client-substrate/src/client/caching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@ impl<C: Chain, B: Client<C>> Client<C> for CachingClient<C, B> {
.await
}

async fn generate_grandpa_key_ownership_proof(
&self,
at: HashOf<C>,
set_id: sp_consensus_grandpa::SetId,
authority_id: sp_consensus_grandpa::AuthorityId,
) -> Result<Option<sp_consensus_grandpa::OpaqueKeyOwnershipProof>> {
self.backend
.generate_grandpa_key_ownership_proof(at, set_id, authority_id)
.await
}

async fn subscribe_beefy_finality_justifications(&self) -> Result<Subscription<Bytes>> {
self.subscribe_finality_justifications(
&self.data.beefy_justifications,
Expand Down
8 changes: 8 additions & 0 deletions relays/client-substrate/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ pub trait Client<C: Chain>: 'static + Send + Sync + Clone + Debug {
async fn subscribe_grandpa_finality_justifications(&self) -> Result<Subscription<Bytes>>
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<C>,
set_id: sp_consensus_grandpa::SetId,
authority_id: sp_consensus_grandpa::AuthorityId,
) -> Result<Option<sp_consensus_grandpa::OpaqueKeyOwnershipProof>>;

/// Subscribe to BEEFY finality justifications.
async fn subscribe_beefy_finality_justifications(&self) -> Result<Subscription<Bytes>>;

Expand Down
16 changes: 16 additions & 0 deletions relays/client-substrate/src/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -310,6 +312,20 @@ impl<C: Chain> Client<C> for RpcClient<C> {
.await
}

async fn generate_grandpa_key_ownership_proof(
&self,
at: HashOf<C>,
set_id: sp_consensus_grandpa::SetId,
authority_id: sp_consensus_grandpa::AuthorityId,
) -> Result<Option<sp_consensus_grandpa::OpaqueKeyOwnershipProof>> {
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<Subscription<Bytes>> {
self.subscribe_finality_justifications("BEEFY", move |client| async move {
SubstrateBeefyClient::<C>::subscribe_justifications(&*client).await
Expand Down

0 comments on commit 7f35621

Please sign in to comment.