Skip to content

Commit

Permalink
Merge pull request #2487 from limebell/dpos/get-worldstate
Browse files Browse the repository at this point in the history
Modify Get methods to take `IWorldState`
  • Loading branch information
limebell authored Mar 26, 2024
2 parents 21b7ce3 + 520bba6 commit 6da9f8a
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 21 deletions.
8 changes: 4 additions & 4 deletions Lib9c.DPoS.Tests/DistributeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ public void ValidatorSetTest()
= (validatorRewardSum * 205)
.DivRem(100 + (101 + 200) * 50 - 101 - 102 + 204 + 306);
var (commissionA, _)
= (validatorRewardA * Validator.CommissionNumer)
.DivRem(Validator.CommissionDenom);
= (validatorRewardA * Validator.CommissionNumerator)
.DivRem(Validator.CommissionDenominator);
var (validatorRewardB, _)
= (validatorRewardSum * 307)
.DivRem(100 + (101 + 200) * 50 - 101 - 102 + 204 + 306);
var (commissionB, _)
= (validatorRewardB * Validator.CommissionNumer)
.DivRem(Validator.CommissionDenom);
= (validatorRewardB * Validator.CommissionNumerator)
.DivRem(Validator.CommissionDenominator);

Assert.Equal(
Asset.ConsensusToken * 0,
Expand Down
4 changes: 2 additions & 2 deletions Lib9c.DPoS/Action/DPoSModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace Lib9c.DPoS.Action
{
public static class DPoSModule
{
public static IValue? GetDPoSState(this IWorld world, Address address)
public static IValue? GetDPoSState(this IWorldState world, Address address)
{
return world.GetAccount(ReservedAddress.DPoSAccountAddress).GetState(address);
return world.GetAccountState(ReservedAddress.DPoSAccountAddress).GetState(address);
}

public static IWorld SetDPoSState(this IWorld world, Address address, IValue value)
Expand Down
4 changes: 2 additions & 2 deletions Lib9c.DPoS/Control/AllocateReward.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ FungibleAssetValue powerDenom
= (validatorRewardSum * powerNumer.RawValue)

Check warning on line 153 in Lib9c.DPoS/Control/AllocateReward.cs

View workflow job for this annotation

GitHub Actions / typos

"Numer" should be "Number".
.DivRem(powerDenom.RawValue);
var (commission, _)
= (validatorReward * Validator.CommissionNumer)
.DivRem(Validator.CommissionDenom);
= (validatorReward * Validator.CommissionNumerator)
.DivRem(Validator.CommissionDenominator);

FungibleAssetValue delegationRewardSum = validatorReward - commission;

Expand Down
4 changes: 1 addition & 3 deletions Lib9c.DPoS/Control/DelegateCtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ namespace Lib9c.DPoS.Control
{
internal static class DelegateCtrl
{
internal static Delegation? GetDelegation(
IWorld states,
Address delegationAddress)
internal static Delegation? GetDelegation(IWorldState states, Address delegationAddress)
{
if (states.GetDPoSState(delegationAddress) is { } value)
{
Expand Down
2 changes: 1 addition & 1 deletion Lib9c.DPoS/Control/RedelegateCtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Lib9c.DPoS.Control
internal static class RedelegateCtrl
{
internal static Redelegation? GetRedelegation(
IWorld states,
IWorldState states,
Address redelegationAddress)
{
if (states.GetDPoSState(redelegationAddress) is { } value)
Expand Down
10 changes: 10 additions & 0 deletions Lib9c.DPoS/Control/UnbondingSetCtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ namespace Lib9c.DPoS.Control
{
internal static class UnbondingSetCtrl
{
internal static UnbondingSet? GetUnbondingSet(IWorldState states)
{
if (states.GetDPoSState(ReservedAddress.UnbondingSet) is { } value)
{
return new UnbondingSet(value);
}

return null;
}

internal static (IWorld, UnbondingSet) FetchUnbondingSet(IWorld states)
{
UnbondingSet unbondingSet;
Expand Down
2 changes: 1 addition & 1 deletion Lib9c.DPoS/Control/UndelegateCtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Lib9c.DPoS.Control
internal static class UndelegateCtrl
{
internal static Undelegation? GetUndelegation(
IWorld state,
IWorldState state,
Address undelegationAddress)
{
if (state.GetDPoSState(undelegationAddress) is { } value)
Expand Down
4 changes: 1 addition & 3 deletions Lib9c.DPoS/Control/ValidatorCtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ namespace Lib9c.DPoS.Control
{
internal static class ValidatorCtrl
{
internal static Validator? GetValidator(
IWorld states,
Address validatorAddress)
internal static Validator? GetValidator(IWorldState states, Address validatorAddress)
{
if (states.GetDPoSState(validatorAddress) is { } value)
{
Expand Down
14 changes: 14 additions & 0 deletions Lib9c.DPoS/Control/ValidatorDelegationSetCtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ namespace Lib9c.DPoS.Control
{
internal static class ValidatorDelegationSetCtrl
{
internal static ValidatorDelegationSet? GetValidatorDelegationSet(
IWorldState states, Address validatorAddress)
{
Address validatorDelegationSetAddress = ValidatorDelegationSet.DeriveAddress(
validatorAddress);

if (states.GetDPoSState(validatorDelegationSetAddress) is { } value)
{
return new ValidatorDelegationSet(value);
}

return null;
}

internal static (IWorld, ValidatorDelegationSet) FetchValidatorDelegationSet(
IWorld states, Address validatorAddress)
{
Expand Down
13 changes: 11 additions & 2 deletions Lib9c.DPoS/Control/ValidatorPowerIndexCtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,17 @@ namespace Lib9c.DPoS.Control
{
internal static class ValidatorPowerIndexCtrl
{
internal static (IWorld, ValidatorPowerIndex) FetchValidatorPowerIndex(
IWorld states)
internal static ValidatorPowerIndex? GetValidatorPowerIndex(IWorldState states)
{
if (states.GetDPoSState(ReservedAddress.ValidatorPowerIndex) is { } value)
{
return new ValidatorPowerIndex(value);
}

return null;
}

internal static (IWorld, ValidatorPowerIndex) FetchValidatorPowerIndex(IWorld states)
{
ValidatorPowerIndex validatorPowerIndex;
if (states.GetDPoSState(ReservedAddress.ValidatorPowerIndex) is { } value)
Expand Down
2 changes: 1 addition & 1 deletion Lib9c.DPoS/Control/ValidatorRewardsCtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Lib9c.DPoS.Control
internal static class ValidatorRewardsCtrl
{
internal static ValidatorRewards? GetValidatorRewards(
IWorld states,
IWorldState states,
Address validatorAddress)
{
if (states.GetDPoSState(validatorAddress) is { } value)
Expand Down
10 changes: 10 additions & 0 deletions Lib9c.DPoS/Control/ValidatorSetCtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ namespace Lib9c.DPoS.Control
{
internal static class ValidatorSetCtrl
{
internal static ValidatorSet? GetValidatorSet(IWorldState states, Address address)
{
if (states.GetDPoSState(address) is { } value)
{
return new ValidatorSet(value);
}

return null;
}

internal static (IWorld, ValidatorSet) FetchValidatorSet(IWorld states, Address address)
{
ValidatorSet validatorSet;
Expand Down
4 changes: 2 additions & 2 deletions Lib9c.DPoS/Model/Validator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public Validator(IValue serialized)
// May be it would be better to be serialized
public static FungibleAssetValue MinSelfDelegation => Asset.ConsensusToken * 1;

public static BigInteger CommissionNumer => 1;
public static BigInteger CommissionNumerator => 1;

public static BigInteger CommissionDenom => 10;
public static BigInteger CommissionDenominator => 10;

public static double CommissionMaxRate => 0.2;

Expand Down
4 changes: 4 additions & 0 deletions Lib9c.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mimisbrunnr/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Minterless/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nekoyume/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Redelegation/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=RUNESTONE/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Soulstone/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tradable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=unbonded/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unbonding/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Undelegation/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unequip/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=unrender/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

0 comments on commit 6da9f8a

Please sign in to comment.