Skip to content

Commit

Permalink
Optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon committed Jul 26, 2019
1 parent 618d2d9 commit 4a111bc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
10 changes: 3 additions & 7 deletions neo/Consensus/ConsensusContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,9 @@ public ConsensusPayload MakePrepareRequest()

List<Transaction> transactions = memoryPoolTransactions.ToList();

uint maxBlockSize;
Transactions = new Dictionary<UInt256, Transaction>();
using (var snapshot = Blockchain.Singleton.GetSnapshot())
{
maxBlockSize = NativeContract.Policy.GetMaxBlockSize(snapshot);
TransactionHashes = new UInt256[NativeContract.Policy.GetMaxTransactionsPerBlock(snapshot)];
}
Transactions = new Dictionary<UInt256, Transaction>();
uint maxBlockSize = NativeContract.Policy.GetMaxBlockSize(Snapshot);
TransactionHashes = new UInt256[NativeContract.Policy.GetMaxTransactionsPerBlock(Snapshot)];

// Prevent that block exceed the max size

Expand Down
23 changes: 10 additions & 13 deletions neo/Consensus/ConsensusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,16 @@ private bool AddTransaction(Transaction tx, bool verify)
{
// if we are the primary for this view, but acting as a backup because we recovered our own
// previously sent prepare request, then we don't want to send a prepare response.
if (context.IsPrimary || context.WatchOnly) return true;

// Check policy
using (var snapshot = Blockchain.Singleton.GetSnapshot())
{
var block = context.CreateBlock();

if (block.Size > NativeContract.Policy.GetMaxBlockSize(snapshot))
{
Log($"rejected block: {block.Hash}{Environment.NewLine} The size '{block.Size}' exceed the policy", LogLevel.Warning);
RequestChangeView(ChangeViewReason.BlockRejectedByPolicy);
return false;
}
if (context.IsPrimary || context.WatchOnly) return true;

// Check policy
var block = context.CreateBlock();

if (block.Size > NativeContract.Policy.GetMaxBlockSize(context.Snapshot))
{
Log($"rejected block: {block.Hash}{Environment.NewLine} The size '{block.Size}' exceed the policy", LogLevel.Warning);
RequestChangeView(ChangeViewReason.BlockRejectedByPolicy);
return false;
}

// Timeout extension due to prepare response sent
Expand Down

0 comments on commit 4a111bc

Please sign in to comment.