diff --git a/neo/Consensus/ConsensusContext.cs b/neo/Consensus/ConsensusContext.cs index 9daa7402f7..583fdc3aa8 100644 --- a/neo/Consensus/ConsensusContext.cs +++ b/neo/Consensus/ConsensusContext.cs @@ -218,13 +218,9 @@ public ConsensusPayload MakePrepareRequest() List transactions = memoryPoolTransactions.ToList(); - uint maxBlockSize; - Transactions = new Dictionary(); - using (var snapshot = Blockchain.Singleton.GetSnapshot()) - { - maxBlockSize = NativeContract.Policy.GetMaxBlockSize(snapshot); - TransactionHashes = new UInt256[NativeContract.Policy.GetMaxTransactionsPerBlock(snapshot)]; - } + Transactions = new Dictionary(); + uint maxBlockSize = NativeContract.Policy.GetMaxBlockSize(Snapshot); + TransactionHashes = new UInt256[NativeContract.Policy.GetMaxTransactionsPerBlock(Snapshot)]; // Prevent that block exceed the max size diff --git a/neo/Consensus/ConsensusService.cs b/neo/Consensus/ConsensusService.cs index e7860ec323..b82fdb4e1d 100644 --- a/neo/Consensus/ConsensusService.cs +++ b/neo/Consensus/ConsensusService.cs @@ -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