galacticcouncil / galacticcouncil/hydration-node

Add oracles and fee payment assets to whitelisted storage

Open
#1,007 0 comments 0 reactions 0 assignees View on GitHub
area/runtime priority/medium type/enhancement
Dominant language
Rust
Stars
208
Forks
109
Avg merge
6d 3h
Merged PRs (30d)
3

Description

This macro should automatically read the storage and add this to base weight but skipping all of the subsequent reads of these storages during the benchmarking.

The two candidates for this are Oracles
https://github.com/galacticcouncil/hydration-node/blob/ea4e622fe5adb0dda12dd4000ac6b55849ff7649/pallets/ema-oracle/src/lib.rs#L179-L188

And

https://github.com/galacticcouncil/hydration-node/blob/ea4e622fe5adb0dda12dd4000ac6b55849ff7649/pallets/transaction-multi-payment/src/lib.rs#L234-L246

We are reading these potentially multiple times per tx execution in a row:

Here we read 2 values from oracle per swap https://github.com/galacticcouncil/hydration-node/blob/ea4e622fe5adb0dda12dd4000ac6b55849ff7649/pallets/dca/src/lib.rs#L906-L918

Here we read oracle values
https://github.com/galacticcouncil/hydration-node/blob/ea4e622fe5adb0dda12dd4000ac6b55849ff7649/pallets/omnipool/src/lib.rs#L730-L740

Here
https://github.com/galacticcouncil/hydration-node/blob/ea4e622fe5adb0dda12dd4000ac6b55849ff7649/pallets/route-executor/src/lib.rs#L343

Here
https://github.com/galacticcouncil/hydration-node/blob/ea4e622fe5adb0dda12dd4000ac6b55849ff7649/math/src/dynamic_fees/math.rs#L43

By implementing this we could save a bunch of weight.

Also we can then get rid of stuff like this.
https://github.com/galacticcouncil/hydration-node/blob/ea4e622fe5adb0dda12dd4000ac6b55849ff7649/pallets/transaction-multi-payment/src/lib.rs#L90-L106

Impl:

```rust
/// Declare the storage as whitelisted from benchmarking.
///
/// Doing so will exclude reads of that value's storage key from counting towards weight
/// calculations during benchmarking.
///
/// This attribute should only be attached to storages that are known to be
/// read/used in every block. This will result in a more accurate benchmarking weight.
///
/// ### Example
/// `
/// #[frame_support::pallet]
/// mod pallet {
/// # use frame_support::pallet_prelude::*;
/// #
/// #[pallet::pallet]
/// pub struct Pallet(_);
///
/// #[pallet::storage]
/// #[pallet::whitelist_storage]
/// pub type MyStorage = StorageValue<_, u32>;
/// #
/// # #[pallet::config]
/// # pub trait Config: frame_system::Config {}
/// }
/// `
pub use frame_support_procedural::whitelist_storage;
```

```
"#[pallet::whitelist_storage]"
```

More candidates for whitelisted storage:
- [ ] Omnipool
- [ ] Stablepools
- [ ] Router

Note: We should make sure the storages are bound and used fairly often. The Blockchain state is quite small and we could fit everything in RAM but it will not be the case always.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.