Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize mempool message #1068

Merged
merged 7 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions neo/Ledger/Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ private void OnNewHeaders(Header[] headers)
system.TaskManager.Tell(new TaskManager.HeaderTaskCompleted(), Sender);
}

private RelayResultReason OnNewTransaction(Transaction transaction)
private RelayResultReason OnNewTransaction(Transaction transaction, bool relay)
shargon marked this conversation as resolved.
Show resolved Hide resolved
{
if (ContainsTransaction(transaction.Hash))
return RelayResultReason.AlreadyExists;
Expand All @@ -377,8 +377,8 @@ private RelayResultReason OnNewTransaction(Transaction transaction)

if (!MemPool.TryAdd(transaction.Hash, transaction))
return RelayResultReason.OutOfMemory;

system.LocalNode.Tell(new LocalNode.RelayDirectly { Inventory = transaction });
if (relay)
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
system.LocalNode.Tell(new LocalNode.RelayDirectly { Inventory = transaction });
return RelayResultReason.Succeed;
}

Expand All @@ -405,8 +405,14 @@ protected override void OnReceive(object message)
case Block block:
Sender.Tell(OnNewBlock(block));
break;
case Transaction[] transactions:
{
// This message comes from a mempool's revalidation, already relayed
foreach (var tx in transactions) OnNewTransaction(tx, false);
break;
}
case Transaction transaction:
Sender.Tell(OnNewTransaction(transaction));
Sender.Tell(OnNewTransaction(transaction, true));
break;
case ConsensusPayload payload:
Sender.Tell(OnNewConsensus(payload));
Expand Down
7 changes: 6 additions & 1 deletion neo/Ledger/MemoryPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,14 @@ internal void UpdatePoolForBlockPersisted(Block block, Snapshot snapshot)

if (policyChanged)
{
var tx = new List<Transaction>();
foreach (PoolItem item in _unverifiedSortedTransactions.Reverse())
if (item.Tx.FeePerByte >= _feePerByte)
_system.Blockchain.Tell(item.Tx, ActorRefs.NoSender);
tx.Add(item.Tx);

if (tx.Count > 0)
_system.Blockchain.Tell(tx.ToArray(), ActorRefs.NoSender);

_unverifiedTransactions.Clear();
vncoelho marked this conversation as resolved.
Show resolved Hide resolved
_unverifiedSortedTransactions.Clear();
}
Expand Down