mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 22:11:02 +00:00
Move Chain trait to runtime primitives (#403)
* extract ChainBase to bp-runtime * post-merge fixes * cargo fmt --all * compilation fixes * reexport BlockNumberOf, HashOf, HeaderOf
This commit is contained in:
committed by
Bastian Köcher
parent
ddeb59d336
commit
9e9ac8df3c
@@ -32,9 +32,7 @@ use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId, AuthorityList as G
|
||||
use sp_api::impl_runtime_apis;
|
||||
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
|
||||
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
|
||||
use sp_runtime::traits::{
|
||||
BlakeTwo256, Block as BlockT, IdentifyAccount, IdentityLookup, NumberFor, OpaqueKeys, Saturating, Verify,
|
||||
};
|
||||
use sp_runtime::traits::{Block as BlockT, IdentifyAccount, IdentityLookup, NumberFor, OpaqueKeys, Saturating, Verify};
|
||||
use sp_runtime::{
|
||||
create_runtime_str, generic, impl_opaque_keys,
|
||||
transaction_validity::{TransactionSource, TransactionValidity},
|
||||
@@ -84,6 +82,9 @@ pub type Index = u32;
|
||||
/// A hash of some data used by the chain.
|
||||
pub type Hash = bp_millau::Hash;
|
||||
|
||||
/// Hashing algorithm used by the chain.
|
||||
pub type Hashing = bp_millau::Hasher;
|
||||
|
||||
/// Digest item type.
|
||||
pub type DigestItem = generic::DigestItem<Hash>;
|
||||
|
||||
@@ -97,7 +98,7 @@ pub mod opaque {
|
||||
pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
|
||||
|
||||
/// Opaque block header type.
|
||||
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
||||
pub type Header = generic::Header<BlockNumber, Hashing>;
|
||||
/// Opaque block type.
|
||||
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
|
||||
/// Opaque block identifier type.
|
||||
@@ -172,9 +173,9 @@ impl frame_system::Trait for Runtime {
|
||||
/// The type for hashing blocks and tries.
|
||||
type Hash = Hash;
|
||||
/// The hashing algorithm used.
|
||||
type Hashing = BlakeTwo256;
|
||||
type Hashing = Hashing;
|
||||
/// The header type.
|
||||
type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
||||
type Header = generic::Header<BlockNumber, Hashing>;
|
||||
/// The ubiquitous event type.
|
||||
type Event = Event;
|
||||
/// The ubiquitous origin type.
|
||||
@@ -309,10 +310,7 @@ impl pallet_session::Trait for Runtime {
|
||||
}
|
||||
|
||||
impl pallet_substrate_bridge::Trait for Runtime {
|
||||
type BridgedHeader = bp_rialto::Header;
|
||||
type BridgedBlockNumber = bp_rialto::BlockNumber;
|
||||
type BridgedBlockHash = bp_rialto::Hash;
|
||||
type BridgedBlockHasher = bp_rialto::Hasher;
|
||||
type BridgedChain = bp_rialto::Rialto;
|
||||
}
|
||||
|
||||
impl pallet_shift_session_manager::Trait for Runtime {}
|
||||
@@ -341,7 +339,7 @@ construct_runtime!(
|
||||
/// The address format for describing accounts.
|
||||
pub type Address = AccountId;
|
||||
/// Block header type as expected by this runtime.
|
||||
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
||||
pub type Header = generic::Header<BlockNumber, Hashing>;
|
||||
/// Block type as expected by this runtime.
|
||||
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
|
||||
/// A Block signed with a Justification
|
||||
|
||||
@@ -39,9 +39,7 @@ use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId, AuthorityList as G
|
||||
use sp_api::impl_runtime_apis;
|
||||
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
|
||||
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
|
||||
use sp_runtime::traits::{
|
||||
BlakeTwo256, Block as BlockT, IdentifyAccount, IdentityLookup, NumberFor, OpaqueKeys, Saturating, Verify,
|
||||
};
|
||||
use sp_runtime::traits::{Block as BlockT, IdentifyAccount, IdentityLookup, NumberFor, OpaqueKeys, Saturating, Verify};
|
||||
use sp_runtime::{
|
||||
create_runtime_str, generic, impl_opaque_keys,
|
||||
transaction_validity::{TransactionSource, TransactionValidity},
|
||||
@@ -92,6 +90,9 @@ pub type Index = u32;
|
||||
/// A hash of some data used by the chain.
|
||||
pub type Hash = bp_rialto::Hash;
|
||||
|
||||
/// Hashing algorithm used by the chain.
|
||||
pub type Hashing = bp_rialto::Hasher;
|
||||
|
||||
/// Digest item type.
|
||||
pub type DigestItem = generic::DigestItem<Hash>;
|
||||
|
||||
@@ -105,7 +106,7 @@ pub mod opaque {
|
||||
pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
|
||||
|
||||
/// Opaque block header type.
|
||||
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
||||
pub type Header = generic::Header<BlockNumber, Hashing>;
|
||||
/// Opaque block type.
|
||||
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
|
||||
/// Opaque block identifier type.
|
||||
@@ -180,9 +181,9 @@ impl frame_system::Trait for Runtime {
|
||||
/// The type for hashing blocks and tries.
|
||||
type Hash = Hash;
|
||||
/// The hashing algorithm used.
|
||||
type Hashing = BlakeTwo256;
|
||||
type Hashing = Hashing;
|
||||
/// The header type.
|
||||
type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
||||
type Header = generic::Header<BlockNumber, Hashing>;
|
||||
/// The ubiquitous event type.
|
||||
type Event = Event;
|
||||
/// The ubiquitous origin type.
|
||||
@@ -415,10 +416,7 @@ impl pallet_session::Trait for Runtime {
|
||||
}
|
||||
|
||||
impl pallet_substrate_bridge::Trait for Runtime {
|
||||
type BridgedHeader = bp_millau::Header;
|
||||
type BridgedBlockNumber = bp_millau::BlockNumber;
|
||||
type BridgedBlockHash = bp_millau::Hash;
|
||||
type BridgedBlockHasher = bp_millau::Hasher;
|
||||
type BridgedChain = bp_millau::Millau;
|
||||
}
|
||||
|
||||
impl pallet_shift_session_manager::Trait for Runtime {}
|
||||
@@ -451,7 +449,7 @@ construct_runtime!(
|
||||
/// The address format for describing accounts.
|
||||
pub type Address = AccountId;
|
||||
/// Block header type as expected by this runtime.
|
||||
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
||||
pub type Header = generic::Header<BlockNumber, Hashing>;
|
||||
/// Block type as expected by this runtime.
|
||||
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
|
||||
/// A Block signed with a Justification
|
||||
|
||||
@@ -11,9 +11,12 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
|
||||
codec = { package = "parity-scale-codec", version = "1.3.1", default-features = false }
|
||||
finality-grandpa = { version = "0.12.3", default-features = false }
|
||||
hash-db = { version = "0.15.2", default-features = false }
|
||||
num-traits = { version = "0.2", default-features = false }
|
||||
serde = { version = "1.0", optional = true }
|
||||
|
||||
# Bridge Dependencies
|
||||
|
||||
bp-runtime = { path = "../../primitives/runtime", default-features = false }
|
||||
|
||||
# Substrate Dependencies
|
||||
|
||||
frame-support = { version = "2.0", default-features = false }
|
||||
@@ -32,12 +35,12 @@ sp-state-machine = "0.8"
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"bp-runtime/std",
|
||||
"codec/std",
|
||||
"finality-grandpa/std",
|
||||
"frame-support/std",
|
||||
"frame-system/std",
|
||||
"hash-db/std",
|
||||
"num-traits/std",
|
||||
"serde",
|
||||
"sp-finality-grandpa/std",
|
||||
"sp-runtime/std",
|
||||
|
||||
@@ -32,18 +32,11 @@
|
||||
#![allow(clippy::large_enum_variant)]
|
||||
|
||||
use crate::storage::{AuthoritySet, ImportedHeader, ScheduledChange};
|
||||
use codec::{Codec, EncodeLike};
|
||||
use frame_support::{
|
||||
decl_error, decl_module, decl_storage,
|
||||
dispatch::{DispatchResult, Parameter},
|
||||
};
|
||||
use bp_runtime::{BlockNumberOf, Chain, HashOf, HeaderOf};
|
||||
use frame_support::{decl_error, decl_module, decl_storage, dispatch::DispatchResult};
|
||||
use frame_system::ensure_signed;
|
||||
use num_traits::AsPrimitive;
|
||||
use sp_runtime::traits::{
|
||||
AtLeast32BitUnsigned, Hash as HashT, Header as HeaderT, MaybeDisplay, MaybeMallocSizeOf, MaybeSerializeDeserialize,
|
||||
Member, SimpleBitOps,
|
||||
};
|
||||
use sp_std::{fmt::Debug, marker::PhantomData, prelude::*, str::FromStr};
|
||||
use sp_runtime::traits::Header as HeaderT;
|
||||
use sp_std::{marker::PhantomData, prelude::*};
|
||||
|
||||
mod justification;
|
||||
mod storage;
|
||||
@@ -54,84 +47,42 @@ mod verifier;
|
||||
mod mock;
|
||||
|
||||
pub trait Trait: frame_system::Trait {
|
||||
/// A type that fulfills the abstract idea of what a Substrate header is.
|
||||
// See here for more info:
|
||||
// https://crates.parity.io/sp_runtime/traits/trait.Header.html
|
||||
type BridgedHeader: Parameter + HeaderT<Number = Self::BridgedBlockNumber, Hash = Self::BridgedBlockHash>;
|
||||
|
||||
/// A type that fulfills the abstract idea of what a Substrate block number is.
|
||||
// Constraits come from the associated Number type of `sp_runtime::traits::Header`
|
||||
// See here for more info:
|
||||
// https://crates.parity.io/sp_runtime/traits/trait.Header.html#associatedtype.Number
|
||||
//
|
||||
// Note that the `AsPrimitive<usize>` trait is required by the Grandpa justification
|
||||
// verifier, and is not usually part of a Substrate Header's Number type.
|
||||
type BridgedBlockNumber: Parameter
|
||||
+ Member
|
||||
+ MaybeSerializeDeserialize
|
||||
+ Debug
|
||||
+ sp_std::hash::Hash
|
||||
+ Copy
|
||||
+ MaybeDisplay
|
||||
+ AtLeast32BitUnsigned
|
||||
+ Codec
|
||||
+ FromStr
|
||||
+ MaybeMallocSizeOf
|
||||
+ AsPrimitive<usize>;
|
||||
|
||||
/// A type that fulfills the abstract idea of what a Substrate hash is.
|
||||
// Constraits come from the associated Hash type of `sp_runtime::traits::Header`
|
||||
// See here for more info:
|
||||
// https://crates.parity.io/sp_runtime/traits/trait.Header.html#associatedtype.Hash
|
||||
type BridgedBlockHash: Parameter
|
||||
+ Member
|
||||
+ MaybeSerializeDeserialize
|
||||
+ Debug
|
||||
+ sp_std::hash::Hash
|
||||
+ Ord
|
||||
+ Copy
|
||||
+ MaybeDisplay
|
||||
+ Default
|
||||
+ SimpleBitOps
|
||||
+ Codec
|
||||
+ AsRef<[u8]>
|
||||
+ AsMut<[u8]>
|
||||
+ MaybeMallocSizeOf
|
||||
+ EncodeLike;
|
||||
|
||||
/// A type that fulfills the abstract idea of what a Substrate hasher (a type
|
||||
/// that produces hashes) is.
|
||||
// Constraits come from the associated Hashing type of `sp_runtime::traits::Header`
|
||||
// See here for more info:
|
||||
// https://crates.parity.io/sp_runtime/traits/trait.Header.html#associatedtype.Hashing
|
||||
type BridgedBlockHasher: HashT<Output = Self::BridgedBlockHash>;
|
||||
/// Chain that we are bridging here.
|
||||
type BridgedChain: Chain;
|
||||
}
|
||||
|
||||
/// Block number of the bridged chain.
|
||||
pub(crate) type BridgedBlockNumber<T> = BlockNumberOf<<T as Trait>::BridgedChain>;
|
||||
/// Block hash of the bridged chain.
|
||||
pub(crate) type BridgedBlockHash<T> = HashOf<<T as Trait>::BridgedChain>;
|
||||
/// Header of the bridged chain.
|
||||
pub(crate) type BridgedHeader<T> = HeaderOf<<T as Trait>::BridgedChain>;
|
||||
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Trait> as SubstrateBridge {
|
||||
/// Hash of the header at the highest known height.
|
||||
BestHeader: T::BridgedBlockHash;
|
||||
BestHeader: BridgedBlockHash<T>;
|
||||
/// Hash of the best finalized header.
|
||||
BestFinalized: T::BridgedBlockHash;
|
||||
BestFinalized: BridgedBlockHash<T>;
|
||||
/// A header which enacts an authority set change and therefore
|
||||
/// requires a Grandpa justification.
|
||||
// Since we won't always have an authority set change scheduled we
|
||||
// won't always have a header which needs a justification.
|
||||
RequiresJustification: Option<T::BridgedBlockHash>;
|
||||
RequiresJustification: Option<BridgedBlockHash<T>>;
|
||||
/// Headers which have been imported into the pallet.
|
||||
ImportedHeaders: map hasher(identity) T::BridgedBlockHash => Option<ImportedHeader<T::BridgedHeader>>;
|
||||
ImportedHeaders: map hasher(identity) BridgedBlockHash<T> => Option<ImportedHeader<BridgedHeader<T>>>;
|
||||
/// The current Grandpa Authority set.
|
||||
CurrentAuthoritySet: AuthoritySet;
|
||||
/// The next scheduled authority set change.
|
||||
// Grandpa doesn't require there to always be a pending change. In fact, most of the time
|
||||
// there will be no pending change available.
|
||||
NextScheduledChange: Option<ScheduledChange<T::BridgedBlockNumber>>;
|
||||
NextScheduledChange: Option<ScheduledChange<BridgedBlockNumber<T>>>;
|
||||
}
|
||||
add_extra_genesis {
|
||||
config(initial_header): Option<T::BridgedHeader>;
|
||||
config(initial_header): Option<BridgedHeader<T>>;
|
||||
config(initial_authority_list): sp_finality_grandpa::AuthorityList;
|
||||
config(initial_set_id): sp_finality_grandpa::SetId;
|
||||
config(first_scheduled_change): Option<ScheduledChange<T::BridgedBlockNumber>>;
|
||||
config(first_scheduled_change): Option<ScheduledChange<BridgedBlockNumber<T>>>;
|
||||
build(|config| {
|
||||
assert!(
|
||||
!config.initial_authority_list.is_empty(),
|
||||
@@ -187,7 +138,7 @@ decl_module! {
|
||||
#[weight = 0]
|
||||
pub fn import_signed_header(
|
||||
origin,
|
||||
header: T::BridgedHeader,
|
||||
header: BridgedHeader<T>,
|
||||
) -> DispatchResult {
|
||||
let _ = ensure_signed(origin)?;
|
||||
frame_support::debug::trace!(target: "sub-bridge", "Got header {:?}", header);
|
||||
@@ -212,7 +163,7 @@ decl_module! {
|
||||
#[weight = 0]
|
||||
pub fn finalize_header(
|
||||
origin,
|
||||
hash: T::BridgedBlockHash,
|
||||
hash: BridgedBlockHash<T>,
|
||||
finality_proof: Vec<u8>,
|
||||
) -> DispatchResult {
|
||||
let _ = ensure_signed(origin)?;
|
||||
@@ -235,7 +186,7 @@ impl<T: Trait> Module<T> {
|
||||
/// Get the highest header that the pallet knows of.
|
||||
// In a future where we support forks this could be a Vec of headers
|
||||
// since we may have multiple headers at the same height.
|
||||
pub fn best_header() -> T::BridgedHeader {
|
||||
pub fn best_header() -> BridgedHeader<T> {
|
||||
PalletStorage::<T>::new().best_header().header
|
||||
}
|
||||
|
||||
@@ -244,12 +195,12 @@ impl<T: Trait> Module<T> {
|
||||
/// Since this has been finalized correctly a user of the bridge
|
||||
/// pallet should be confident that any transactions that were
|
||||
/// included in this or any previous header will not be reverted.
|
||||
pub fn best_finalized() -> T::BridgedHeader {
|
||||
pub fn best_finalized() -> BridgedHeader<T> {
|
||||
PalletStorage::<T>::new().best_finalized_header().header
|
||||
}
|
||||
|
||||
/// Check if a particular header is known to the bridge pallet.
|
||||
pub fn is_known_header(hash: T::BridgedBlockHash) -> bool {
|
||||
pub fn is_known_header(hash: BridgedBlockHash<T>) -> bool {
|
||||
PalletStorage::<T>::new().header_exists(hash)
|
||||
}
|
||||
|
||||
@@ -259,7 +210,7 @@ impl<T: Trait> Module<T> {
|
||||
// One thing worth noting here is that this approach won't work well
|
||||
// once we track forks since there could be an older header on a
|
||||
// different fork which isn't an ancestor of our best finalized header.
|
||||
pub fn is_finalized_header(hash: T::BridgedBlockHash) -> bool {
|
||||
pub fn is_finalized_header(hash: BridgedBlockHash<T>) -> bool {
|
||||
let storage = PalletStorage::<T>::new();
|
||||
if let Some(header) = storage.header_by_hash(hash) {
|
||||
header.number() <= storage.best_finalized_header().number()
|
||||
@@ -272,7 +223,7 @@ impl<T: Trait> Module<T> {
|
||||
/// and still needs a finality proof.
|
||||
///
|
||||
/// Will return None if there are no headers which are missing finality proofs.
|
||||
pub fn requires_justification() -> Option<T::BridgedHeader> {
|
||||
pub fn requires_justification() -> Option<BridgedHeader<T>> {
|
||||
let storage = PalletStorage::<T>::new();
|
||||
let hash = storage.unfinalized_header()?;
|
||||
let imported_header = storage.header_by_hash(hash).expect(
|
||||
@@ -352,42 +303,42 @@ impl<T> PalletStorage<T> {
|
||||
}
|
||||
|
||||
impl<T: Trait> BridgeStorage for PalletStorage<T> {
|
||||
type Header = T::BridgedHeader;
|
||||
type Header = BridgedHeader<T>;
|
||||
|
||||
fn write_header(&mut self, header: &ImportedHeader<T::BridgedHeader>) {
|
||||
fn write_header(&mut self, header: &ImportedHeader<BridgedHeader<T>>) {
|
||||
let hash = header.header.hash();
|
||||
<ImportedHeaders<T>>::insert(hash, header);
|
||||
}
|
||||
|
||||
fn best_header(&self) -> ImportedHeader<Self::Header> {
|
||||
fn best_header(&self) -> ImportedHeader<BridgedHeader<T>> {
|
||||
let hash = <BestHeader<T>>::get();
|
||||
self.header_by_hash(hash)
|
||||
.expect("A header must have been written at genesis, therefore this must always exist")
|
||||
}
|
||||
|
||||
fn update_best_header(&mut self, hash: T::BridgedBlockHash) {
|
||||
fn update_best_header(&mut self, hash: BridgedBlockHash<T>) {
|
||||
<BestHeader<T>>::put(hash)
|
||||
}
|
||||
|
||||
fn best_finalized_header(&self) -> ImportedHeader<T::BridgedHeader> {
|
||||
fn best_finalized_header(&self) -> ImportedHeader<BridgedHeader<T>> {
|
||||
let hash = <BestFinalized<T>>::get();
|
||||
self.header_by_hash(hash)
|
||||
.expect("A finalized header was added at genesis, therefore this must always exist")
|
||||
}
|
||||
|
||||
fn update_best_finalized(&self, hash: T::BridgedBlockHash) {
|
||||
fn update_best_finalized(&self, hash: BridgedBlockHash<T>) {
|
||||
<BestFinalized<T>>::put(hash)
|
||||
}
|
||||
|
||||
fn header_exists(&self, hash: T::BridgedBlockHash) -> bool {
|
||||
fn header_exists(&self, hash: BridgedBlockHash<T>) -> bool {
|
||||
<ImportedHeaders<T>>::contains_key(hash)
|
||||
}
|
||||
|
||||
fn header_by_hash(&self, hash: T::BridgedBlockHash) -> Option<ImportedHeader<T::BridgedHeader>> {
|
||||
fn header_by_hash(&self, hash: BridgedBlockHash<T>) -> Option<ImportedHeader<BridgedHeader<T>>> {
|
||||
<ImportedHeaders<T>>::get(hash)
|
||||
}
|
||||
|
||||
fn unfinalized_header(&self) -> Option<T::BridgedBlockHash> {
|
||||
fn unfinalized_header(&self) -> Option<BridgedBlockHash<T>> {
|
||||
<RequiresJustification<T>>::get()
|
||||
}
|
||||
|
||||
@@ -420,11 +371,11 @@ impl<T: Trait> BridgeStorage for PalletStorage<T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn scheduled_set_change(&self) -> Option<ScheduledChange<T::BridgedBlockNumber>> {
|
||||
fn scheduled_set_change(&self) -> Option<ScheduledChange<BridgedBlockNumber<T>>> {
|
||||
<NextScheduledChange<T>>::get()
|
||||
}
|
||||
|
||||
fn schedule_next_set_change(&self, next_change: ScheduledChange<T::BridgedBlockNumber>) {
|
||||
fn schedule_next_set_change(&self, next_change: ScheduledChange<BridgedBlockNumber<T>>) {
|
||||
<NextScheduledChange<T>>::put(next_change)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#![cfg(test)]
|
||||
|
||||
use crate::Trait;
|
||||
use bp_runtime::Chain;
|
||||
use frame_support::{impl_outer_origin, parameter_types, weights::Weight};
|
||||
use sp_runtime::{
|
||||
testing::{Header, H256},
|
||||
@@ -73,10 +74,17 @@ impl frame_system::Trait for TestRuntime {
|
||||
}
|
||||
|
||||
impl Trait for TestRuntime {
|
||||
type BridgedHeader = <Self as frame_system::Trait>::Header;
|
||||
type BridgedBlockNumber = <Self as frame_system::Trait>::BlockNumber;
|
||||
type BridgedBlockHash = <Self as frame_system::Trait>::Hash;
|
||||
type BridgedBlockHasher = <Self as frame_system::Trait>::Hashing;
|
||||
type BridgedChain = TestBridgedChain;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TestBridgedChain;
|
||||
|
||||
impl Chain for TestBridgedChain {
|
||||
type BlockNumber = <TestRuntime as frame_system::Trait>::BlockNumber;
|
||||
type Hash = <TestRuntime as frame_system::Trait>::Hash;
|
||||
type Hasher = <TestRuntime as frame_system::Trait>::Hashing;
|
||||
type Header = <TestRuntime as frame_system::Trait>::Header;
|
||||
}
|
||||
|
||||
pub fn run_test<T>(test: impl FnOnce() -> T) -> T {
|
||||
@@ -85,13 +93,14 @@ pub fn run_test<T>(test: impl FnOnce() -> T) -> T {
|
||||
|
||||
pub mod helpers {
|
||||
use super::*;
|
||||
use crate::{BridgedBlockHash, BridgedBlockNumber, BridgedHeader};
|
||||
use finality_grandpa::voter_set::VoterSet;
|
||||
use sp_finality_grandpa::{AuthorityId, AuthorityList};
|
||||
use sp_keyring::Ed25519Keyring;
|
||||
|
||||
pub type TestHeader = <TestRuntime as Trait>::BridgedHeader;
|
||||
pub type TestNumber = <TestRuntime as Trait>::BridgedBlockNumber;
|
||||
pub type TestHash = <TestRuntime as Trait>::BridgedBlockHash;
|
||||
pub type TestHeader = BridgedHeader<TestRuntime>;
|
||||
pub type TestNumber = BridgedBlockNumber<TestRuntime>;
|
||||
pub type TestHash = BridgedBlockHash<TestRuntime>;
|
||||
pub type HeaderId = (TestHash, TestNumber);
|
||||
|
||||
pub fn test_header(num: TestNumber) -> TestHeader {
|
||||
|
||||
@@ -8,7 +8,13 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
|
||||
|
||||
[dependencies]
|
||||
|
||||
# Bridge Dependencies
|
||||
|
||||
bp-runtime = { path = "../runtime", default-features = false }
|
||||
|
||||
# Substrate Based Dependencies
|
||||
|
||||
frame-support = { version = "2.0", default-features = false }
|
||||
sp-api = { version = "2.0", default-features = false }
|
||||
sp-core = { version = "2.0", default-features = false }
|
||||
sp-runtime = { version = "2.0", default-features = false }
|
||||
@@ -17,6 +23,8 @@ sp-std = { version = "2.0", default-features = false }
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"bp-runtime/std",
|
||||
"frame-support/std",
|
||||
"sp-api/std",
|
||||
"sp-core/std",
|
||||
"sp-runtime/std",
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
// Runtime-generated DecodeLimit::decode_all_With_depth_limit
|
||||
#![allow(clippy::unnecessary_mut_passed)]
|
||||
|
||||
use bp_runtime::Chain;
|
||||
use frame_support::RuntimeDebug;
|
||||
use sp_core::Hasher as HasherT;
|
||||
use sp_runtime::traits::BlakeTwo256;
|
||||
use sp_std::prelude::*;
|
||||
@@ -36,6 +38,17 @@ pub type Hasher = BlakeTwo256;
|
||||
/// The header type used by Millau.
|
||||
pub type Header = sp_runtime::generic::Header<BlockNumber, Hasher>;
|
||||
|
||||
/// Millau chain.
|
||||
#[derive(RuntimeDebug)]
|
||||
pub struct Millau;
|
||||
|
||||
impl Chain for Millau {
|
||||
type BlockNumber = BlockNumber;
|
||||
type Hash = Hash;
|
||||
type Hasher = Hasher;
|
||||
type Header = Header;
|
||||
}
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
/// API for querying information about Millau headers from the Bridge Pallet instance.
|
||||
///
|
||||
|
||||
@@ -8,15 +8,23 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
|
||||
|
||||
[dependencies]
|
||||
|
||||
# Bridge Dependencies
|
||||
|
||||
bp-runtime = { path = "../runtime", default-features = false }
|
||||
|
||||
# Substrate Based Dependencies
|
||||
sp-api = { version = "2.0.0", default-features = false }
|
||||
sp-core = { version = "2.0.0", default-features = false }
|
||||
sp-runtime = { version = "2.0.0", default-features = false }
|
||||
sp-std = { version = "2.0.0", default-features = false }
|
||||
|
||||
frame-support = { version = "2.0", default-features = false }
|
||||
sp-api = { version = "2.0", default-features = false }
|
||||
sp-core = { version = "2.0", default-features = false }
|
||||
sp-runtime = { version = "2.0", default-features = false }
|
||||
sp-std = { version = "2.0", default-features = false }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"bp-runtime/std",
|
||||
"frame-support/std",
|
||||
"sp-api/std",
|
||||
"sp-core/std",
|
||||
"sp-runtime/std",
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
// Runtime-generated DecodeLimit::decode_all_With_depth_limit
|
||||
#![allow(clippy::unnecessary_mut_passed)]
|
||||
|
||||
use bp_runtime::Chain;
|
||||
use frame_support::RuntimeDebug;
|
||||
use sp_core::Hasher as HasherT;
|
||||
use sp_runtime::traits::BlakeTwo256;
|
||||
use sp_std::prelude::*;
|
||||
@@ -36,6 +38,17 @@ pub type Hasher = BlakeTwo256;
|
||||
/// The header type used by Rialto.
|
||||
pub type Header = sp_runtime::generic::Header<BlockNumber, Hasher>;
|
||||
|
||||
/// Rialto chain.
|
||||
#[derive(RuntimeDebug)]
|
||||
pub struct Rialto;
|
||||
|
||||
impl Chain for Rialto {
|
||||
type BlockNumber = BlockNumber;
|
||||
type Hash = Hash;
|
||||
type Hasher = Hasher;
|
||||
type Header = Header;
|
||||
}
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
/// API for querying information about Rialto headers from the Bridge Pallet instance.
|
||||
///
|
||||
|
||||
@@ -8,14 +8,22 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
|
||||
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "1.3.1", default-features = false }
|
||||
num-traits = { version = "0.2", default-features = false }
|
||||
|
||||
# Substrate Dependencies
|
||||
|
||||
frame-support = { version = "2.0", default-features = false }
|
||||
sp-io = { version = "2.0", default-features = false }
|
||||
sp-runtime = { version = "2.0", default-features = false }
|
||||
sp-std = { version = "2.0", default-features = false }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"codec/std",
|
||||
"frame-support/std",
|
||||
"num-traits/std",
|
||||
"sp-io/std",
|
||||
"sp-runtime/std",
|
||||
"sp-std/std",
|
||||
]
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
// Copyright 2019-2020 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/>.
|
||||
|
||||
use frame_support::Parameter;
|
||||
use num_traits::AsPrimitive;
|
||||
use sp_runtime::traits::{
|
||||
AtLeast32BitUnsigned, Hash as HashT, Header as HeaderT, MaybeDisplay, MaybeMallocSizeOf, MaybeSerializeDeserialize,
|
||||
Member, SimpleBitOps,
|
||||
};
|
||||
use sp_std::str::FromStr;
|
||||
|
||||
/// Minimal Substrate-based chain representation that may be used from no_std environment.
|
||||
pub trait Chain {
|
||||
/// A type that fulfills the abstract idea of what a Substrate block number is.
|
||||
// Constraits come from the associated Number type of `sp_runtime::traits::Header`
|
||||
// See here for more info:
|
||||
// https://crates.parity.io/sp_runtime/traits/trait.Header.html#associatedtype.Number
|
||||
//
|
||||
// Note that the `AsPrimitive<usize>` trait is required by the Grandpa justification
|
||||
// verifier, and is not usually part of a Substrate Header's Number type.
|
||||
type BlockNumber: Parameter
|
||||
+ Member
|
||||
+ MaybeSerializeDeserialize
|
||||
+ sp_std::hash::Hash
|
||||
+ Copy
|
||||
+ MaybeDisplay
|
||||
+ AtLeast32BitUnsigned
|
||||
+ FromStr
|
||||
+ MaybeMallocSizeOf
|
||||
+ AsPrimitive<usize>;
|
||||
|
||||
/// A type that fulfills the abstract idea of what a Substrate hash is.
|
||||
// Constraits come from the associated Hash type of `sp_runtime::traits::Header`
|
||||
// See here for more info:
|
||||
// https://crates.parity.io/sp_runtime/traits/trait.Header.html#associatedtype.Hash
|
||||
type Hash: Parameter
|
||||
+ Member
|
||||
+ MaybeSerializeDeserialize
|
||||
+ sp_std::hash::Hash
|
||||
+ Ord
|
||||
+ Copy
|
||||
+ MaybeDisplay
|
||||
+ Default
|
||||
+ SimpleBitOps
|
||||
+ AsRef<[u8]>
|
||||
+ AsMut<[u8]>
|
||||
+ MaybeMallocSizeOf;
|
||||
|
||||
/// A type that fulfills the abstract idea of what a Substrate hasher (a type
|
||||
/// that produces hashes) is.
|
||||
// Constraits come from the associated Hashing type of `sp_runtime::traits::Header`
|
||||
// See here for more info:
|
||||
// https://crates.parity.io/sp_runtime/traits/trait.Header.html#associatedtype.Hashing
|
||||
type Hasher: HashT<Output = Self::Hash>;
|
||||
|
||||
/// A type that fulfills the abstract idea of what a Substrate header is.
|
||||
// See here for more info:
|
||||
// https://crates.parity.io/sp_runtime/traits/trait.Header.html
|
||||
type Header: Parameter + HeaderT<Number = Self::BlockNumber, Hash = Self::Hash>;
|
||||
}
|
||||
|
||||
/// Block number used by the chain.
|
||||
pub type BlockNumberOf<C> = <C as Chain>::BlockNumber;
|
||||
|
||||
/// Hash type used by the chain.
|
||||
pub type HashOf<C> = <C as Chain>::Hash;
|
||||
|
||||
/// Hasher type used by the chain.
|
||||
pub type HasherOf<C> = <C as Chain>::Header;
|
||||
|
||||
/// Header type used by the chain.
|
||||
pub type HeaderOf<C> = <C as Chain>::Header;
|
||||
@@ -21,6 +21,10 @@
|
||||
use codec::{Decode, Encode};
|
||||
use sp_io::hashing::blake2_256;
|
||||
|
||||
pub use chain::{BlockNumberOf, Chain, HashOf, HasherOf, HeaderOf};
|
||||
|
||||
mod chain;
|
||||
|
||||
/// Call-dispatch module prefix.
|
||||
pub const CALL_DISPATCH_MODULE_PREFIX: &[u8] = b"pallet-bridge/call-dispatch";
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Types used to connect to the Millau-Substrate chain.
|
||||
|
||||
use relay_substrate_client::Chain;
|
||||
use relay_substrate_client::{Chain, ChainBase};
|
||||
|
||||
use headers_relay::sync_types::SourceHeader;
|
||||
use sp_runtime::traits::Header as HeaderT;
|
||||
@@ -28,10 +28,14 @@ pub type HeaderId = relay_utils::HeaderId<millau_runtime::Hash, millau_runtime::
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Millau;
|
||||
|
||||
impl Chain for Millau {
|
||||
impl ChainBase for Millau {
|
||||
type BlockNumber = millau_runtime::BlockNumber;
|
||||
type Hash = millau_runtime::Hash;
|
||||
type Hasher = millau_runtime::Hashing;
|
||||
type Header = millau_runtime::Header;
|
||||
}
|
||||
|
||||
impl Chain for Millau {
|
||||
type AccountId = millau_runtime::AccountId;
|
||||
type Index = millau_runtime::Index;
|
||||
type SignedBlock = millau_runtime::SignedBlock;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
use codec::Encode;
|
||||
use headers_relay::sync_types::SourceHeader;
|
||||
use relay_substrate_client::{Chain, Client, TransactionSignScheme};
|
||||
use relay_substrate_client::{Chain, ChainBase, Client, TransactionSignScheme};
|
||||
use sp_core::Pair;
|
||||
use sp_runtime::{
|
||||
generic::SignedPayload,
|
||||
@@ -32,10 +32,14 @@ pub type HeaderId = relay_utils::HeaderId<rialto_runtime::Hash, rialto_runtime::
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Rialto;
|
||||
|
||||
impl Chain for Rialto {
|
||||
impl ChainBase for Rialto {
|
||||
type BlockNumber = rialto_runtime::BlockNumber;
|
||||
type Hash = rialto_runtime::Hash;
|
||||
type Hasher = rialto_runtime::Hashing;
|
||||
type Header = rialto_runtime::Header;
|
||||
}
|
||||
|
||||
impl Chain for Rialto {
|
||||
type AccountId = rialto_runtime::AccountId;
|
||||
type Index = rialto_runtime::Index;
|
||||
type SignedBlock = rialto_runtime::SignedBlock;
|
||||
|
||||
@@ -14,6 +14,7 @@ num-traits = "0.2"
|
||||
|
||||
# Bridge dependencies
|
||||
|
||||
bp-runtime = { path = "../../primitives/runtime" }
|
||||
headers-relay = { path = "../headers-relay" }
|
||||
relay-utils = { path = "../utils" }
|
||||
|
||||
|
||||
@@ -16,51 +16,19 @@
|
||||
|
||||
use crate::client::Client;
|
||||
|
||||
use bp_runtime::Chain as ChainBase;
|
||||
use frame_support::Parameter;
|
||||
use jsonrpsee::common::{DeserializeOwned, Serialize};
|
||||
use sp_core::Pair;
|
||||
use sp_runtime::{
|
||||
generic::SignedBlock,
|
||||
traits::{
|
||||
AtLeast32Bit, AtLeast32BitUnsigned, Bounded, CheckEqual, Dispatchable, Header as HeaderT, MaybeDisplay,
|
||||
MaybeMallocSizeOf, MaybeSerialize, MaybeSerializeDeserialize, Member, SimpleBitOps,
|
||||
},
|
||||
traits::{AtLeast32Bit, Dispatchable, MaybeDisplay, MaybeSerialize, MaybeSerializeDeserialize, Member},
|
||||
Justification,
|
||||
};
|
||||
use sp_std::fmt::Debug;
|
||||
|
||||
/// Substrate-based chain from minimal relay-client point of view.
|
||||
pub trait Chain {
|
||||
/// The block number type used by the runtime.
|
||||
type BlockNumber: Parameter
|
||||
+ Member
|
||||
+ MaybeSerializeDeserialize
|
||||
+ Debug
|
||||
+ MaybeDisplay
|
||||
+ AtLeast32BitUnsigned
|
||||
+ Default
|
||||
+ Bounded
|
||||
+ Copy
|
||||
+ sp_std::hash::Hash
|
||||
+ sp_std::str::FromStr
|
||||
+ MaybeMallocSizeOf;
|
||||
/// The output of the `Hashing` function.
|
||||
type Hash: Parameter
|
||||
+ Member
|
||||
+ MaybeSerializeDeserialize
|
||||
+ Debug
|
||||
+ MaybeDisplay
|
||||
+ SimpleBitOps
|
||||
+ Ord
|
||||
+ Default
|
||||
+ Copy
|
||||
+ CheckEqual
|
||||
+ sp_std::hash::Hash
|
||||
+ AsRef<[u8]>
|
||||
+ AsMut<[u8]>
|
||||
+ MaybeMallocSizeOf;
|
||||
/// The block header.
|
||||
type Header: Parameter + HeaderT<Number = Self::BlockNumber, Hash = Self::Hash>;
|
||||
pub trait Chain: ChainBase {
|
||||
/// The user account identifier type for the runtime.
|
||||
type AccountId: Parameter + Member + MaybeSerializeDeserialize + Debug + MaybeDisplay + Ord + Default;
|
||||
/// Account index (aka nonce) type. This stores the number of previous transactions associated
|
||||
@@ -96,15 +64,6 @@ pub trait TransactionSignScheme {
|
||||
) -> Self::SignedTransaction;
|
||||
}
|
||||
|
||||
/// Header type used by the chain.
|
||||
pub type HeaderOf<C> = <C as Chain>::Header;
|
||||
|
||||
/// Hash type used by the chain.
|
||||
pub type HashOf<C> = <C as Chain>::Hash;
|
||||
|
||||
/// Block number used by the chain.
|
||||
pub type BlockNumberOf<C> = <C as Chain>::BlockNumber;
|
||||
|
||||
impl<Block> BlockWithJustification for SignedBlock<Block> {
|
||||
fn justification(&self) -> Option<&Justification> {
|
||||
self.justification.as_ref()
|
||||
|
||||
@@ -25,9 +25,10 @@ mod rpc;
|
||||
|
||||
pub mod headers_source;
|
||||
|
||||
pub use crate::chain::{BlockNumberOf, BlockWithJustification, Chain, HashOf, HeaderOf, TransactionSignScheme};
|
||||
pub use crate::chain::{BlockWithJustification, Chain, TransactionSignScheme};
|
||||
pub use crate::client::{Client, OpaqueGrandpaAuthoritiesSet};
|
||||
pub use crate::error::{Error, Result};
|
||||
pub use bp_runtime::{BlockNumberOf, Chain as ChainBase, HashOf, HeaderOf};
|
||||
|
||||
/// Substrate connection params.
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
Reference in New Issue
Block a user