Add equivocation detector crate and implement clients (#2348) (#2353)

* Split FinalitySyncPipeline and SourceClient

* Move some logic to finality_base

* Add empty equivocation detection clients

* Add equivocation reporting logic to the source client

* Use convenience trait for SubstrateFinalitySyncPipeline

* Define JustificationVerificationContext for GRANDPA

* Equivocation source client: finality_verification_context()

* Equivocation source client: synced_headers_finality_info()

* reuse HeaderFinalityInfo

* Define EquivocationsFinder

* Fix spellcheck

* Address review comments

* Avoid equivocations lookup errors
This commit is contained in:
Serban Iorga
2023-08-16 08:20:09 +03:00
committed by Bastian Köcher
parent 9bfad80664
commit 48cae06a77
35 changed files with 931 additions and 375 deletions
+5 -4
View File
@@ -16,16 +16,17 @@
use crate::calls::UtilityCall;
use bp_header_chain::UnderlyingChainWithGrandpaProvider;
use bp_header_chain::ChainWithGrandpa as ChainWithGrandpaBase;
use bp_messages::MessageNonce;
use bp_runtime::{
Chain as ChainBase, ChainId, EncodedOrDecodedCall, HashOf, Parachain as ParachainBase,
TransactionEra, TransactionEraOf, UnderlyingChainProvider,
};
use codec::{Codec, Encode};
use codec::{Codec, Decode, Encode};
use jsonrpsee::core::{DeserializeOwned, Serialize};
use num_traits::Zero;
use sc_transaction_pool_api::TransactionStatus;
use scale_info::TypeInfo;
use sp_core::{storage::StorageKey, Pair};
use sp_runtime::{
generic::SignedBlock,
@@ -78,7 +79,7 @@ pub trait RelayChain: Chain {
///
/// Keep in mind that parachains are relying on relay chain GRANDPA, so they should not implement
/// this trait.
pub trait ChainWithGrandpa: Chain + UnderlyingChainWithGrandpaProvider {
pub trait ChainWithGrandpa: Chain + ChainWithGrandpaBase {
/// Name of the runtime API method that is returning the GRANDPA info associated with the
/// headers accepted by the `submit_finality_proofs` extrinsic in the queried block.
///
@@ -87,7 +88,7 @@ pub trait ChainWithGrandpa: Chain + UnderlyingChainWithGrandpaProvider {
const SYNCED_HEADERS_GRANDPA_INFO_METHOD: &'static str;
/// The type of the key owner proof used by the grandpa engine.
type KeyOwnerProof;
type KeyOwnerProof: Decode + TypeInfo + Send;
}
/// Substrate-based parachain from minimal relay-client point of view.
@@ -22,8 +22,8 @@ use crate::{
SubstrateAuthorClient, SubstrateChainClient, SubstrateFinalityClient,
SubstrateFrameSystemClient, SubstrateStateClient, SubstrateSystemClient,
},
transaction_stall_timeout, AccountKeyPairOf, ConnectionParams, Error, HashOf, HeaderIdOf,
Result, SignParam, TransactionTracker, UnsignedTransaction,
transaction_stall_timeout, AccountKeyPairOf, ChainWithGrandpa, ConnectionParams, Error, HashOf,
HeaderIdOf, Result, SignParam, TransactionTracker, UnsignedTransaction,
};
use async_std::sync::{Arc, Mutex, RwLock};
@@ -715,15 +715,16 @@ impl<C: Chain> Client<C> {
Ok(Subscription(Mutex::new(receiver)))
}
// TODO: remove warning after implementing
// https://github.com/paritytech/parity-bridges-common/issues/39
#[allow(dead_code)]
async fn generate_grandpa_key_ownership_proof(
/// Generates a proof of key ownership for the given authority in the given set.
pub 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>> {
) -> Result<Option<sp_consensus_grandpa::OpaqueKeyOwnershipProof>>
where
C: ChainWithGrandpa,
{
self.typed_state_call(
SUB_API_GRANDPA_GENERATE_KEY_OWNERSHIP_PROOF.into(),
(set_id, authority_id),