Skip to content

Commit

Permalink
guard unallocated sp reward writeout
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Nov 14, 2023
1 parent 259da36 commit 87f6ce3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion mobile_verifier/src/reward_shares.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl ServiceProviderShares {
})
}

pub fn unallocated_reward(
pub fn into_unallocated_reward(
unallocated_amount: Decimal,
reward_period: &'_ Range<DateTime<Utc>>,
) -> anyhow::Result<proto::MobileRewardShare> {
Expand Down
16 changes: 10 additions & 6 deletions mobile_verifier/src/rewarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,16 @@ where

// write out any unallocated service provider reward
let unallocated_sp_reward_amount = total_sp_rewards - Decimal::from(allocated_sp_rewards);
let unallocated_sp_reward =
ServiceProviderShares::unallocated_reward(unallocated_sp_reward_amount, reward_period)?;
self.mobile_rewards
.write(unallocated_sp_reward, [])
.await?
.await??;
if unallocated_sp_reward_amount > dec!(0) {
let unallocated_sp_reward = ServiceProviderShares::into_unallocated_reward(
unallocated_sp_reward_amount,
reward_period,
)?;
self.mobile_rewards
.write(unallocated_sp_reward, [])
.await?
.await??;
}

let written_files = self.mobile_rewards.commit().await?.await??;

Expand Down

0 comments on commit 87f6ce3

Please sign in to comment.