mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-19 08:45:41 +00:00
4c7539cab5
* Use beefy branch with scale-info * Add patches * Sprinkle some TypeInfo derives * Add some TypeInfo deriv * Cargo.lock * Derive TypeInfo and skip type params for Xcm types * Cargo.lock * Fix up scale_info bounds attributes * Fix up dependencies * Use my own beefy-primitives branch * Bump BEEFY * Update patches * Add some scale-info dependencies and TypeInfo derives * More TypeInfo decoration * Update scale-info * Some TypeInfos and remove more Event pallet::metadata * Moar TypeInfos * TypeInfos galore, fix up metadata runtime API * TypeInfo * TypeInfos, update other runtime metadata APIs * Fix up Kusama, comment out some `usize` QueueSize parameter types * Remove local diener patches * Cargo.lock * Cargo.lock * Update to scale-info crates.io release * Update primitive-types branch * Update pallet-beefy to use custom branch * Update other parity-common deps * Update parity-common patches * bump a bunch of deps in parity-common * Remove parity-common patches * Bump finality-grandpa version * Cargo.lock * Update scale-info to 0.9.1 * Add recursion_limit for runtime-parachains * Add some scale_info attributes * Cargo.lock * Revert finality-grandpa bump * Cargo.lock, scale-info update * cargo update * Make sure using patched version of finality-grandpa * Use patched scale-info * Update to scale-info 0.10.0 * Update finality-grandpa * Cargo.lock * Update beefy deps * Update beefy deps again * Add scale-info dependency * Remove deprecated pallet::metadata attributes. * Add some missing scale-info deps and derives * Use some variant struct call syntax * Add missing TypeInfo impl * Add some more TypeInfo impls * Convert some call enum struct variant constructors * More scale-info deps and derives * Call enum struct variants * TypeInfo derives * Call enum variant structs * scale-info deps and derives * Call enum variant struct constructors * Use beefy-primitives scale-info feature * Use grandpa-bridge-gadget master branch * Remove finality-grandpa patch * Add missing scale_info dependency and derive * Fix up some call variant constructors * Add missing scale_info dependency * Fix some test errors * More TypeInfo derives * More call variant structs * Call variant structs in tests * Cargo.lock * Fmt * Fix more call struct variants * Another call struct variant * add scale-info/std features explicitly * More call struct variants * Add missing scale-info dependency * Fmt * review: activate scale-info/std where missing * Remove some duplicate std feature activation * review: add scale_info bounds() attr * More call variant structs * Remove recursion limit * Update beefy-primitives * Update beefy-primitives * Fix simnet call variant struct errors * Fmt * cargo update -p beefy-primitives * Add some missing TypeInfo derives * Fix some call variants * Fix some call variant underscores * Cargo.lock * Cargo.lock * Add missing TypeInfo derive * Add some more missing TypeInfo derives * Even more missing TypeInfo derives * Add TypeInfo derives to new xcm types * Fmt * Cargo.lock * Add missing TypeInfo impls * Cargo.lock * More missing TypeInfos * Fixes * Cargo.lock * Cargo.lock * Add TypeInfo impls to xcm v2 * Update to scale-info 1.0 * Update finality-grandpa 0.14.4, patch for now * Update beefy * Remove patched finality-grandpa * Add TypeInfo impl to Outcome * Fixes * Call variant struct * Call variant struct * Fix test * Add TypeInfo impl * Cargo.lock * Cargo.lock * Cargo.lock * git checkout master Cargo.lock * update Substrate * Add missing scale-info features for beefy-primitives * Fmt * Remove check for now * Update beefy-primitives, removes scale-info feature * Update beefy-primitives again Co-authored-by: adoerr <0xad@gmx.net> Co-authored-by: Andronik Ordian <write@reusable.software> Co-authored-by: thiolliere <gui.thiolliere@gmail.com> Co-authored-by: parity-processbot <> Co-authored-by: Bastian Köcher <info@kchr.de>
135 lines
4.7 KiB
Rust
135 lines
4.7 KiB
Rust
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
|
|
// This file is part of Parity Bridges Common.
|
|
|
|
// Parity Bridges Common is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Parity Bridges Common is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//! Defines traits which represent a common interface for Substrate pallets which want to
|
|
//! incorporate bridge functionality.
|
|
|
|
#![cfg_attr(not(feature = "std"), no_std)]
|
|
|
|
use codec::{Codec, Decode, Encode, EncodeLike};
|
|
use core::clone::Clone;
|
|
use core::cmp::Eq;
|
|
use core::default::Default;
|
|
use core::fmt::Debug;
|
|
use scale_info::TypeInfo;
|
|
#[cfg(feature = "std")]
|
|
use serde::{Deserialize, Serialize};
|
|
use sp_finality_grandpa::{AuthorityList, ConsensusLog, SetId, GRANDPA_ENGINE_ID};
|
|
use sp_runtime::RuntimeDebug;
|
|
use sp_runtime::{generic::OpaqueDigestItemId, traits::Header as HeaderT};
|
|
|
|
pub mod justification;
|
|
|
|
/// A type that can be used as a parameter in a dispatchable function.
|
|
///
|
|
/// When using `decl_module` all arguments for call functions must implement this trait.
|
|
pub trait Parameter: Codec + EncodeLike + Clone + Eq + Debug {}
|
|
impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq + Debug {}
|
|
|
|
/// A GRANDPA Authority List and ID.
|
|
#[derive(Default, Encode, Decode, RuntimeDebug, PartialEq, Clone, TypeInfo)]
|
|
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
|
pub struct AuthoritySet {
|
|
/// List of GRANDPA authorities for the current round.
|
|
pub authorities: AuthorityList,
|
|
/// Monotonic identifier of the current GRANDPA authority set.
|
|
pub set_id: SetId,
|
|
}
|
|
|
|
impl AuthoritySet {
|
|
/// Create a new GRANDPA Authority Set.
|
|
pub fn new(authorities: AuthorityList, set_id: SetId) -> Self {
|
|
Self { authorities, set_id }
|
|
}
|
|
}
|
|
|
|
/// Data required for initializing the bridge pallet.
|
|
///
|
|
/// The bridge needs to know where to start its sync from, and this provides that initial context.
|
|
#[derive(Default, Encode, Decode, RuntimeDebug, PartialEq, Eq, Clone, TypeInfo)]
|
|
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
|
pub struct InitializationData<H: HeaderT> {
|
|
/// The header from which we should start syncing.
|
|
pub header: H,
|
|
/// The initial authorities of the pallet.
|
|
pub authority_list: AuthorityList,
|
|
/// The ID of the initial authority set.
|
|
pub set_id: SetId,
|
|
/// Should the pallet block transaction immediately after initialization.
|
|
pub is_halted: bool,
|
|
}
|
|
|
|
/// base trait for verifying transaction inclusion proofs.
|
|
pub trait InclusionProofVerifier {
|
|
/// 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>;
|
|
}
|
|
|
|
/// A trait for pallets which want to keep track of finalized headers from a bridged chain.
|
|
pub trait HeaderChain<H, E> {
|
|
/// Get the best finalized header known to the header chain.
|
|
fn best_finalized() -> H;
|
|
|
|
/// Get the best authority set known to the header chain.
|
|
fn authority_set() -> AuthoritySet;
|
|
|
|
/// Write a header finalized by GRANDPA to the underlying pallet storage.
|
|
fn append_header(header: H) -> Result<(), E>;
|
|
}
|
|
|
|
impl<H: Default, E> HeaderChain<H, E> for () {
|
|
fn best_finalized() -> H {
|
|
H::default()
|
|
}
|
|
|
|
fn authority_set() -> AuthoritySet {
|
|
AuthoritySet::default()
|
|
}
|
|
|
|
fn append_header(_header: H) -> Result<(), E> {
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
/// Abstract finality proof that is justifying block finality.
|
|
pub trait FinalityProof<Number>: Clone + Send + Sync + Debug {
|
|
/// Return number of header that this proof is generated for.
|
|
fn target_header_number(&self) -> Number;
|
|
}
|
|
|
|
/// Find header digest that schedules next GRANDPA authorities set.
|
|
pub fn find_grandpa_authorities_scheduled_change<H: HeaderT>(
|
|
header: &H,
|
|
) -> Option<sp_finality_grandpa::ScheduledChange<H::Number>> {
|
|
let id = OpaqueDigestItemId::Consensus(&GRANDPA_ENGINE_ID);
|
|
|
|
let filter_log = |log: ConsensusLog<H::Number>| match log {
|
|
ConsensusLog::ScheduledChange(change) => Some(change),
|
|
_ => None,
|
|
};
|
|
|
|
// find the first consensus digest with the right ID which converts to
|
|
// the right kind of consensus log.
|
|
header.digest().convert_first(|l| l.try_to(id).and_then(filter_log))
|
|
}
|