Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cache frequently used storage #1012

Draft
wants to merge 2 commits into
base: polkadot-stable2409
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ frame-benchmarking-cli = { git = "https://github.com/galacticcouncil/polkadot-sd
frame-executive = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch = "stable2409-patch", default-features = false }
frame-remote-externalities = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch = "stable2409-patch", default-features = false }
frame-support = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch = "stable2409-patch", default-features = false, features = ["tuples-96"] }
frame-support-procedural = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch = "stable2409-patch", default-features = false }
frame-system = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch = "stable2409-patch", default-features = false }
frame-system-benchmarking = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch = "stable2409-patch", default-features = false }
frame-system-rpc-runtime-api = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch = "stable2409-patch", default-features = false }
Expand Down
2 changes: 2 additions & 0 deletions pallets/asset-registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ orml-traits = { workspace = true }

# Substrate dependencies
frame-support = { workspace = true }
frame-support-procedural = { workspace = true }
frame-system = { workspace = true }
sp-core = { workspace = true }
sp-arithmetic = { workspace = true }
Expand Down Expand Up @@ -57,6 +58,7 @@ std = [
"serde/std",
"codec/std",
"frame-support/std",
"frame-support-procedural/std",
"frame-system/std",
"sp-runtime/std",
"sp-core/std",
Expand Down
3 changes: 3 additions & 0 deletions pallets/asset-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ use polkadot_xcm::v3::Junctions::X1;
use polkadot_xcm::v3::MultiLocation;
use sp_runtime::TransactionOutcome;

pub use frame_support_procedural::whitelist_storage;

/// Default value of existential deposit. This value is used if existential deposit wasn't
/// provided.
pub const DEFAULT_ED: Balance = 1;
Expand Down Expand Up @@ -225,6 +227,7 @@ pub mod pallet {
StorageMap<_, Blake2_128Concat, T::AssetNativeLocation, T::AssetId, OptionQuery>;

#[pallet::storage]
#[pallet::whitelist_storage]
/// Number of accounts that paid existential deposits for insufficient assets.
/// This storage is used by `SufficiencyCheck`.
pub type ExistentialDepositCounter<T: Config> = StorageValue<_, u128, ValueQuery>;
Expand Down
2 changes: 2 additions & 0 deletions pallets/broadcast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ sp-api = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
frame-support = { workspace = true }
frame-support-procedural = { workspace = true }
frame-system = { workspace = true }

[features]
Expand All @@ -34,6 +35,7 @@ std = [
"codec/std",
"scale-info/std",
"frame-support/std",
"frame-support-procedural/std",
"frame-system/std",
"sp-std/std",
"sp-api/std",
Expand Down
5 changes: 5 additions & 0 deletions pallets/broadcast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const LOG_TARGET: &str = "runtime::amm-support";

type ExecutionIdStack = BoundedVec<ExecutionType, ConstU32<MAX_STACK_SIZE>>;

pub use frame_support_procedural::whitelist_storage;

#[frame_support::pallet]
pub mod pallet {
use super::*;
Expand All @@ -57,11 +59,13 @@ pub mod pallet {
}

#[pallet::storage]
#[pallet::whitelist_storage]
/// Next available incremental ID
#[pallet::getter(fn incremental_id)]
pub(super) type IncrementalId<T: Config> = StorageValue<_, IncrementalIdType, ValueQuery>;

#[pallet::storage]
#[pallet::whitelist_storage]
/// Execution context to figure out where the trade is originated from
#[pallet::getter(fn execution_context)]
pub(super) type ExecutionContext<T: Config> = StorageValue<_, ExecutionIdStack, ValueQuery>;
Expand All @@ -70,6 +74,7 @@ pub mod pallet {
/// After the stack is full, we start to increase the overflow count,
/// so we how many times we can ignore the removal from the context.
#[pallet::storage]
#[pallet::whitelist_storage]
pub(super) type OverflowCount<T: Config> = StorageValue<_, u32, ValueQuery>;

#[pallet::error]
Expand Down
2 changes: 2 additions & 0 deletions pallets/dca/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ sp-std = { workspace = true }

# FRAME
frame-support = { workspace = true }
frame-support-procedural = { workspace = true }
frame-system = { workspace = true }

#cumumlus
Expand Down Expand Up @@ -68,6 +69,7 @@ default = ["std"]
std = [
"codec/std",
"frame-support/std",
"frame-support-procedural/std",
"frame-system/std",
"sp-runtime/std",
"sp-std/std",
Expand Down
3 changes: 3 additions & 0 deletions pallets/dca/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ pub mod pallet {
use hydradx_traits::fee::SwappablePaymentAssetTrader;
use hydradx_traits::{NativePriceOracle, PriceOracle};

pub use frame_support_procedural::whitelist_storage;

use super::*;

#[pallet::pallet]
Expand Down Expand Up @@ -405,6 +407,7 @@ pub mod pallet {

/// Id sequencer for schedules
#[pallet::storage]
#[pallet::whitelist_storage]
#[pallet::getter(fn next_schedule_id)]
pub type ScheduleIdSequencer<T: Config> = StorageValue<_, ScheduleId, ValueQuery>;

Expand Down
2 changes: 2 additions & 0 deletions pallets/ema-oracle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ hydra-dx-math = { workspace = true }
# Substrate dependencies
frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-support-procedural = { workspace = true }
frame-system = { workspace = true }
sp-arithmetic = { workspace = true }
sp-core = { workspace = true }
Expand All @@ -48,6 +49,7 @@ std = [
"serde",
"codec/std",
"frame-support/std",
"frame-support-procedural/std",
"frame-system/std",
"frame-benchmarking/std",
"log/std",
Expand Down
4 changes: 4 additions & 0 deletions pallets/ema-oracle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ impl BenchmarkHelper<AssetId> for () {
}
}

pub use frame_support_procedural::whitelist_storage;

#[allow(clippy::type_complexity)]
#[frame_support::pallet]
pub mod pallet {
Expand Down Expand Up @@ -165,6 +167,7 @@ pub mod pallet {

/// Accumulator for oracle data in current block that will be recorded at the end of the block.
#[pallet::storage]
#[pallet::whitelist_storage]
#[pallet::getter(fn accumulator)]
pub type Accumulator<T: Config> = StorageValue<
_,
Expand All @@ -190,6 +193,7 @@ pub mod pallet {

/// Assets that are whitelisted and tracked by the pallet.
#[pallet::storage]
#[pallet::whitelist_storage]
pub type WhitelistedAssets<T: Config> =
StorageValue<_, BoundedBTreeSet<(Source, (AssetId, AssetId)), T::MaxUniqueEntries>, ValueQuery>;

Expand Down
2 changes: 2 additions & 0 deletions pallets/omnipool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ sp-std = { workspace = true }

# FRAME
frame-support = { workspace = true }
frame-support-procedural = { workspace = true }
frame-system = { workspace = true }

# ORML
Expand Down Expand Up @@ -63,6 +64,7 @@ std = [
"sp-runtime/std",
"sp-std/std",
"frame-support/std",
"frame-support-procedural/std",
"frame-system/std",
"scale-info/std",
"sp-core/std",
Expand Down
5 changes: 5 additions & 0 deletions pallets/omnipool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ pub use weights::WeightInfo;
pub type NFTCollectionIdOf<T> =
<<T as Config>::NFTHandler as Inspect<<T as frame_system::Config>::AccountId>>::CollectionId;

pub use frame_support_procedural::whitelist_storage;

#[frame_support::pallet]
pub mod pallet {
use super::*;
Expand Down Expand Up @@ -241,6 +243,7 @@ pub mod pallet {
pub(super) type Assets<T: Config> = StorageMap<_, Blake2_128Concat, T::AssetId, AssetState<Balance>>;

#[pallet::storage]
#[pallet::whitelist_storage]
/// Imbalance of hub asset
#[pallet::getter(fn current_imbalance)]
pub(super) type HubAssetImbalance<T: Config> = StorageValue<_, SimpleImbalance<Balance>, ValueQuery>;
Expand All @@ -252,6 +255,7 @@ pub mod pallet {
}

#[pallet::storage]
#[pallet::whitelist_storage]
/// Tradable state of hub asset.
pub(super) type HubAssetTradability<T: Config> =
StorageValue<_, Tradability, ValueQuery, DefaultHubAssetTradability>;
Expand All @@ -263,6 +267,7 @@ pub mod pallet {
StorageMap<_, Blake2_128Concat, T::PositionItemId, Position<Balance, T::AssetId>>;

#[pallet::storage]
#[pallet::whitelist_storage]
#[pallet::getter(fn next_position_id)]
/// Position ids sequencer
pub(super) type NextPositionId<T: Config> = StorageValue<_, T::PositionItemId, ValueQuery>;
Expand Down
2 changes: 2 additions & 0 deletions pallets/otc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ sp-core = { workspace = true }

# FRAME
frame-support = { workspace = true }
frame-support-procedural = { workspace = true }
frame-system = { workspace = true }

# ORML dependencies
Expand All @@ -44,6 +45,7 @@ default = ["std"]
std = [
"codec/std",
"frame-support/std",
"frame-support-procedural/std",
"frame-system/std",
"sp-runtime/std",
"sp-core/std",
Expand Down
3 changes: 3 additions & 0 deletions pallets/otc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ pub type NamedReserveIdentifier = [u8; 8];

pub const NAMED_RESERVE_ID: NamedReserveIdentifier = *b"otcorder";

pub use frame_support_procedural::whitelist_storage;

#[derive(Encode, Decode, Debug, Eq, PartialEq, Clone, TypeInfo, MaxEncodedLen)]
pub struct Order<AccountId, AssetId> {
pub owner: AccountId,
Expand Down Expand Up @@ -180,6 +182,7 @@ pub mod pallet {

/// ID sequencer for Orders
#[pallet::storage]
#[pallet::whitelist_storage]
#[pallet::getter(fn next_order_id)]
pub type NextOrderId<T: Config> = StorageValue<_, OrderId, ValueQuery>;

Expand Down
2 changes: 2 additions & 0 deletions pallets/route-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ orml-traits = { workspace = true }
# Substrate dependencies
frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-support-procedural = { workspace = true }
frame-system = { workspace = true }
sp-std = { workspace = true }
sp-core = { workspace = true }
Expand Down Expand Up @@ -51,6 +52,7 @@ std = [
"scale-info/std",
"sp-std/std",
"frame-support/std",
"frame-support-procedural/std",
"frame-system/std",
"orml-tokens/std",
"orml-traits/std",
Expand Down
3 changes: 3 additions & 0 deletions pallets/route-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ pub use pallet::*;

pub const MAX_NUMBER_OF_TRADES: u32 = 5;

pub use frame_support_procedural::whitelist_storage;

#[frame_support::pallet]
pub mod pallet {
use super::*;
Expand Down Expand Up @@ -175,6 +177,7 @@ pub mod pallet {

///Flag to indicate when to skip ED handling
#[pallet::storage]
#[pallet::whitelist_storage]
#[pallet::getter(fn last_trade_position)]
pub type SkipEd<T: Config> = StorageValue<_, types::SkipEd, OptionQuery>;

Expand Down
4 changes: 4 additions & 0 deletions runtime/hydradx/src/benchmarking/omnipool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ runtime_benchmarks! {
// Register new asset in asset registry
let token_id = register_asset(b"FCK".to_vec(), Balance::one()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?;

log::info!(target: "benchmark", "Token ID: {}", token_id);

// Create account for token provider and set balance
let owner: AccountId = account("owner", 0, 1);

Expand Down Expand Up @@ -188,6 +190,8 @@ runtime_benchmarks! {
// Create account for token provider and set balance
let owner: AccountId = account("owner", 0, 1);

log::info!(target: "benchmark", "Token ID: {}", token_id);

let token_price = FixedU128::from((1,5));
let token_amount = 200_000_000_000_000_u128;

Expand Down
15 changes: 13 additions & 2 deletions runtime/hydradx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,6 @@ impl_runtime_apis! {
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsiscsBenchmark;

let mut list = Vec::<BenchmarkList>::new();

list_benchmarks!(list, extra);

orml_list_benchmark!(list, extra, pallet_currencies, benchmarking::currencies);
Expand Down Expand Up @@ -1170,7 +1169,10 @@ impl_runtime_apis! {
}
}

let whitelist: Vec<TrackedStorageKey> = vec![
use frame_support::traits::WhitelistedStorageKeys;
let mut whitelisted_storage = AllPalletsWithSystem::whitelisted_storage_keys();
let mut whitelist: Vec<TrackedStorageKey> = vec![
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// --- Might wanna delete as it should be part of whitelisted storage already --- //
// Block Number
hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
// Total Issuance
Expand All @@ -1181,7 +1183,15 @@ impl_runtime_apis! {
hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),
// System Events
hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),
// --- Speed --- //
// Omnipool assets 0
hex!("97bd8c21bba825270fe6b1b8b3961ac3682a59d51ab9e48a8c8cc418ff9708d211d2df4e979aa105cf552e9544ebd2b500000000").to_vec().into(),
// Omnipool assets 2
hex!("97bd8c21bba825270fe6b1b8b3961ac3682a59d51ab9e48a8c8cc418ff9708d2754faa9acf0378f8c3543d9f132d85bc02000000").to_vec().into(),
// Omnipool 100001 (benchmarking)
hex!("97bd8c21bba825270fe6b1b8b3961ac3682a59d51ab9e48a8c8cc418ff9708d266bc47c64821db8bf16ce3409f3b26cd41420f00").to_vec().into(),
];
whitelist.append(&mut whitelisted_storage);

let mut batches = Vec::<BenchmarkBatch>::new();
let params = (&config, &whitelist);
Expand All @@ -1202,6 +1212,7 @@ impl_runtime_apis! {
orml_add_benchmark!(params, batches, pallet_omnipool_liquidity_mining, benchmarking::omnipool_liquidity_mining);

if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }

Ok(batches)
}
}
Expand Down
Loading