-
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.
- Loading branch information
Showing
20 changed files
with
1,108 additions
and
23 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
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,30 @@ | ||
using System; | ||
using System.Numerics; | ||
|
||
namespace Nekoyume.Action.DPoS.Control | ||
{ | ||
public static class Environment | ||
{ | ||
public const long SignedBlocksWindow = 10000; | ||
|
||
public const double MinSignedPerWindow = 0.5; | ||
|
||
public static readonly TimeSpan DowntimeJailDuration = TimeSpan.FromSeconds(60); | ||
|
||
public static readonly BigInteger SlashFractionDoubleSign = new BigInteger(20); // 0.05 | ||
|
||
public static readonly BigInteger SlashFractionDowntime = new BigInteger(10000); // 0.0001 | ||
|
||
public const long ValidatorUpdateDelay = 1; | ||
|
||
public const long MaxAgeNumBlocks = 100000; | ||
|
||
public static readonly TimeSpan MaxAgeDuration = TimeSpan.FromSeconds(172800); // s (즉, 48시간) | ||
|
||
public const long MaxBytes = 1048576; // (즉, 1MB) | ||
|
||
public static readonly DateTimeOffset DoubleSignJailEndTime = DateTimeOffset.FromUnixTimeSeconds(253402300799); | ||
|
||
public const int MissedBlockBitmapChunkSize = 1024; | ||
} | ||
} |
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,97 @@ | ||
#nullable enable | ||
using Nekoyume.Action.DPoS.Exception; | ||
using Nekoyume.Action.DPoS.Model; | ||
using Libplanet.Action; | ||
using Libplanet.Action.State; | ||
using Libplanet.Crypto; | ||
using System.Collections.Immutable; | ||
using Libplanet.Types.Assets; | ||
|
||
namespace Nekoyume.Action.DPoS.Control | ||
{ | ||
internal static class EvidenceCtrl | ||
{ | ||
internal static Evidence? GetEvidence(IWorldState states, Address validatorAddress) | ||
{ | ||
var address = Evidence.DeriveAddress(validatorAddress); | ||
if (states.GetDPoSState(address) is { } value) | ||
{ | ||
return new Evidence(value); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
internal static IWorld SetEvidence(IWorld world, Evidence evidence) | ||
{ | ||
var address = Evidence.DeriveAddress(evidence.Address); | ||
var value = evidence.Serialize(); | ||
return world.SetDPoSState(address, value); | ||
} | ||
|
||
internal static IWorld Remove(IWorld world, Evidence evidence) | ||
{ | ||
var address = Evidence.DeriveAddress(evidence.Address); | ||
return world.RemoveDPoSState(address); | ||
} | ||
|
||
internal static IWorld Execute( | ||
IWorld world, | ||
IActionContext actionContext, | ||
Address validatorAddress, | ||
Evidence evidence, | ||
IImmutableSet<Currency> nativeTokens) | ||
{ | ||
if (!(ValidatorCtrl.GetValidator(world, validatorAddress) is { } validator)) | ||
{ | ||
throw new NullValidatorException(validatorAddress); | ||
} | ||
|
||
if (validator.Status == BondingStatus.Unbonded) | ||
{ | ||
return world; | ||
} | ||
|
||
var blockHeight = actionContext.BlockIndex; | ||
var infractionHeight = evidence.Height; | ||
var ageBlocks = blockHeight - infractionHeight; | ||
|
||
if (ageBlocks > Environment.MaxAgeNumBlocks) | ||
{ | ||
return world; | ||
} | ||
|
||
if (ValidatorCtrl.IsTombstoned(world, validatorAddress)) | ||
{ | ||
return world; | ||
} | ||
|
||
var distributionHeight = infractionHeight - Environment.ValidatorUpdateDelay; | ||
var slashFractionDoubleSign = Environment.SlashFractionDoubleSign; | ||
|
||
world = SlashCtrl.SlashWithInfractionReason( | ||
world, | ||
actionContext, | ||
validatorAddress, | ||
distributionHeight, | ||
evidence.Power, | ||
slashFractionDoubleSign, | ||
Infraction.DoubleSign, | ||
nativeTokens | ||
); | ||
|
||
if (!validator.Jailed) | ||
{ | ||
world = ValidatorCtrl.Jail(world, validatorAddress); | ||
} | ||
|
||
world = ValidatorCtrl.JailUntil( | ||
world: world, | ||
validatorAddress: validatorAddress, | ||
blockHeight: long.MaxValue); | ||
world = ValidatorCtrl.Tombstone(world, validatorAddress); | ||
world = Remove(world, evidence); | ||
return world; | ||
} | ||
} | ||
} |
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.