mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 04:01:02 +00:00
Bump xcm-v3 + substrate (#1767)
* Bump xcm-v3 + substrate * More fixes * Added `#[pallet::call_index` * Fixes for MMR (TODO:plese check) * More call indexes * Cumulus bump * Fixes for mmr * Fixes for weights * Fixes for xcm * MMR fixes + cargo fmt * Fix some rpc errors (bump jsonrpsee version) * Fix cumulus stuff * Fixes cumulus * clippy * more clipy * Fix test + unused deps * PR fixes * cargo update (bump xcm-v3) Co-authored-by: Serban Iorga <serban@parity.io>
This commit is contained in:
committed by
Bastian Köcher
parent
add2914a5c
commit
5fdc89d651
@@ -10,7 +10,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.0.9", features = ["derive"] }
|
||||
jsonrpsee = { version = "0.15.1", features = ["server"] }
|
||||
jsonrpsee = { version = "0.16.2", features = ["server"] }
|
||||
serde_json = "1.0.79"
|
||||
|
||||
# Bridge dependencies
|
||||
@@ -21,14 +21,14 @@ millau-runtime = { path = "../runtime" }
|
||||
|
||||
beefy-gadget = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
beefy-gadget-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
beefy-primitives = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-beefy = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
node-inspect = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
pallet-mmr-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
mmr-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master", features = ["wasmtime"] }
|
||||
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master"}
|
||||
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
// 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 beefy_primitives::crypto::AuthorityId as BeefyId;
|
||||
use millau_runtime::{
|
||||
AccountId, AuraConfig, BalancesConfig, BeefyConfig, BridgeRialtoMessagesConfig,
|
||||
BridgeRialtoParachainMessagesConfig, BridgeWestendGrandpaConfig, GenesisConfig, GrandpaConfig,
|
||||
SessionConfig, SessionKeys, Signature, SudoConfig, SystemConfig, WASM_BINARY,
|
||||
};
|
||||
use sp_beefy::crypto::AuthorityId as BeefyId;
|
||||
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
|
||||
use sp_core::{sr25519, Pair, Public};
|
||||
use sp_finality_grandpa::AuthorityId as GrandpaId;
|
||||
|
||||
@@ -272,7 +272,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
|
||||
use sc_finality_grandpa::FinalityProofProvider as GrandpaFinalityProofProvider;
|
||||
|
||||
use beefy_gadget_rpc::{Beefy, BeefyApiServer};
|
||||
use pallet_mmr_rpc::{Mmr, MmrApiServer};
|
||||
use mmr_rpc::{Mmr, MmrApiServer};
|
||||
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
|
||||
use sc_finality_grandpa_rpc::{Grandpa, GrandpaApiServer};
|
||||
use sc_rpc::DenyUnsafe;
|
||||
@@ -391,7 +391,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
|
||||
if role.is_authority() { Some(keystore_container.sync_keystore()) } else { None };
|
||||
|
||||
let justifications_protocol_name = beefy_on_demand_justifications_handler.protocol_name();
|
||||
let payload_provider = beefy_primitives::mmr::MmrRootProvider::new(client.clone());
|
||||
let payload_provider = sp_beefy::mmr::MmrRootProvider::new(client.clone());
|
||||
let beefy_params = beefy_gadget::BeefyParams {
|
||||
client: client.clone(),
|
||||
backend,
|
||||
|
||||
@@ -31,7 +31,7 @@ pallet-shift-session-manager = { path = "../../../modules/shift-session-manager"
|
||||
|
||||
# Substrate Dependencies
|
||||
|
||||
beefy-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
sp-beefy = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
|
||||
frame-executive = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
@@ -56,7 +56,6 @@ sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch =
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
sp-mmr-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
sp-offchain = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
sp-session = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
@@ -81,7 +80,7 @@ substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", bran
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"beefy-primitives/std",
|
||||
"sp-beefy/std",
|
||||
"bp-messages/std",
|
||||
"bp-millau/std",
|
||||
"bp-parachains/std",
|
||||
|
||||
@@ -32,7 +32,6 @@ pub mod rialto_messages;
|
||||
pub mod rialto_parachain_messages;
|
||||
pub mod xcm_config;
|
||||
|
||||
use beefy_primitives::{crypto::AuthorityId as BeefyId, mmr::MmrLeafVersion, ValidatorSet};
|
||||
use bp_parachains::SingleParaStoredHeaderDataBuilder;
|
||||
use bp_runtime::HeaderId;
|
||||
use pallet_grandpa::{
|
||||
@@ -40,9 +39,9 @@ use pallet_grandpa::{
|
||||
};
|
||||
use pallet_transaction_payment::{FeeDetails, Multiplier, RuntimeDispatchInfo};
|
||||
use sp_api::impl_runtime_apis;
|
||||
use sp_beefy::{crypto::AuthorityId as BeefyId, mmr::MmrLeafVersion, ValidatorSet};
|
||||
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
|
||||
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
|
||||
use sp_mmr_primitives::{DataOrHash, EncodableOpaqueLeaf, Error as MmrError, Proof as MmrProof};
|
||||
use sp_runtime::{
|
||||
create_runtime_str, generic, impl_opaque_keys,
|
||||
traits::{Block as BlockT, IdentityLookup, Keccak256, NumberFor, OpaqueKeys},
|
||||
@@ -64,7 +63,8 @@ pub use frame_support::{
|
||||
parameter_types,
|
||||
traits::{ConstU32, ConstU8, Currency, ExistenceRequirement, Imbalance, KeyOwnerProofSystem},
|
||||
weights::{
|
||||
constants::WEIGHT_PER_SECOND, ConstantMultiplier, IdentityFee, RuntimeDbWeight, Weight,
|
||||
constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, IdentityFee, RuntimeDbWeight,
|
||||
Weight,
|
||||
},
|
||||
RuntimeDebug, StorageValue,
|
||||
};
|
||||
@@ -281,7 +281,7 @@ parameter_types! {
|
||||
|
||||
pub struct BeefyDummyDataProvider;
|
||||
|
||||
impl beefy_primitives::mmr::BeefyDataProvider<()> for BeefyDummyDataProvider {
|
||||
impl sp_beefy::mmr::BeefyDataProvider<()> for BeefyDummyDataProvider {
|
||||
fn extra_data() {}
|
||||
}
|
||||
|
||||
@@ -766,62 +766,30 @@ impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
impl beefy_primitives::BeefyApi<Block> for Runtime {
|
||||
impl sp_beefy::BeefyApi<Block> for Runtime {
|
||||
fn validator_set() -> Option<ValidatorSet<BeefyId>> {
|
||||
Beefy::validator_set()
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_mmr_primitives::MmrApi<Block, mmr::Hash, BlockNumber> for Runtime {
|
||||
fn generate_proof(block_number: BlockNumber)
|
||||
-> Result<(EncodableOpaqueLeaf, MmrProof<mmr::Hash>), MmrError>
|
||||
{
|
||||
Mmr::generate_batch_proof(vec![block_number])
|
||||
.and_then(|(leaves, proof)| Ok((
|
||||
mmr::EncodableOpaqueLeaf::from_leaf(&leaves[0]),
|
||||
mmr::BatchProof::into_single_leaf_proof(proof)?
|
||||
)))
|
||||
}
|
||||
|
||||
fn verify_proof(leaf: EncodableOpaqueLeaf, proof: MmrProof<mmr::Hash>)
|
||||
-> Result<(), MmrError>
|
||||
{
|
||||
let leaf: mmr::Leaf = leaf
|
||||
.into_opaque_leaf()
|
||||
.try_decode()
|
||||
.ok_or(MmrError::Verify)?;
|
||||
Mmr::verify_leaves(vec![leaf], mmr::Proof::into_batch_proof(proof))
|
||||
}
|
||||
|
||||
fn verify_proof_stateless(
|
||||
root: mmr::Hash,
|
||||
leaf: EncodableOpaqueLeaf,
|
||||
proof: MmrProof<mmr::Hash>
|
||||
) -> Result<(), MmrError> {
|
||||
let node = DataOrHash::Data(leaf.into_opaque_leaf());
|
||||
pallet_mmr::verify_leaves_proof::<mmr::Hashing, _>(
|
||||
root,
|
||||
vec![node],
|
||||
pallet_mmr::primitives::Proof::into_batch_proof(proof),
|
||||
)
|
||||
}
|
||||
|
||||
fn mmr_root() -> Result<mmr::Hash, MmrError> {
|
||||
impl pallet_mmr::primitives::MmrApi<
|
||||
Block,
|
||||
mmr::Hash,
|
||||
BlockNumber,
|
||||
> for Runtime {
|
||||
fn mmr_root() -> Result<mmr::Hash, mmr::Error> {
|
||||
Ok(Mmr::mmr_root())
|
||||
}
|
||||
|
||||
fn generate_batch_proof(block_numbers: Vec<BlockNumber>)
|
||||
-> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<mmr::Hash>), mmr::Error>
|
||||
{
|
||||
Mmr::generate_batch_proof(block_numbers)
|
||||
.map(|(leaves, proof)| (leaves.into_iter().map(|leaf| mmr::EncodableOpaqueLeaf::from_leaf(&leaf)).collect(), proof))
|
||||
fn mmr_leaf_count() -> Result<mmr::LeafIndex, mmr::Error> {
|
||||
Ok(Mmr::mmr_leaves())
|
||||
}
|
||||
|
||||
fn generate_historical_batch_proof(
|
||||
fn generate_proof(
|
||||
block_numbers: Vec<BlockNumber>,
|
||||
best_known_block_number: BlockNumber
|
||||
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<mmr::Hash>), mmr::Error> {
|
||||
Mmr::generate_historical_batch_proof(block_numbers, best_known_block_number).map(
|
||||
best_known_block_number: Option<BlockNumber>,
|
||||
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::Proof<mmr::Hash>), mmr::Error> {
|
||||
Mmr::generate_proof(block_numbers, best_known_block_number).map(
|
||||
|(leaves, proof)| {
|
||||
(
|
||||
leaves
|
||||
@@ -834,7 +802,7 @@ impl_runtime_apis! {
|
||||
)
|
||||
}
|
||||
|
||||
fn verify_batch_proof(leaves: Vec<mmr::EncodableOpaqueLeaf>, proof: mmr::BatchProof<mmr::Hash>)
|
||||
fn verify_proof(leaves: Vec<mmr::EncodableOpaqueLeaf>, proof: mmr::Proof<mmr::Hash>)
|
||||
-> Result<(), mmr::Error>
|
||||
{
|
||||
let leaves = leaves.into_iter().map(|leaf|
|
||||
@@ -844,10 +812,10 @@ impl_runtime_apis! {
|
||||
Mmr::verify_leaves(leaves, proof)
|
||||
}
|
||||
|
||||
fn verify_batch_proof_stateless(
|
||||
fn verify_proof_stateless(
|
||||
root: mmr::Hash,
|
||||
leaves: Vec<mmr::EncodableOpaqueLeaf>,
|
||||
proof: mmr::BatchProof<mmr::Hash>
|
||||
proof: mmr::Proof<mmr::Hash>
|
||||
) -> Result<(), mmr::Error> {
|
||||
let nodes = leaves.into_iter().map(|leaf|mmr::DataOrHash::Data(leaf.into_opaque_leaf())).collect();
|
||||
pallet_mmr::verify_leaves_proof::<mmr::Hashing, _>(root, nodes, proof)
|
||||
|
||||
@@ -32,6 +32,7 @@ use bridge_runtime_common::{
|
||||
use frame_support::{
|
||||
parameter_types,
|
||||
traits::{ConstU32, Everything, Nothing},
|
||||
weights::Weight,
|
||||
};
|
||||
use xcm::latest::prelude::*;
|
||||
use xcm_builder::{
|
||||
@@ -97,7 +98,8 @@ pub const BASE_XCM_WEIGHT: u64 = 1_000_000_000;
|
||||
|
||||
parameter_types! {
|
||||
/// The amount of weight an XCM operation takes. This is a safe overestimate.
|
||||
pub const BaseXcmWeight: u64 = BASE_XCM_WEIGHT;
|
||||
// TODO: https://github.com/paritytech/parity-bridges-common/issues/1543 - check `set_proof_size` 0 or 64*1024 or 1026?
|
||||
pub const BaseXcmWeight: Weight = Weight::from_parts(BASE_XCM_WEIGHT, 0);
|
||||
/// Maximum number of instructions in a single XCM fragment. A sanity check against weight
|
||||
/// calculations getting too crazy.
|
||||
pub const MaxInstructions: u32 = 100;
|
||||
@@ -150,6 +152,7 @@ impl xcm_executor::Config for XcmConfig {
|
||||
type MessageExporter = ();
|
||||
type UniversalAliases = Nothing;
|
||||
type CallDispatcher = RuntimeCall;
|
||||
type SafeCallFilter = Everything;
|
||||
}
|
||||
|
||||
/// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior
|
||||
@@ -159,6 +162,11 @@ pub type LocalOriginToLocation = (
|
||||
SignedToAccountId32<RuntimeOrigin, AccountId, ThisNetwork>,
|
||||
);
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
parameter_types! {
|
||||
pub ReachableDest: Option<MultiLocation> = todo!("We dont use benchmarks for pallet_xcm, so if you hit this message, you need to remove this and define value instead");
|
||||
}
|
||||
|
||||
impl pallet_xcm::Config for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
// We don't allow any messages to be sent via the transaction yet. This is basically safe to
|
||||
@@ -188,6 +196,9 @@ impl pallet_xcm::Config for Runtime {
|
||||
type TrustedLockers = ();
|
||||
type SovereignAccountOf = SovereignAccountOf;
|
||||
type MaxLockers = frame_support::traits::ConstU32<8>;
|
||||
type WeightInfo = pallet_xcm::TestWeightInfo;
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
type ReachableDest = ReachableDest;
|
||||
}
|
||||
|
||||
/// With-Rialto bridge.
|
||||
|
||||
@@ -23,7 +23,7 @@ codec = { package = 'parity-scale-codec', version = '3.1.5' }
|
||||
serde = { version = '1.0', features = ['derive'] }
|
||||
|
||||
# RPC related Dependencies
|
||||
jsonrpsee = { version = "0.15.1", features = ["server"] }
|
||||
jsonrpsee = { version = "0.16.2", features = ["server"] }
|
||||
|
||||
# Local Dependencies
|
||||
rialto-parachain-runtime = { path = '../runtime' }
|
||||
@@ -47,8 +47,7 @@ sc-executor = { git = "https://github.com/paritytech/substrate", branch = "maste
|
||||
sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-rpc-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-service = { git = "https://github.com/paritytech/substrate", branch = "master", features = ['wasmtime'] }
|
||||
sc-sysinfo = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-service = { git = "https://github.com/paritytech/substrate", branch = "master"}
|
||||
sc-telemetry = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
@@ -74,8 +73,6 @@ cumulus-client-service = { git = "https://github.com/paritytech/cumulus", branch
|
||||
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "master" }
|
||||
cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech/cumulus", branch = "master" }
|
||||
cumulus-relay-chain-interface = { git = "https://github.com/paritytech/cumulus", branch = "master" }
|
||||
cumulus-relay-chain-inprocess-interface = { git = "https://github.com/paritytech/cumulus", branch = "master" }
|
||||
cumulus-relay-chain-minimal-node = { git = "https://github.com/paritytech/cumulus", branch = "master" }
|
||||
|
||||
# Polkadot dependencies
|
||||
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "master" }
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
// 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/>.
|
||||
|
||||
#![allow(clippy::large_enum_variant)]
|
||||
|
||||
use crate::chain_spec;
|
||||
use clap::Parser;
|
||||
use std::path::PathBuf;
|
||||
|
||||
@@ -138,7 +138,6 @@ macro_rules! construct_async_run {
|
||||
runner.async_run(|$config| {
|
||||
let $components = new_partial::<
|
||||
RuntimeApi,
|
||||
ParachainRuntimeExecutor,
|
||||
_
|
||||
>(
|
||||
&$config,
|
||||
|
||||
@@ -30,17 +30,16 @@ use rialto_parachain_runtime::RuntimeApi;
|
||||
// Cumulus Imports
|
||||
use cumulus_client_cli::CollatorOptions;
|
||||
use cumulus_client_consensus_aura::{AuraConsensus, BuildAuraConsensusParams, SlotProportion};
|
||||
use cumulus_client_consensus_common::{ParachainBlockImport, ParachainConsensus};
|
||||
use cumulus_client_consensus_common::{
|
||||
ParachainBlockImport as TParachainBlockImport, ParachainConsensus,
|
||||
};
|
||||
use cumulus_client_network::BlockAnnounceValidator;
|
||||
use cumulus_client_service::{
|
||||
prepare_node_config, start_collator, start_full_node, StartCollatorParams, StartFullNodeParams,
|
||||
};
|
||||
use cumulus_primitives_core::ParaId;
|
||||
use cumulus_relay_chain_inprocess_interface::build_inprocess_relay_chain;
|
||||
use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface, RelayChainResult};
|
||||
use cumulus_relay_chain_minimal_node::build_minimal_relay_chain_node;
|
||||
use polkadot_service::CollatorPair;
|
||||
|
||||
use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface};
|
||||
use sc_consensus::ImportQueue;
|
||||
// Substrate Imports
|
||||
use sc_executor::{NativeElseWasmExecutor, NativeExecutionDispatch};
|
||||
use sc_network::{NetworkBlock, NetworkService};
|
||||
@@ -57,6 +56,12 @@ type Header = sp_runtime::generic::Header<BlockNumber, sp_runtime::traits::Blake
|
||||
pub type Block = sp_runtime::generic::Block<Header, sp_runtime::OpaqueExtrinsic>;
|
||||
type Hash = sp_core::H256;
|
||||
|
||||
type ParachainClient<RuntimeApi> =
|
||||
TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ParachainRuntimeExecutor>>;
|
||||
type ParachainBackend = TFullBackend<Block>;
|
||||
type ParachainBlockImport<RuntimeApi> =
|
||||
TParachainBlockImport<Block, Arc<ParachainClient<RuntimeApi>>, ParachainBackend>;
|
||||
|
||||
pub type ParachainRuntimeExecutor = ExecutorDispatch;
|
||||
|
||||
// Our native executor instance.
|
||||
@@ -79,51 +84,39 @@ impl NativeExecutionDispatch for ExecutorDispatch {
|
||||
/// Use this macro if you don't actually need the full service, but just the builder in order to
|
||||
/// be able to perform chain operations.
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub fn new_partial<RuntimeApi, Executor, BIQ>(
|
||||
pub fn new_partial<RuntimeApi, BIQ>(
|
||||
config: &Configuration,
|
||||
build_import_queue: BIQ,
|
||||
) -> Result<
|
||||
PartialComponents<
|
||||
TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>,
|
||||
TFullBackend<Block>,
|
||||
ParachainClient<RuntimeApi>,
|
||||
ParachainBackend,
|
||||
(),
|
||||
sc_consensus::DefaultImportQueue<
|
||||
Block,
|
||||
TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>,
|
||||
>,
|
||||
sc_transaction_pool::FullPool<
|
||||
Block,
|
||||
TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>,
|
||||
>,
|
||||
(Option<Telemetry>, Option<TelemetryWorkerHandle>),
|
||||
sc_consensus::DefaultImportQueue<Block, ParachainClient<RuntimeApi>>,
|
||||
sc_transaction_pool::FullPool<Block, ParachainClient<RuntimeApi>>,
|
||||
(ParachainBlockImport<RuntimeApi>, Option<Telemetry>, Option<TelemetryWorkerHandle>),
|
||||
>,
|
||||
sc_service::Error,
|
||||
>
|
||||
where
|
||||
RuntimeApi: ConstructRuntimeApi<Block, TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
RuntimeApi: ConstructRuntimeApi<Block, ParachainClient<RuntimeApi>> + Send + Sync + 'static,
|
||||
RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
|
||||
+ sp_api::Metadata<Block>
|
||||
+ sp_session::SessionKeys<Block>
|
||||
+ sp_api::ApiExt<
|
||||
Block,
|
||||
StateBackend = sc_client_api::StateBackendFor<TFullBackend<Block>, Block>,
|
||||
StateBackend = sc_client_api::StateBackendFor<ParachainBackend, Block>,
|
||||
> + sp_offchain::OffchainWorkerApi<Block>
|
||||
+ sp_block_builder::BlockBuilder<Block>,
|
||||
sc_client_api::StateBackendFor<TFullBackend<Block>, Block>: sp_api::StateBackend<BlakeTwo256>,
|
||||
Executor: NativeExecutionDispatch + 'static,
|
||||
sc_client_api::StateBackendFor<ParachainBackend, Block>: sp_api::StateBackend<BlakeTwo256>,
|
||||
BIQ: FnOnce(
|
||||
Arc<TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>>,
|
||||
Arc<ParachainClient<RuntimeApi>>,
|
||||
ParachainBlockImport<RuntimeApi>,
|
||||
&Configuration,
|
||||
Option<TelemetryHandle>,
|
||||
&TaskManager,
|
||||
) -> Result<
|
||||
sc_consensus::DefaultImportQueue<
|
||||
Block,
|
||||
TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>,
|
||||
>,
|
||||
sc_consensus::DefaultImportQueue<Block, ParachainClient<RuntimeApi>>,
|
||||
sc_service::Error,
|
||||
>,
|
||||
{
|
||||
@@ -138,7 +131,7 @@ where
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
let executor = sc_executor::NativeElseWasmExecutor::<Executor>::new(
|
||||
let executor = sc_executor::NativeElseWasmExecutor::<ParachainRuntimeExecutor>::new(
|
||||
config.wasm_method,
|
||||
config.default_heap_pages,
|
||||
config.max_runtime_instances,
|
||||
@@ -168,8 +161,11 @@ where
|
||||
client.clone(),
|
||||
);
|
||||
|
||||
let block_import = ParachainBlockImport::new(client.clone(), backend.clone());
|
||||
|
||||
let import_queue = build_import_queue(
|
||||
client.clone(),
|
||||
block_import.clone(),
|
||||
config,
|
||||
telemetry.as_ref().map(|telemetry| telemetry.handle()),
|
||||
&task_manager,
|
||||
@@ -183,38 +179,17 @@ where
|
||||
task_manager,
|
||||
transaction_pool,
|
||||
select_chain: (),
|
||||
other: (telemetry, telemetry_worker_handle),
|
||||
other: (block_import, telemetry, telemetry_worker_handle),
|
||||
};
|
||||
|
||||
Ok(params)
|
||||
}
|
||||
|
||||
async fn build_relay_chain_interface(
|
||||
polkadot_config: Configuration,
|
||||
parachain_config: &Configuration,
|
||||
telemetry_worker_handle: Option<TelemetryWorkerHandle>,
|
||||
task_manager: &mut TaskManager,
|
||||
collator_options: CollatorOptions,
|
||||
hwbench: Option<sc_sysinfo::HwBench>,
|
||||
) -> RelayChainResult<(Arc<(dyn RelayChainInterface + 'static)>, Option<CollatorPair>)> {
|
||||
match collator_options.relay_chain_rpc_url {
|
||||
Some(relay_chain_url) =>
|
||||
build_minimal_relay_chain_node(polkadot_config, task_manager, relay_chain_url).await,
|
||||
None => build_inprocess_relay_chain(
|
||||
polkadot_config,
|
||||
parachain_config,
|
||||
telemetry_worker_handle,
|
||||
task_manager,
|
||||
hwbench,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// Start a node with the given parachain `Configuration` and relay chain `Configuration`.
|
||||
///
|
||||
/// This is the actual implementation that is abstract over the executor and the runtime api.
|
||||
#[sc_tracing::logging::prefix_logs_with("Parachain")]
|
||||
async fn start_node_impl<RuntimeApi, Executor, RB, BIQ, BIC>(
|
||||
async fn start_node_impl<RuntimeApi, RB, BIQ, BIC>(
|
||||
parachain_config: Configuration,
|
||||
polkadot_config: Configuration,
|
||||
collator_options: CollatorOptions,
|
||||
@@ -222,63 +197,45 @@ async fn start_node_impl<RuntimeApi, Executor, RB, BIQ, BIC>(
|
||||
rpc_ext_builder: RB,
|
||||
build_import_queue: BIQ,
|
||||
build_consensus: BIC,
|
||||
) -> sc_service::error::Result<(
|
||||
TaskManager,
|
||||
Arc<TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>>,
|
||||
)>
|
||||
) -> sc_service::error::Result<(TaskManager, Arc<ParachainClient<RuntimeApi>>)>
|
||||
where
|
||||
RuntimeApi: ConstructRuntimeApi<Block, TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
RuntimeApi: ConstructRuntimeApi<Block, ParachainClient<RuntimeApi>> + Send + Sync + 'static,
|
||||
RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
|
||||
+ sp_api::Metadata<Block>
|
||||
+ sp_session::SessionKeys<Block>
|
||||
+ sp_api::ApiExt<
|
||||
Block,
|
||||
StateBackend = sc_client_api::StateBackendFor<TFullBackend<Block>, Block>,
|
||||
StateBackend = sc_client_api::StateBackendFor<ParachainBackend, Block>,
|
||||
> + sp_offchain::OffchainWorkerApi<Block>
|
||||
+ sp_block_builder::BlockBuilder<Block>
|
||||
+ cumulus_primitives_core::CollectCollationInfo<Block>,
|
||||
sc_client_api::StateBackendFor<TFullBackend<Block>, Block>: sp_api::StateBackend<BlakeTwo256>,
|
||||
Executor: NativeExecutionDispatch + 'static,
|
||||
sc_client_api::StateBackendFor<ParachainBackend, Block>: sp_api::StateBackend<BlakeTwo256>,
|
||||
RB: Fn(
|
||||
sc_rpc_api::DenyUnsafe,
|
||||
Arc<TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>>,
|
||||
Arc<
|
||||
sc_transaction_pool::FullPool<
|
||||
Block,
|
||||
TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>,
|
||||
>,
|
||||
>,
|
||||
Arc<ParachainClient<RuntimeApi>>,
|
||||
Arc<sc_transaction_pool::FullPool<Block, ParachainClient<RuntimeApi>>>,
|
||||
) -> Result<jsonrpsee::RpcModule<()>, sc_service::Error>
|
||||
+ Send
|
||||
+ Clone
|
||||
+ 'static,
|
||||
BIQ: FnOnce(
|
||||
Arc<TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>>,
|
||||
Arc<ParachainClient<RuntimeApi>>,
|
||||
ParachainBlockImport<RuntimeApi>,
|
||||
&Configuration,
|
||||
Option<TelemetryHandle>,
|
||||
&TaskManager,
|
||||
) -> Result<
|
||||
sc_consensus::DefaultImportQueue<
|
||||
Block,
|
||||
TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>,
|
||||
>,
|
||||
sc_consensus::DefaultImportQueue<Block, ParachainClient<RuntimeApi>>,
|
||||
sc_service::Error,
|
||||
>,
|
||||
BIC: FnOnce(
|
||||
Arc<TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>>,
|
||||
Arc<ParachainClient<RuntimeApi>>,
|
||||
ParachainBlockImport<RuntimeApi>,
|
||||
Option<&Registry>,
|
||||
Option<TelemetryHandle>,
|
||||
&TaskManager,
|
||||
Arc<dyn RelayChainInterface>,
|
||||
Arc<
|
||||
sc_transaction_pool::FullPool<
|
||||
Block,
|
||||
TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>,
|
||||
>,
|
||||
>,
|
||||
Arc<sc_transaction_pool::FullPool<Block, ParachainClient<RuntimeApi>>>,
|
||||
Arc<NetworkService<Block, Hash>>,
|
||||
SyncCryptoStorePtr,
|
||||
bool,
|
||||
@@ -286,23 +243,24 @@ where
|
||||
{
|
||||
let parachain_config = prepare_node_config(parachain_config);
|
||||
|
||||
let params = new_partial::<RuntimeApi, Executor, BIQ>(¶chain_config, build_import_queue)?;
|
||||
let (mut telemetry, telemetry_worker_handle) = params.other;
|
||||
let params = new_partial::<RuntimeApi, BIQ>(¶chain_config, build_import_queue)?;
|
||||
let (block_import, mut telemetry, telemetry_worker_handle) = params.other;
|
||||
|
||||
let mut task_manager = params.task_manager;
|
||||
let (relay_chain_interface, collator_key) = build_relay_chain_interface(
|
||||
polkadot_config,
|
||||
¶chain_config,
|
||||
telemetry_worker_handle,
|
||||
&mut task_manager,
|
||||
collator_options,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.map_err(|e| match e {
|
||||
RelayChainError::ServiceError(polkadot_service::Error::Sub(x)) => x,
|
||||
s => s.to_string().into(),
|
||||
})?;
|
||||
let (relay_chain_interface, collator_key) =
|
||||
cumulus_client_service::build_relay_chain_interface(
|
||||
polkadot_config,
|
||||
¶chain_config,
|
||||
telemetry_worker_handle,
|
||||
&mut task_manager,
|
||||
collator_options,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.map_err(|e| match e {
|
||||
RelayChainError::ServiceError(polkadot_service::Error::Sub(x)) => x,
|
||||
s => s.to_string().into(),
|
||||
})?;
|
||||
|
||||
let client = params.client.clone();
|
||||
let backend = params.backend.clone();
|
||||
@@ -312,14 +270,15 @@ where
|
||||
let validator = parachain_config.role.is_authority();
|
||||
let prometheus_registry = parachain_config.prometheus_registry().cloned();
|
||||
let transaction_pool = params.transaction_pool.clone();
|
||||
let import_queue = cumulus_client_service::SharedImportQueue::new(params.import_queue);
|
||||
let import_queue_service = params.import_queue.service();
|
||||
|
||||
let (network, system_rpc_tx, tx_handler_controller, start_network) =
|
||||
sc_service::build_network(sc_service::BuildNetworkParams {
|
||||
config: ¶chain_config,
|
||||
client: client.clone(),
|
||||
transaction_pool: transaction_pool.clone(),
|
||||
spawn_handle: task_manager.spawn_handle(),
|
||||
import_queue: import_queue.clone(),
|
||||
import_queue: params.import_queue,
|
||||
block_announce_validator_builder: Some(Box::new(|_| {
|
||||
Box::new(block_announce_validator)
|
||||
})),
|
||||
@@ -356,6 +315,7 @@ where
|
||||
if validator {
|
||||
let parachain_consensus = build_consensus(
|
||||
client.clone(),
|
||||
block_import,
|
||||
prometheus_registry.as_ref(),
|
||||
telemetry.as_ref().map(|t| t.handle()),
|
||||
&task_manager,
|
||||
@@ -377,7 +337,7 @@ where
|
||||
relay_chain_interface,
|
||||
spawner,
|
||||
parachain_consensus,
|
||||
import_queue,
|
||||
import_queue: import_queue_service,
|
||||
collator_key: collator_key.expect("Command line arguments do not allow this. qed"),
|
||||
relay_chain_slot_duration,
|
||||
};
|
||||
@@ -391,7 +351,7 @@ where
|
||||
para_id: id,
|
||||
relay_chain_interface,
|
||||
relay_chain_slot_duration,
|
||||
import_queue,
|
||||
import_queue: import_queue_service,
|
||||
};
|
||||
|
||||
start_full_node(params)?;
|
||||
@@ -405,17 +365,13 @@ where
|
||||
/// Build the import queue for the the parachain runtime.
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub fn parachain_build_import_queue(
|
||||
client: Arc<TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ParachainRuntimeExecutor>>>,
|
||||
client: Arc<ParachainClient<RuntimeApi>>,
|
||||
block_import: ParachainBlockImport<RuntimeApi>,
|
||||
config: &Configuration,
|
||||
telemetry: Option<TelemetryHandle>,
|
||||
task_manager: &TaskManager,
|
||||
) -> Result<
|
||||
sc_consensus::DefaultImportQueue<
|
||||
Block,
|
||||
TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ParachainRuntimeExecutor>>,
|
||||
>,
|
||||
sc_service::Error,
|
||||
> {
|
||||
) -> Result<sc_consensus::DefaultImportQueue<Block, ParachainClient<RuntimeApi>>, sc_service::Error>
|
||||
{
|
||||
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;
|
||||
|
||||
cumulus_client_consensus_aura::import_queue::<
|
||||
@@ -426,18 +382,18 @@ pub fn parachain_build_import_queue(
|
||||
_,
|
||||
_,
|
||||
>(cumulus_client_consensus_aura::ImportQueueParams {
|
||||
block_import: ParachainBlockImport::new(client.clone()),
|
||||
block_import,
|
||||
client,
|
||||
create_inherent_data_providers: move |_, _| async move {
|
||||
let time = sp_timestamp::InherentDataProvider::from_system_time();
|
||||
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
|
||||
|
||||
let slot =
|
||||
sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
|
||||
*time,
|
||||
*timestamp,
|
||||
slot_duration,
|
||||
);
|
||||
|
||||
Ok((slot, time))
|
||||
Ok((slot, timestamp))
|
||||
},
|
||||
registry: config.prometheus_registry(),
|
||||
spawner: &task_manager.spawn_essential_handle(),
|
||||
@@ -452,11 +408,8 @@ pub async fn start_node(
|
||||
polkadot_config: Configuration,
|
||||
collator_options: CollatorOptions,
|
||||
id: ParaId,
|
||||
) -> sc_service::error::Result<(
|
||||
TaskManager,
|
||||
Arc<TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ParachainRuntimeExecutor>>>,
|
||||
)> {
|
||||
start_node_impl::<RuntimeApi, ParachainRuntimeExecutor, _, _, _>(
|
||||
) -> sc_service::error::Result<(TaskManager, Arc<ParachainClient<RuntimeApi>>)> {
|
||||
start_node_impl::<RuntimeApi, _, _, _>(
|
||||
parachain_config,
|
||||
polkadot_config,
|
||||
collator_options,
|
||||
@@ -475,6 +428,7 @@ pub async fn start_node(
|
||||
},
|
||||
parachain_build_import_queue,
|
||||
|client,
|
||||
block_import,
|
||||
prometheus_registry,
|
||||
telemetry,
|
||||
task_manager,
|
||||
@@ -483,11 +437,13 @@ pub async fn start_node(
|
||||
sync_oracle,
|
||||
keystore,
|
||||
force_authoring| {
|
||||
let client2 = client.clone();
|
||||
let block_import2 = block_import;
|
||||
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;
|
||||
|
||||
let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
|
||||
task_manager.spawn_handle(),
|
||||
client.clone(),
|
||||
client,
|
||||
transaction_pool,
|
||||
prometheus_registry,
|
||||
telemetry.clone(),
|
||||
@@ -521,8 +477,8 @@ pub async fn start_node(
|
||||
Ok((slot, time, parachain_inherent))
|
||||
}
|
||||
},
|
||||
block_import: ParachainBlockImport::new(client.clone()),
|
||||
para_client: client,
|
||||
block_import: block_import2,
|
||||
para_client: client2,
|
||||
backoff_authoring_blocks: Option::<()>::None,
|
||||
sync_oracle,
|
||||
keystore,
|
||||
|
||||
@@ -52,7 +52,9 @@ pub use frame_support::{
|
||||
match_types, parameter_types,
|
||||
traits::{ConstU32, Everything, IsInVec, Nothing, Randomness},
|
||||
weights::{
|
||||
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
|
||||
constants::{
|
||||
BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND,
|
||||
},
|
||||
IdentityFee, Weight,
|
||||
},
|
||||
StorageValue,
|
||||
@@ -370,7 +372,9 @@ pub type XcmOriginToTransactDispatchOrigin = (
|
||||
pub const BASE_XCM_WEIGHT: u64 = 1_000_000_000;
|
||||
|
||||
parameter_types! {
|
||||
pub UnitWeightCost: u64 = BASE_XCM_WEIGHT;
|
||||
/// The amount of weight an XCM operation takes. This is a safe overestimate.
|
||||
// TODO: https://github.com/paritytech/parity-bridges-common/issues/1543 - check `set_proof_size` 0 or 64*1024 or 1026?
|
||||
pub UnitWeightCost: Weight = Weight::from_parts(BASE_XCM_WEIGHT, 0);
|
||||
// One UNIT buys 1 second of weight.
|
||||
pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::parent(), UNIT);
|
||||
pub const MaxInstructions: u32 = 100;
|
||||
@@ -419,6 +423,7 @@ impl Config for XcmConfig {
|
||||
type MessageExporter = ();
|
||||
type UniversalAliases = Nothing;
|
||||
type CallDispatcher = RuntimeCall;
|
||||
type SafeCallFilter = Everything;
|
||||
}
|
||||
|
||||
/// No local origins on this chain are allowed to dispatch XCM sends/executions.
|
||||
@@ -457,6 +462,11 @@ impl XcmBridge for ToMillauBridge {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
parameter_types! {
|
||||
pub ReachableDest: Option<MultiLocation> = todo!("We dont use benchmarks for pallet_xcm, so if you hit this message, you need to remove this and define value instead");
|
||||
}
|
||||
|
||||
impl pallet_xcm::Config for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
|
||||
@@ -477,6 +487,9 @@ impl pallet_xcm::Config for Runtime {
|
||||
type SovereignAccountOf = ();
|
||||
type MaxLockers = frame_support::traits::ConstU32<8>;
|
||||
type UniversalLocation = UniversalLocation;
|
||||
type WeightInfo = pallet_xcm::TestWeightInfo;
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
type ReachableDest = ReachableDest;
|
||||
}
|
||||
|
||||
impl cumulus_pallet_xcm::Config for Runtime {
|
||||
|
||||
@@ -18,12 +18,12 @@ rialto-runtime = { path = "../runtime" }
|
||||
|
||||
# Substrate Dependencies
|
||||
|
||||
beefy-primitives = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-beefy = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
node-inspect = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master", features = ["wasmtime"] }
|
||||
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master"}
|
||||
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-service = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-authority-discovery = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
// 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 beefy_primitives::crypto::AuthorityId as BeefyId;
|
||||
use frame_support::weights::Weight;
|
||||
use polkadot_primitives::v2::{AssignmentId, ValidatorId};
|
||||
use rialto_runtime::{
|
||||
@@ -24,6 +23,7 @@ use rialto_runtime::{
|
||||
};
|
||||
use serde_json::json;
|
||||
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
|
||||
use sp_beefy::crypto::AuthorityId as BeefyId;
|
||||
use sp_consensus_babe::AuthorityId as BabeId;
|
||||
use sp_core::{sr25519, Pair, Public};
|
||||
use sp_finality_grandpa::AuthorityId as GrandpaId;
|
||||
|
||||
@@ -26,7 +26,7 @@ pallet-shift-session-manager = { path = "../../../modules/shift-session-manager"
|
||||
|
||||
# Substrate Dependencies
|
||||
|
||||
beefy-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
sp-beefy = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
|
||||
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
|
||||
frame-executive = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
@@ -51,7 +51,6 @@ sp-consensus-babe = { git = "https://github.com/paritytech/substrate", branch =
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
sp-mmr-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
sp-offchain = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
sp-session = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
@@ -79,7 +78,7 @@ substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", bran
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"beefy-primitives/std",
|
||||
"sp-beefy/std",
|
||||
"bp-messages/std",
|
||||
"bp-millau/std",
|
||||
"bp-relayers/std",
|
||||
@@ -104,7 +103,6 @@ std = [
|
||||
"pallet-grandpa/std",
|
||||
"pallet-mmr/std",
|
||||
"pallet-xcm/std",
|
||||
"sp-mmr-primitives/std",
|
||||
"pallet-shift-session-manager/std",
|
||||
"pallet-sudo/std",
|
||||
"pallet-timestamp/std",
|
||||
|
||||
@@ -32,19 +32,15 @@ pub mod millau_messages;
|
||||
pub mod parachains;
|
||||
pub mod xcm_config;
|
||||
|
||||
use beefy_primitives::{crypto::AuthorityId as BeefyId, mmr::MmrLeafVersion, ValidatorSet};
|
||||
use bp_runtime::HeaderId;
|
||||
use pallet_grandpa::{
|
||||
fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList,
|
||||
};
|
||||
use pallet_mmr::primitives as mmr;
|
||||
use pallet_transaction_payment::{FeeDetails, Multiplier, RuntimeDispatchInfo};
|
||||
use sp_api::impl_runtime_apis;
|
||||
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
|
||||
use sp_beefy::{crypto::AuthorityId as BeefyId, mmr::MmrLeafVersion, ValidatorSet};
|
||||
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
|
||||
use sp_mmr_primitives::{
|
||||
DataOrHash, EncodableOpaqueLeaf, Error as MmrError, LeafDataProvider, Proof as MmrProof,
|
||||
};
|
||||
use sp_runtime::{
|
||||
create_runtime_str, generic, impl_opaque_keys,
|
||||
traits::{AccountIdLookup, Block as BlockT, Keccak256, NumberFor, OpaqueKeys},
|
||||
@@ -62,7 +58,7 @@ pub use frame_support::{
|
||||
dispatch::DispatchClass,
|
||||
parameter_types,
|
||||
traits::{ConstU32, ConstU8, Currency, ExistenceRequirement, Imbalance, KeyOwnerProofSystem},
|
||||
weights::{constants::WEIGHT_PER_SECOND, IdentityFee, RuntimeDbWeight, Weight},
|
||||
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, IdentityFee, RuntimeDbWeight, Weight},
|
||||
StorageValue,
|
||||
};
|
||||
|
||||
@@ -269,9 +265,6 @@ impl pallet_grandpa::Config for Runtime {
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
type MmrHash = <Keccak256 as sp_runtime::traits::Hash>::Output;
|
||||
type MmrHashing = <Runtime as pallet_mmr::Config>::Hashing;
|
||||
|
||||
impl pallet_mmr::Config for Runtime {
|
||||
const INDEXING_PREFIX: &'static [u8] = b"mmr";
|
||||
type Hashing = Keccak256;
|
||||
@@ -300,7 +293,7 @@ parameter_types! {
|
||||
|
||||
pub struct BeefyDummyDataProvider;
|
||||
|
||||
impl beefy_primitives::mmr::BeefyDataProvider<()> for BeefyDummyDataProvider {
|
||||
impl sp_beefy::mmr::BeefyDataProvider<()> for BeefyDummyDataProvider {
|
||||
fn extra_data() {}
|
||||
}
|
||||
|
||||
@@ -574,6 +567,16 @@ pub type Executive = frame_executive::Executive<
|
||||
AllPalletsWithSystem,
|
||||
>;
|
||||
|
||||
/// MMR helper types.
|
||||
mod mmr {
|
||||
use super::Runtime;
|
||||
pub use pallet_mmr::primitives::*;
|
||||
|
||||
pub type Leaf = <<Runtime as pallet_mmr::Config>::LeafData as LeafDataProvider>::LeafData;
|
||||
pub type Hash = <Runtime as pallet_mmr::Config>::Hash;
|
||||
pub type Hashing = <Runtime as pallet_mmr::Config>::Hashing;
|
||||
}
|
||||
|
||||
impl_runtime_apis! {
|
||||
impl sp_api::Core<Block> for Runtime {
|
||||
fn version() -> RuntimeVersion {
|
||||
@@ -622,66 +625,30 @@ impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
impl beefy_primitives::BeefyApi<Block> for Runtime {
|
||||
impl sp_beefy::BeefyApi<Block> for Runtime {
|
||||
fn validator_set() -> Option<ValidatorSet<BeefyId>> {
|
||||
Beefy::validator_set()
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_mmr_primitives::MmrApi<Block, Hash, BlockNumber> for Runtime {
|
||||
fn generate_proof(block_number: BlockNumber)
|
||||
-> Result<(EncodableOpaqueLeaf, MmrProof<Hash>), MmrError>
|
||||
{
|
||||
Mmr::generate_batch_proof(vec![block_number])
|
||||
.and_then(|(leaves, proof)| Ok((
|
||||
mmr::EncodableOpaqueLeaf::from_leaf(&leaves[0]),
|
||||
mmr::BatchProof::into_single_leaf_proof(proof)?
|
||||
)))
|
||||
}
|
||||
|
||||
fn verify_proof(leaf: EncodableOpaqueLeaf, proof: MmrProof<Hash>)
|
||||
-> Result<(), MmrError>
|
||||
{
|
||||
pub type Leaf = <
|
||||
<Runtime as pallet_mmr::Config>::LeafData as LeafDataProvider
|
||||
>::LeafData;
|
||||
|
||||
let leaf: Leaf = leaf
|
||||
.into_opaque_leaf()
|
||||
.try_decode()
|
||||
.ok_or(MmrError::Verify)?;
|
||||
Mmr::verify_leaves(vec![leaf], mmr::Proof::into_batch_proof(proof))
|
||||
}
|
||||
|
||||
fn verify_proof_stateless(
|
||||
root: Hash,
|
||||
leaf: EncodableOpaqueLeaf,
|
||||
proof: MmrProof<Hash>
|
||||
) -> Result<(), MmrError> {
|
||||
let node = DataOrHash::Data(leaf.into_opaque_leaf());
|
||||
pallet_mmr::verify_leaves_proof::<MmrHashing, _>(
|
||||
root,
|
||||
vec![node],
|
||||
pallet_mmr::primitives::Proof::into_batch_proof(proof),
|
||||
)
|
||||
}
|
||||
|
||||
fn mmr_root() -> Result<Hash, MmrError> {
|
||||
impl pallet_mmr::primitives::MmrApi<
|
||||
Block,
|
||||
mmr::Hash,
|
||||
BlockNumber,
|
||||
> for Runtime {
|
||||
fn mmr_root() -> Result<mmr::Hash, mmr::Error> {
|
||||
Ok(Mmr::mmr_root())
|
||||
}
|
||||
|
||||
fn generate_batch_proof(block_numbers: Vec<BlockNumber>)
|
||||
-> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<MmrHash>), mmr::Error>
|
||||
{
|
||||
Mmr::generate_batch_proof(block_numbers)
|
||||
.map(|(leaves, proof)| (leaves.into_iter().map(|leaf| mmr::EncodableOpaqueLeaf::from_leaf(&leaf)).collect(), proof))
|
||||
fn mmr_leaf_count() -> Result<mmr::LeafIndex, mmr::Error> {
|
||||
Ok(Mmr::mmr_leaves())
|
||||
}
|
||||
|
||||
fn generate_historical_batch_proof(
|
||||
fn generate_proof(
|
||||
block_numbers: Vec<BlockNumber>,
|
||||
best_known_block_number: BlockNumber
|
||||
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<MmrHash>), mmr::Error> {
|
||||
Mmr::generate_historical_batch_proof(block_numbers, best_known_block_number).map(
|
||||
best_known_block_number: Option<BlockNumber>,
|
||||
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::Proof<mmr::Hash>), mmr::Error> {
|
||||
Mmr::generate_proof(block_numbers, best_known_block_number).map(
|
||||
|(leaves, proof)| {
|
||||
(
|
||||
leaves
|
||||
@@ -694,26 +661,23 @@ impl_runtime_apis! {
|
||||
)
|
||||
}
|
||||
|
||||
fn verify_batch_proof(leaves: Vec<mmr::EncodableOpaqueLeaf>, proof: mmr::BatchProof<MmrHash>)
|
||||
fn verify_proof(leaves: Vec<mmr::EncodableOpaqueLeaf>, proof: mmr::Proof<mmr::Hash>)
|
||||
-> Result<(), mmr::Error>
|
||||
{
|
||||
type Leaf = <
|
||||
<Runtime as pallet_mmr::Config>::LeafData as LeafDataProvider
|
||||
>::LeafData;
|
||||
let leaves = leaves.into_iter().map(|leaf|
|
||||
leaf.into_opaque_leaf()
|
||||
.try_decode()
|
||||
.ok_or(mmr::Error::Verify)).collect::<Result<Vec<Leaf>, mmr::Error>>()?;
|
||||
.ok_or(mmr::Error::Verify)).collect::<Result<Vec<mmr::Leaf>, mmr::Error>>()?;
|
||||
Mmr::verify_leaves(leaves, proof)
|
||||
}
|
||||
|
||||
fn verify_batch_proof_stateless(
|
||||
root: MmrHash,
|
||||
fn verify_proof_stateless(
|
||||
root: mmr::Hash,
|
||||
leaves: Vec<mmr::EncodableOpaqueLeaf>,
|
||||
proof: mmr::BatchProof<MmrHash>
|
||||
proof: mmr::Proof<mmr::Hash>
|
||||
) -> Result<(), mmr::Error> {
|
||||
let nodes = leaves.into_iter().map(|leaf|mmr::DataOrHash::Data(leaf.into_opaque_leaf())).collect();
|
||||
pallet_mmr::verify_leaves_proof::<MmrHashing, _>(root, nodes, proof)
|
||||
pallet_mmr::verify_leaves_proof::<mmr::Hashing, _>(root, nodes, proof)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ use bridge_runtime_common::{
|
||||
use frame_support::{
|
||||
parameter_types,
|
||||
traits::{ConstU32, Everything, Nothing},
|
||||
weights::Weight,
|
||||
};
|
||||
use xcm::latest::prelude::*;
|
||||
use xcm_builder::{
|
||||
@@ -91,7 +92,8 @@ pub const BASE_XCM_WEIGHT: u64 = 1_000_000_000;
|
||||
|
||||
parameter_types! {
|
||||
/// The amount of weight an XCM operation takes. This is a safe overestimate.
|
||||
pub const BaseXcmWeight: u64 = BASE_XCM_WEIGHT;
|
||||
// TODO: https://github.com/paritytech/parity-bridges-common/issues/1543 - check `set_proof_size` 0 or 64*1024 or 1026?
|
||||
pub const BaseXcmWeight: Weight = Weight::from_parts(BASE_XCM_WEIGHT, 0);
|
||||
/// Maximum number of instructions in a single XCM fragment. A sanity check against weight
|
||||
/// calculations getting too crazy.
|
||||
pub const MaxInstructions: u32 = 100;
|
||||
@@ -142,6 +144,7 @@ impl xcm_executor::Config for XcmConfig {
|
||||
type MessageExporter = ();
|
||||
type UniversalAliases = Nothing;
|
||||
type CallDispatcher = RuntimeCall;
|
||||
type SafeCallFilter = Everything;
|
||||
}
|
||||
|
||||
/// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior
|
||||
@@ -151,6 +154,11 @@ pub type LocalOriginToLocation = (
|
||||
SignedToAccountId32<RuntimeOrigin, AccountId, ThisNetwork>,
|
||||
);
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
parameter_types! {
|
||||
pub ReachableDest: Option<MultiLocation> = todo!("We dont use benchmarks for pallet_xcm, so if you hit this message, you need to remove this and define value instead");
|
||||
}
|
||||
|
||||
impl pallet_xcm::Config for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
// We don't allow any messages to be sent via the transaction yet. This is basically safe to
|
||||
@@ -180,6 +188,9 @@ impl pallet_xcm::Config for Runtime {
|
||||
type TrustedLockers = ();
|
||||
type SovereignAccountOf = SovereignAccountOf;
|
||||
type MaxLockers = frame_support::traits::ConstU32<8>;
|
||||
type WeightInfo = pallet_xcm::TestWeightInfo;
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
type ReachableDest = ReachableDest;
|
||||
}
|
||||
|
||||
/// With-Millau bridge.
|
||||
|
||||
@@ -452,7 +452,7 @@ pub mod target {
|
||||
// I have no idea why this method takes `&mut` reference and there's nothing
|
||||
// about that in documentation. Hope it'll only mutate iff error is returned.
|
||||
let weight = XcmWeigher::weight(&mut payload.xcm.1);
|
||||
let weight = Weight::from_ref_time(weight.unwrap_or_else(|e| {
|
||||
let weight = weight.unwrap_or_else(|e| {
|
||||
log::debug!(
|
||||
target: "runtime::bridge-dispatch",
|
||||
"Failed to compute dispatch weight of incoming XCM message {:?}/{}: {:?}",
|
||||
@@ -463,8 +463,8 @@ pub mod target {
|
||||
|
||||
// we shall return 0 and then the XCM executor will fail to execute XCM
|
||||
// if we'll return something else (e.g. maximal value), the lane may stuck
|
||||
0
|
||||
}));
|
||||
Weight::zero()
|
||||
});
|
||||
|
||||
payload.weight = Some(weight);
|
||||
weight
|
||||
@@ -498,8 +498,8 @@ pub mod target {
|
||||
location,
|
||||
xcm,
|
||||
hash,
|
||||
weight_limit.unwrap_or_else(Weight::zero).ref_time(),
|
||||
weight_credit.ref_time(),
|
||||
weight_limit.unwrap_or_else(Weight::zero),
|
||||
weight_credit,
|
||||
);
|
||||
Ok(xcm_outcome)
|
||||
};
|
||||
|
||||
@@ -648,7 +648,9 @@ mod tests {
|
||||
|
||||
fn dispatch_info() -> DispatchInfo {
|
||||
DispatchInfo {
|
||||
weight: frame_support::weights::constants::WEIGHT_PER_SECOND,
|
||||
weight: Weight::from_ref_time(
|
||||
frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND,
|
||||
),
|
||||
class: frame_support::dispatch::DispatchClass::Normal,
|
||||
pays_fee: frame_support::dispatch::Pays::Yes,
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master
|
||||
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
beefy-primitives = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-beefy = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
mmr-lib = { package = "ckb-merkle-mountain-range", version = "0.3.2" }
|
||||
pallet-beefy-mmr = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
pallet-mmr = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
|
||||
@@ -152,6 +152,7 @@ pub mod pallet {
|
||||
BridgedMmrHashing<T, I>: 'static + Send + Sync,
|
||||
{
|
||||
/// Initialize pallet with BEEFY authority set and best known finalized block number.
|
||||
#[pallet::call_index(0)]
|
||||
#[pallet::weight((T::DbWeight::get().reads_writes(2, 3), DispatchClass::Operational))]
|
||||
pub fn initialize(
|
||||
origin: OriginFor<T>,
|
||||
@@ -169,6 +170,7 @@ pub mod pallet {
|
||||
/// Change `PalletOwner`.
|
||||
///
|
||||
/// May only be called either by root, or by `PalletOwner`.
|
||||
#[pallet::call_index(1)]
|
||||
#[pallet::weight((T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational))]
|
||||
pub fn set_owner(origin: OriginFor<T>, new_owner: Option<T::AccountId>) -> DispatchResult {
|
||||
<Self as OwnedBridgeModule<_>>::set_owner(origin, new_owner)
|
||||
@@ -177,6 +179,7 @@ pub mod pallet {
|
||||
/// Halt or resume all pallet operations.
|
||||
///
|
||||
/// May only be called either by root, or by `PalletOwner`.
|
||||
#[pallet::call_index(2)]
|
||||
#[pallet::weight((T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational))]
|
||||
pub fn set_operating_mode(
|
||||
origin: OriginFor<T>,
|
||||
@@ -193,6 +196,7 @@ pub mod pallet {
|
||||
///
|
||||
/// If successful in verification, it will update the underlying storage with the data
|
||||
/// provided in the newly submitted commitment.
|
||||
#[pallet::call_index(3)]
|
||||
#[pallet::weight(0)]
|
||||
pub fn submit_commitment(
|
||||
origin: OriginFor<T>,
|
||||
@@ -410,12 +414,12 @@ pub mod pallet {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use beefy_primitives::mmr::BeefyAuthoritySet;
|
||||
use bp_runtime::{BasicOperatingMode, OwnedBridgeModuleError};
|
||||
use bp_test_utils::generate_owned_bridge_module_tests;
|
||||
use frame_support::{assert_noop, assert_ok, traits::Get};
|
||||
use mock::*;
|
||||
use mock_chain::*;
|
||||
use sp_beefy::mmr::BeefyAuthoritySet;
|
||||
use sp_runtime::DispatchError;
|
||||
|
||||
fn next_block() {
|
||||
|
||||
@@ -32,7 +32,7 @@ use sp_runtime::{
|
||||
Perbill,
|
||||
};
|
||||
|
||||
pub use beefy_primitives::crypto::{AuthorityId as BeefyId, Pair as BeefyPair};
|
||||
pub use sp_beefy::crypto::{AuthorityId as BeefyId, Pair as BeefyPair};
|
||||
use sp_core::crypto::Wraps;
|
||||
use sp_runtime::traits::Keccak256;
|
||||
|
||||
@@ -49,7 +49,7 @@ pub type TestBridgedMmrHashing = BridgedMmrHashing<TestRuntime, ()>;
|
||||
pub type TestBridgedMmrHash = BridgedMmrHash<TestRuntime, ()>;
|
||||
pub type TestBridgedBeefyMmrLeafExtra = BridgedBeefyMmrLeafExtra<TestRuntime, ()>;
|
||||
pub type TestBridgedMmrProof = BridgedMmrProof<TestRuntime, ()>;
|
||||
pub type TestBridgedRawMmrLeaf = beefy_primitives::mmr::MmrLeaf<
|
||||
pub type TestBridgedRawMmrLeaf = sp_beefy::mmr::MmrLeaf<
|
||||
TestBridgedBlockNumber,
|
||||
TestBridgedBlockHash,
|
||||
TestBridgedMmrHash,
|
||||
@@ -138,7 +138,7 @@ impl ChainWithBeefy for TestBridgedChain {
|
||||
type MmrHash = <Keccak256 as Hash>::Output;
|
||||
type BeefyMmrLeafExtra = ();
|
||||
type AuthorityId = BeefyId;
|
||||
type Signature = beefy_primitives::crypto::AuthoritySignature;
|
||||
type Signature = sp_beefy::crypto::AuthoritySignature;
|
||||
type AuthorityIdToMerkleLeaf = pallet_beefy_mmr::BeefyEcdsaToEthereum;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,11 +26,11 @@ use crate::{
|
||||
utils::get_authorities_mmr_root,
|
||||
};
|
||||
|
||||
use beefy_primitives::mmr::{BeefyNextAuthoritySet, MmrLeafVersion};
|
||||
use bp_beefy::{BeefyPayload, Commitment, ValidatorSetId, MMR_ROOT_PAYLOAD_ID};
|
||||
use codec::Encode;
|
||||
use pallet_mmr::NodeIndex;
|
||||
use rand::Rng;
|
||||
use sp_beefy::mmr::{BeefyNextAuthoritySet, MmrLeafVersion};
|
||||
use sp_core::Pair;
|
||||
use sp_runtime::traits::{Hash, Header as HeaderT};
|
||||
use std::collections::HashMap;
|
||||
@@ -188,7 +188,7 @@ impl HeaderBuilder {
|
||||
next_validator_keys.iter().map(|pair| pair.public()).collect::<Vec<_>>();
|
||||
let next_validators_mmr_root =
|
||||
get_authorities_mmr_root::<TestRuntime, (), _>(next_validators.iter());
|
||||
let leaf = beefy_primitives::mmr::MmrLeaf {
|
||||
let leaf = sp_beefy::mmr::MmrLeaf {
|
||||
version: MmrLeafVersion::new(1, 0),
|
||||
parent_number_and_hash: (header.number().saturating_sub(1), *header.parent_hash()),
|
||||
beefy_next_authority_set: BeefyNextAuthoritySet {
|
||||
@@ -227,7 +227,7 @@ impl HeaderBuilder {
|
||||
let leaf_index = *self.header.number() - 1;
|
||||
let leaf_count = *self.header.number();
|
||||
self.leaf_proof = Some(f(TestBridgedMmrProof {
|
||||
leaf_index,
|
||||
leaf_indices: vec![leaf_index],
|
||||
leaf_count,
|
||||
items: proof.proof_items().iter().map(|i| i.hash()).collect(),
|
||||
}));
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::{
|
||||
BridgedBeefyCommitmentHasher, BridgedBeefyMmrLeaf, BridgedBeefySignedCommitment, BridgedChain,
|
||||
BridgedMmrHash, BridgedMmrHashing, BridgedMmrProof, Config, Error, LOG_TARGET,
|
||||
};
|
||||
use bp_beefy::{merkle_root, verify_mmr_leaves_proof, BeefyVerify, MmrDataOrHash, MmrProof};
|
||||
use bp_beefy::{merkle_root, verify_mmr_leaves_proof, BeefyVerify, MmrDataOrHash};
|
||||
use codec::Encode;
|
||||
use frame_support::ensure;
|
||||
use sp_runtime::traits::{Convert, Hash};
|
||||
@@ -131,7 +131,6 @@ pub(crate) fn verify_beefy_mmr_leaf<T: Config<I>, I: 'static>(
|
||||
mmr_proof: BridgedMmrProof<T, I>,
|
||||
mmr_root: BridgedMmrHash<T, I>,
|
||||
) -> Result<(), Error<T, I>> {
|
||||
let mmr_proof_leaf_index = mmr_proof.leaf_index;
|
||||
let mmr_proof_leaf_count = mmr_proof.leaf_count;
|
||||
let mmr_proof_length = mmr_proof.items.len();
|
||||
|
||||
@@ -140,16 +139,15 @@ pub(crate) fn verify_beefy_mmr_leaf<T: Config<I>, I: 'static>(
|
||||
verify_mmr_leaves_proof(
|
||||
mmr_root,
|
||||
vec![BridgedMmrDataOrHash::<T, I>::Hash(mmr_leaf_hash)],
|
||||
MmrProof::into_batch_proof(mmr_proof),
|
||||
mmr_proof,
|
||||
)
|
||||
.map_err(|e| {
|
||||
log::error!(
|
||||
target: LOG_TARGET,
|
||||
"MMR proof of leaf {:?} (root: {:?}, leaf: {}, leaf count: {}, len: {}) \
|
||||
"MMR proof of leaf {:?} (root: {:?}, leaf count: {}, len: {}) \
|
||||
verification has failed with error: {:?}",
|
||||
mmr_leaf_hash,
|
||||
mmr_root,
|
||||
mmr_proof_leaf_index,
|
||||
mmr_proof_leaf_count,
|
||||
mmr_proof_length,
|
||||
e,
|
||||
@@ -163,9 +161,9 @@ pub(crate) fn verify_beefy_mmr_leaf<T: Config<I>, I: 'static>(
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{mock::*, mock_chain::*, *};
|
||||
use beefy_primitives::ValidatorSet;
|
||||
use bp_beefy::{BeefyPayload, MMR_ROOT_PAYLOAD_ID};
|
||||
use frame_support::{assert_noop, assert_ok};
|
||||
use sp_beefy::ValidatorSet;
|
||||
|
||||
#[test]
|
||||
fn submit_commitment_checks_metadata() {
|
||||
@@ -280,7 +278,7 @@ mod tests {
|
||||
|
||||
// Fails if mmr proof is incorrect.
|
||||
let mut header = ChainBuilder::new(1).append_finalized_header().to_header();
|
||||
header.leaf_proof.leaf_index += 1;
|
||||
header.leaf_proof.leaf_indices[0] += 1;
|
||||
assert_noop!(
|
||||
import_commitment(header),
|
||||
Error::<TestRuntime, ()>::MmrProofVerificationFailed,
|
||||
|
||||
@@ -150,6 +150,7 @@ pub mod pallet {
|
||||
///
|
||||
/// If successful in verification, it will write the target header to the underlying storage
|
||||
/// pallet.
|
||||
#[pallet::call_index(0)]
|
||||
#[pallet::weight(T::WeightInfo::submit_finality_proof(
|
||||
justification.commit.precommits.len().try_into().unwrap_or(u32::MAX),
|
||||
justification.votes_ancestries.len().try_into().unwrap_or(u32::MAX),
|
||||
@@ -221,6 +222,7 @@ pub mod pallet {
|
||||
/// This function is only allowed to be called from a trusted origin and writes to storage
|
||||
/// with practically no checks in terms of the validity of the data. It is important that
|
||||
/// you ensure that valid data is being passed in.
|
||||
#[pallet::call_index(1)]
|
||||
#[pallet::weight((T::DbWeight::get().reads_writes(2, 5), DispatchClass::Operational))]
|
||||
pub fn initialize(
|
||||
origin: OriginFor<T>,
|
||||
@@ -244,6 +246,7 @@ pub mod pallet {
|
||||
/// Change `PalletOwner`.
|
||||
///
|
||||
/// May only be called either by root, or by `PalletOwner`.
|
||||
#[pallet::call_index(2)]
|
||||
#[pallet::weight((T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational))]
|
||||
pub fn set_owner(origin: OriginFor<T>, new_owner: Option<T::AccountId>) -> DispatchResult {
|
||||
<Self as OwnedBridgeModule<_>>::set_owner(origin, new_owner)
|
||||
@@ -252,6 +255,7 @@ pub mod pallet {
|
||||
/// Halt or resume all pallet operations.
|
||||
///
|
||||
/// May only be called either by root, or by `PalletOwner`.
|
||||
#[pallet::call_index(3)]
|
||||
#[pallet::weight((T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational))]
|
||||
pub fn set_operating_mode(
|
||||
origin: OriginFor<T>,
|
||||
|
||||
@@ -226,6 +226,7 @@ pub mod pallet {
|
||||
/// Change `PalletOwner`.
|
||||
///
|
||||
/// May only be called either by root, or by `PalletOwner`.
|
||||
#[pallet::call_index(0)]
|
||||
#[pallet::weight((T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational))]
|
||||
pub fn set_owner(origin: OriginFor<T>, new_owner: Option<T::AccountId>) -> DispatchResult {
|
||||
<Self as OwnedBridgeModule<_>>::set_owner(origin, new_owner)
|
||||
@@ -234,6 +235,7 @@ pub mod pallet {
|
||||
/// Halt or resume all/some pallet operations.
|
||||
///
|
||||
/// May only be called either by root, or by `PalletOwner`.
|
||||
#[pallet::call_index(1)]
|
||||
#[pallet::weight((T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational))]
|
||||
pub fn set_operating_mode(
|
||||
origin: OriginFor<T>,
|
||||
@@ -247,6 +249,7 @@ pub mod pallet {
|
||||
/// The weight of the call assumes that the transaction always brings outbound lane
|
||||
/// state update. Because of that, the submitter (relayer) has no benefit of not including
|
||||
/// this data in the transaction, so reward confirmations lags should be minimal.
|
||||
#[pallet::call_index(2)]
|
||||
#[pallet::weight(T::WeightInfo::receive_messages_proof_weight(proof, *messages_count, *dispatch_weight))]
|
||||
pub fn receive_messages_proof(
|
||||
origin: OriginFor<T>,
|
||||
@@ -399,6 +402,7 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
/// Receive messages delivery proof from bridged chain.
|
||||
#[pallet::call_index(3)]
|
||||
#[pallet::weight(T::WeightInfo::receive_messages_delivery_proof_weight(
|
||||
proof,
|
||||
relayers_state,
|
||||
|
||||
@@ -263,6 +263,7 @@ pub mod pallet {
|
||||
/// `polkadot-runtime-parachains::paras` pallet instance, deployed at the bridged chain.
|
||||
/// The proof is supposed to be crafted at the `relay_header_hash` that must already be
|
||||
/// imported by corresponding GRANDPA pallet at this chain.
|
||||
#[pallet::call_index(0)]
|
||||
#[pallet::weight(WeightInfoOf::<T, I>::submit_parachain_heads_weight(
|
||||
T::DbWeight::get(),
|
||||
parachain_heads_proof,
|
||||
@@ -395,6 +396,7 @@ pub mod pallet {
|
||||
/// Change `PalletOwner`.
|
||||
///
|
||||
/// May only be called either by root, or by `PalletOwner`.
|
||||
#[pallet::call_index(1)]
|
||||
#[pallet::weight((T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational))]
|
||||
pub fn set_owner(origin: OriginFor<T>, new_owner: Option<T::AccountId>) -> DispatchResult {
|
||||
<Self as OwnedBridgeModule<_>>::set_owner(origin, new_owner)
|
||||
@@ -403,6 +405,7 @@ pub mod pallet {
|
||||
/// Halt or resume all pallet operations.
|
||||
///
|
||||
/// May only be called either by root, or by `PalletOwner`.
|
||||
#[pallet::call_index(2)]
|
||||
#[pallet::weight((T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational))]
|
||||
pub fn set_operating_mode(
|
||||
origin: OriginFor<T>,
|
||||
|
||||
@@ -65,6 +65,7 @@ pub mod pallet {
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Claim accumulated rewards.
|
||||
#[pallet::call_index(0)]
|
||||
#[pallet::weight(T::WeightInfo::claim_rewards())]
|
||||
pub fn claim_rewards(origin: OriginFor<T>, lane_id: LaneId) -> DispatchResult {
|
||||
let relayer = ensure_signed(origin)?;
|
||||
|
||||
@@ -18,7 +18,7 @@ bp-runtime = { path = "../runtime", default-features = false }
|
||||
# Substrate Dependencies
|
||||
|
||||
beefy-merkle-tree = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
beefy-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
sp-beefy = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
pallet-beefy-mmr = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
pallet-mmr = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
@@ -28,7 +28,6 @@ sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", d
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"beefy-primitives/std",
|
||||
"bp-runtime/std",
|
||||
"codec/std",
|
||||
"frame-support/std",
|
||||
@@ -36,6 +35,7 @@ std = [
|
||||
"pallet-mmr/std",
|
||||
"scale-info/std",
|
||||
"serde",
|
||||
"sp-beefy/std",
|
||||
"sp-runtime/std",
|
||||
"sp-std/std"
|
||||
]
|
||||
|
||||
@@ -20,18 +20,18 @@
|
||||
#![warn(missing_docs)]
|
||||
|
||||
pub use beefy_merkle_tree::{merkle_root, Keccak256 as BeefyKeccak256};
|
||||
pub use beefy_primitives::{
|
||||
pub use pallet_beefy_mmr::BeefyEcdsaToEthereum;
|
||||
pub use pallet_mmr::{
|
||||
primitives::{DataOrHash as MmrDataOrHash, Proof as MmrProof},
|
||||
verify_leaves_proof as verify_mmr_leaves_proof,
|
||||
};
|
||||
pub use sp_beefy::{
|
||||
crypto::{AuthorityId as EcdsaValidatorId, AuthoritySignature as EcdsaValidatorSignature},
|
||||
known_payloads::MMR_ROOT_ID as MMR_ROOT_PAYLOAD_ID,
|
||||
mmr::{BeefyAuthoritySet, MmrLeafVersion},
|
||||
BeefyAuthorityId, BeefyVerify, Commitment, Payload as BeefyPayload, SignedCommitment,
|
||||
ValidatorSet, ValidatorSetId, BEEFY_ENGINE_ID,
|
||||
};
|
||||
pub use pallet_beefy_mmr::BeefyEcdsaToEthereum;
|
||||
pub use pallet_mmr::{
|
||||
primitives::{DataOrHash as MmrDataOrHash, Proof as MmrProof},
|
||||
verify_leaves_proof as verify_mmr_leaves_proof,
|
||||
};
|
||||
|
||||
use bp_runtime::{BasicOperatingMode, BlockNumberOf, Chain, HashOf};
|
||||
use codec::{Decode, Encode};
|
||||
@@ -99,7 +99,7 @@ pub type BeefyAuthorityIdOf<C> = <C as ChainWithBeefy>::AuthorityId;
|
||||
/// BEEFY validator set, containing both validator identifiers and the numeric set id.
|
||||
pub type BeefyAuthoritySetOf<C> = ValidatorSet<BeefyAuthorityIdOf<C>>;
|
||||
/// BEEFY authority set, containing both validator identifiers and the numeric set id.
|
||||
pub type BeefyAuthoritySetInfoOf<C> = beefy_primitives::mmr::BeefyAuthoritySet<MmrHashOf<C>>;
|
||||
pub type BeefyAuthoritySetInfoOf<C> = sp_beefy::mmr::BeefyAuthoritySet<MmrHashOf<C>>;
|
||||
/// BEEFY validator signature used by given Substrate chain.
|
||||
pub type BeefyValidatorSignatureOf<C> = <C as ChainWithBeefy>::Signature;
|
||||
/// Signed BEEFY commitment used by given Substrate chain.
|
||||
@@ -119,12 +119,8 @@ pub type BeefyMmrLeafExtraOf<C> = <C as ChainWithBeefy>::BeefyMmrLeafExtra;
|
||||
/// the given Substrate chain.
|
||||
pub type BeefyAuthorityIdToMerkleLeafOf<C> = <C as ChainWithBeefy>::AuthorityIdToMerkleLeaf;
|
||||
/// Actual type of leafs in the BEEFY MMR.
|
||||
pub type BeefyMmrLeafOf<C> = beefy_primitives::mmr::MmrLeaf<
|
||||
BlockNumberOf<C>,
|
||||
HashOf<C>,
|
||||
MmrHashOf<C>,
|
||||
BeefyMmrLeafExtraOf<C>,
|
||||
>;
|
||||
pub type BeefyMmrLeafOf<C> =
|
||||
sp_beefy::mmr::MmrLeaf<BlockNumberOf<C>, HashOf<C>, MmrHashOf<C>, BeefyMmrLeafExtraOf<C>>;
|
||||
|
||||
/// Data required for initializing the BEEFY pallet.
|
||||
///
|
||||
|
||||
@@ -39,7 +39,8 @@ pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
|
||||
/// time.
|
||||
///
|
||||
/// This is a copy-paste from the cumulus repo's `parachains-common` crate.
|
||||
pub const MAXIMUM_BLOCK_WEIGHT: Weight = constants::WEIGHT_PER_SECOND
|
||||
// TODO: https://github.com/paritytech/parity-bridges-common/issues/1543 - remove `set_proof_size`
|
||||
const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_ref_time(constants::WEIGHT_REF_TIME_PER_SECOND)
|
||||
.saturating_div(2)
|
||||
.set_proof_size(polkadot_primitives::v2::MAX_POV_SIZE as u64);
|
||||
|
||||
@@ -55,9 +56,9 @@ parameter_types! {
|
||||
NORMAL_DISPATCH_RATIO,
|
||||
);
|
||||
|
||||
pub const BlockExecutionWeight: Weight = constants::WEIGHT_PER_NANOS.saturating_mul(5_000_000);
|
||||
pub const BlockExecutionWeight: Weight = Weight::from_ref_time(constants::WEIGHT_REF_TIME_PER_NANOS).saturating_mul(5_000_000);
|
||||
|
||||
pub const ExtrinsicBaseWeight: Weight = constants::WEIGHT_PER_NANOS.saturating_mul(125_000);
|
||||
pub const ExtrinsicBaseWeight: Weight = Weight::from_ref_time(constants::WEIGHT_REF_TIME_PER_NANOS).saturating_mul(125_000);
|
||||
|
||||
pub BlockWeights: limits::BlockWeights = limits::BlockWeights::builder()
|
||||
.base_block(BlockExecutionWeight::get())
|
||||
|
||||
@@ -27,7 +27,7 @@ use bp_messages::{
|
||||
use bp_runtime::{decl_bridge_runtime_apis, Chain};
|
||||
use frame_support::{
|
||||
dispatch::DispatchClass,
|
||||
weights::{constants::WEIGHT_PER_SECOND, IdentityFee, Weight},
|
||||
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, IdentityFee, Weight},
|
||||
RuntimeDebug,
|
||||
};
|
||||
use frame_system::limits;
|
||||
@@ -60,7 +60,9 @@ pub const TX_EXTRA_BYTES: u32 = 103;
|
||||
///
|
||||
/// This represents 0.5 seconds of compute assuming a target block time of six seconds.
|
||||
// TODO: https://github.com/paritytech/parity-bridges-common/issues/1543 - remove `set_proof_size`
|
||||
pub const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.set_proof_size(1_000).saturating_div(2);
|
||||
pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_ref_time(WEIGHT_REF_TIME_PER_SECOND)
|
||||
.set_proof_size(1_000)
|
||||
.saturating_div(2);
|
||||
|
||||
/// Represents the portion of a block that will be used by Normal extrinsics.
|
||||
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
|
||||
|
||||
@@ -24,7 +24,7 @@ use bp_messages::{
|
||||
use bp_runtime::{decl_bridge_runtime_apis, Chain, Parachain};
|
||||
use frame_support::{
|
||||
dispatch::DispatchClass,
|
||||
weights::{constants::WEIGHT_PER_SECOND, IdentityFee, Weight},
|
||||
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, IdentityFee, Weight},
|
||||
RuntimeDebug,
|
||||
};
|
||||
use frame_system::limits;
|
||||
@@ -55,7 +55,9 @@ pub const TX_EXTRA_BYTES: u32 = 104;
|
||||
///
|
||||
/// This represents two seconds of compute assuming a target block time of six seconds.
|
||||
// TODO: https://github.com/paritytech/parity-bridges-common/issues/1543 - remove `set_proof_size`
|
||||
pub const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.set_proof_size(1_000).saturating_mul(2);
|
||||
pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_ref_time(WEIGHT_REF_TIME_PER_SECOND)
|
||||
.set_proof_size(1_000)
|
||||
.saturating_mul(2);
|
||||
|
||||
/// Represents the portion of a block that will be used by Normal extrinsics.
|
||||
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
|
||||
|
||||
@@ -24,7 +24,7 @@ use bp_messages::{
|
||||
use bp_runtime::{decl_bridge_runtime_apis, Chain};
|
||||
use frame_support::{
|
||||
dispatch::DispatchClass,
|
||||
weights::{constants::WEIGHT_PER_SECOND, IdentityFee, Weight},
|
||||
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, IdentityFee, Weight},
|
||||
RuntimeDebug,
|
||||
};
|
||||
use frame_system::limits;
|
||||
@@ -49,7 +49,9 @@ pub const TX_EXTRA_BYTES: u32 = 104;
|
||||
///
|
||||
/// This represents two seconds of compute assuming a target block time of six seconds.
|
||||
// TODO: https://github.com/paritytech/parity-bridges-common/issues/1543 - remove `set_proof_size`
|
||||
pub const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.set_proof_size(1_000).saturating_mul(2);
|
||||
pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_ref_time(WEIGHT_REF_TIME_PER_SECOND)
|
||||
.set_proof_size(1_000)
|
||||
.saturating_mul(2);
|
||||
|
||||
/// Represents the portion of a block that will be used by Normal extrinsics.
|
||||
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
|
||||
|
||||
@@ -23,7 +23,7 @@ use frame_support::{
|
||||
dispatch::DispatchClass,
|
||||
parameter_types,
|
||||
weights::{
|
||||
constants::{BlockExecutionWeight, WEIGHT_PER_SECOND},
|
||||
constants::{BlockExecutionWeight, WEIGHT_REF_TIME_PER_SECOND},
|
||||
Weight,
|
||||
},
|
||||
Blake2_128Concat, RuntimeDebug,
|
||||
@@ -74,7 +74,9 @@ const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
|
||||
///
|
||||
/// This is a copy-paste from the Polkadot repo's `polkadot-runtime-common` crate.
|
||||
// TODO: https://github.com/paritytech/parity-bridges-common/issues/1543 - remove `set_proof_size`
|
||||
pub const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.set_proof_size(1_000).saturating_mul(2);
|
||||
pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_ref_time(WEIGHT_REF_TIME_PER_SECOND)
|
||||
.set_proof_size(1_000)
|
||||
.saturating_mul(2);
|
||||
|
||||
/// All Polkadot-like chains assume that an on-initialize consumes 1 percent of the weight on
|
||||
/// average, hence a single extrinsic will not be allowed to consume more than
|
||||
|
||||
@@ -21,7 +21,7 @@ use num_traits::{AsPrimitive, Bounded, CheckedSub, Saturating, SaturatingAdd, Ze
|
||||
use sp_runtime::{
|
||||
traits::{
|
||||
AtLeast32Bit, AtLeast32BitUnsigned, Hash as HashT, Header as HeaderT, MaybeDisplay,
|
||||
MaybeMallocSizeOf, MaybeSerialize, MaybeSerializeDeserialize, Member, SimpleBitOps, Verify,
|
||||
MaybeSerialize, MaybeSerializeDeserialize, Member, SimpleBitOps, Verify,
|
||||
},
|
||||
FixedPointOperand,
|
||||
};
|
||||
@@ -107,7 +107,6 @@ pub trait Chain: Send + Sync + 'static {
|
||||
+ MaybeDisplay
|
||||
+ AtLeast32BitUnsigned
|
||||
+ FromStr
|
||||
+ MaybeMallocSizeOf
|
||||
+ AsPrimitive<usize>
|
||||
+ Default
|
||||
+ Saturating
|
||||
@@ -128,7 +127,6 @@ pub trait Chain: Send + Sync + 'static {
|
||||
+ SimpleBitOps
|
||||
+ AsRef<[u8]>
|
||||
+ AsMut<[u8]>
|
||||
+ MaybeMallocSizeOf
|
||||
+ MaxEncodedLen;
|
||||
|
||||
/// A type that fulfills the abstract idea of what a Substrate hasher (a type
|
||||
|
||||
@@ -495,7 +495,7 @@ mod tests {
|
||||
// Any significant change in this values should attract additional attention.
|
||||
//
|
||||
// TODO: https://github.com/paritytech/parity-bridges-common/issues/1543 - remove `set_proof_size`
|
||||
(1024, Weight::from_ref_time(216_609_134_667).set_proof_size(217)),
|
||||
(1024, Weight::from_ref_time(216_600_684_000).set_proof_size(217)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user