Co #14338: pallet-glutton: over-unity consumption (#2730)

* Fix types

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fix import

* ".git/.scripts/commands/fmt/fmt.sh"

* Fix more

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Actually fix stuff

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* update glutton genesis script

* Update Substrate and Polkadot

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: NachoPal <ignacio.palacios.santos@gmail.com>
Co-authored-by: command-bot <>
This commit is contained in:
Oliver Tale-Yazdi
2023-06-13 18:37:47 +02:00
committed by GitHub
parent 49815cee3c
commit 6a4063917d
6 changed files with 431 additions and 395 deletions
@@ -19,7 +19,10 @@ use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use sc_client_api::UsageProvider;
use sp_api::{Core, ProvideRuntimeApi};
use sp_arithmetic::Perbill;
use sp_arithmetic::{
traits::{One, Zero},
FixedPointNumber,
};
use core::time::Duration;
use cumulus_primitives_core::ParaId;
@@ -46,15 +49,12 @@ fn benchmark_block_import(c: &mut Criterion) {
group.measurement_time(Duration::from_secs(120));
let mut initialize_glutton_pallet = true;
for (compute_percent, storage_percent) in &[
(Perbill::from_percent(100), Perbill::from_percent(0)),
(Perbill::from_percent(100), Perbill::from_percent(100)),
] {
for (compute_ratio, storage_ratio) in &[(One::one(), Zero::zero()), (One::one(), One::one())] {
let block = utils::set_glutton_parameters(
&client,
initialize_glutton_pallet,
compute_percent,
storage_percent,
compute_ratio,
storage_ratio,
);
initialize_glutton_pallet = false;
@@ -73,8 +73,9 @@ fn benchmark_block_import(c: &mut Criterion) {
group.bench_function(
format!(
"(compute = {:?}, storage = {:?}) block import",
compute_percent, storage_percent
"(compute = {:?} %, storage = {:?} %) block import",
compute_ratio.saturating_mul_int(100),
storage_ratio.saturating_mul_int(100)
),
|b| {
b.iter_batched(
@@ -18,7 +18,10 @@
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use sc_client_api::UsageProvider;
use sp_arithmetic::Perbill;
use sp_arithmetic::{
traits::{One, Zero},
FixedPointNumber,
};
use core::time::Duration;
use cumulus_primitives_core::ParaId;
@@ -47,15 +50,12 @@ fn benchmark_block_production_compute(c: &mut Criterion) {
group.measurement_time(Duration::from_secs(120));
let mut initialize_glutton_pallet = true;
for (compute_level, storage_level) in &[
(Perbill::from_percent(100), Perbill::from_percent(0)),
(Perbill::from_percent(100), Perbill::from_percent(100)),
] {
for (compute_ratio, storage_ratio) in &[(One::one(), Zero::zero()), (One::one(), One::one())] {
let block = utils::set_glutton_parameters(
&client,
initialize_glutton_pallet,
compute_level,
storage_level,
compute_ratio,
storage_ratio,
);
runtime.block_on(utils::import_block(&client, &block, false));
initialize_glutton_pallet = false;
@@ -68,8 +68,9 @@ fn benchmark_block_production_compute(c: &mut Criterion) {
group.bench_function(
format!(
"(compute = {:?}, storage = {:?}, proof = true) block production",
compute_level, storage_level
"(compute = {:?} %, storage = {:?} %) block import",
compute_ratio.saturating_mul_int(100),
storage_ratio.saturating_mul_int(100)
),
|b| {
b.iter_batched(
@@ -89,8 +90,9 @@ fn benchmark_block_production_compute(c: &mut Criterion) {
group.bench_function(
format!(
"(compute = {:?}, storage = {:?}, proof = false) block production",
compute_level, storage_level
"(compute = {:?} %, storage = {:?} %) block import",
compute_ratio.saturating_mul_int(100),
storage_ratio.saturating_mul_int(100)
),
|b| {
b.iter_batched(
@@ -32,7 +32,10 @@ use sc_executor_common::wasm_runtime::WasmModule;
use sp_api::ProvideRuntimeApi;
use frame_system_rpc_runtime_api::AccountNonceApi;
use sp_arithmetic::Perbill;
use sp_arithmetic::{
traits::{One, Zero},
FixedU64,
};
use sp_consensus::BlockOrigin;
use sp_keyring::Sr25519Keyring::Alice;
use sp_runtime::traits::Header as HeaderT;
@@ -69,14 +72,11 @@ fn benchmark_block_validation(c: &mut Criterion) {
group.sample_size(20);
group.measurement_time(Duration::from_secs(120));
// In the first iteration we want to initialie the glutton pallet
// In the first iteration we want to initialize the glutton pallet.
let mut is_first = true;
for (compute_percent, storage_percent) in &[
(Perbill::from_percent(100), Perbill::from_percent(0)),
(Perbill::from_percent(100), Perbill::from_percent(100)),
] {
for (compute_ratio, storage_ratio) in &[(One::one(), Zero::zero()), (One::one(), One::one())] {
let parachain_block =
set_glutton_parameters(&client, is_first, compute_percent, storage_percent);
set_glutton_parameters(&client, is_first, compute_ratio, storage_ratio);
is_first = false;
runtime.block_on(import_block(&client, parachain_block.clone().into_block(), false));
@@ -114,7 +114,7 @@ fn benchmark_block_validation(c: &mut Criterion) {
group.bench_function(
format!(
"(compute = {:?}, storage = {:?}, proof_size = {}kb) block validation",
compute_percent, storage_percent, proof_size_in_kb
compute_ratio, storage_ratio, proof_size_in_kb
),
|b| {
b.iter_batched(
@@ -145,8 +145,8 @@ fn verify_expected_result(runtime: &Box<dyn WasmModule>, encoded_params: &[u8],
fn set_glutton_parameters(
client: &Client,
initialize: bool,
compute_percent: &Perbill,
storage_percent: &Perbill,
compute_ratio: &FixedU64,
storage_ratio: &FixedU64,
) -> ParachainBlockData {
let parent_hash = client.usage_info().chain.best_hash;
let parent_header = client.header(parent_hash).expect("Just fetched this hash.").unwrap();
@@ -181,7 +181,7 @@ fn set_glutton_parameters(
client,
Alice.into(),
SudoCall::sudo {
call: Box::new(GluttonCall::set_compute { compute: *compute_percent }.into()),
call: Box::new(GluttonCall::set_compute { compute: *compute_ratio }.into()),
},
Some(last_nonce),
);
@@ -192,7 +192,7 @@ fn set_glutton_parameters(
client,
Alice.into(),
SudoCall::sudo {
call: Box::new(GluttonCall::set_storage { storage: *storage_percent }.into()),
call: Box::new(GluttonCall::set_storage { storage: *storage_ratio }.into()),
},
Some(last_nonce),
);
+6 -7
View File
@@ -35,14 +35,13 @@ use sc_consensus::{
use sc_executor::DEFAULT_HEAP_ALLOC_STRATEGY;
use sc_executor_common::runtime_blob::RuntimeBlob;
use sp_api::ProvideRuntimeApi;
use sp_arithmetic::Perbill;
use sp_blockchain::{ApplyExtrinsicFailed::Validity, Error::ApplyExtrinsicFailed};
use sp_consensus::BlockOrigin;
use sp_core::{sr25519, Pair};
use sp_keyring::Sr25519Keyring::Alice;
use sp_runtime::{
transaction_validity::{InvalidTransaction, TransactionValidityError},
AccountId32, OpaqueExtrinsic,
AccountId32, FixedU64, OpaqueExtrinsic,
};
/// Accounts to use for transfer transactions. Enough for 5000 transactions.
@@ -127,7 +126,7 @@ pub fn create_benchmarking_transfer_extrinsics(
src_accounts: &[sr25519::Pair],
dst_accounts: &[sr25519::Pair],
) -> (usize, Vec<OpaqueExtrinsic>) {
// Add as many tranfer extrinsics as possible into a single block.
// Add as many transfer extrinsics as possible into a single block.
let mut block_builder = client.new_block(Default::default()).unwrap();
let mut max_transfer_count = 0;
let mut extrinsics = Vec::new();
@@ -200,8 +199,8 @@ pub fn get_wasm_module() -> Box<dyn sc_executor_common::wasm_runtime::WasmModule
pub fn set_glutton_parameters(
client: &TestClient,
initialize: bool,
compute_percent: &Perbill,
storage_percent: &Perbill,
compute_ratio: &FixedU64,
storage_ratio: &FixedU64,
) -> NodeBlock {
let parent_hash = client.usage_info().chain.best_hash;
let parent_header = client.header(parent_hash).expect("Just fetched this hash.").unwrap();
@@ -231,7 +230,7 @@ pub fn set_glutton_parameters(
let set_compute = construct_extrinsic(
client,
SudoCall::sudo {
call: Box::new(GluttonCall::set_compute { compute: *compute_percent }.into()),
call: Box::new(GluttonCall::set_compute { compute: *compute_ratio }.into()),
},
Alice.into(),
Some(last_nonce),
@@ -243,7 +242,7 @@ pub fn set_glutton_parameters(
let set_storage = construct_extrinsic(
client,
SudoCall::sudo {
call: Box::new(GluttonCall::set_storage { storage: *storage_percent }.into()),
call: Box::new(GluttonCall::set_storage { storage: *storage_ratio }.into()),
},
Alice.into(),
Some(last_nonce),