update Substrate/Polkadot/Cumulus refs (#1562)

* update Substrate/Polkadot/Cumulus refs

* finality-grandpa 0.16

* fix miillau-runtime compilation

* fix rialto runtime compilation

* fixed rialto-parachain runtime compilation

* backport GRANDPA test fixes

* helper instead of removed record_all_keys

* substrate-relay is compiling

* millau-bridge-node at least compiles

* rialto-bridge-node at least compiles

* rialto-parachain-collator compiles

* fixings tests (wip)

* fmt

* fixed BEEFY alert

* clippy

* removed unused dep

* -extra var

* move Leaf to mod mmr

* fix benchmarks
This commit is contained in:
Svyatoslav Nikolsky
2022-09-09 10:56:39 +03:00
committed by Bastian Köcher
parent ad38cdb873
commit 95c30c780c
32 changed files with 416 additions and 292 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[dependencies]
clap = { version = "3.1", features = ["derive"] }
jsonrpc-core = "18.0"
jsonrpsee = { version = "0.15.1", features = ["server"] }
serde_json = "1.0.79"
# Bridge dependencies
+45 -51
View File
@@ -16,19 +16,7 @@
//! Service and ServiceFactory implementation. Specialized wrapper over substrate service.
// =====================================================================================
// =====================================================================================
// =====================================================================================
// UPDATE GUIDE:
// 1) replace everything with node-template/src/service.rs contents (found in main Substrate repo);
// 2) from old code keep `rpc_extensions_builder` - we use our own custom RPCs;
// 3) from old code keep the Beefy gadget;
// 4) fix compilation errors;
// 5) test :)
// =====================================================================================
// =====================================================================================
// =====================================================================================
use jsonrpsee::RpcModule;
use millau_runtime::{self, opaque::Block, RuntimeApi};
use sc_client_api::{BlockBackend, ExecutorProvider};
use sc_consensus_aura::{ImportQueueParams, SlotProportion, StartAuraParams};
@@ -83,6 +71,8 @@ pub fn new_partial(
FullSelectChain,
>,
sc_finality_grandpa::LinkHalf<Block, FullClient, FullSelectChain>,
beefy_gadget::BeefyVoterLinks<Block>,
beefy_gadget::BeefyRPCLinks<Block>,
Option<Telemetry>,
),
>,
@@ -140,11 +130,18 @@ pub fn new_partial(
telemetry.as_ref().map(|x| x.handle()),
)?;
let (beefy_block_import, beefy_voter_links, beefy_rpc_links) =
beefy_gadget::beefy_block_import_and_links(
grandpa_block_import.clone(),
backend.clone(),
client.clone(),
);
let slot_duration = sc_consensus_aura::slot_duration(&*client)?;
let import_queue =
sc_consensus_aura::import_queue::<AuraPair, _, _, _, _, _, _>(ImportQueueParams {
block_import: grandpa_block_import.clone(),
block_import: beefy_block_import,
justification_import: Some(Box::new(grandpa_block_import.clone())),
client: client.clone(),
create_inherent_data_providers: move |_, ()| async move {
@@ -175,7 +172,7 @@ pub fn new_partial(
keystore_container,
select_chain,
transaction_pool,
other: (grandpa_block_import, grandpa_link, telemetry),
other: (grandpa_block_import, grandpa_link, beefy_voter_links, beefy_rpc_links, telemetry),
})
}
@@ -196,7 +193,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
mut keystore_container,
select_chain,
transaction_pool,
other: (block_import, grandpa_link, mut telemetry),
other: (block_import, grandpa_link, beefy_voter_links, beefy_rpc_links, mut telemetry),
} = new_partial(&config)?;
if let Some(url) = &config.keystore_remote {
@@ -264,18 +261,16 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
let enable_grandpa = !config.disable_grandpa;
let prometheus_registry = config.prometheus_registry().cloned();
let shared_voter_state = SharedVoterState::empty();
let (beefy_commitment_link, beefy_commitment_stream) =
beefy_gadget::notification::BeefySignedCommitmentStream::<Block>::channel();
let (beefy_best_block_link, beefy_best_block_stream) =
beefy_gadget::notification::BeefyBestBlockStream::<Block>::channel();
let rpc_extensions_builder = {
use sc_finality_grandpa::FinalityProofProvider as GrandpaFinalityProofProvider;
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
use sc_finality_grandpa_rpc::{GrandpaApi, GrandpaRpcHandler};
use beefy_gadget_rpc::{Beefy, BeefyApiServer};
use pallet_mmr_rpc::{Mmr, MmrApiServer};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use sc_finality_grandpa_rpc::{Grandpa, GrandpaApiServer};
use sc_rpc::DenyUnsafe;
use substrate_frame_rpc_system::{FullSystem, SystemApi};
use substrate_frame_rpc_system::{System, SystemApiServer};
let backend = backend.clone();
let client = client.clone();
@@ -291,33 +286,33 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
);
Box::new(move |_, subscription_executor: sc_rpc::SubscriptionTaskExecutor| {
let mut io = jsonrpc_core::IoHandler::default();
io.extend_with(SystemApi::to_delegate(FullSystem::new(
client.clone(),
pool.clone(),
DenyUnsafe::No,
)));
io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new(
client.clone(),
)));
io.extend_with(GrandpaApi::to_delegate(GrandpaRpcHandler::new(
shared_authority_set.clone(),
shared_voter_state.clone(),
justification_stream.clone(),
subscription_executor.clone(),
finality_proof_provider.clone(),
)));
io.extend_with(beefy_gadget_rpc::BeefyApi::to_delegate(
beefy_gadget_rpc::BeefyRpcHandler::<Block>::new(
beefy_commitment_stream.clone(),
beefy_best_block_stream.clone(),
let mut io = RpcModule::new(());
let map_err = |e| sc_service::Error::Other(format!("{}", e));
io.merge(System::new(client.clone(), pool.clone(), DenyUnsafe::No).into_rpc())
.map_err(map_err)?;
io.merge(TransactionPayment::new(client.clone()).into_rpc()).map_err(map_err)?;
io.merge(
Grandpa::new(
subscription_executor.clone(),
shared_authority_set.clone(),
shared_voter_state.clone(),
justification_stream.clone(),
finality_proof_provider.clone(),
)
.into_rpc(),
)
.map_err(map_err)?;
io.merge(
Beefy::<Block>::new(
beefy_rpc_links.from_voter_justif_stream.clone(),
beefy_rpc_links.from_voter_best_beefy_stream.clone(),
subscription_executor,
)
.map_err(|e| sc_service::Error::Other(format!("{}", e)))?,
));
io.extend_with(pallet_mmr_rpc::MmrApi::to_delegate(pallet_mmr_rpc::Mmr::new(
client.clone(),
)));
.map_err(|e| sc_service::Error::Other(format!("{}", e)))?
.into_rpc(),
)
.map_err(map_err)?;
io.merge(Mmr::new(client.clone()).into_rpc()).map_err(map_err)?;
Ok(io)
})
};
@@ -328,7 +323,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
keystore: keystore_container.sync_keystore(),
task_manager: &mut task_manager,
transaction_pool: transaction_pool.clone(),
rpc_extensions_builder,
rpc_builder: rpc_extensions_builder.clone(),
backend: backend.clone(),
system_rpc_tx,
config,
@@ -397,11 +392,10 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
runtime: client,
key_store: keystore.clone(),
network: network.clone(),
signed_commitment_sender: beefy_commitment_link,
beefy_best_block_sender: beefy_best_block_link,
min_block_delta: 2,
prometheus_registry: prometheus_registry.clone(),
protocol_name: beefy_protocol_name,
links: beefy_voter_links,
};
// Start the BEEFY bridge gadget.
+60 -22
View File
@@ -52,9 +52,7 @@ use pallet_transaction_payment::{FeeDetails, Multiplier, RuntimeDispatchInfo};
use sp_api::impl_runtime_apis;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_mmr_primitives::{
DataOrHash, EncodableOpaqueLeaf, Error as MmrError, LeafDataProvider, Proof as MmrProof,
};
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},
@@ -238,6 +236,8 @@ impl pallet_aura::Config for Runtime {
impl pallet_beefy::Config for Runtime {
type BeefyId = BeefyId;
type MaxAuthorities = MaxAuthorities;
type OnNewValidatorSet = MmrLeaf;
}
impl pallet_grandpa::Config for Runtime {
@@ -256,12 +256,21 @@ impl pallet_grandpa::Config for Runtime {
type MaxAuthorities = MaxAuthorities;
}
type MmrHash = <Keccak256 as sp_runtime::traits::Hash>::Output;
/// MMR helper types.
mod mmr {
use super::Runtime;
pub use pallet_mmr::primitives::*;
use sp_runtime::traits::Keccak256;
pub type Leaf = <<Runtime as pallet_mmr::Config>::LeafData as LeafDataProvider>::LeafData;
pub type Hash = <Keccak256 as sp_runtime::traits::Hash>::Output;
pub type Hashing = <Runtime as pallet_mmr::Config>::Hashing;
}
impl pallet_mmr::Config for Runtime {
const INDEXING_PREFIX: &'static [u8] = b"mmr";
type Hashing = Keccak256;
type Hash = MmrHash;
type Hash = mmr::Hash;
type OnNewRoot = pallet_beefy_mmr::DepositBeefyDigest<Runtime>;
type WeightInfo = ();
type LeafData = pallet_beefy_mmr::Pallet<Runtime>;
@@ -355,6 +364,7 @@ impl pallet_transaction_payment::Config for Runtime {
AdjustmentVariable,
MinimumMultiplier,
>;
type Event = Event;
}
impl pallet_sudo::Config for Runtime {
@@ -562,7 +572,7 @@ construct_runtime!(
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},
// Consensus support.
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>},
@@ -744,41 +754,69 @@ impl_runtime_apis! {
}
}
impl sp_mmr_primitives::MmrApi<Block, MmrHash> for Runtime {
impl sp_mmr_primitives::MmrApi<Block, mmr::Hash> for Runtime {
fn generate_proof(leaf_index: u64)
-> Result<(EncodableOpaqueLeaf, MmrProof<MmrHash>), MmrError>
-> Result<(EncodableOpaqueLeaf, MmrProof<mmr::Hash>), MmrError>
{
Mmr::generate_proof(leaf_index)
.map(|(leaf, proof)| (EncodableOpaqueLeaf::from_leaf(&leaf), proof))
Mmr::generate_batch_proof(vec![leaf_index])
.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<MmrHash>)
fn verify_proof(leaf: EncodableOpaqueLeaf, proof: MmrProof<mmr::Hash>)
-> Result<(), MmrError>
{
pub type Leaf = <
<Runtime as pallet_mmr::Config>::LeafData as LeafDataProvider
>::LeafData;
let leaf: Leaf = leaf
let leaf: mmr::Leaf = leaf
.into_opaque_leaf()
.try_decode()
.ok_or(MmrError::Verify)?;
Mmr::verify_leaf(leaf, proof)
Mmr::verify_leaves(vec![leaf], mmr::Proof::into_batch_proof(proof))
}
fn verify_proof_stateless(
root: MmrHash,
root: mmr::Hash,
leaf: EncodableOpaqueLeaf,
proof: MmrProof<MmrHash>
proof: MmrProof<mmr::Hash>
) -> Result<(), MmrError> {
type MmrHashing = <Runtime as pallet_mmr::Config>::Hashing;
let node = DataOrHash::Data(leaf.into_opaque_leaf());
pallet_mmr::verify_leaf_proof::<MmrHashing, _>(root, node, proof)
pallet_mmr::verify_leaves_proof::<mmr::Hashing, _>(
root,
vec![node],
pallet_mmr::primitives::Proof::into_batch_proof(proof),
)
}
fn mmr_root() -> Result<MmrHash, MmrError> {
fn mmr_root() -> Result<mmr::Hash, MmrError> {
Ok(Mmr::mmr_root())
}
fn generate_batch_proof(leaf_indices: Vec<pallet_mmr::primitives::LeafIndex>)
-> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<mmr::Hash>), mmr::Error>
{
Mmr::generate_batch_proof(leaf_indices)
.map(|(leaves, proof)| (leaves.into_iter().map(|leaf| mmr::EncodableOpaqueLeaf::from_leaf(&leaf)).collect(), proof))
}
fn verify_batch_proof(leaves: Vec<mmr::EncodableOpaqueLeaf>, proof: mmr::BatchProof<mmr::Hash>)
-> Result<(), mmr::Error>
{
let leaves = leaves.into_iter().map(|leaf|
leaf.into_opaque_leaf()
.try_decode()
.ok_or(mmr::Error::Verify)).collect::<Result<Vec<mmr::Leaf>, mmr::Error>>()?;
Mmr::verify_leaves(leaves, proof)
}
fn verify_batch_proof_stateless(
root: mmr::Hash,
leaves: Vec<mmr::EncodableOpaqueLeaf>,
proof: mmr::BatchProof<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)
}
}
impl fg_primitives::GrandpaApi<Block> for Runtime {
+2 -1
View File
@@ -156,6 +156,7 @@ impl xcm_executor::Config for XcmConfig {
type FeeManager = ();
type MessageExporter = ();
type UniversalAliases = Nothing;
type CallDispatcher = Call;
}
/// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior
@@ -270,7 +271,7 @@ mod tests {
fn xcm_messages_are_sent_using_bridge_router() {
new_test_ext().execute_with(|| {
let xcm: Xcm<()> = vec![Instruction::Trap(42)].into();
let expected_fee = MultiAssets::from((Here, 4_345_002_552_u64));
let expected_fee = MultiAssets::from((Here, 4_259_858_152_u64));
let expected_hash =
([0u8, 0u8, 0u8, 0u8], 1u64).using_encoded(sp_io::hashing::blake2_256);
+1 -1
View File
@@ -30,7 +30,7 @@ bp-rialto-parachain = { path = "../../../primitives/chain-rialto-parachain" }
pallet-bridge-messages = { path = "../../../modules/messages" }
# RPC related Dependencies
jsonrpc-core = '18.0'
jsonrpsee = { version = "0.15.1", features = ["server"] }
# Local Dependencies
rialto-parachain-runtime = { path = '../runtime' }
+2 -2
View File
@@ -59,7 +59,7 @@ pub enum Subcommand {
#[derive(Debug, Parser)]
pub struct ExportGenesisStateCommand {
/// Output file name or stdout if unspecified.
#[clap(parse(from_os_str))]
#[clap(action)]
pub output: Option<PathBuf>,
/// Id of the parachain this state is for.
@@ -81,7 +81,7 @@ pub struct ExportGenesisStateCommand {
#[derive(Debug, Parser)]
pub struct ExportGenesisWasmCommand {
/// Output file name or stdout if unspecified.
#[clap(parse(from_os_str))]
#[clap(action)]
pub output: Option<PathBuf>,
/// Write output in binary. Default is to write in hex.
@@ -20,11 +20,10 @@ use crate::{
service::{new_partial, ParachainRuntimeExecutor},
};
use codec::Encode;
use cumulus_client_service::genesis::generate_genesis_block;
use cumulus_client_cli::generate_genesis_block;
use cumulus_primitives_core::ParaId;
use frame_benchmarking_cli::BenchmarkCmd;
use log::info;
use polkadot_parachain::primitives::AccountIdConversion;
use rialto_parachain_runtime::{Block, RuntimeApi};
use sc_cli::{
ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams,
@@ -32,7 +31,7 @@ use sc_cli::{
};
use sc_service::config::{BasePath, PrometheusConfig};
use sp_core::hexdisplay::HexDisplay;
use sp_runtime::traits::Block as BlockT;
use sp_runtime::traits::{AccountIdConversion, Block as BlockT};
use std::{io::Write, net::SocketAddr};
fn load_spec(
@@ -219,7 +218,7 @@ pub fn run() -> Result<()> {
params.parachain_id.expect("Missing ParaId").into(),
)?;
let state_version = Cli::native_runtime_version(&spec).state_version();
let block: Block = generate_genesis_block(&spec, state_version)?;
let block: Block = generate_genesis_block(&*spec, state_version)?;
let raw_header = block.header().encode();
let output_buf = if params.raw {
raw_header
@@ -288,11 +287,11 @@ pub fn run() -> Result<()> {
let id = ParaId::from(cli.parachain_id.or(para_id).expect("Missing ParaId"));
let parachain_account =
AccountIdConversion::<polkadot_primitives::v2::AccountId>::into_account(&id);
AccountIdConversion::<polkadot_primitives::v2::AccountId>::into_account_truncating(&id);
let state_version =
RelayChainCli::native_runtime_version(&config.chain_spec).state_version();
let block: Block = generate_genesis_block(&config.chain_spec, state_version)
let block: Block = generate_genesis_block(&*config.chain_spec, state_version)
.map_err(|e| format!("{:?}", e))?;
let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
@@ -402,12 +401,8 @@ impl CliConfiguration<Self> for RelayChainCli {
self.base.base.role(is_dev)
}
fn transaction_pool(&self) -> Result<sc_service::config::TransactionPoolOptions> {
self.base.base.transaction_pool()
}
fn state_cache_child_ratio(&self) -> Result<Option<usize>> {
self.base.base.state_cache_child_ratio()
fn transaction_pool(&self, is_dev: bool) -> Result<sc_service::config::TransactionPoolOptions> {
self.base.base.transaction_pool(is_dev)
}
fn rpc_methods(&self) -> Result<sc_service::config::RpcMethods> {
@@ -42,8 +42,8 @@ use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface};
// Substrate Imports
use sc_client_api::ExecutorProvider;
use sc_executor::{NativeElseWasmExecutor, NativeExecutionDispatch};
use sc_network::NetworkService;
use sc_service::{Configuration, PartialComponents, Role, TFullBackend, TFullClient, TaskManager};
use sc_network::{NetworkBlock, NetworkService};
use sc_service::{Configuration, PartialComponents, TFullBackend, TFullClient, TaskManager};
use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};
use sp_api::ConstructRuntimeApi;
use sp_keystore::SyncCryptoStorePtr;
@@ -229,8 +229,9 @@ where
TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>,
>,
>,
) -> jsonrpc_core::IoHandler<sc_rpc::Metadata>
) -> Result<jsonrpsee::RpcModule<()>, sc_service::Error>
+ Send
+ Clone
+ 'static,
BIQ: FnOnce(
Arc<TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>>,
@@ -261,10 +262,6 @@ where
bool,
) -> Result<Box<dyn ParachainConsensus<Block>>, sc_service::Error>,
{
if matches!(parachain_config.role, Role::Light) {
return Err("Light client not supported!".into())
}
let parachain_config = prepare_node_config(parachain_config);
let params = new_partial::<RuntimeApi, Executor, BIQ>(&parachain_config, build_import_queue)?;
@@ -276,6 +273,7 @@ where
&parachain_config,
telemetry_worker_handle,
&mut task_manager,
None,
)
.map_err(|e| match e {
RelayChainError::ServiceError(polkadot_service::Error::Sub(x)) => x,
@@ -307,11 +305,11 @@ where
let rpc_client = client.clone();
let rpc_transaction_pool = transaction_pool.clone();
let rpc_extensions_builder = Box::new(move |deny_unsafe, _| {
Ok(rpc_ext_builder(deny_unsafe, rpc_client.clone(), rpc_transaction_pool.clone()))
rpc_ext_builder(deny_unsafe, rpc_client.clone(), rpc_transaction_pool.clone())
});
sc_service::spawn_tasks(sc_service::SpawnTasksParams {
rpc_extensions_builder,
rpc_builder: rpc_extensions_builder.clone(),
client: client.clone(),
transaction_pool: transaction_pool.clone(),
task_manager: &mut task_manager,
@@ -441,18 +439,17 @@ pub async fn start_node(
polkadot_config,
collator_options,
id,
|deny_unsafe, client, pool| {
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
use substrate_frame_rpc_system::{FullSystem, SystemApi};
|_deny_unsafe, client, pool| {
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use sc_rpc::DenyUnsafe;
use substrate_frame_rpc_system::{System, SystemApiServer};
let mut io = jsonrpc_core::IoHandler::default();
io.extend_with(SystemApi::to_delegate(FullSystem::new(
client.clone(),
pool,
deny_unsafe,
)));
io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new(client)));
io
let mut io = jsonrpsee::RpcModule::new(());
let map_err = |e| sc_service::Error::Other(format!("{}", e));
io.merge(System::new(client.clone(), pool, DenyUnsafe::No).into_rpc())
.map_err(map_err)?;
io.merge(TransactionPayment::new(client).into_rpc()).map_err(map_err)?;
Ok(io)
},
parachain_build_import_queue,
|client,
@@ -34,6 +34,7 @@ use bridge_runtime_common::messages::{
source::{estimate_message_dispatch_and_delivery_fee, XcmBridge, XcmBridgeAdapter},
MessageBridge,
};
use cumulus_pallet_parachain_system::AnyRelayNumber;
use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::{
@@ -274,6 +275,7 @@ impl pallet_transaction_payment::Config for Runtime {
type WeightToFee = IdentityFee<Balance>;
type LengthToFee = IdentityFee<Balance>;
type FeeMultiplierUpdate = ();
type Event = Event;
}
impl pallet_sudo::Config for Runtime {
@@ -295,6 +297,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type ReservedDmpWeight = ReservedDmpWeight;
type XcmpMessageHandler = XcmpQueue;
type ReservedXcmpWeight = ReservedXcmpWeight;
type CheckAssociatedRelayNumber = AnyRelayNumber;
}
impl parachain_info::Config for Runtime {}
@@ -419,6 +422,7 @@ impl Config for XcmConfig {
type FeeManager = ();
type MessageExporter = ();
type UniversalAliases = Nothing;
type CallDispatcher = Call;
}
/// No local origins on this chain are allowed to dispatch XCM sends/executions.
@@ -596,7 +600,7 @@ construct_runtime!(
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>},
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage},
TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},
ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Storage, Inherent, Event<T>} = 20,
ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,
@@ -860,7 +864,7 @@ mod tests {
let xcm: Xcm<()> = vec![Instruction::Trap(42)].into();
let send_result = send_xcm::<XcmRouter>(dest.into(), xcm);
let expected_fee = MultiAssets::from((Here, Fungibility::Fungible(4_345_002_552_u128)));
let expected_fee = MultiAssets::from((Here, Fungibility::Fungible(4_259_858_152_u128)));
let expected_hash =
([0u8, 0u8, 0u8, 0u8], 1u64).using_encoded(sp_io::hashing::blake2_256);
assert_eq!(send_result, Ok((expected_hash, expected_fee)),);
+24 -28
View File
@@ -17,7 +17,7 @@
use crate::cli::{Cli, Subcommand};
use frame_benchmarking_cli::BenchmarkCmd;
use rialto_runtime::{Block, RuntimeApi};
use sc_cli::{ChainSpec, Role, RuntimeVersion, SubstrateCli};
use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli};
impl SubstrateCli for Cli {
fn impl_name() -> String {
@@ -186,34 +186,30 @@ pub fn run() -> sc_cli::Result<()> {
// let is_collator = crate::service::IsCollator::No;
let overseer_gen = polkadot_service::overseer::RealOverseerGen;
runner.run_node_until_exit(|config| async move {
match config.role {
Role::Light => Err(sc_cli::Error::Service(sc_service::Error::Other(
"Light client is not supported by this node".into(),
))),
_ => {
let is_collator = polkadot_service::IsCollator::No;
let grandpa_pause = None;
let enable_beefy = true;
let jaeger_agent = None;
let telemetry_worker_handle = None;
let program_path = None;
let overseer_enable_anyways = false;
let is_collator = polkadot_service::IsCollator::No;
let grandpa_pause = None;
let enable_beefy = true;
let jaeger_agent = None;
let telemetry_worker_handle = None;
let program_path = None;
let overseer_enable_anyways = false;
polkadot_service::new_full::<rialto_runtime::RuntimeApi, ExecutorDispatch, _>(
config,
is_collator,
grandpa_pause,
enable_beefy,
jaeger_agent,
telemetry_worker_handle,
program_path,
overseer_enable_anyways,
overseer_gen,
)
.map(|full| full.task_manager)
.map_err(service_error)
},
}
polkadot_service::new_full::<rialto_runtime::RuntimeApi, ExecutorDispatch, _>(
config,
is_collator,
grandpa_pause,
enable_beefy,
jaeger_agent,
telemetry_worker_handle,
program_path,
overseer_enable_anyways,
overseer_gen,
None,
None,
None,
)
.map(|full| full.task_manager)
.map_err(service_error)
})
},
}
+48 -6
View File
@@ -42,6 +42,7 @@ use bridge_runtime_common::messages::{
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;
@@ -252,6 +253,8 @@ impl pallet_babe::Config for Runtime {
impl pallet_beefy::Config for Runtime {
type BeefyId = BeefyId;
type MaxAuthorities = MaxAuthorities;
type OnNewValidatorSet = MmrLeaf;
}
impl pallet_grandpa::Config for Runtime {
@@ -270,6 +273,9 @@ 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;
@@ -367,6 +373,7 @@ impl pallet_transaction_payment::Config for Runtime {
AdjustmentVariable,
MinimumMultiplier,
>;
type Event = Event;
}
impl pallet_sudo::Config for Runtime {
@@ -484,7 +491,7 @@ construct_runtime!(
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},
// Consensus support.
AuthorityDiscovery: pallet_authority_discovery::{Pallet, Config},
@@ -620,8 +627,11 @@ impl_runtime_apis! {
fn generate_proof(leaf_index: u64)
-> Result<(EncodableOpaqueLeaf, MmrProof<Hash>), MmrError>
{
Mmr::generate_proof(leaf_index)
.map(|(leaf, proof)| (EncodableOpaqueLeaf::from_leaf(&leaf), proof))
Mmr::generate_batch_proof(vec![leaf_index])
.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>)
@@ -635,7 +645,7 @@ impl_runtime_apis! {
.into_opaque_leaf()
.try_decode()
.ok_or(MmrError::Verify)?;
Mmr::verify_leaf(leaf, proof)
Mmr::verify_leaves(vec![leaf], mmr::Proof::into_batch_proof(proof))
}
fn verify_proof_stateless(
@@ -643,14 +653,46 @@ impl_runtime_apis! {
leaf: EncodableOpaqueLeaf,
proof: MmrProof<Hash>
) -> Result<(), MmrError> {
type MmrHashing = <Runtime as pallet_mmr::Config>::Hashing;
let node = DataOrHash::Data(leaf.into_opaque_leaf());
pallet_mmr::verify_leaf_proof::<MmrHashing, _>(root, node, proof)
pallet_mmr::verify_leaves_proof::<MmrHashing, _>(
root,
vec![node],
pallet_mmr::primitives::Proof::into_batch_proof(proof),
)
}
fn mmr_root() -> Result<Hash, MmrError> {
Ok(Mmr::mmr_root())
}
fn generate_batch_proof(leaf_indices: Vec<pallet_mmr::primitives::LeafIndex>)
-> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<MmrHash>), mmr::Error>
{
Mmr::generate_batch_proof(leaf_indices)
.map(|(leaves, proof)| (leaves.into_iter().map(|leaf| mmr::EncodableOpaqueLeaf::from_leaf(&leaf)).collect(), proof))
}
fn verify_batch_proof(leaves: Vec<mmr::EncodableOpaqueLeaf>, proof: mmr::BatchProof<MmrHash>)
-> 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>>()?;
Mmr::verify_leaves(leaves, proof)
}
fn verify_batch_proof_stateless(
root: MmrHash,
leaves: Vec<mmr::EncodableOpaqueLeaf>,
proof: mmr::BatchProof<MmrHash>
) -> 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)
}
}
impl bp_millau::MillauFinalityApi<Block> for Runtime {
+4 -2
View File
@@ -18,7 +18,7 @@
use crate::{
AccountId, Babe, Balance, Balances, BlockNumber, Call, Event, Origin, Registrar, Runtime,
Slots, UncheckedExtrinsic,
ShiftSessionManager, Slots, UncheckedExtrinsic,
};
use frame_support::{parameter_types, weights::Weight};
@@ -95,7 +95,9 @@ impl parachains_paras_inherent::Config for Runtime {
impl parachains_scheduler::Config for Runtime {}
impl parachains_session_info::Config for Runtime {}
impl parachains_session_info::Config for Runtime {
type ValidatorSet = ShiftSessionManager;
}
impl parachains_shared::Config for Runtime {}
+2 -1
View File
@@ -146,6 +146,7 @@ impl xcm_executor::Config for XcmConfig {
type FeeManager = ();
type MessageExporter = ();
type UniversalAliases = Nothing;
type CallDispatcher = Call;
}
/// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior
@@ -237,7 +238,7 @@ mod tests {
let xcm: Xcm<()> = vec![Instruction::Trap(42)].into();
let send_result = send_xcm::<XcmRouter>(dest.into(), xcm);
let expected_fee = MultiAssets::from((Here, 4_345_002_552_u128));
let expected_fee = MultiAssets::from((Here, 4_259_858_152_u128));
let expected_hash =
([0u8, 0u8, 0u8, 0u8], 1u64).using_encoded(sp_io::hashing::blake2_256);
assert_eq!(send_result, Ok((expected_hash, expected_fee)),);
@@ -27,7 +27,7 @@ use crate::messages::{
};
use bp_messages::{storage_keys, MessageData, MessageKey, MessagePayload};
use bp_runtime::StorageProofSize;
use bp_runtime::{record_all_trie_keys, StorageProofSize};
use codec::Encode;
use frame_support::weights::{GetDispatchInfo, Weight};
use pallet_bridge_messages::benchmarking::{
@@ -36,7 +36,7 @@ use pallet_bridge_messages::benchmarking::{
use sp_core::Hasher;
use sp_runtime::traits::{Header, IdentifyAccount, MaybeSerializeDeserialize, Zero};
use sp_std::{fmt::Debug, prelude::*};
use sp_trie::{record_all_keys, trie_types::TrieDBMutV1, LayoutV1, MemoryDB, Recorder, TrieMut};
use sp_trie::{trie_types::TrieDBMutBuilderV1, LayoutV1, MemoryDB, Recorder, TrieMut};
/// Prepare outbound message for the `send_message` call.
pub fn prepare_outbound_message<B>(
@@ -117,7 +117,7 @@ where
let mut root = Default::default();
let mut mdb = MemoryDB::default();
{
let mut trie = TrieDBMutV1::<BHH>::new(&mut mdb, &mut root);
let mut trie = TrieDBMutBuilderV1::<BHH>::new(&mut mdb, &mut root).build();
trie.insert(&storage_key, &params.inbound_lane_data.encode())
.map_err(|_| "TrieMut::insert has failed")
.expect("TrieMut::insert should not fail in benchmarks");
@@ -125,10 +125,10 @@ where
root = grow_trie(root, &mut mdb, params.size);
// generate storage proof to be delivered to This chain
let mut proof_recorder = Recorder::<BHH::Out>::new();
record_all_keys::<LayoutV1<BHH>, _>(&mdb, &root, &mut proof_recorder)
.map_err(|_| "record_all_keys has failed")
.expect("record_all_keys should not fail in benchmarks");
let mut proof_recorder = Recorder::<LayoutV1<BHH>>::new();
record_all_trie_keys::<LayoutV1<BHH>, _>(&mdb, &root, &mut proof_recorder)
.map_err(|_| "record_all_trie_keys has failed")
.expect("record_all_trie_keys should not fail in benchmarks");
let storage_proof = proof_recorder.drain().into_iter().map(|n| n.data.to_vec()).collect();
// finally insert header with given state root to our storage
@@ -160,7 +160,7 @@ where
let mut root = Default::default();
let mut mdb = MemoryDB::default();
{
let mut trie = TrieDBMutV1::<BHH>::new(&mut mdb, &mut root);
let mut trie = TrieDBMutBuilderV1::<BHH>::new(&mut mdb, &mut root).build();
// insert messages
for nonce in params.message_nonces.clone() {
@@ -195,10 +195,10 @@ where
root = grow_trie(root, &mut mdb, params.size);
// generate storage proof to be delivered to This chain
let mut proof_recorder = Recorder::<BHH::Out>::new();
record_all_keys::<LayoutV1<BHH>, _>(&mdb, &root, &mut proof_recorder)
.map_err(|_| "record_all_keys has failed")
.expect("record_all_keys should not fail in benchmarks");
let mut proof_recorder = Recorder::<LayoutV1<BHH>>::new();
record_all_trie_keys::<LayoutV1<BHH>, _>(&mdb, &root, &mut proof_recorder)
.map_err(|_| "record_all_trie_keys has failed")
.expect("record_all_trie_keys should not fail in benchmarks");
let storage_proof = proof_recorder.drain().into_iter().map(|n| n.data.to_vec()).collect();
(root, storage_proof)
@@ -241,18 +241,16 @@ pub fn grow_trie<H: Hasher>(
let mut key_index = 0;
loop {
// generate storage proof to be delivered to This chain
let mut proof_recorder = Recorder::<H::Out>::new();
record_all_keys::<LayoutV1<H>, _>(mdb, &root, &mut proof_recorder)
.map_err(|_| "record_all_keys has failed")
.expect("record_all_keys should not fail in benchmarks");
let mut proof_recorder = Recorder::<LayoutV1<H>>::new();
record_all_trie_keys::<LayoutV1<H>, _>(mdb, &root, &mut proof_recorder)
.map_err(|_| "record_all_trie_keys has failed")
.expect("record_all_trie_keys should not fail in benchmarks");
let size: usize = proof_recorder.drain().into_iter().map(|n| n.data.len()).sum();
if size > minimal_trie_size as _ {
return root
}
let mut trie = TrieDBMutV1::<H>::from_existing(mdb, &mut root)
.map_err(|_| "TrieDBMutV1::from_existing has failed")
.expect("TrieDBMutV1::from_existing should not fail in benchmarks");
let mut trie = TrieDBMutBuilderV1::<H>::from_existing(mdb, &mut root).build();
for _ in 0..iterations {
trie.insert(&key_index.encode(), &vec![42u8; leaf_size as _])
.map_err(|_| "TrieMut::insert has failed")
@@ -52,7 +52,7 @@ impl<
..
}) => {
let inbound_lane_data =
pallet_bridge_messages::InboundLanes::<T, I>::get(&proof.lane);
pallet_bridge_messages::InboundLanes::<T, I>::get(proof.lane);
if proof.nonces_end <= inbound_lane_data.last_delivered_nonce() {
log::trace!(
target: pallet_bridge_messages::LOG_TARGET,
@@ -74,7 +74,7 @@ impl<
let latest_delivered_nonce = relayers_state.last_delivered_nonce;
let outbound_lane_data =
pallet_bridge_messages::OutboundLanes::<T, I>::get(&proof.lane);
pallet_bridge_messages::OutboundLanes::<T, I>::get(proof.lane);
if latest_delivered_nonce <= outbound_lane_data.latest_received_nonce {
log::trace!(
target: pallet_bridge_messages::LOG_TARGET,
@@ -22,12 +22,12 @@ use crate::messages_benchmarking::{grow_trie, insert_header_to_grandpa_pallet};
use bp_parachains::parachain_head_storage_key_at_source;
use bp_polkadot_core::parachains::{ParaHash, ParaHead, ParaHeadsProof, ParaId};
use bp_runtime::StorageProofSize;
use bp_runtime::{record_all_trie_keys, StorageProofSize};
use codec::Encode;
use frame_support::traits::Get;
use pallet_bridge_parachains::{RelayBlockHash, RelayBlockHasher, RelayBlockNumber};
use sp_std::prelude::*;
use sp_trie::{record_all_keys, trie_types::TrieDBMutV1, LayoutV1, MemoryDB, Recorder, TrieMut};
use sp_trie::{trie_types::TrieDBMutBuilderV1, LayoutV1, MemoryDB, Recorder, TrieMut};
/// Prepare proof of messages for the `receive_messages_proof` call.
///
@@ -53,7 +53,8 @@ where
let mut state_root = Default::default();
let mut mdb = MemoryDB::default();
{
let mut trie = TrieDBMutV1::<RelayBlockHasher>::new(&mut mdb, &mut state_root);
let mut trie =
TrieDBMutBuilderV1::<RelayBlockHasher>::new(&mut mdb, &mut state_root).build();
// insert parachain heads
for parachain in parachains {
@@ -69,10 +70,10 @@ where
state_root = grow_trie(state_root, &mut mdb, size);
// generate heads storage proof
let mut proof_recorder = Recorder::<RelayBlockHash>::new();
record_all_keys::<LayoutV1<RelayBlockHasher>, _>(&mdb, &state_root, &mut proof_recorder)
.map_err(|_| "record_all_keys has failed")
.expect("record_all_keys should not fail in benchmarks");
let mut proof_recorder = Recorder::<LayoutV1<RelayBlockHasher>>::new();
record_all_trie_keys::<LayoutV1<RelayBlockHasher>, _>(&mdb, &state_root, &mut proof_recorder)
.map_err(|_| "record_all_trie_keys has failed")
.expect("record_all_trie_keys should not fail in benchmarks");
let proof = proof_recorder.drain().into_iter().map(|n| n.data.to_vec()).collect();
let (relay_block_number, relay_block_hash) =
+1 -1
View File
@@ -9,7 +9,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
finality-grandpa = { version = "0.15.0", default-features = false }
finality-grandpa = { version = "0.16.0", default-features = false }
log = { version = "0.4.17", default-features = false }
num-traits = { version = "0.2", default-features = false }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
+9 -9
View File
@@ -741,7 +741,7 @@ pub mod pallet {
#[pallet::genesis_build]
impl<T: Config<I>, I: 'static> GenesisBuild<T, I> for GenesisConfig<T, I> {
fn build(&self) {
PalletOperatingMode::<T, I>::put(&self.operating_mode);
PalletOperatingMode::<T, I>::put(self.operating_mode);
if let Some(ref owner) = self.owner {
PalletOwner::<T, I>::put(owner);
}
@@ -1022,7 +1022,7 @@ impl<T: Config<I>, I: 'static> InboundLaneStorage for RuntimeInboundLaneStorage<
Some(data) => data,
None => {
let data: InboundLaneData<T::InboundRelayer> =
InboundLanes::<T, I>::get(&self.lane_id).into();
InboundLanes::<T, I>::get(self.lane_id).into();
*self.cached_data.try_borrow_mut().expect(
"we're in the single-threaded environment;\
we have no recursive borrows; qed",
@@ -1037,7 +1037,7 @@ impl<T: Config<I>, I: 'static> InboundLaneStorage for RuntimeInboundLaneStorage<
"we're in the single-threaded environment;\
we have no recursive borrows; qed",
) = Some(data.clone());
InboundLanes::<T, I>::insert(&self.lane_id, StoredInboundLaneData::<T, I>(data))
InboundLanes::<T, I>::insert(self.lane_id, StoredInboundLaneData::<T, I>(data))
}
}
@@ -1055,11 +1055,11 @@ impl<T: Config<I>, I: 'static> OutboundLaneStorage for RuntimeOutboundLaneStorag
}
fn data(&self) -> OutboundLaneData {
OutboundLanes::<T, I>::get(&self.lane_id)
OutboundLanes::<T, I>::get(self.lane_id)
}
fn set_data(&mut self, data: OutboundLaneData) {
OutboundLanes::<T, I>::insert(&self.lane_id, data)
OutboundLanes::<T, I>::insert(self.lane_id, data)
}
#[cfg(test)]
@@ -1134,7 +1134,7 @@ mod tests {
fn inbound_unrewarded_relayers_state(
lane: bp_messages::LaneId,
) -> bp_messages::UnrewardedRelayersState {
let inbound_lane_data = InboundLanes::<TestRuntime, ()>::get(&lane).0;
let inbound_lane_data = InboundLanes::<TestRuntime, ()>::get(lane).0;
let last_delivered_nonce = inbound_lane_data.last_delivered_nonce();
let relayers = inbound_lane_data.relayers;
bp_messages::UnrewardedRelayersState {
@@ -1656,7 +1656,7 @@ mod tests {
receive_messages_delivery_proof();
assert_eq!(
OutboundLanes::<TestRuntime, ()>::get(&TEST_LANE_ID).latest_received_nonce,
OutboundLanes::<TestRuntime, ()>::get(TEST_LANE_ID).latest_received_nonce,
1,
);
});
@@ -1839,7 +1839,7 @@ mod tests {
0, // weight may be zero in this case (all messages are improperly encoded)
),);
assert_eq!(InboundLanes::<TestRuntime>::get(&TEST_LANE_ID).last_delivered_nonce(), 1,);
assert_eq!(InboundLanes::<TestRuntime>::get(TEST_LANE_ID).last_delivered_nonce(), 1,);
});
}
@@ -1860,7 +1860,7 @@ mod tests {
REGULAR_PAYLOAD.declared_weight + REGULAR_PAYLOAD.declared_weight,
),);
assert_eq!(InboundLanes::<TestRuntime>::get(&TEST_LANE_ID).last_delivered_nonce(), 3,);
assert_eq!(InboundLanes::<TestRuntime>::get(TEST_LANE_ID).last_delivered_nonce(), 3,);
});
}
+10 -12
View File
@@ -258,7 +258,7 @@ pub mod pallet {
target: LOG_TARGET,
"The head of parachain {:?} is None. {}",
parachain,
if ParasInfo::<T, I>::contains_key(&parachain) {
if ParasInfo::<T, I>::contains_key(parachain) {
"Looks like it is not yet registered at the source relay chain"
} else {
"Looks like it has been deregistered from the source relay chain"
@@ -514,7 +514,7 @@ pub mod pallet {
#[pallet::genesis_build]
impl<T: Config<I>, I: 'static> GenesisBuild<T, I> for GenesisConfig<T, I> {
fn build(&self) {
PalletOperatingMode::<T, I>::put(&self.operating_mode);
PalletOperatingMode::<T, I>::put(self.operating_mode);
if let Some(ref owner) = self.owner {
PalletOwner::<T, I>::put(owner);
}
@@ -532,8 +532,8 @@ mod tests {
use bp_parachains::{BestParaHeadHash, ImportedParaHeadsKeyProvider, ParasInfoKeyProvider};
use bp_runtime::{
BasicOperatingMode, OwnedBridgeModuleError, StorageDoubleMapKeyProvider,
StorageMapKeyProvider,
record_all_trie_keys, BasicOperatingMode, OwnedBridgeModuleError,
StorageDoubleMapKeyProvider, StorageMapKeyProvider,
};
use bp_test_utils::{
authority_list, generate_owned_bridge_module_tests, make_default_justification,
@@ -546,9 +546,7 @@ mod tests {
weights::Weight,
};
use sp_runtime::DispatchError;
use sp_trie::{
record_all_keys, trie_types::TrieDBMutV1, LayoutV1, MemoryDB, Recorder, TrieMut,
};
use sp_trie::{trie_types::TrieDBMutBuilderV1, LayoutV1, MemoryDB, Recorder, TrieMut};
type BridgesGrandpaPalletInstance = pallet_bridge_grandpa::Instance1;
type WeightInfo = <TestRuntime as Config>::WeightInfo;
@@ -590,7 +588,7 @@ mod tests {
let mut root = Default::default();
let mut mdb = MemoryDB::default();
{
let mut trie = TrieDBMutV1::<RelayBlockHasher>::new(&mut mdb, &mut root);
let mut trie = TrieDBMutBuilderV1::<RelayBlockHasher>::new(&mut mdb, &mut root).build();
for (parachain, head) in heads {
let storage_key =
parachain_head_storage_key_at_source(PARAS_PALLET_NAME, ParaId(parachain));
@@ -602,10 +600,10 @@ mod tests {
}
// generate storage proof to be delivered to This chain
let mut proof_recorder = Recorder::<RelayBlockHash>::new();
record_all_keys::<LayoutV1<RelayBlockHasher>, _>(&mdb, &root, &mut proof_recorder)
.map_err(|_| "record_all_keys has failed")
.expect("record_all_keys should not fail in benchmarks");
let mut proof_recorder = Recorder::<LayoutV1<RelayBlockHasher>>::new();
record_all_trie_keys::<LayoutV1<RelayBlockHasher>, _>(&mdb, &root, &mut proof_recorder)
.map_err(|_| "record_all_trie_keys has failed")
.expect("record_all_trie_keys should not fail in benchmarks");
let storage_proof = proof_recorder.drain().into_iter().map(|n| n.data.to_vec()).collect();
(root, ParaHeadsProof(storage_proof), parachains)
@@ -148,8 +148,8 @@ mod tests {
run_test(|| {
register_relayers_rewards::<TestRuntime>(&RELAYER_2, relayers_rewards(), 10);
assert_eq!(RelayerRewards::<TestRuntime>::get(&RELAYER_1), Some(80));
assert_eq!(RelayerRewards::<TestRuntime>::get(&RELAYER_2), Some(120));
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_1), Some(80));
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_2), Some(120));
});
}
@@ -158,9 +158,9 @@ mod tests {
run_test(|| {
register_relayers_rewards::<TestRuntime>(&RELAYER_3, relayers_rewards(), 10);
assert_eq!(RelayerRewards::<TestRuntime>::get(&RELAYER_1), Some(80));
assert_eq!(RelayerRewards::<TestRuntime>::get(&RELAYER_2), Some(70));
assert_eq!(RelayerRewards::<TestRuntime>::get(&RELAYER_3), Some(50));
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_1), Some(80));
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_2), Some(70));
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_3), Some(50));
});
}
@@ -169,9 +169,9 @@ mod tests {
run_test(|| {
register_relayers_rewards::<TestRuntime>(&RELAYER_3, relayers_rewards(), 1000);
assert_eq!(RelayerRewards::<TestRuntime>::get(&RELAYER_1), None);
assert_eq!(RelayerRewards::<TestRuntime>::get(&RELAYER_2), None);
assert_eq!(RelayerRewards::<TestRuntime>::get(&RELAYER_3), Some(200));
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_1), None);
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_2), None);
assert_eq!(RelayerRewards::<TestRuntime>::get(RELAYER_3), Some(200));
});
}
}
@@ -19,6 +19,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
use frame_support::traits::{ValidatorSet, ValidatorSetWithIdentification};
use sp_std::prelude::*;
pub use pallet::*;
@@ -49,6 +50,24 @@ pub mod pallet {
pub(super) type InitialValidators<T: Config> = StorageValue<_, Vec<T::ValidatorId>>;
}
impl<T: pallet_session::Config + Config> ValidatorSet<T::AccountId> for Pallet<T> {
type ValidatorId = T::ValidatorId;
type ValidatorIdOf = T::ValidatorIdOf;
fn session_index() -> sp_staking::SessionIndex {
pallet_session::Pallet::<T>::current_index()
}
fn validators() -> Vec<Self::ValidatorId> {
pallet_session::Pallet::<T>::validators()
}
}
impl<T: Config> ValidatorSetWithIdentification<T::AccountId> for Pallet<T> {
type Identification = ();
type IdentificationOf = ();
}
impl<T: Config> pallet_session::SessionManager<T::ValidatorId> for Pallet<T> {
fn end_session(_: sp_staking::SessionIndex) {}
fn start_session(_: sp_staking::SessionIndex) {}
+1 -2
View File
@@ -8,7 +8,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
finality-grandpa = { version = "0.15.0", default-features = false }
finality-grandpa = { version = "0.16.0", default-features = false }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
serde = { version = "1.0", optional = true }
@@ -25,7 +25,6 @@ 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]
assert_matches = "1.5"
bp-test-utils = { path = "../test-utils" }
hex = "0.4"
hex-literal = "0.3"
@@ -20,7 +20,6 @@
//! Some of tests in this module may partially duplicate tests from `justification.rs`,
//! but their purpose is different.
use assert_matches::assert_matches;
use bp_header_chain::justification::{verify_justification, Error, GrandpaJustification};
use bp_test_utils::{
header_id, make_justification_for_header, signed_precommit, test_header, Account,
@@ -106,7 +105,7 @@ pub fn make_default_justification(header: &TestHeader) -> GrandpaJustification<T
//
// 1) to return `Err()` (which only may happen if `finality_grandpa::Chain` implementation
// returns an error);
// 2) to return `Ok(validation_result) if validation_result.ghost().is_none()`.
// 2) to return `Ok(validation_result)` if `validation_result.is_valid()` is false.
//
// Our implementation would just return error in both cases.
@@ -126,16 +125,17 @@ fn same_result_when_precommit_target_has_lower_number_than_commit_target() {
),
Err(Error::PrecommitIsNotCommitDescendant),
);
// original implementation returns empty GHOST
assert_matches!(
finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.map(|result| result.ghost().cloned()),
Ok(None)
);
// original implementation returns `Ok(validation_result)`
// with `validation_result.is_valid() == false`.
let result = finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.unwrap();
assert!(!result.is_valid());
}
#[test]
@@ -158,21 +158,27 @@ fn same_result_when_precommit_target_is_not_descendant_of_commit_target() {
),
Err(Error::PrecommitIsNotCommitDescendant),
);
// original implementation returns empty GHOST
assert_matches!(
finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.map(|result| result.ghost().cloned()),
Ok(None)
);
// original implementation returns `Ok(validation_result)`
// with `validation_result.is_valid() == false`.
let result = finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.unwrap();
assert!(!result.is_valid());
}
#[test]
fn same_result_when_justification_contains_duplicate_vote() {
let mut justification = make_default_justification(&test_header(1));
let mut justification = make_justification_for_header(JustificationGeneratorParams {
header: test_header(1),
authorities: minimal_accounts_set(),
ancestors: 0,
..Default::default()
});
// the justification may contain exactly the same vote (i.e. same precommit and same signature)
// multiple times && it isn't treated as an error by original implementation
justification.commit.precommits.push(justification.commit.precommits[0].clone());
@@ -188,21 +194,26 @@ fn same_result_when_justification_contains_duplicate_vote() {
),
Ok(()),
);
// original implementation returns non-empty GHOST
assert_matches!(
finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.map(|result| result.ghost().cloned()),
Ok(Some(_))
);
// original implementation returns `Ok(validation_result)`
// with `validation_result.is_valid() == true`.
let result = finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.unwrap();
assert!(result.is_valid());
}
#[test]
fn same_result_when_authority_equivocates_once_in_a_round() {
let mut justification = make_default_justification(&test_header(1));
let mut justification = make_justification_for_header(JustificationGeneratorParams {
header: test_header(1),
authorities: minimal_accounts_set(),
ancestors: 0,
..Default::default()
});
// the justification original implementation allows authority to submit two different
// votes in a single round, of which only first is 'accepted'
justification.commit.precommits.push(signed_precommit::<TestHeader>(
@@ -222,21 +233,26 @@ fn same_result_when_authority_equivocates_once_in_a_round() {
),
Ok(()),
);
// original implementation returns non-empty GHOST
assert_matches!(
finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.map(|result| result.ghost().cloned()),
Ok(Some(_))
);
// original implementation returns `Ok(validation_result)`
// with `validation_result.is_valid() == true`.
let result = finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.unwrap();
assert!(result.is_valid());
}
#[test]
fn same_result_when_authority_equivocates_twice_in_a_round() {
let mut justification = make_default_justification(&test_header(1));
let mut justification = make_justification_for_header(JustificationGeneratorParams {
header: test_header(1),
authorities: minimal_accounts_set(),
ancestors: 0,
..Default::default()
});
// there's some code in the original implementation that should return an error when
// same authority submits more than two different votes in a single round:
// https://github.com/paritytech/finality-grandpa/blob/6aeea2d1159d0f418f0b86e70739f2130629ca09/src/lib.rs#L473
@@ -266,16 +282,16 @@ fn same_result_when_authority_equivocates_twice_in_a_round() {
),
Ok(()),
);
// original implementation returns non-empty GHOST
assert_matches!(
finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.map(|result| result.ghost().cloned()),
Ok(Some(_))
);
// original implementation returns `Ok(validation_result)`
// with `validation_result.is_valid() == true`.
let result = finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.unwrap();
assert!(result.is_valid());
}
#[test]
@@ -299,14 +315,14 @@ fn same_result_when_there_are_not_enough_cumulative_weight_to_finalize_commit_ta
),
Err(Error::TooLowCumulativeWeight),
);
// original implementation returns empty GHOST
assert_matches!(
finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.map(|result| result.ghost().cloned()),
Ok(None)
);
// original implementation returns `Ok(validation_result)`
// with `validation_result.is_valid() == false`.
let result = finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.unwrap();
assert!(!result.is_valid());
}
+2
View File
@@ -23,6 +23,7 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
trie-db = { version = "0.24.0", default-features = false }
[dev-dependencies]
hex-literal = "0.3"
@@ -43,4 +44,5 @@ std = [
"sp-std/std",
"sp-state-machine/std",
"sp-trie/std",
"trie-db/std",
]
+2 -1
View File
@@ -37,7 +37,8 @@ pub use frame_support::storage::storage_prefix as storage_value_final_key;
use num_traits::{CheckedSub, One};
use sp_runtime::transaction_validity::TransactionValidity;
pub use storage_proof::{
Error as StorageProofError, ProofSize as StorageProofSize, StorageProofChecker,
record_all_keys as record_all_trie_keys, Error as StorageProofError,
ProofSize as StorageProofSize, StorageProofChecker,
};
#[cfg(feature = "std")]
@@ -19,8 +19,11 @@
use codec::Decode;
use hash_db::{HashDB, Hasher, EMPTY_PREFIX};
use sp_runtime::RuntimeDebug;
use sp_std::vec::Vec;
use sp_trie::{read_trie_value, LayoutV1, MemoryDB, StorageProof};
use sp_std::{boxed::Box, vec::Vec};
use sp_trie::{
read_trie_value, LayoutV1, MemoryDB, Recorder, StorageProof, Trie, TrieConfiguration,
TrieDBBuilder, TrieError, TrieHash,
};
/// Storage proof size requirements.
///
@@ -70,7 +73,7 @@ where
/// incomplete or otherwise invalid proof, this function returns an error.
pub fn read_value(&self, key: &[u8]) -> Result<Option<Vec<u8>>, Error> {
// LayoutV1 or LayoutV0 is identical for proof that only read values.
read_trie_value::<LayoutV1<H>, _>(&self.db, &self.root, key)
read_trie_value::<LayoutV1<H>, _>(&self.db, &self.root, key, None, None)
.map_err(|_| Error::StorageValueUnavailable)
}
@@ -124,6 +127,24 @@ pub fn craft_valid_storage_proof() -> (sp_core::H256, StorageProof) {
(root, proof)
}
/// Record all keys for a given root.
pub fn record_all_keys<L: TrieConfiguration, DB>(
db: &DB,
root: &TrieHash<L>,
recorder: &mut Recorder<L>,
) -> Result<(), Box<TrieError<L>>>
where
DB: hash_db::HashDBRef<L::Hash, trie_db::DBValue>,
{
let trie = TrieDBBuilder::<L>::new(db, root).with_recorder(recorder).build();
for x in trie.iter()? {
let (key, _) = x?;
trie.get(&key)?;
}
Ok(())
}
#[cfg(test)]
pub mod tests {
use super::*;
+1 -1
View File
@@ -9,7 +9,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
bp-header-chain = { path = "../header-chain", default-features = false }
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
ed25519-dalek = { version = "1.0", default-features = false, features = ["u64_backend"] }
finality-grandpa = { version = "0.15.0", default-features = false }
finality-grandpa = { version = "0.16.0", default-features = false }
sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
+1 -1
View File
@@ -70,4 +70,4 @@ bp-test-utils = { path = "../../primitives/test-utils" }
hex-literal = "0.3"
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" }
tempfile = "3.2"
finality-grandpa = { version = "0.15.0" }
finality-grandpa = { version = "0.16.0" }
+2 -2
View File
@@ -19,7 +19,7 @@ use bp_runtime::{
Chain as ChainBase, EncodedOrDecodedCall, HashOf, TransactionEra, TransactionEraOf,
};
use codec::{Codec, Encode};
use frame_support::weights::{Weight, WeightToFeePolynomial};
use frame_support::weights::{Weight, WeightToFee};
use jsonrpsee::core::{DeserializeOwned, Serialize};
use num_traits::Zero;
use sc_transaction_pool_api::TransactionStatus;
@@ -61,7 +61,7 @@ pub trait Chain: ChainBase + Clone {
type Call: Clone + Codec + Dispatchable + Debug + Send;
/// Type that is used by the chain, to convert from weight to fee.
type WeightToFee: WeightToFeePolynomial<Balance = Self::Balance>;
type WeightToFee: WeightToFee<Balance = Self::Balance>;
}
/// Substrate-based relay chain that supports parachains.
@@ -22,7 +22,7 @@ bp-parachains = { path = "../../primitives/parachains" }
bp-polkadot-core = { path = "../../primitives/polkadot-core" }
bridge-runtime-common = { path = "../../bin/runtime-common" }
finality-grandpa = { version = "0.15.0" }
finality-grandpa = { version = "0.16.0" }
finality-relay = { path = "../finality" }
parachains-relay = { path = "../parachains" }
relay-utils = { path = "../utils" }
@@ -510,7 +510,7 @@ mod tests {
// i.e. weight reserved for messages dispatch allows dispatch of non-trivial messages.
//
// Any significant change in this values should attract additional attention.
(1024, 216_583_333_334),
(1024, 216_609_134_667),
);
}
}
@@ -36,7 +36,7 @@ use bridge_runtime_common::messages::{
source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof,
};
use codec::Encode;
use frame_support::weights::{Weight, WeightToFeePolynomial};
use frame_support::weights::{Weight, WeightToFee};
use messages_relay::{
message_lane::{MessageLane, SourceHeaderIdOf, TargetHeaderIdOf},
message_lane_loop::{TargetClient, TargetClientState},
@@ -502,8 +502,8 @@ fn compute_fee_multiplier<C: Chain>(
) -> FixedU128 {
let adjusted_weight_fee_difference =
larger_adjusted_weight_fee.saturating_sub(smaller_adjusted_weight_fee);
let smaller_tx_unadjusted_weight_fee = WeightToFeeOf::<C>::calc(&smaller_tx_weight);
let larger_tx_unadjusted_weight_fee = WeightToFeeOf::<C>::calc(&larger_tx_weight);
let smaller_tx_unadjusted_weight_fee = WeightToFeeOf::<C>::weight_to_fee(&smaller_tx_weight);
let larger_tx_unadjusted_weight_fee = WeightToFeeOf::<C>::weight_to_fee(&larger_tx_weight);
FixedU128::saturating_from_rational(
adjusted_weight_fee_difference,
larger_tx_unadjusted_weight_fee.saturating_sub(smaller_tx_unadjusted_weight_fee),
@@ -516,7 +516,7 @@ fn compute_prepaid_messages_refund<C: ChainWithMessages>(
total_prepaid_nonces: MessageNonce,
fee_multiplier: FixedU128,
) -> BalanceOf<C> {
fee_multiplier.saturating_mul_int(WeightToFeeOf::<C>::calc(
fee_multiplier.saturating_mul_int(WeightToFeeOf::<C>::weight_to_fee(
&C::PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN.saturating_mul(total_prepaid_nonces),
))
}
@@ -560,16 +560,15 @@ mod tests {
#[test]
fn compute_fee_multiplier_returns_sane_results() {
let multiplier = FixedU128::saturating_from_rational(1, 1000);
let multiplier: FixedU128 = bp_rococo::WeightToFee::weight_to_fee(&1).into();
let smaller_weight = 1_000_000;
let smaller_adjusted_weight_fee =
multiplier.saturating_mul_int(WeightToFeeOf::<Rococo>::calc(&smaller_weight));
multiplier.saturating_mul_int(WeightToFeeOf::<Rococo>::weight_to_fee(&smaller_weight));
let larger_weight = smaller_weight + 200_000;
let larger_adjusted_weight_fee =
multiplier.saturating_mul_int(WeightToFeeOf::<Rococo>::calc(&larger_weight));
multiplier.saturating_mul_int(WeightToFeeOf::<Rococo>::weight_to_fee(&larger_weight));
assert_eq!(
compute_fee_multiplier::<Rococo>(
smaller_adjusted_weight_fee,