-
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 #330 from LATOKEN/binary-broadcast-spam-bug-fix
Binary broadcast spam bug fix
- Loading branch information
Showing
3 changed files
with
85 additions
and
1 deletion.
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,46 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.CompilerServices; | ||
using Lachain.Logger; | ||
using Lachain.Consensus.BinaryAgreement; | ||
using Lachain.Consensus; | ||
using Lachain.Consensus.Messages; | ||
using Lachain.Proto; | ||
using Lachain.Utility.Utils; | ||
|
||
namespace Lachain.ConsensusTest | ||
{ | ||
public class BinaryBroadcastSpammer : BinaryBroadcast | ||
{ | ||
private readonly BinaryBroadcastId _broadcastId; | ||
public BinaryBroadcastSpammer( | ||
BinaryBroadcastId broadcastId, IPublicConsensusKeySet wallet, IConsensusBroadcaster broadcaster) | ||
: base(broadcastId, wallet, broadcaster) | ||
{ | ||
_broadcastId = broadcastId; | ||
} | ||
|
||
public void SpamBVal(bool bval) | ||
{ | ||
var b = bval ? 1 : 0; | ||
var msg = CreateBValMessage(b); | ||
for (int i = 0 ; i < N ; i++) Broadcaster.Broadcast(msg); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.Synchronized)] | ||
private ConsensusMessage CreateBValMessage(int value) | ||
{ | ||
var message = new ConsensusMessage | ||
{ | ||
Bval = new BValMessage | ||
{ | ||
Agreement = _broadcastId.Agreement, | ||
Epoch = _broadcastId.Epoch, | ||
Value = value == 1 | ||
} | ||
}; | ||
return message; | ||
} | ||
} | ||
} |
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