mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 04:01:02 +00:00
Update Substrate Dependency (#566)
* Update `sp-io` dependency * Rename Trait to Config * RustFmt * Bump `sp-io` again * Use new frame_system weight types in Rialto and Millau runtimes * Update test Runtimes to use new weight types * Bump `sp-io` again * Update to not-the latest first. * Update benchmarks. * Another Trai. * Move new weight types into runtime primitive crates This allows us to check limits for extrinsics from other parts of the codebase without pulling in the entire chain runtime. * Remove leftover comments * Move new functions to a better location * Small formatting fixes * Add actual documentation to new weight config types * Decrease maximum block weight of Millau chain * Decreease maximum block length of Millau chain Co-authored-by: Tomasz Drwięga <tomasz@parity.io>
This commit is contained in:
committed by
Bastian Köcher
parent
8a5b51a944
commit
ee655b1057
@@ -22,6 +22,7 @@ serde = { version = "1.0.101", optional = true, features = ["derive"] }
|
||||
# Substrate Based Dependencies
|
||||
|
||||
frame-support = { git = "https://github.com/paritytech/substrate.git", branch = "master" , default-features = false }
|
||||
frame-system = { git = "https://github.com/paritytech/substrate.git", branch = "master" , default-features = false }
|
||||
sp-api = { git = "https://github.com/paritytech/substrate.git", branch = "master" , default-features = false }
|
||||
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "master" , default-features = false }
|
||||
sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "master" , default-features = false }
|
||||
@@ -36,6 +37,7 @@ std = [
|
||||
"bp-runtime/std",
|
||||
"fixed-hash/std",
|
||||
"frame-support/std",
|
||||
"frame-system/std",
|
||||
"hash256-std-hasher/std",
|
||||
"impl-codec/std",
|
||||
"impl-serde",
|
||||
|
||||
@@ -24,11 +24,14 @@ mod millau_hash;
|
||||
|
||||
use bp_message_lane::{LaneId, MessageNonce, UnrewardedRelayersState};
|
||||
use bp_runtime::Chain;
|
||||
use frame_support::{weights::Weight, RuntimeDebug};
|
||||
use frame_support::{
|
||||
weights::{constants::WEIGHT_PER_MILLIS, DispatchClass, Weight},
|
||||
RuntimeDebug,
|
||||
};
|
||||
use sp_core::Hasher as HasherT;
|
||||
use sp_runtime::{
|
||||
traits::{IdentifyAccount, Verify},
|
||||
MultiSignature, MultiSigner,
|
||||
MultiSignature, MultiSigner, Perbill,
|
||||
};
|
||||
use sp_std::prelude::*;
|
||||
use sp_trie::{trie_types::Layout, TrieConfiguration};
|
||||
@@ -68,23 +71,25 @@ impl sp_runtime::traits::Hash for BlakeTwoAndKeccak256 {
|
||||
}
|
||||
}
|
||||
|
||||
/// Maximal weight of single Millau block.
|
||||
pub const MAXIMUM_BLOCK_WEIGHT: Weight = 10_000_000_000;
|
||||
/// Portion of block reserved for regular transactions.
|
||||
pub const AVAILABLE_BLOCK_RATIO: u32 = 75;
|
||||
/// Maximal weight of single Millau extrinsic (65% of maximum block weight = 75% for regular
|
||||
/// transactions minus 10% for initialization).
|
||||
pub const MAXIMUM_EXTRINSIC_WEIGHT: Weight = MAXIMUM_BLOCK_WEIGHT / 100 * (AVAILABLE_BLOCK_RATIO as Weight - 10);
|
||||
/// Maximal size of Millau block.
|
||||
pub const MAXIMUM_BLOCK_SIZE: u32 = 2 * 1024 * 1024;
|
||||
/// Maximal size of single normal Millau extrinsic (75% of maximal block size).
|
||||
pub const MAXIMUM_EXTRINSIC_SIZE: u32 = MAXIMUM_BLOCK_SIZE / 100 * AVAILABLE_BLOCK_RATIO;
|
||||
/// Maximum weight of single Millau block.
|
||||
///
|
||||
/// This represents 0.1 seconds of compute assuming a target block time of six seconds.
|
||||
pub const MAXIMUM_BLOCK_WEIGHT: Weight = 10 * WEIGHT_PER_MILLIS;
|
||||
|
||||
/// Represents the average portion of a block's weight that will be used by an
|
||||
/// `on_initialize()` runtime call.
|
||||
pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
|
||||
|
||||
/// Represents the portion of a block that will be used by Normal extrinsics.
|
||||
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
|
||||
|
||||
// TODO: may need to be updated after https://github.com/paritytech/parity-bridges-common/issues/78
|
||||
/// Maximal number of messages in single delivery transaction.
|
||||
pub const MAX_MESSAGES_IN_DELIVERY_TRANSACTION: MessageNonce = 1024;
|
||||
|
||||
/// Maximal number of unrewarded relayer entries at inbound lane.
|
||||
pub const MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE: MessageNonce = 1024;
|
||||
|
||||
/// Maximal number of unconfirmed messages at inbound lane.
|
||||
pub const MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE: MessageNonce = 1024;
|
||||
|
||||
@@ -155,6 +160,44 @@ impl sp_runtime::traits::Convert<sp_core::H256, AccountId> for AccountIdConverte
|
||||
hash.to_fixed_bytes().into()
|
||||
}
|
||||
}
|
||||
|
||||
/// Get a struct which defines the weight limits and values used during extrinsic execution.
|
||||
pub fn runtime_block_weights() -> frame_system::limits::BlockWeights {
|
||||
frame_system::limits::BlockWeights::builder()
|
||||
// Allowance for Normal class
|
||||
.for_class(DispatchClass::Normal, |weights| {
|
||||
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
|
||||
})
|
||||
// Allowance for Operational class
|
||||
.for_class(DispatchClass::Operational, |weights| {
|
||||
weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
|
||||
// Extra reserved space for Operational class
|
||||
weights.reserved = Some(MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
|
||||
})
|
||||
// By default Mandatory class is not limited at all.
|
||||
// This parameter is used to derive maximal size of a single extrinsic.
|
||||
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
|
||||
.build_or_panic()
|
||||
}
|
||||
|
||||
/// Get the maximum weight (compute time) that a Normal extrinsic on the Millau chain can use.
|
||||
pub fn max_extrinsic_weight() -> Weight {
|
||||
runtime_block_weights()
|
||||
.get(DispatchClass::Normal)
|
||||
.max_extrinsic
|
||||
.unwrap_or(Weight::MAX)
|
||||
}
|
||||
|
||||
/// Get a struct which tracks the length in bytes for each extrinsic class in a Millau block.
|
||||
pub fn runtime_block_length() -> frame_system::limits::BlockLength {
|
||||
frame_system::limits::BlockLength::max_with_normal_ratio(2 * 1024 * 1024, NORMAL_DISPATCH_RATIO)
|
||||
}
|
||||
|
||||
/// Get the maximum length in bytes that a Normal extrinsic on the Millau chain requires.
|
||||
pub fn max_extrinsic_size() -> u32 {
|
||||
*runtime_block_length().max.get(DispatchClass::Normal)
|
||||
}
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
/// API for querying information about Millau headers from the Bridge Pallet instance.
|
||||
///
|
||||
|
||||
@@ -18,7 +18,7 @@ use parity_util_mem::MallocSizeOf;
|
||||
use sp_runtime::traits::CheckEqual;
|
||||
|
||||
// `sp_core::H512` can't be used, because it doesn't implement `CheckEqual`, which is required
|
||||
// by `frame_system::Trait::Hash`.
|
||||
// by `frame_system::Config::Hash`.
|
||||
|
||||
fixed_hash::construct_fixed_hash! {
|
||||
/// Hash type used in Millau chain.
|
||||
|
||||
Reference in New Issue
Block a user