From 9304e04cfc25e702816575a4dcd08632e0e063b7 Mon Sep 17 00:00:00 2001 From: yuandu Date: Tue, 10 Oct 2023 14:59:28 +0800 Subject: [PATCH 1/2] fix: farm genesis validation --- modules/farm/types/genesis.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/farm/types/genesis.go b/modules/farm/types/genesis.go index b2131b50..91bfef17 100644 --- a/modules/farm/types/genesis.go +++ b/modules/farm/types/genesis.go @@ -75,7 +75,17 @@ func ValidateGenesis(data GenesisState) error { return fmt.Errorf("rewardPerBlock must be positive, but got %s", r.RewardPerBlock.String()) } + // If the unexpired pool rule has been updated, rewardPerShare will not be zero. if !r.RewardPerShare.IsPositive() { + // No reward has ever been distributed. + if r.RemainingReward.Equal(r.TotalReward) { + continue + } + // The pool is expired and the reward is refund to the creator + if !r.RemainingReward.Equal(r.TotalReward) && pool.EndHeight == pool.LastHeightDistrRewards { + continue + } + return fmt.Errorf("rewardPerShare must be positive, but got %s", r.RewardPerShare.String()) } } From de46200f85fd42481562610504f056ad485d6864 Mon Sep 17 00:00:00 2001 From: yuandu Date: Wed, 11 Oct 2023 10:48:08 +0800 Subject: [PATCH 2/2] remove redundant conditonal logic --- modules/farm/types/genesis.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/farm/types/genesis.go b/modules/farm/types/genesis.go index 91bfef17..4e35fbbd 100644 --- a/modules/farm/types/genesis.go +++ b/modules/farm/types/genesis.go @@ -82,7 +82,7 @@ func ValidateGenesis(data GenesisState) error { continue } // The pool is expired and the reward is refund to the creator - if !r.RemainingReward.Equal(r.TotalReward) && pool.EndHeight == pool.LastHeightDistrRewards { + if pool.EndHeight == pool.LastHeightDistrRewards { continue }