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

pallet-base-fee storage utility functions #585

Merged
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
28 changes: 23 additions & 5 deletions frame/base-fee/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@

pub use pallet::*;

use frame_support::{traits::Get, weights::Weight};
use sp_core::U256;
use sp_runtime::Permill;

#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::{dispatch::DispatchResult, pallet_prelude::*};
use frame_system::pallet_prelude::*;
use sp_core::U256;
use sp_runtime::Permill;

pub trait BaseFeeThreshold {
fn lower() -> Permill;
Expand Down Expand Up @@ -210,23 +213,23 @@ pub mod pallet {
#[pallet::weight(10_000 + T::DbWeight::get().writes(1))]
pub fn set_base_fee_per_gas(origin: OriginFor<T>, fee: U256) -> DispatchResult {
ensure_root(origin)?;
<BaseFeePerGas<T>>::put(fee);
let _ = Self::set_base_fee_per_gas_inner(fee);
Self::deposit_event(Event::NewBaseFeePerGas(fee));
Ok(())
}

#[pallet::weight(10_000 + T::DbWeight::get().writes(1))]
pub fn set_is_active(origin: OriginFor<T>, is_active: bool) -> DispatchResult {
ensure_root(origin)?;
<IsActive<T>>::put(is_active);
let _ = Self::set_is_active_inner(is_active);
Self::deposit_event(Event::IsActive(is_active));
Ok(())
}

#[pallet::weight(10_000 + T::DbWeight::get().writes(1))]
pub fn set_elasticity(origin: OriginFor<T>, elasticity: Permill) -> DispatchResult {
ensure_root(origin)?;
<Elasticity<T>>::put(elasticity);
let _ = Self::set_elasticity_inner(elasticity);
Self::deposit_event(Event::NewElasticity(elasticity));
Ok(())
}
Expand All @@ -239,6 +242,21 @@ pub mod pallet {
}
}

impl<T: Config> Pallet<T> {
pub fn set_base_fee_per_gas_inner(value: U256) -> Weight {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you explain the reason for doing this, it doesn't seem necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are just some convenience functions to set the storage i.e. to update the storage values on runtime upgrade from outside the pallet or write integration tests.

Copy link
Member

Choose a reason for hiding this comment

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

Can you rename the name to without inner? I believe this won't conflict with Call as they are stored in a separate enum.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I also believed that was the case and previously tried, but the compiler throws duplicate definitions error.

<BaseFeePerGas<T>>::put(value);
T::DbWeight::get().write
}
pub fn set_elasticity_inner(value: Permill) -> Weight {
<Elasticity<T>>::put(value);
T::DbWeight::get().write
}
pub fn set_is_active_inner(value: bool) -> Weight {
<IsActive<T>>::put(value);
T::DbWeight::get().write
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down