-
Notifications
You must be signed in to change notification settings - Fork 8
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 #261 from LATOKEN/validator-ddos-attack-fix
Validator ddos attack fix
- Loading branch information
Showing
7 changed files
with
307 additions
and
39 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
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,34 @@ | ||
namespace Lachain.Consensus.CommonCoin | ||
{ | ||
public static class CoinToss | ||
{ | ||
/* | ||
RootProtocol requests for one CommonCoin protocol | ||
BinaryAgreement requests many CommonCoin protocols sequentially | ||
For each odd epoch BinaryAgreements takes false, true, result of common coin | ||
So for epoch 1 => false, epoch 3 => true, epoch 5 => result of common coin | ||
and the cycle continues | ||
*/ | ||
public static long TossCoin(long epoch) | ||
{ | ||
return (epoch / 2) % 3; | ||
} | ||
|
||
// epoch will be odd and TossCoin value will be 2 | ||
public static bool CreateCoinId(long epoch) | ||
{ | ||
return (epoch > 0) && ((epoch & 1) != 0) && TossCoin(epoch) == 2; | ||
} | ||
|
||
public static long NextCoinCreationEpoch(long epoch) | ||
{ | ||
return epoch + 6; | ||
} | ||
|
||
public static long TotalValidCommonCoin(long lowEpoch, long highEpoch) | ||
{ | ||
if (!CreateCoinId(lowEpoch) || !CreateCoinId(highEpoch)) return -1; | ||
return (highEpoch - lowEpoch) / 6 + 1; | ||
} | ||
} | ||
} |
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.