Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhangTao1596 committed Jun 14, 2022
1 parent 11a7747 commit e2ad61e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/DBFTPlugin/Consensus/ConsensusContext.MakePayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,21 @@ internal void EnsureMaxBlockLimitation(IEnumerable<Transaction> txs, uint pID)
TransactionHashes[pID] = hashes.ToArray();
}

internal IEnumerable<Transaction> 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();

Expand Down
3 changes: 3 additions & 0 deletions src/DBFTPlugin/Consensus/ConsensusContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ECPoint, uint> LastSeenMessage { get; private set; }
Expand Down Expand Up @@ -252,6 +254,7 @@ public void Reset(byte viewNumber)
break;
}
cachedMessages = new Dictionary<UInt256, ConsensusMessage>();
LastProposal = Array.Empty<UInt256>();
for (uint pID = 0; pID <= 1; pID++)
{
Block[pID].Header.MerkleRoot = null;
Expand Down
3 changes: 2 additions & 1 deletion src/DBFTPlugin/Consensus/ConsensusService.OnMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UInt256, Transaction>();
context.VerificationContext[pOrF] = new TransactionVerificationContext();
for (int i = 0; i < context.PreparationPayloads[pOrF].Length; i++)
Expand Down

0 comments on commit e2ad61e

Please sign in to comment.