diff --git a/Lib9c/Delegation/RewardBase.cs b/Lib9c/Delegation/RewardBase.cs index 515524f31b..3577ce79a3 100644 --- a/Lib9c/Delegation/RewardBase.cs +++ b/Lib9c/Delegation/RewardBase.cs @@ -22,7 +22,7 @@ public class RewardBase : IBencodable, IEquatable private const string StateTypeName = "reward_base"; private const long StateVersion = 1; public const int Margin = 2; - private readonly IComparer _currencyComparer = new CurrencyComparer(); + private static readonly IComparer _currencyComparer = new CurrencyComparer(); public RewardBase( Address address, @@ -79,7 +79,7 @@ public RewardBase( throw new ArgumentException("Duplicated currency in reward base."); } - RewardPortion = rewardPortion.ToImmutableDictionary(f => f.Currency, f => f); + RewardPortion = rewardPortion.ToImmutableSortedDictionary(f => f.Currency, f => f, _currencyComparer); SigFig = sigfig; StartHeight = startHeight; } @@ -106,7 +106,7 @@ public RewardBase(Address address, List bencoded) throw new ArgumentException("Duplicated currency in reward base."); } - RewardPortion = rewardPortion.ToImmutableDictionary(f => f.Currency, f => f); + RewardPortion = rewardPortion.ToImmutableSortedDictionary(f => f.Currency, f => f, _currencyComparer); SigFig = (Integer)bencoded[4]; try @@ -122,7 +122,7 @@ public RewardBase(Address address, List bencoded) private RewardBase( Address address, BigInteger totalShares, - ImmutableDictionary rewardPortion, + ImmutableSortedDictionary rewardPortion, int sigfig, long? startHeight = null) { @@ -141,7 +141,7 @@ private RewardBase( public int SigFig { get; private set; } - public ImmutableDictionary RewardPortion { get; } + public ImmutableSortedDictionary RewardPortion { get; } public List Bencoded { @@ -199,9 +199,10 @@ private static RewardBase UpdateTotalShares(RewardBase rewardBase, BigInteger to { var newSigFig = Math.Max(rewardBase.SigFig, RecommendedSigFig(totalShares)); var multiplier = Multiplier(newSigFig - rewardBase.SigFig); - var newPortion = rewardBase.RewardPortion.ToImmutableDictionary( + var newPortion = rewardBase.RewardPortion.ToImmutableSortedDictionary( kvp => kvp.Key, - kvp => kvp.Value * multiplier); + kvp => kvp.Value * multiplier, + _currencyComparer); return new RewardBase( rewardBase.Address, @@ -233,7 +234,7 @@ public bool Equals(RewardBase? other) || (other is RewardBase rewardBase && Address == rewardBase.Address && TotalShares == rewardBase.TotalShares - && RewardPortion.Equals(rewardBase.RewardPortion) + && RewardPortion.SequenceEqual(rewardBase.RewardPortion) && SigFig == rewardBase.SigFig); public override int GetHashCode()