Skip to content

Commit

Permalink
Fix for issue paritytech#11090 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
tifecool committed Mar 24, 2022
1 parent 3aa2ad0 commit d99d164
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
resolver = "2"

members = [
"bin/node-template/weights",
"bin/node-template/runtime/constants",
"bin/node-template/node",
"bin/node-template/pallets/template",
"bin/node-template/runtime",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "node-template-weights"
name = "node-template-runtime-constants"
version = "4.0.0-dev"
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"
Expand All @@ -16,30 +16,30 @@ serde = { version = "1.0.136", optional = true, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "max-encoded-len"] }
scale-info = { version = "2.0.1", default-features = false, features = ["derive"] }
frame-metadata = { version = "15.0.0", default-features = false, features = ["v14"] }
sp-std = { version = "4.0.0", default-features = false, path = "../../../primitives/std" }
sp-io = { version = "6.0.0", default-features = false, path = "../../../primitives/io" }
sp-runtime = { version = "6.0.0", default-features = false, path = "../../../primitives/runtime" }
sp-tracing = { version = "5.0.0", default-features = false, path = "../../../primitives/tracing" }
sp-core = { version = "6.0.0", default-features = false, path = "../../../primitives/core" }
sp-arithmetic = { version = "5.0.0", default-features = false, path = "../../../primitives/arithmetic" }
sp-inherents = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/inherents" }
sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/staking" }
sp-std = { version = "4.0.0", default-features = false, path = "../../../../primitives/std" }
sp-io = { version = "6.0.0", default-features = false, path = "../../../../primitives/io" }
sp-runtime = { version = "6.0.0", default-features = false, path = "../../../../primitives/runtime" }
sp-tracing = { version = "5.0.0", default-features = false, path = "../../../../primitives/tracing" }
sp-core = { version = "6.0.0", default-features = false, path = "../../../../primitives/core" }
sp-arithmetic = { version = "5.0.0", default-features = false, path = "../../../../primitives/arithmetic" }
sp-inherents = { version = "4.0.0-dev", default-features = false, path = "../../../../primitives/inherents" }
sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../../../primitives/staking" }
tt-call = "1.0.8"
frame-support-procedural = { version = "4.0.0-dev", default-features = false, path = "../../../frame/support/procedural" }
frame-support = { version = "4.0.0-dev", default-features = false, path = "../../../frame/support" }
frame-support-procedural = { version = "4.0.0-dev", default-features = false, path = "../../../../frame/support/procedural" }
frame-support = { version = "4.0.0-dev", default-features = false, path = "../../../../frame/support" }
paste = "1.0"
once_cell = { version = "1", default-features = false, optional = true }
sp-state-machine = { version = "0.12.0", optional = true, path = "../../../primitives/state-machine" }
sp-state-machine = { version = "0.12.0", optional = true, path = "../../../../primitives/state-machine" }
bitflags = "1.3"
impl-trait-for-tuples = "0.2.1"
smallvec = "1.8.0"
log = { version = "0.4.14", default-features = false }
sp-core-hashing-proc-macro = { version = "5.0.0", path = "../../../primitives/core/hashing/proc-macro" }
sp-core-hashing-proc-macro = { version = "5.0.0", path = "../../../../primitives/core/hashing/proc-macro" }

[dev-dependencies]
assert_matches = "1.3.0"
pretty_assertions = "1.0.0"
frame-system = { version = "4.0.0-dev", path = "../../../frame/system" }
frame-system = { version = "4.0.0-dev", path = "../../../../frame/system" }
parity-util-mem = { version = "0.11.0", default-features = false, features = ["primitive-types"] }

[features]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod block_weights;
pub mod extrinsic_weights;
pub mod paritydb_weights;
pub mod rocksdb_weights;

pub mod weights;
56 changes: 56 additions & 0 deletions bin/node-template/runtime/constants/src/weights.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
mod block_weights;
mod extrinsic_weights;
mod paritydb_weights;
mod rocksdb_weights;

use codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_runtime::RuntimeDebug;

/// Numeric range of a transaction weight.
pub type Weight = u64;

/// The weight of database operations that the runtime can invoke.
#[derive(Clone, Copy, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode, TypeInfo)]
pub struct RuntimeDbWeight {
pub read: Weight,
pub write: Weight,
}

impl RuntimeDbWeight {
pub fn reads(self, r: Weight) -> Weight {
self.read.saturating_mul(r)
}

pub fn writes(self, w: Weight) -> Weight {
self.write.saturating_mul(w)
}

pub fn reads_writes(self, r: Weight, w: Weight) -> Weight {
let read_weight = self.read.saturating_mul(r);
let write_weight = self.write.saturating_mul(w);
read_weight.saturating_add(write_weight)
}
}

pub mod constants {
use super::Weight;

pub const WEIGHT_PER_SECOND: Weight = 1_000_000_000_000;
pub const WEIGHT_PER_MILLIS: Weight = WEIGHT_PER_SECOND / 1000;
// 1_000_000_000
pub const WEIGHT_PER_MICROS: Weight = WEIGHT_PER_MILLIS / 1000;
// 1_000_000
pub const WEIGHT_PER_NANOS: Weight = WEIGHT_PER_MICROS / 1000; // 1_000

// Expose the Block and Extrinsic base weights.
pub use super::{
block_weights::constants::BlockExecutionWeight,
extrinsic_weights::constants::ExtrinsicBaseWeight,
};

// Expose the DB weights.
pub use super::{
paritydb_weights::constants::ParityDbWeight, rocksdb_weights::constants::RocksDbWeight,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
pub mod constants {
use frame_support::{
parameter_types,
weights::{constants, Weight},
};
use super::super::{constants, Weight};

parameter_types! {
/// Importing a block with 0 Extrinsics.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
pub mod constants {
use frame_support::{
parameter_types,
weights::{constants, Weight},
};
use super::super::{constants, Weight};

parameter_types! {
/// Executing a NO-OP `System::remarks` Extrinsic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
pub mod constants {
use frame_support::{
parameter_types,
weights::{constants, RuntimeDbWeight},
};
use super::super::{constants, RuntimeDbWeight};

parameter_types! {
/// ParityDB can be enabled with a feature flag, but is still experimental. These weights
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
pub mod constants {
use frame_support::{
parameter_types,
weights::{constants, RuntimeDbWeight},
};
use super::super::{constants, RuntimeDbWeight};

parameter_types! {
/// By default, Substrate uses RocksDB, so this will be the weight used throughout
Expand Down

0 comments on commit d99d164

Please sign in to comment.