Skip to content

Commit 86cab12

Browse files
committed
only storage mpower for account for date from api if that account/date does not already exist in storage
1 parent d4d5d6e commit 86cab12

File tree

1 file changed

+16
-2
lines changed
  • pallets/mining/rewards-allowance/src

1 file changed

+16
-2
lines changed

pallets/mining/rewards-allowance/src/lib.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,8 +2586,22 @@ pub mod pallet {
25862586
pub fn set_mpower_of_account_for_date(account_id: Vec<u8>, start_of_requested_date_millis: Date, mpower: u128) -> Result<u128, DispatchError> {
25872587
let mpower_current_u128 = mpower.clone();
25882588

2589-
// TODO - use .get to check if the new mpower value differs from the value that is already in storage
2589+
// check if the new mpower value differs from the value that is already in storage
25902590
// for the given key, and only insert if it is different
2591+
let mpower_for_account_for_date = <MPowerForAccountForDate<T>>::get(
2592+
(
2593+
start_of_requested_date_millis.clone(),
2594+
account_id.clone(),
2595+
)
2596+
);
2597+
match mpower_for_account_for_date {
2598+
None => {
2599+
},
2600+
Some(x) => {
2601+
log::warn!("Existing storage value of mPower for account for date of data retrieved from API");
2602+
return Err(DispatchError::Other("Existing storage value of mPower for account for date of data retrieved from API"));
2603+
}
2604+
}
25912605

25922606
// Update storage. Override the default that may have been set in on_initialize
25932607
<MPowerForAccountForDate<T>>::insert(
@@ -3005,7 +3019,7 @@ pub mod pallet {
30053019
/// Add new mPower on-chain.
30063020
fn add_mpower(account_id: T::AccountId, start_of_requested_date_millis: Date, mpower_data_vec: Vec<MPowerPayloadData<T>>) -> Option<Vec<MPowerPayloadData<T>>> {
30073021
// note: AccountId as Vec<u8> is [0, 0, ... 0] since its an unsigned transaction
3008-
log::info!("Adding mPower to storage for date: {:?}", start_of_requested_date_millis.clone());
3022+
log::info!("Processing mPower for account for date into storage: {:?}", start_of_requested_date_millis.clone());
30093023

30103024
for (index, mpower_data_item) in mpower_data_vec.iter().enumerate() {
30113025
Self::set_mpower_of_account_for_date(

0 commit comments

Comments
 (0)