Skip to content

Commit

Permalink
Reduce the length of the array
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon committed Jul 26, 2019
1 parent 4a111bc commit a013394
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions neo/Consensus/ConsensusContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,14 @@ public ConsensusPayload MakePrepareRequest()

Transactions = new Dictionary<UInt256, Transaction>();
uint maxBlockSize = NativeContract.Policy.GetMaxBlockSize(Snapshot);
TransactionHashes = new UInt256[NativeContract.Policy.GetMaxTransactionsPerBlock(Snapshot)];
TransactionHashes = new UInt256[Math.Min(transactions.Count, NativeContract.Policy.GetMaxTransactionsPerBlock(Snapshot))];

// Prevent that block exceed the max size

Block.Transactions = new Transaction[0];
var fixedSize = Block.Size + IO.Helper.GetVarSize(TransactionHashes.Length); // ensure that the var size grows without exceed the max size

for (int x = 0, max = Math.Min(Transactions.Count, transactions.Count); x < max; x++)
for (int x = 0, max = TransactionHashes.Length; x < max; x++)
{
var tx = transactions[x];

Expand All @@ -240,7 +240,10 @@ public ConsensusPayload MakePrepareRequest()

// Truncate null values

Array.Resize(ref TransactionHashes, Transactions.Count);
if (TransactionHashes.Length > Transactions.Count)
{
Array.Resize(ref TransactionHashes, Transactions.Count);
}

// Create valid request

Expand Down

0 comments on commit a013394

Please sign in to comment.