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:
Hernando Castano
2020-12-16 04:52:53 -05:00
committed by Bastian Köcher
parent 8a5b51a944
commit ee655b1057
31 changed files with 328 additions and 293 deletions
+2
View File
@@ -16,6 +16,7 @@ bp-runtime = { path = "../runtime", default-features = false }
# 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-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "master" , default-features = false }
@@ -27,6 +28,7 @@ std = [
"bp-message-lane/std",
"bp-runtime/std",
"frame-support/std",
"frame-system/std",
"sp-api/std",
"sp-core/std",
"sp-runtime/std",
+54 -12
View File
@@ -22,31 +22,36 @@
use bp_message_lane::{LaneId, MessageNonce, UnrewardedRelayersState};
use bp_runtime::Chain;
use frame_support::{weights::Weight, RuntimeDebug};
use frame_support::{
weights::{constants::WEIGHT_PER_SECOND, DispatchClass, Weight},
RuntimeDebug,
};
use sp_core::Hasher as HasherT;
use sp_runtime::{
traits::{BlakeTwo256, Convert, IdentifyAccount, Verify},
MultiSignature, MultiSigner,
MultiSignature, MultiSigner, Perbill,
};
use sp_std::prelude::*;
/// Maximal weight of single Rialto block.
pub const MAXIMUM_BLOCK_WEIGHT: Weight = 2_000_000_000_000;
/// Portion of block reserved for regular transactions.
pub const AVAILABLE_BLOCK_RATIO: u32 = 75;
/// Maximal weight of single Rialto 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 Rialto block.
pub const MAXIMUM_BLOCK_SIZE: u32 = 5 * 1024 * 1024;
/// Maximal size of single normal Rialto extrinsic (75% of maximal block size).
pub const MAXIMUM_EXTRINSIC_SIZE: u32 = MAXIMUM_BLOCK_SIZE / 100 * AVAILABLE_BLOCK_RATIO;
///
/// This represents two seconds of compute assuming a target block time of six seconds.
pub const MAXIMUM_BLOCK_WEIGHT: Weight = 2 * WEIGHT_PER_SECOND;
/// 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 = 128;
/// Maximal number of unrewarded relayer entries at inbound lane.
pub const MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE: MessageNonce = 128;
/// Maximal number of unconfirmed messages at inbound lane.
pub const MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE: MessageNonce = 128;
@@ -131,6 +136,43 @@ pub fn derive_account_from_millau_id(id: bp_runtime::SourceAccount<AccountId>) -
AccountIdConverter::convert(encoded_id)
}
/// 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(5 * 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 Rialto headers from the Bridge Pallet instance.
///