diff --git a/neo/Consensus/ConsensusContext.cs b/neo/Consensus/ConsensusContext.cs index 583fdc3aa8..d527e3d029 100644 --- a/neo/Consensus/ConsensusContext.cs +++ b/neo/Consensus/ConsensusContext.cs @@ -220,14 +220,14 @@ public ConsensusPayload MakePrepareRequest() Transactions = new Dictionary(); 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]; @@ -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