From e2ad61e06cc562db062440f9592aae7601e22416 Mon Sep 17 00:00:00 2001 From: ZhangTao1596 Date: Tue, 14 Jun 2022 10:28:12 +0800 Subject: [PATCH] apply https://github.com/neo-project/neo/issues/2058 --- .../Consensus/ConsensusContext.MakePayload.cs | 14 +++++++++++++- src/DBFTPlugin/Consensus/ConsensusContext.cs | 3 +++ .../Consensus/ConsensusService.OnMessage.cs | 3 ++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/DBFTPlugin/Consensus/ConsensusContext.MakePayload.cs b/src/DBFTPlugin/Consensus/ConsensusContext.MakePayload.cs index 8fba17d9e..390545ec1 100644 --- a/src/DBFTPlugin/Consensus/ConsensusContext.MakePayload.cs +++ b/src/DBFTPlugin/Consensus/ConsensusContext.MakePayload.cs @@ -105,9 +105,21 @@ internal void EnsureMaxBlockLimitation(IEnumerable txs, uint pID) TransactionHashes[pID] = hashes.ToArray(); } + internal IEnumerable PickTransactions() + { + var verifiedTxes = neoSystem.MemPool.GetSortedVerifiedTransactions(); + if (ViewNumber > 0 && LastProposal.Length > 0) + { + var txes = verifiedTxes.Where(p => LastProposal.Contains(p.Hash)); + if (txes.Count() > LastProposal.Length / 2) + return txes; + } + return verifiedTxes; + } + public ExtensiblePayload MakePrepareRequest(uint pID) { - EnsureMaxBlockLimitation(neoSystem.MemPool.GetSortedVerifiedTransactions(), pID); + EnsureMaxBlockLimitation(PickTransactions(), pID); Block[pID].Header.Timestamp = Math.Max(TimeProvider.Current.UtcNow.ToTimestampMS(), PrevHeader.Timestamp + 1); Block[pID].Header.Nonce = GetNonce(); diff --git a/src/DBFTPlugin/Consensus/ConsensusContext.cs b/src/DBFTPlugin/Consensus/ConsensusContext.cs index 37f32e4ef..aec03cadd 100644 --- a/src/DBFTPlugin/Consensus/ConsensusContext.cs +++ b/src/DBFTPlugin/Consensus/ConsensusContext.cs @@ -43,6 +43,8 @@ public partial class ConsensusContext : IDisposable, ISerializable public ExtensiblePayload[][] CommitPayloads = new ExtensiblePayload[2][]; public ExtensiblePayload[] ChangeViewPayloads; public ExtensiblePayload[] LastChangeViewPayloads; + public UInt256[] LastProposal; + // LastSeenMessage array stores the height of the last seen message, for each validator. // if this node never heard from validator i, LastSeenMessage[i] will be -1. public Dictionary LastSeenMessage { get; private set; } @@ -252,6 +254,7 @@ public void Reset(byte viewNumber) break; } cachedMessages = new Dictionary(); + LastProposal = Array.Empty(); for (uint pID = 0; pID <= 1; pID++) { Block[pID].Header.MerkleRoot = null; diff --git a/src/DBFTPlugin/Consensus/ConsensusService.OnMessage.cs b/src/DBFTPlugin/Consensus/ConsensusService.OnMessage.cs index dfce488da..0c1f368bb 100644 --- a/src/DBFTPlugin/Consensus/ConsensusService.OnMessage.cs +++ b/src/DBFTPlugin/Consensus/ConsensusService.OnMessage.cs @@ -107,7 +107,8 @@ private void OnPrepareRequestReceived(ExtensiblePayload payload, PrepareRequest context.Block[pOrF].Header.Timestamp = message.Timestamp; context.Block[pOrF].Header.Nonce = message.Nonce; context.TransactionHashes[pOrF] = message.TransactionHashes; - + context.LastProposal = message.TransactionHashes; + context.Transactions[pOrF] = new Dictionary(); context.VerificationContext[pOrF] = new TransactionVerificationContext(); for (int i = 0; i < context.PreparationPayloads[pOrF].Length; i++)