Skip to content

Commit

Permalink
Move Chain trait to runtime primitives (paritytech#403)
Browse files Browse the repository at this point in the history
* extract ChainBase to bp-runtime

* post-merge fixes

* cargo fmt --all

* compilation fixes

* reexport BlockNumberOf, HashOf, HeaderOf
  • Loading branch information
svyatonik authored and serban300 committed Apr 9, 2024
1 parent b896ad6 commit 5789356
Show file tree
Hide file tree
Showing 17 changed files with 238 additions and 171 deletions.
20 changes: 9 additions & 11 deletions bridges/bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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>;

Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {}
Expand Down Expand Up @@ -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
Expand Down
20 changes: 9 additions & 11 deletions bridges/bin/rialto/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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>;

Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {}
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions bridges/modules/substrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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",
Expand Down
Loading

0 comments on commit 5789356

Please sign in to comment.