Skip to content

Commit

Permalink
feat(stakes): remove empty stake entries from by_validator and by_wit…
Browse files Browse the repository at this point in the history
…hdrawer
  • Loading branch information
drcpu-github committed Nov 27, 2024
1 parent 40d0871 commit e76d748
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions data_structures/src/staking/stakes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,18 @@ where
// No need to keep the entry if the stake has gone to zero
if final_coins.is_zero() {
by_address_entry.remove();
if let Some(ref mut stakes) = self.by_validator.get_mut(&key.validator) {
stakes.remove(stakes.iter().position(|stake| stake.read_value().coins == 0.into()).unwrap());
if stakes.is_empty() {
self.by_validator.remove(&key.validator);
}
}
if let Some(ref mut stakes) = self.by_withdrawer.get_mut(&key.withdrawer) {
stakes.remove(stakes.iter().position(|stake| stake.read_value().coins == 0.into()).unwrap());
if stakes.is_empty() {
self.by_withdrawer.remove(&key.withdrawer);
}
}
self.by_coins.remove(&CoinsAndAddresses {
coins: initial_coins,
addresses: key,
Expand Down

0 comments on commit e76d748

Please sign in to comment.