Reduce iterations when delegator last_claimed_height is 0 (#1609)

* Reduce iterations when delegator last_claimed_height is 0

* Fix typo
This commit is contained in:
Drazen Urch
2022-09-15 17:10:35 +02:00
committed by GitHub
parent 7290e479db
commit 974163da97
4 changed files with 342 additions and 267 deletions
+332 -266
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -70,6 +70,7 @@ pub(crate) fn mixnodes<'a>(
)
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct StoredMixnodeBond {
pub pledge_amount: Coin,
+8 -1
View File
@@ -554,6 +554,13 @@ pub fn calculate_delegator_reward(
.map(|(_, delegation)| delegation)
.collect::<Vec<Delegation>>();
// If last_claimed_height is 0 iterate from earlest_delegation, try avoiding gas query limit
let iter_from = if last_claimed_height == 0 {
delegations.iter().fold(0, |acc, x| acc.min(x.block_height))
} else {
last_claimed_height
};
// Accumulate outside of the loop to gain some speed, on a log of checkpoints
let mut delegation_at_height = Uint128::zero();
@@ -563,7 +570,7 @@ pub fn calculate_delegator_reward(
.prefix(mix_identity)
.keys(
storage,
Some(Bound::inclusive(last_claimed_height)),
Some(Bound::inclusive(iter_from)),
None,
Order::Ascending,
)
@@ -23,6 +23,7 @@ fn generate_storage_key(storage: &mut dyn Storage) -> Result<u32, ContractError>
Ok(key)
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct Account {
pub owner_address: Addr,