Skip to content

Commit

Permalink
chore: 'AuthorisedCaller' storage item is removed
Browse files Browse the repository at this point in the history
  • Loading branch information
yahortsaryk committed Nov 14, 2024
1 parent 9e86512 commit a0328fc
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 114 deletions.
1 change: 0 additions & 1 deletion node/service/chain-specs/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@
},
"ddcPayouts": {
"feederAccount": null,
"authorisedCaller": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
"debtorCustomers": [
[
"0x0000000000000000000000000000000000000001",
Expand Down
8 changes: 0 additions & 8 deletions pallets/ddc-payouts/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,6 @@ fn set_validation_era<T: Config>(

benchmarks! {

set_authorised_caller {
let dac_account = create_account::<T>("dac_account", 0, 0);

}: _(RawOrigin::Root, dac_account.clone())
verify {
assert_eq!(AuthorisedCaller::<T>::get(), Some(dac_account));
}

begin_billing_report {

let cluster_id = ClusterId::from([1; 20]);
Expand Down
29 changes: 3 additions & 26 deletions pallets/ddc-payouts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub(crate) mod mock;
#[cfg(test)]
mod tests;

pub mod migrations;

use ddc_primitives::{
traits::{
bucket::BucketManager,
Expand Down Expand Up @@ -105,7 +107,7 @@ pub mod pallet {

/// The current storage version.
const STORAGE_VERSION: frame_support::traits::StorageVersion =
frame_support::traits::StorageVersion::new(0);
frame_support::traits::StorageVersion::new(1);

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
Expand Down Expand Up @@ -227,9 +229,6 @@ pub mod pallet {
cluster_id: ClusterId,
era: DdcEra,
},
AuthorisedCaller {
authorised_caller: T::AccountId,
},
ChargeError {
cluster_id: ClusterId,
era: DdcEra,
Expand Down Expand Up @@ -276,10 +275,6 @@ pub mod pallet {
BillingReport<T>,
>;

#[pallet::storage]
#[pallet::getter(fn authorised_caller)]
pub type AuthorisedCaller<T: Config> = StorageValue<_, T::AccountId>;

#[pallet::storage]
#[pallet::getter(fn debtor_customers)]
pub type DebtorCustomers<T: Config> =
Expand Down Expand Up @@ -342,23 +337,6 @@ pub mod pallet {

#[pallet::call]
impl<T: Config> Pallet<T> {
// todo! remove extrensics from payout pallet and factor the extrensics implementation into
// PayoutProcessor trait
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::set_authorised_caller())]
pub fn set_authorised_caller(
origin: OriginFor<T>,
authorised_caller: T::AccountId,
) -> DispatchResult {
ensure_root(origin)?; // requires Governance approval

AuthorisedCaller::<T>::put(authorised_caller.clone());

Self::deposit_event(Event::<T>::AuthorisedCaller { authorised_caller });

Ok(())
}

#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::begin_billing_report())]
pub fn begin_billing_report(
Expand Down Expand Up @@ -1169,7 +1147,6 @@ pub mod pallet {
}
}

AuthorisedCaller::<T>::set(self.authorised_caller.clone());
for (cluster_id, customer_id, debt) in &self.debtor_customers {
DebtorCustomers::<T>::insert(cluster_id, customer_id, debt);
}
Expand Down
69 changes: 69 additions & 0 deletions pallets/ddc-payouts/src/migrations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use frame_support::{migration, traits::OnRuntimeUpgrade};
use log;

use super::*;

const LOG_TARGET: &str = "ddc-payouts";

pub mod v1 {
use frame_support::pallet_prelude::*;

use super::*;

pub fn migrate_to_v1<T: Config>() -> Weight {
let on_chain_version = Pallet::<T>::on_chain_storage_version();
let current_version = Pallet::<T>::current_storage_version();

log::info!(
target: LOG_TARGET,
"Running migration with current storage version {:?} / onchain {:?}",
current_version,
on_chain_version
);

if on_chain_version == 0 && current_version == 1 {
log::info!(target: LOG_TARGET, "Running migration to v1.");

let res = migration::clear_storage_prefix(
<Pallet<T>>::name().as_bytes(),
b"AuthorisedCaller",
b"",
None,
None,
);

log::info!(
target: LOG_TARGET,
"Cleared '{}' entries from 'AuthorisedCaller' storage prefix.",
res.unique
);

if res.maybe_cursor.is_some() {
log::error!(
target: LOG_TARGET,
"Storage prefix 'AuthorisedCaller' is not completely cleared."
);
}

// Update storage version.
StorageVersion::new(1).put::<Pallet<T>>();
log::info!(
target: LOG_TARGET,
"Storage migrated to version {:?}",
current_version
);

T::DbWeight::get().reads_writes(1, res.unique.into())
} else {
log::info!(target: LOG_TARGET, " >>> Unused migration!");
T::DbWeight::get().reads(1)
}
}

pub struct MigrateToV1<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> {
fn on_runtime_upgrade() -> Weight {
migrate_to_v1::<T>()
}
}
}
45 changes: 0 additions & 45 deletions pallets/ddc-payouts/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use sp_std::marker::PhantomData;

/// Weight functions needed for pallet_ddc_payouts.
pub trait WeightInfo {
fn set_authorised_caller() -> Weight;
fn begin_billing_report() -> Weight;
fn begin_charging_customers() -> Weight;
fn send_charging_customers_batch(b: u32, ) -> Weight;
Expand All @@ -42,32 +41,20 @@ pub trait WeightInfo {
/// Weights for pallet_ddc_payouts using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: `DdcPayouts::AuthorisedCaller` (r:0 w:1)
// Proof: `DdcPayouts::AuthorisedCaller` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
fn set_authorised_caller() -> Weight {
Weight::from_parts(12_694_000_u64, 0)
.saturating_add(T::DbWeight::get().writes(1_u64))
}
// Storage: `DdcPayouts::AuthorisedCaller` (r:1 w:0)
// Proof: `DdcPayouts::AuthorisedCaller` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
// Storage: `DdcPayouts::ActiveBillingReports` (r:1 w:1)
// Proof: `DdcPayouts::ActiveBillingReports` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn begin_billing_report() -> Weight {
Weight::from_parts(26_119_000_u64, 0)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
// Storage: `DdcPayouts::AuthorisedCaller` (r:1 w:0)
// Proof: `DdcPayouts::AuthorisedCaller` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
// Storage: `DdcPayouts::ActiveBillingReports` (r:1 w:1)
// Proof: `DdcPayouts::ActiveBillingReports` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn begin_charging_customers() -> Weight {
Weight::from_parts(28_303_000_u64, 0)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
// Storage: `DdcPayouts::AuthorisedCaller` (r:1 w:0)
// Proof: `DdcPayouts::AuthorisedCaller` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
// Storage: `DdcPayouts::ActiveBillingReports` (r:1 w:1)
// Proof: `DdcPayouts::ActiveBillingReports` (`max_values`: None, `max_size`: None, mode: `Measured`)
// Storage: `DdcClusters::ClustersGovParams` (r:1 w:0)
Expand All @@ -88,8 +75,6 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(T::DbWeight::get().writes(5_u64))
.saturating_add(T::DbWeight::get().writes((2_u64).saturating_mul(b as u64)))
}
// Storage: `DdcPayouts::AuthorisedCaller` (r:1 w:0)
// Proof: `DdcPayouts::AuthorisedCaller` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
// Storage: `DdcPayouts::ActiveBillingReports` (r:1 w:1)
// Proof: `DdcPayouts::ActiveBillingReports` (`max_values`: None, `max_size`: None, mode: `Measured`)
// Storage: `DdcClusters::ClustersGovParams` (r:1 w:0)
Expand All @@ -111,17 +96,13 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(T::DbWeight::get().reads(12_u64))
.saturating_add(T::DbWeight::get().writes(4_u64))
}
// Storage: `DdcPayouts::AuthorisedCaller` (r:1 w:0)
// Proof: `DdcPayouts::AuthorisedCaller` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
// Storage: `DdcPayouts::ActiveBillingReports` (r:1 w:1)
// Proof: `DdcPayouts::ActiveBillingReports` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn begin_rewarding_providers() -> Weight {
Weight::from_parts(29_155_000_u64, 0)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
// Storage: `DdcPayouts::AuthorisedCaller` (r:1 w:0)
// Proof: `DdcPayouts::AuthorisedCaller` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
// Storage: `DdcPayouts::ActiveBillingReports` (r:1 w:1)
// Proof: `DdcPayouts::ActiveBillingReports` (`max_values`: None, `max_size`: None, mode: `Measured`)
// Storage: `System::Account` (r:1000 w:1000)
Expand All @@ -136,17 +117,13 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(T::DbWeight::get().writes(2_u64))
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(b as u64)))
}
// Storage: `DdcPayouts::AuthorisedCaller` (r:1 w:0)
// Proof: `DdcPayouts::AuthorisedCaller` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
// Storage: `DdcPayouts::ActiveBillingReports` (r:1 w:1)
// Proof: `DdcPayouts::ActiveBillingReports` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn end_rewarding_providers() -> Weight {
Weight::from_parts(29_986_000_u64, 0)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
// Storage: `DdcPayouts::AuthorisedCaller` (r:1 w:0)
// Proof: `DdcPayouts::AuthorisedCaller` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
// Storage: `DdcPayouts::ActiveBillingReports` (r:1 w:1)
// Proof: `DdcPayouts::ActiveBillingReports` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn end_billing_report() -> Weight {
Expand All @@ -158,32 +135,20 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {

// For backwards compatibility and tests
impl WeightInfo for () {
// Storage: `DdcPayouts::AuthorisedCaller` (r:0 w:1)
// Proof: `DdcPayouts::AuthorisedCaller` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
fn set_authorised_caller() -> Weight {
Weight::from_parts(12_694_000_u64, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
// Storage: `DdcPayouts::AuthorisedCaller` (r:1 w:0)
// Proof: `DdcPayouts::AuthorisedCaller` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
// Storage: `DdcPayouts::ActiveBillingReports` (r:1 w:1)
// Proof: `DdcPayouts::ActiveBillingReports` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn begin_billing_report() -> Weight {
Weight::from_parts(26_119_000_u64, 0)
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
// Storage: `DdcPayouts::AuthorisedCaller` (r:1 w:0)
// Proof: `DdcPayouts::AuthorisedCaller` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
// Storage: `DdcPayouts::ActiveBillingReports` (r:1 w:1)
// Proof: `DdcPayouts::ActiveBillingReports` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn begin_charging_customers() -> Weight {
Weight::from_parts(28_303_000_u64, 0)
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
// Storage: `DdcPayouts::AuthorisedCaller` (r:1 w:0)
// Proof: `DdcPayouts::AuthorisedCaller` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
// Storage: `DdcPayouts::ActiveBillingReports` (r:1 w:1)
// Proof: `DdcPayouts::ActiveBillingReports` (`max_values`: None, `max_size`: None, mode: `Measured`)
// Storage: `DdcClusters::ClustersGovParams` (r:1 w:0)
Expand All @@ -204,8 +169,6 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().writes(5_u64))
.saturating_add(RocksDbWeight::get().writes((2_u64).saturating_mul(b as u64)))
}
// Storage: `DdcPayouts::AuthorisedCaller` (r:1 w:0)
// Proof: `DdcPayouts::AuthorisedCaller` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
// Storage: `DdcPayouts::ActiveBillingReports` (r:1 w:1)
// Proof: `DdcPayouts::ActiveBillingReports` (`max_values`: None, `max_size`: None, mode: `Measured`)
// Storage: `DdcClusters::ClustersGovParams` (r:1 w:0)
Expand All @@ -227,17 +190,13 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().reads(12_u64))
.saturating_add(RocksDbWeight::get().writes(4_u64))
}
// Storage: `DdcPayouts::AuthorisedCaller` (r:1 w:0)
// Proof: `DdcPayouts::AuthorisedCaller` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
// Storage: `DdcPayouts::ActiveBillingReports` (r:1 w:1)
// Proof: `DdcPayouts::ActiveBillingReports` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn begin_rewarding_providers() -> Weight {
Weight::from_parts(29_155_000_u64, 0)
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
// Storage: `DdcPayouts::AuthorisedCaller` (r:1 w:0)
// Proof: `DdcPayouts::AuthorisedCaller` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
// Storage: `DdcPayouts::ActiveBillingReports` (r:1 w:1)
// Proof: `DdcPayouts::ActiveBillingReports` (`max_values`: None, `max_size`: None, mode: `Measured`)
// Storage: `System::Account` (r:1000 w:1000)
Expand All @@ -252,17 +211,13 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().writes(2_u64))
.saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(b as u64)))
}
// Storage: `DdcPayouts::AuthorisedCaller` (r:1 w:0)
// Proof: `DdcPayouts::AuthorisedCaller` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
// Storage: `DdcPayouts::ActiveBillingReports` (r:1 w:1)
// Proof: `DdcPayouts::ActiveBillingReports` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn end_rewarding_providers() -> Weight {
Weight::from_parts(29_986_000_u64, 0)
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
// Storage: `DdcPayouts::AuthorisedCaller` (r:1 w:0)
// Proof: `DdcPayouts::AuthorisedCaller` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
// Storage: `DdcPayouts::ActiveBillingReports` (r:1 w:1)
// Proof: `DdcPayouts::ActiveBillingReports` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn end_billing_report() -> Weight {
Expand Down
33 changes: 1 addition & 32 deletions runtime/cere-dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,22 +527,6 @@ impl_opaque_keys! {
}
}

fn transform_session_keys(v: AccountId, old: OldSessionKeys) -> SessionKeys {
SessionKeys {
grandpa: old.grandpa,
babe: old.babe,
im_online: old.im_online,
authority_discovery: old.authority_discovery,
ddc_verification: {
let mut id: ddc_primitives::sr25519::AuthorityId =
sp_core::sr25519::Public::from_raw([0u8; 32]).into();
let id_raw: &mut [u8] = id.as_mut();
id_raw[0..32].copy_from_slice(v.as_ref());
id_raw[0..4].copy_from_slice(b"cer!");
id
},
}
}
impl pallet_session::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type ValidatorId = <Self as frame_system::Config>::AccountId;
Expand Down Expand Up @@ -1446,6 +1430,7 @@ type Migrations = (
pallet_nomination_pools::migration::versioned_migrations::V6ToV7<Runtime>,
pallet_staking::migrations::v14::MigrateToV14<Runtime>,
pallet_grandpa::migrations::MigrateV4ToV5<Runtime>,
pallet_ddc_payouts::migrations::v1::MigrateToV1<Runtime>,
);

/// Executive: handles dispatch to the various modules.
Expand All @@ -1458,22 +1443,6 @@ pub type Executive = frame_executive::Executive<
Migrations,
>;

pub mod migrations {
use super::*;

/// When this is removed, should also remove `OldSessionKeys`.
pub struct UpgradeSessionKeys;
impl frame_support::traits::OnRuntimeUpgrade for UpgradeSessionKeys {
fn on_runtime_upgrade() -> Weight {
Session::upgrade_keys::<OldSessionKeys, _>(transform_session_keys);
Perbill::from_percent(50) * RuntimeBlockWeights::get().max_block
}
}

/// Unreleased migrations. Add new ones here:
pub type Unreleased = (UpgradeSessionKeys,);
}

type EventRecord = frame_system::EventRecord<
<Runtime as frame_system::Config>::RuntimeEvent,
<Runtime as frame_system::Config>::Hash,
Expand Down
Loading

0 comments on commit a0328fc

Please sign in to comment.