Skip to content

Commit a635048

Browse files
svyatonikbkchr
authored andcommitted
Register-parachain subcommand of substrate-relay (#1170)
* register parachain relay subcommand * revert cargo patch * added basic test * fmt
1 parent 4b525f4 commit a635048

File tree

15 files changed

+732
-62
lines changed

15 files changed

+732
-62
lines changed

bridges/bin/rialto-parachain/runtime/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ codec = { package = 'parity-scale-codec', version = '2.0.0', default-features =
1515
log = { version = "0.4.14", default-features = false }
1616
serde = { version = '1.0', optional = true, features = ['derive'] }
1717

18+
# Bridge depedencies
19+
20+
bp-rialto-parachain = { path = "../../../primitives/chain-rialto-parachain", default-features = false }
21+
1822
# Substrate Dependencies
1923
## Substrate Primitive Dependencies
2024
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
@@ -77,6 +81,7 @@ runtime-benchmarks = [
7781
'pallet-timestamp/runtime-benchmarks',
7882
]
7983
std = [
84+
"bp-rialto-parachain/std",
8085
"codec/std",
8186
"serde",
8287
"log/std",

bridges/bin/rialto-parachain/runtime/src/lib.rs

Lines changed: 12 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ use sp_api::impl_runtime_apis;
3030
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
3131
use sp_runtime::{
3232
create_runtime_str, generic, impl_opaque_keys,
33-
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount, Verify},
33+
traits::{AccountIdLookup, Block as BlockT},
3434
transaction_validity::{TransactionSource, TransactionValidity},
35-
ApplyExtrinsicResult, MultiSignature,
35+
ApplyExtrinsicResult,
3636
};
3737

3838
use sp_std::prelude::*;
@@ -50,14 +50,19 @@ pub use frame_support::{
5050
},
5151
StorageValue,
5252
};
53-
use frame_system::limits::{BlockLength, BlockWeights};
53+
pub use frame_system::Call as SystemCall;
5454
pub use pallet_balances::Call as BalancesCall;
5555
pub use pallet_timestamp::Call as TimestampCall;
5656
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
5757
#[cfg(any(feature = "std", test))]
5858
pub use sp_runtime::BuildStorage;
5959
pub use sp_runtime::{MultiAddress, Perbill, Permill};
6060

61+
pub use bp_rialto_parachain::{
62+
AccountId, Balance, BlockLength, BlockNumber, BlockWeights, Hash, Hasher as Hashing, Header,
63+
Index, Signature, MAXIMUM_BLOCK_WEIGHT,
64+
};
65+
6166
// Polkadot & XCM imports
6267
use pallet_xcm::XcmPassthrough;
6368
use polkadot_parachain::primitives::Sibling;
@@ -71,26 +76,8 @@ use xcm_builder::{
7176
};
7277
use xcm_executor::{Config, XcmExecutor};
7378

74-
// /// Import the template pallet.
75-
// pub use template;
76-
77-
/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
78-
pub type Signature = MultiSignature;
79-
/// Some way of identifying an account on the chain. We intentionally make it equivalent
80-
/// to the public key of our transaction signing scheme.
81-
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
82-
/// Balance of an account.
83-
pub type Balance = u128;
84-
/// Index of a transaction in the chain.
85-
pub type Index = u32;
86-
/// A hash of some data used by the chain.
87-
pub type Hash = sp_core::H256;
88-
/// An index to a block.
89-
pub type BlockNumber = u32;
9079
/// The address format for describing accounts.
9180
pub type Address = MultiAddress<AccountId, ()>;
92-
/// Block header type as expected by this runtime.
93-
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
9481
/// Block type as expected by this runtime.
9582
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
9683
/// A Block signed with a Justification
@@ -168,38 +155,9 @@ pub fn native_version() -> NativeVersion {
168155
NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
169156
}
170157

171-
/// We assume that approximately 10 percent of the block weight is consumed by `on_initalize`
172-
/// handlers. This is used to limit the maximal weight of a single extrinsic.
173-
const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
174-
/// We allow `Normal` extrinsics to fill up the block up to 75 percent, the rest can be used
175-
/// by Operational extrinsics.
176-
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
177-
/// We allow for 2 seconds of compute with a 12 second average block time.
178-
const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND * 2;
179-
180158
parameter_types! {
181159
pub const BlockHashCount: BlockNumber = 250;
182160
pub const Version: RuntimeVersion = VERSION;
183-
pub RuntimeBlockLength: BlockLength =
184-
BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
185-
pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
186-
.base_block(BlockExecutionWeight::get())
187-
.for_class(DispatchClass::all(), |weights| {
188-
weights.base_extrinsic = ExtrinsicBaseWeight::get();
189-
})
190-
.for_class(DispatchClass::Normal, |weights| {
191-
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
192-
})
193-
.for_class(DispatchClass::Operational, |weights| {
194-
weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
195-
// Operational transactions have some extra reserved space, so that they
196-
// are included even if block reached `MAXIMUM_BLOCK_WEIGHT`.
197-
weights.reserved = Some(
198-
MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT
199-
);
200-
})
201-
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
202-
.build_or_panic();
203161
pub const SS58Prefix: u8 = 48;
204162
}
205163

@@ -219,9 +177,9 @@ impl frame_system::Config for Runtime {
219177
/// The type for hashing blocks and tries.
220178
type Hash = Hash;
221179
/// The hashing algorithm used.
222-
type Hashing = BlakeTwo256;
180+
type Hashing = Hashing;
223181
/// The header type.
224-
type Header = generic::Header<BlockNumber, BlakeTwo256>;
182+
type Header = generic::Header<BlockNumber, Hashing>;
225183
/// The ubiquitous event type.
226184
type Event = Event;
227185
/// The ubiquitous origin type.
@@ -244,9 +202,9 @@ impl frame_system::Config for Runtime {
244202
/// Weight information for the extrinsics of this pallet.
245203
type SystemWeightInfo = ();
246204
/// Block & extrinsics weights: base values and limits.
247-
type BlockWeights = RuntimeBlockWeights;
205+
type BlockWeights = BlockWeights;
248206
/// The maximum length of a block (in bytes).
249-
type BlockLength = RuntimeBlockLength;
207+
type BlockLength = BlockLength;
250208
/// This is used as an identifier of the chain. 42 is the generic substrate prefix.
251209
type SS58Prefix = SS58Prefix;
252210
/// The action to take on a Runtime Upgrade
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[package]
2+
name = "bp-rialto-parachain"
3+
description = "Primitives of Rialto parachain runtime."
4+
version = "0.1.0"
5+
authors = ["Parity Technologies <[email protected]>"]
6+
edition = "2018"
7+
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
8+
9+
[dependencies]
10+
11+
# Bridge Dependencies
12+
13+
bp-messages = { path = "../messages", default-features = false }
14+
bp-runtime = { path = "../runtime", default-features = false }
15+
16+
# Substrate Based Dependencies
17+
18+
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
19+
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
20+
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
21+
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
22+
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
23+
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
24+
25+
[features]
26+
default = ["std"]
27+
std = [
28+
"bp-messages/std",
29+
"bp-runtime/std",
30+
"frame-support/std",
31+
"frame-system/std",
32+
"sp-api/std",
33+
"sp-core/std",
34+
"sp-runtime/std",
35+
"sp-std/std",
36+
]
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
2+
// This file is part of Parity Bridges Common.
3+
4+
// Parity Bridges Common is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// Parity Bridges Common is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
16+
17+
#![cfg_attr(not(feature = "std"), no_std)]
18+
// RuntimeApi generated functions
19+
#![allow(clippy::too_many_arguments)]
20+
// Runtime-generated DecodeLimit::decode_all_With_depth_limit
21+
#![allow(clippy::unnecessary_mut_passed)]
22+
23+
use bp_runtime::Chain;
24+
use frame_support::{
25+
weights::{constants::WEIGHT_PER_SECOND, DispatchClass, IdentityFee, Weight},
26+
RuntimeDebug,
27+
};
28+
use frame_system::limits;
29+
use sp_core::Hasher as HasherT;
30+
use sp_runtime::{
31+
traits::{BlakeTwo256, IdentifyAccount, Verify},
32+
MultiSignature, MultiSigner, Perbill,
33+
};
34+
35+
/// Maximal weight of single Rialto parachain block.
36+
///
37+
/// This represents two seconds of compute assuming a target block time of six seconds.
38+
pub const MAXIMUM_BLOCK_WEIGHT: Weight = 2 * WEIGHT_PER_SECOND;
39+
40+
/// Represents the average portion of a block's weight that will be used by an
41+
/// `on_initialize()` runtime call.
42+
pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
43+
44+
/// Represents the portion of a block that will be used by Normal extrinsics.
45+
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
46+
47+
/// Block number type used in Rialto.
48+
pub type BlockNumber = u32;
49+
50+
/// Hash type used in Rialto.
51+
pub type Hash = <BlakeTwo256 as HasherT>::Out;
52+
53+
/// The type of object that can produce hashes on Rialto.
54+
pub type Hasher = BlakeTwo256;
55+
56+
/// The header type used by Rialto.
57+
pub type Header = sp_runtime::generic::Header<BlockNumber, Hasher>;
58+
59+
/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
60+
pub type Signature = MultiSignature;
61+
62+
/// Some way of identifying an account on the chain. We intentionally make it equivalent
63+
/// to the public key of our transaction signing scheme.
64+
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
65+
66+
/// Public key of the chain account that may be used to verify signatures.
67+
pub type AccountSigner = MultiSigner;
68+
69+
/// Balance of an account.
70+
pub type Balance = u128;
71+
72+
/// An instant or duration in time.
73+
pub type Moment = u64;
74+
75+
/// Index of a transaction in the parachain.
76+
pub type Index = u32;
77+
78+
/// Weight-to-Fee type used by Rialto parachain.
79+
pub type WeightToFee = IdentityFee<Balance>;
80+
81+
/// Rialto parachain.
82+
#[derive(RuntimeDebug)]
83+
pub struct RialtoParachain;
84+
85+
impl Chain for RialtoParachain {
86+
type BlockNumber = BlockNumber;
87+
type Hash = Hash;
88+
type Hasher = Hasher;
89+
type Header = Header;
90+
91+
type AccountId = AccountId;
92+
type Balance = Balance;
93+
type Index = Index;
94+
type Signature = Signature;
95+
}
96+
97+
frame_support::parameter_types! {
98+
pub BlockLength: limits::BlockLength =
99+
limits::BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
100+
pub BlockWeights: limits::BlockWeights = limits::BlockWeights::builder()
101+
// Allowance for Normal class
102+
.for_class(DispatchClass::Normal, |weights| {
103+
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
104+
})
105+
// Allowance for Operational class
106+
.for_class(DispatchClass::Operational, |weights| {
107+
weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
108+
// Extra reserved space for Operational class
109+
weights.reserved = Some(MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
110+
})
111+
// By default Mandatory class is not limited at all.
112+
// This parameter is used to derive maximal size of a single extrinsic.
113+
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
114+
.build_or_panic();
115+
}
116+
117+
/// Get the maximum weight (compute time) that a Normal extrinsic on the Millau chain can use.
118+
pub fn max_extrinsic_weight() -> Weight {
119+
BlockWeights::get()
120+
.get(DispatchClass::Normal)
121+
.max_extrinsic
122+
.unwrap_or(Weight::MAX)
123+
}
124+
125+
/// Get the maximum length in bytes that a Normal extrinsic on the Millau chain requires.
126+
pub fn max_extrinsic_size() -> u32 {
127+
*BlockLength::get().max.get(DispatchClass::Normal)
128+
}

bridges/primitives/chain-rialto/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ pub fn max_extrinsic_size() -> u32 {
231231
/// Name of the With-Millau messages pallet instance in the Rialto runtime.
232232
pub const WITH_MILLAU_MESSAGES_PALLET_NAME: &str = "BridgeMillauMessages";
233233

234+
/// Name of the parachain registrar pallet in the Rialto runtime.
235+
pub const PARAS_REGISTRAR_PALLET_NAME: &str = "Registrar";
236+
237+
/// Name of the parachains pallet in the Rialto runtime.
238+
pub const PARAS_PALLET_NAME: &str = "Paras";
239+
234240
/// Name of the `RialtoFinalityApi::best_finalized` runtime method.
235241
pub const BEST_FINALIZED_RIALTO_HEADER_METHOD: &str = "RialtoFinalityApi_best_finalized";
236242

bridges/primitives/runtime/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub use chain::{
2828
AccountIdOf, AccountPublicOf, BalanceOf, BlockNumberOf, Chain, HashOf, HasherOf, HeaderOf,
2929
IndexOf, SignatureOf, TransactionEraOf,
3030
};
31+
pub use frame_support::storage::storage_prefix as storage_value_final_key;
3132
pub use storage_proof::{Error as StorageProofError, StorageProofChecker};
3233

3334
#[cfg(feature = "std")]
@@ -216,6 +217,15 @@ pub fn storage_map_final_key_blake2_128concat(
216217
)
217218
}
218219

220+
///
221+
pub fn storage_map_final_key_twox64_concat(
222+
pallet_prefix: &str,
223+
map_name: &str,
224+
key: &[u8],
225+
) -> StorageKey {
226+
storage_map_final_key_identity(pallet_prefix, map_name, &frame_support::Twox64Concat::hash(key))
227+
}
228+
219229
/// This is a copy of the
220230
/// `frame_support::storage::generator::StorageMap::storage_map_final_key` for `Identity` maps.
221231
///

bridges/relays/bin-substrate/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ bp-message-dispatch = { path = "../../primitives/message-dispatch" }
2828
bp-millau = { path = "../../primitives/chain-millau" }
2929
bp-polkadot = { path = "../../primitives/chain-polkadot" }
3030
bp-rialto = { path = "../../primitives/chain-rialto" }
31+
bp-rialto-parachain = { path = "../../primitives/chain-rialto-parachain" }
3132
bp-rococo = { path = "../../primitives/chain-rococo" }
3233
bp-token-swap = { path = "../../primitives/token-swap" }
3334
bp-wococo = { path = "../../primitives/chain-wococo" }
@@ -44,11 +45,13 @@ relay-kusama-client = { path = "../client-kusama" }
4445
relay-millau-client = { path = "../client-millau" }
4546
relay-polkadot-client = { path = "../client-polkadot" }
4647
relay-rialto-client = { path = "../client-rialto" }
48+
relay-rialto-parachain-client = { path = "../client-rialto-parachain" }
4749
relay-rococo-client = { path = "../client-rococo" }
4850
relay-wococo-client = { path = "../client-wococo" }
4951
relay-substrate-client = { path = "../client-substrate" }
5052
relay-utils = { path = "../utils" }
5153
relay-westend-client = { path = "../client-westend" }
54+
rialto-parachain-runtime = { path = "../../bin/rialto-parachain/runtime" }
5255
rialto-runtime = { path = "../../bin/rialto/runtime" }
5356
substrate-relay-helper = { path = "../lib-substrate-relay" }
5457

@@ -61,6 +64,13 @@ sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" }
6164
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
6265
sp-version = { git = "https://github.com/paritytech/substrate", branch = "master" }
6366

67+
# Polkadot Dependencies
68+
69+
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "master" }
70+
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "master" }
71+
polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", branch = "master" }
72+
polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "master" }
73+
6474
[dev-dependencies]
6575
hex-literal = "0.3"
6676
pallet-bridge-grandpa = { path = "../../modules/grandpa" }

bridges/relays/bin-substrate/src/chains/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ mod kusama;
3434
mod millau;
3535
mod polkadot;
3636
mod rialto;
37+
mod rialto_parachain;
3738
mod rococo;
3839
mod westend;
3940
mod wococo;

0 commit comments

Comments
 (0)