Skip to content

Commit

Permalink
503 make spacewalk benchmarks run successfully for pendulum runtimes (#…
Browse files Browse the repository at this point in the history
…505)

* Make WeightInfo trait publicly exported

* Fix wrapped currency id for external benchmarks use, increase amounts used in benchmarks to be greater than ED

* Re-run benchmarks for all Spacewalk pallets

* Fix failing CI

* Fix failing CI

* Fix failing CI

* Fix failing test

* Bump sysinfo version and fix errors after update

* Remove unused import

* Remove get_wrapped_currency_id function

* Modify CI to free more storage

* Display free space after apt upgrade

* Remove df -h

* Modify build.yml to test CI

* Dummy commit

* Revert sysinfo crate version

* Change runner image

* Change runner image to latest

* Don't remove swap file

* Downgrade to ubuntu 20.04

* Modify CI free disk space step

* Delete more stuff when running CI

* Modify CI free disk space step

* Modify CI free disk space step

* Modify CI free disk space step

* Revert to ubuntu-latest

* Don't remove swap file

---------

Co-authored-by: Marcel Ebert <mail@marcel-ebert.de>
  • Loading branch information
bogdanS98 and ebma authored Apr 15, 2024
1 parent 6a33fe6 commit b1dc81f
Show file tree
Hide file tree
Showing 37 changed files with 354 additions and 319 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
push:
branches:
- 'main'

jobs:
build:
name: Build
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/ci-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
name: continuous-integration-main
jobs:
ci:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
env:
RUST_BACKTRACE: full
# Make sure CI fails on all warnings, including Clippy lints
Expand All @@ -15,12 +15,18 @@ jobs:
steps:
- name: Freeing up more disk space
run: |
free -h
sudo rm -rf /usr/local/lib/android # will release about 10 GB if you don't need Android
sudo rm -rf /usr/share/dotnet # will release about 20GB if you don't need .NET
sudo rm -rf /opt/ghc
sudo rm -rf /usr/local/share/boost
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo apt-get remove -y 'php.*' --fix-missing
sudo apt-get remove -y '^mongodb-.*' --fix-missing
sudo apt-get remove -y '^mysql-.*' --fix-missing
sudo apt-get clean
df -h
- uses: actions/checkout@v2

