-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2507 from limebell/dpos/actionbase
Separate PoSAction and implement ActionBase
- Loading branch information
Showing
10 changed files
with
132 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System.Collections.Immutable; | ||
using Bencodex.Types; | ||
using Libplanet.Action; | ||
using Libplanet.Action.State; | ||
using Nekoyume.Action.DPoS.Control; | ||
using Nekoyume.Action.DPoS.Misc; | ||
using Nekoyume.Action.DPoS.Model; | ||
using Nekoyume.Module; | ||
|
||
namespace Nekoyume.Action.DPoS | ||
{ | ||
/// <summary> | ||
/// A BeginBlock action for DPoS that updates <see cref="ValidatorSet"/>. | ||
/// </summary> | ||
public sealed class DPoSBeginBlockAction : ActionBase | ||
{ | ||
/// <summary> | ||
/// Creates a new instance of <see cref="DPoSBeginBlockAction"/>. | ||
/// </summary> | ||
public DPoSBeginBlockAction() | ||
{ | ||
} | ||
|
||
/// <inheritdoc cref="IAction.PlainValue"/> | ||
public override IValue PlainValue => new Bencodex.Types.Boolean(true); | ||
|
||
/// <inheritdoc cref="IAction.LoadPlainValue(IValue)"/> | ||
public override void LoadPlainValue(IValue plainValue) | ||
{ | ||
// Method intentionally left empty. | ||
} | ||
|
||
/// <inheritdoc cref="IAction.Execute(IActionContext)"/> | ||
public override IWorld Execute(IActionContext context) | ||
{ | ||
var states = context.PreviousState; | ||
|
||
// Allocate reward | ||
var nativeTokens = ImmutableHashSet.Create( | ||
Asset.GovernanceToken, Asset.ConsensusToken, Asset.Share); | ||
states = AllocateReward.Execute( | ||
states, | ||
context, | ||
nativeTokens, | ||
context.LastCommit?.Votes, | ||
context.Miner); | ||
|
||
return states; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System.Collections.Immutable; | ||
using Bencodex.Types; | ||
using Libplanet.Action; | ||
using Libplanet.Action.State; | ||
using Nekoyume.Action.DPoS.Control; | ||
using Nekoyume.Action.DPoS.Misc; | ||
using Nekoyume.Action.DPoS.Model; | ||
using Nekoyume.Module; | ||
|
||
namespace Nekoyume.Action.DPoS | ||
{ | ||
/// <summary> | ||
/// A EndBlock action for DPoS that updates <see cref="ValidatorSet"/>. | ||
/// </summary> | ||
public sealed class DPoSEndBlockAction : ActionBase | ||
{ | ||
/// <summary> | ||
/// Creates a new instance of <see cref="DPoSBeginBlockAction"/>. | ||
/// </summary> | ||
public DPoSEndBlockAction() | ||
{ | ||
} | ||
|
||
/// <inheritdoc cref="IAction.PlainValue"/> | ||
public override IValue PlainValue => new Bencodex.Types.Boolean(true); | ||
|
||
/// <inheritdoc cref="IAction.LoadPlainValue(IValue)"/> | ||
public override void LoadPlainValue(IValue plainValue) | ||
{ | ||
// Method intentionally left empty. | ||
} | ||
|
||
/// <inheritdoc cref="IAction.Execute(IActionContext)"/> | ||
public override IWorld Execute(IActionContext context) | ||
{ | ||
var states = context.PreviousState; | ||
|
||
// Update ValidatorSet | ||
states = ValidatorSetCtrl.Update(states, context); | ||
ValidatorSet bondedSet; | ||
(states, bondedSet) = ValidatorSetCtrl.FetchBondedValidatorSet(states); | ||
foreach (var validator in bondedSet.Set) | ||
{ | ||
states = states.SetValidator( | ||
new Libplanet.Types.Consensus.Validator( | ||
validator.OperatorPublicKey, | ||
validator.ConsensusToken.RawValue)); | ||
} | ||
|
||
return states; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.