mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 05:51:02 +00:00
Introduce Minimal Header Chain: Proving Interface (#287)
* Add header-chain primitive crate * Make MinimalHeaderChain functionaly the same as PeerBlockchain * Use a better doc comment for MinimalHeaderChain * Fix benchmark compilation * Rust Fmt * Remove Substrate based dependencies * Rename MinimalHeaderChain to BaseHeaderChain
This commit is contained in:
committed by
Bastian Köcher
parent
a0555d8118
commit
29244ba76d
@@ -8,6 +8,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
|
||||
|
||||
[dependencies]
|
||||
bp-currency-exchange = { path = "../../primitives/currency-exchange", default-features = false }
|
||||
bp-header-chain = { path = "../../primitives/header-chain", default-features = false }
|
||||
codec = { package = "parity-scale-codec", version = "1.3.1", default-features = false }
|
||||
serde = { version = "1.0", optional = true }
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
//! So we are giving runtime opportunity to prepare environment and construct proof
|
||||
//! before invoking module calls.
|
||||
|
||||
use super::{Call, Instance, Module as CurrencyExchangeModule, PeerBlockchain, Trait as CurrencyExchangeTrait};
|
||||
use super::{BaseHeaderChain, Call, Instance, Module as CurrencyExchangeModule, Trait as CurrencyExchangeTrait};
|
||||
use sp_std::prelude::*;
|
||||
|
||||
use frame_benchmarking::{account, benchmarks_instance};
|
||||
@@ -50,7 +50,7 @@ pub trait Trait<I: Instance>: CurrencyExchangeTrait<I> {
|
||||
/// Prepare proof for importing exchange transaction.
|
||||
fn make_proof(
|
||||
proof_params: ProofParams<Self::AccountId>,
|
||||
) -> <<Self as CurrencyExchangeTrait<I>>::PeerBlockchain as PeerBlockchain>::TransactionInclusionProof;
|
||||
) -> <<Self as CurrencyExchangeTrait<I>>::PeerBlockchain as BaseHeaderChain>::TransactionInclusionProof;
|
||||
}
|
||||
|
||||
benchmarks_instance! {
|
||||
|
||||
@@ -21,7 +21,8 @@
|
||||
use bp_currency_exchange::{
|
||||
CurrencyConverter, DepositInto, Error as ExchangeError, MaybeLockFundsTransaction, RecipientsMap,
|
||||
};
|
||||
use frame_support::{decl_error, decl_module, decl_storage, ensure, Parameter};
|
||||
use bp_header_chain::BaseHeaderChain;
|
||||
use frame_support::{decl_error, decl_module, decl_storage, ensure};
|
||||
use sp_runtime::DispatchResult;
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
@@ -33,28 +34,15 @@ pub trait OnTransactionSubmitted<AccountId> {
|
||||
fn on_valid_transaction_submitted(submitter: AccountId);
|
||||
}
|
||||
|
||||
/// Peer blockchain interface.
|
||||
pub trait PeerBlockchain {
|
||||
/// Transaction type.
|
||||
type Transaction: Parameter;
|
||||
/// Transaction inclusion proof type.
|
||||
type TransactionInclusionProof: Parameter;
|
||||
|
||||
/// Verify that transaction is a part of given block.
|
||||
///
|
||||
/// Returns Some(transaction) if proof is valid and None otherwise.
|
||||
fn verify_transaction_inclusion_proof(proof: &Self::TransactionInclusionProof) -> Option<Self::Transaction>;
|
||||
}
|
||||
|
||||
/// The module configuration trait
|
||||
pub trait Trait<I = DefaultInstance>: frame_system::Trait {
|
||||
/// Handler for transaction submission result.
|
||||
type OnTransactionSubmitted: OnTransactionSubmitted<Self::AccountId>;
|
||||
/// Represents the blockchain that we'll be exchanging currency with.
|
||||
type PeerBlockchain: PeerBlockchain;
|
||||
type PeerBlockchain: BaseHeaderChain;
|
||||
/// Peer blockchain transaction parser.
|
||||
type PeerMaybeLockFundsTransaction: MaybeLockFundsTransaction<
|
||||
Transaction = <Self::PeerBlockchain as PeerBlockchain>::Transaction,
|
||||
Transaction = <Self::PeerBlockchain as BaseHeaderChain>::Transaction,
|
||||
>;
|
||||
/// Map between blockchains recipients.
|
||||
type RecipientsMap: RecipientsMap<
|
||||
@@ -101,7 +89,7 @@ decl_module! {
|
||||
#[weight = 0] // TODO: update me (https://github.com/paritytech/parity-bridges-common/issues/78)
|
||||
pub fn import_peer_transaction(
|
||||
origin,
|
||||
proof: <<T as Trait<I>>::PeerBlockchain as PeerBlockchain>::TransactionInclusionProof,
|
||||
proof: <<T as Trait<I>>::PeerBlockchain as BaseHeaderChain>::TransactionInclusionProof,
|
||||
) -> DispatchResult {
|
||||
let submitter = frame_system::ensure_signed(origin)?;
|
||||
|
||||
@@ -146,7 +134,7 @@ decl_storage! {
|
||||
impl<T: Trait<I>, I: Instance> Module<T, I> {
|
||||
/// Returns true if currency exchange module is able to import given transaction proof in
|
||||
/// its current state.
|
||||
pub fn filter_transaction_proof(proof: &<T::PeerBlockchain as PeerBlockchain>::TransactionInclusionProof) -> bool {
|
||||
pub fn filter_transaction_proof(proof: &<T::PeerBlockchain as BaseHeaderChain>::TransactionInclusionProof) -> bool {
|
||||
if let Err(err) = prepare_deposit_details::<T, I>(proof) {
|
||||
frame_support::debug::trace!(
|
||||
target: "runtime",
|
||||
@@ -192,7 +180,7 @@ struct DepositDetails<T: Trait<I>, I: Instance> {
|
||||
/// Verify and parse transaction proof, preparing everything required for importing
|
||||
/// this transaction proof.
|
||||
fn prepare_deposit_details<T: Trait<I>, I: Instance>(
|
||||
proof: &<<T as Trait<I>>::PeerBlockchain as PeerBlockchain>::TransactionInclusionProof,
|
||||
proof: &<<T as Trait<I>>::PeerBlockchain as BaseHeaderChain>::TransactionInclusionProof,
|
||||
) -> Result<DepositDetails<T, I>, Error<T, I>> {
|
||||
// ensure that transaction is included in finalized block that we know of
|
||||
let transaction = <T as Trait<I>>::PeerBlockchain::verify_transaction_inclusion_proof(proof)
|
||||
@@ -251,7 +239,7 @@ mod tests {
|
||||
|
||||
pub struct DummyBlockchain;
|
||||
|
||||
impl PeerBlockchain for DummyBlockchain {
|
||||
impl BaseHeaderChain for DummyBlockchain {
|
||||
type Transaction = RawTransaction;
|
||||
type TransactionInclusionProof = (bool, RawTransaction);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user