- name: Install package
Expand Down Expand Up @@ -80,4 +86,4 @@ jobs:
with:
command: clippy
# We are a bit more forgiving when it comes to the code in tests and only check for correctness
args: --all-features --all-targets -- -A clippy::all -W clippy::correctness -A clippy::forget_copy -A clippy::forget_ref
args: --all-features --all-targets -- -A clippy::all -W clippy::correctness -A clippy::forget_copy -A clippy::forget_ref
24 changes: 6 additions & 18 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions clients/runner/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,6 @@ mod tests {
use tempdir::TempDir;

use std::{
convert::TryInto,
fmt::Debug,
fs::{self, File},
io::Write,
Expand Down Expand Up @@ -842,7 +841,7 @@ mod tests {
runner.expect_set_child_proc().return_const(());
let pid = Runner::terminate_proc_and_wait(&mut runner).unwrap();
let pid_i32: i32 = pid.try_into().unwrap();
let s = System::new_all();
let s = System::new();
// Get all running processes
let processes = s.processes();
// Get the child process based on its pid
Expand Down
3 changes: 3 additions & 0 deletions pallets/currency/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ try-runtime = [
"orml-currencies/try-runtime",
"orml-tokens/try-runtime",
]
# This feature is only used for defining `GetWrappedCurrencyId` config parameter in the runtime
# `GetWrappedCurrencyId` is only used in other pallets' benchmarks
runtime-benchmarks = []
8 changes: 8 additions & 0 deletions pallets/currency/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ pub mod pallet {
#[pallet::constant]
type GetRelayChainCurrencyId: Get<CurrencyId<Self>>;

#[cfg(feature = "runtime-benchmarks")]
type GetWrappedCurrencyId: Get<CurrencyId<Self>>;

type AssetConversion: StaticLookup<Source = CurrencyId<Self>, Target = Asset>;
type BalanceConversion: StaticLookup<Source = BalanceOf<Self>, Target = i64>;
type CurrencyConversion: types::CurrencyConversion<Amount<Self>, CurrencyId<Self>>;
Expand Down Expand Up @@ -182,6 +185,11 @@ pub mod getters {
pub fn get_native_currency_id<T: Config>() -> CurrencyId<T> {
<T as orml_currencies::Config>::GetNativeCurrencyId::get()
}

#[cfg(feature = "runtime-benchmarks")]
pub fn get_wrapped_currency_id<T: Config>() -> CurrencyId<T> {
<T as Config>::GetWrappedCurrencyId::get()
}
}

pub fn get_free_balance<T: Config>(
Expand Down
9 changes: 7 additions & 2 deletions pallets/currency/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
};

use crate::testing_constants::{DEFAULT_COLLATERAL_CURRENCY, DEFAULT_NATIVE_CURRENCY};
use crate::testing_constants::{
DEFAULT_COLLATERAL_CURRENCY, DEFAULT_NATIVE_CURRENCY, DEFAULT_WRAPPED_CURRENCY,
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
Expand Down Expand Up @@ -102,6 +104,8 @@ impl pallet_balances::Config for Test {
parameter_types! {
pub const GetNativeCurrencyId: CurrencyId = DEFAULT_NATIVE_CURRENCY;
pub const GetRelayChainCurrencyId: CurrencyId = DEFAULT_COLLATERAL_CURRENCY;
#[cfg(feature = "runtime-benchmarks")]
pub const GetWrappedCurrencyId: CurrencyId = DEFAULT_WRAPPED_CURRENCY;
pub const MaxLocks: u32 = 50;
}

Expand Down Expand Up @@ -165,7 +169,8 @@ impl crate::Config for Test {
type SignedFixedPoint = SignedFixedPoint;
type Balance = Balance;
type GetRelayChainCurrencyId = GetRelayChainCurrencyId;

#[cfg(feature = "runtime-benchmarks")]
type GetWrappedCurrencyId = GetWrappedCurrencyId;
type AssetConversion = primitives::AssetConversion;
type BalanceConversion = primitives::BalanceConversion;
type CurrencyConversion = CurrencyConvert;
Expand Down
4 changes: 0 additions & 4 deletions pallets/currency/src/testing_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,3 @@ pub const DEFAULT_WRAPPED_CURRENCY_4: CurrencyId = CurrencyId::AlphaNum4(
11, 4, 144, 240, 123, 51, 33, 72, 34, 159, 33,
],
);

pub fn get_wrapped_currency_id() -> CurrencyId {
DEFAULT_WRAPPED_CURRENCY
}
10 changes: 5 additions & 5 deletions pallets/fee/src/default_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! Autogenerated weights for fee
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2024-03-13, STEPS: `100`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2024-04-02, STEPS: `100`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `Bogdans-M2-MacBook-Pro.local`, CPU: `<UNKNOWN>`
//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
Expand Down Expand Up @@ -58,7 +58,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 2_000_000 picoseconds.
Weight::from_parts(3_000_000, 0)
Weight::from_parts(2_000_000, 0)
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: Fee RedeemFee (r:0 w:1)
Expand All @@ -68,7 +68,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 2_000_000 picoseconds.
Weight::from_parts(2_000_000, 0)
Weight::from_parts(3_000_000, 0)
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: Fee PremiumRedeemFee (r:0 w:1)
Expand Down Expand Up @@ -122,7 +122,7 @@ impl WeightInfo for () {
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 2_000_000 picoseconds.
Weight::from_parts(3_000_000, 0)
Weight::from_parts(2_000_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: Fee RedeemFee (r:0 w:1)
Expand All @@ -132,7 +132,7 @@ impl WeightInfo for () {
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 2_000_000 picoseconds.
Weight::from_parts(2_000_000, 0)
Weight::from_parts(3_000_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: Fee PremiumRedeemFee (r:0 w:1)
Expand Down
5 changes: 4 additions & 1 deletion pallets/fee/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ impl orml_currencies::Config for Test {
parameter_types! {
pub const GetNativeCurrencyId: CurrencyId = DEFAULT_NATIVE_CURRENCY;
pub const GetRelayChainCurrencyId: CurrencyId = DEFAULT_COLLATERAL_CURRENCY;
#[cfg(feature = "runtime-benchmarks")]
pub const GetWrappedCurrencyId: CurrencyId = DEFAULT_WRAPPED_CURRENCY;
pub const MaxLocks: u32 = 50;
}

Expand Down Expand Up @@ -219,7 +221,8 @@ impl currency::Config for Test {
type SignedFixedPoint = SignedFixedPoint;
type Balance = Balance;
type GetRelayChainCurrencyId = GetRelayChainCurrencyId;

#[cfg(feature = "runtime-benchmarks")]
type GetWrappedCurrencyId = GetWrappedCurrencyId;
type AssetConversion = primitives::AssetConversion;
type BalanceConversion = primitives::BalanceConversion;
type CurrencyConversion = CurrencyConvert;
Expand Down
21 changes: 9 additions & 12 deletions pallets/issue/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ use sp_core::{Get, H256};
use sp_runtime::{traits::One, FixedPointNumber};
use sp_std::prelude::*;

use currency::{
getters::{get_relay_chain_currency_id as get_collateral_currency_id, *},
testing_constants::get_wrapped_currency_id,
};
use currency::getters::{get_relay_chain_currency_id as get_collateral_currency_id, *};
use oracle::Pallet as Oracle;
use primitives::{CurrencyId, VaultCurrencyPair, VaultId};
use security::Pallet as Security;
Expand Down Expand Up @@ -42,15 +39,15 @@ fn mint_collateral<T: crate::Config>(account_id: &T::AccountId, amount: BalanceO
fn get_currency_pair<T: crate::Config>() -> DefaultVaultCurrencyPair<T> {
VaultCurrencyPair {
collateral: get_collateral_currency_id::<T>(),
wrapped: get_wrapped_currency_id(),
wrapped: get_wrapped_currency_id::<T>(),
}
}

fn get_vault_id<T: crate::Config>() -> DefaultVaultId<T> {
VaultId::new(
account("Vault", 0, 0),
get_collateral_currency_id::<T>(),
get_wrapped_currency_id(),
get_wrapped_currency_id::<T>(),
)
}

Expand All @@ -69,7 +66,7 @@ benchmarks! {
let relayer_id: T::AccountId = account("Relayer", 0, 0);

Oracle::<T>::_set_exchange_rate(origin.clone(), get_collateral_currency_id::<T>(), <T as currency::Config>::UnsignedFixedPoint::one()).unwrap();
Oracle::<T>::_set_exchange_rate(origin.clone(), get_wrapped_currency_id(), <T as currency::Config>::UnsignedFixedPoint::one()).unwrap();
Oracle::<T>::_set_exchange_rate(origin.clone(), get_wrapped_currency_id::<T>(), <T as currency::Config>::UnsignedFixedPoint::one()).unwrap();
Oracle::<T>::_set_exchange_rate(origin.clone(), <T as vault_registry::Config>::GetGriefingCollateralCurrencyId::get(), <T as currency::Config>::UnsignedFixedPoint::one()).unwrap();

mint_collateral::<T>(&origin, (1u32 << 31).into());
Expand All @@ -93,7 +90,7 @@ benchmarks! {
mint_collateral::<T>(&relayer_id, (1u32 << 31).into());

let vault_stellar_address = DEFAULT_STELLAR_PUBLIC_KEY;
let value: Amount<T> = Amount::new(2u32.into(), get_wrapped_currency_id());
let value: Amount<T> = Amount::new(2u32.into(), get_wrapped_currency_id::<T>());

let issue_id = H256::zero();
let issue_request = IssueRequest {
Expand All @@ -120,7 +117,7 @@ benchmarks! {
VaultRegistry::<T>::_set_system_collateral_ceiling(get_currency_pair::<T>(), 1_000_000_000u32.into());
VaultRegistry::<T>::_set_secure_collateral_threshold(get_currency_pair::<T>(), <T as currency::Config>::UnsignedFixedPoint::checked_from_rational(1, 100000).unwrap());
Oracle::<T>::_set_exchange_rate(origin.clone(), get_collateral_currency_id::<T>(), <T as currency::Config>::UnsignedFixedPoint::one()).unwrap();
Oracle::<T>::_set_exchange_rate(origin.clone(), get_wrapped_currency_id(), <T as currency::Config>::UnsignedFixedPoint::one()).unwrap();
Oracle::<T>::_set_exchange_rate(origin.clone(), get_wrapped_currency_id::<T>(), <T as currency::Config>::UnsignedFixedPoint::one()).unwrap();
register_vault::<T>(vault_id.clone());

VaultRegistry::<T>::try_increase_to_be_issued_tokens(&vault_id, &value).unwrap();
Expand All @@ -135,7 +132,7 @@ benchmarks! {
mint_collateral::<T>(&vault_id.account_id, (1u32 << 31).into());

let vault_stellar_address = DEFAULT_STELLAR_PUBLIC_KEY;
let value = Amount::new(2u32.into(), get_wrapped_currency_id());
let value = Amount::new(2u32.into(), get_wrapped_currency_id::<T>());

let issue_id = H256::zero();
let issue_request = IssueRequest {
Expand All @@ -159,7 +156,7 @@ benchmarks! {
VaultRegistry::<T>::_set_system_collateral_ceiling(get_currency_pair::<T>(), 1_000_000_000u32.into());
VaultRegistry::<T>::_set_secure_collateral_threshold(get_currency_pair::<T>(), <T as currency::Config>::UnsignedFixedPoint::checked_from_rational(1, 100000).unwrap());
Oracle::<T>::_set_exchange_rate(origin.clone(), get_collateral_currency_id::<T>(), <T as currency::Config>::UnsignedFixedPoint::one()).unwrap();
Oracle::<T>::_set_exchange_rate(origin.clone(), get_wrapped_currency_id(), <T as currency::Config>::UnsignedFixedPoint::one()).unwrap();
Oracle::<T>::_set_exchange_rate(origin.clone(), get_wrapped_currency_id::<T>(), <T as currency::Config>::UnsignedFixedPoint::one()).unwrap();
register_vault::<T>(vault_id.clone());

VaultRegistry::<T>::try_increase_to_be_issued_tokens(&vault_id, &value).unwrap();
Expand All @@ -172,7 +169,7 @@ benchmarks! {

rate_limit_update {
let limit_volume_amount: Option<BalanceOf<T>> = Some(1u32.into());
let limit_volume_currency_id: T::CurrencyId = get_wrapped_currency_id();
let limit_volume_currency_id: T::CurrencyId = get_wrapped_currency_id::<T>();
let interval_length: T::BlockNumber = 1u32.into();
}: _(RawOrigin::Root, limit_volume_amount, limit_volume_currency_id, interval_length)

Expand Down
Loading

0 comments on commit b1dc81f

Please sign in to comment.