From 87f6ce3b81ea935b97bfcc466126b385556c24cc Mon Sep 17 00:00:00 2001 From: Andrew McKenzie Date: Tue, 14 Nov 2023 17:14:36 +0000 Subject: [PATCH] guard unallocated sp reward writeout --- mobile_verifier/src/reward_shares.rs | 2 +- mobile_verifier/src/rewarder.rs | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/mobile_verifier/src/reward_shares.rs b/mobile_verifier/src/reward_shares.rs index 559f2d7e9..765e33fb8 100644 --- a/mobile_verifier/src/reward_shares.rs +++ b/mobile_verifier/src/reward_shares.rs @@ -286,7 +286,7 @@ impl ServiceProviderShares { }) } - pub fn unallocated_reward( + pub fn into_unallocated_reward( unallocated_amount: Decimal, reward_period: &'_ Range>, ) -> anyhow::Result { diff --git a/mobile_verifier/src/rewarder.rs b/mobile_verifier/src/rewarder.rs index a4dec38af..a11775d48 100644 --- a/mobile_verifier/src/rewarder.rs +++ b/mobile_verifier/src/rewarder.rs @@ -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??;