Skip to content

Commit

Permalink
bugfix: fix logic error in dpos methods
Browse files Browse the repository at this point in the history
  • Loading branch information
limebell committed Apr 9, 2024
1 parent 24bca50 commit 939328c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 0 additions & 2 deletions Lib9c/Action/DPoS/Control/Bond.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ internal static (IWorld, FungibleAssetValue) Cancel(
Address delegationAddress,
IImmutableSet<Currency> nativeTokens)
{
long blockHeight = ctx.BlockIndex;

// Currency check
if (!share.Currency.Equals(Asset.Share))
{
Expand Down
7 changes: 7 additions & 0 deletions Lib9c/Action/DPoS/Control/DelegateCtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Nekoyume.Action.DPoS.Model;
using Nekoyume.Action.DPoS.Util;
using Nekoyume.Module;
using Serilog;

namespace Nekoyume.Action.DPoS.Control
{
Expand Down Expand Up @@ -122,6 +123,12 @@ internal static IWorld Distribute(
delegation.LatestDistributeHeight,
blockHeight);

// Skip if there is no reward to distribute.
if (delegationRewardSum.RawValue == 0)
{
continue;
}

if (!(ValidatorCtrl.TokenPortionByShare(
states,
delegation.ValidatorAddress,
Expand Down
17 changes: 11 additions & 6 deletions Lib9c/Action/DPoS/Control/ValidatorCtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,17 @@ internal static IWorld Unbond(
validator.UnbondingCompletionBlockHeight = blockHeight + UnbondingSet.Period;
if (validator.Status == BondingStatus.Bonded)
{
states = states.TransferAsset(
ctx,
ReservedAddress.BondedPool,
ReservedAddress.UnbondedPool,
Asset.GovernanceFromConsensus(
states.GetBalance(validator.Address, Asset.ConsensusToken)));
var consensusToken = states.GetBalance(validator.Address, Asset.ConsensusToken);
if (consensusToken.RawValue > 0)
{
// Transfer consensus token to unbonded pool if remaining.
states = states.TransferAsset(
ctx,
ReservedAddress.BondedPool,
ReservedAddress.UnbondedPool,
Asset.GovernanceFromConsensus(
states.GetBalance(validator.Address, Asset.ConsensusToken)));
}
}

validator.Status = BondingStatus.Unbonding;
Expand Down

0 comments on commit 939328c

Please sign in to comment.