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

Expose HighPriorityTxType #39

Merged
merged 9 commits into from
Jan 20, 2019
Merged
Changes from 5 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
9 changes: 5 additions & 4 deletions SimplePolicy/SimplePolicyPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ public IEnumerable<Transaction> FilterForBlock(IEnumerable<Transaction> transact

public int MaxTxPerBlock => Settings.Default.MaxTransactionsPerBlock;
public int MaxLowPriorityTxPerBlock => Settings.Default.MaxFreeTransactionsPerBlock;
public EnumSet<TransactionType> HigherLowPriorityTxTypes => Settings.Default.HighPriorityTxType;

private static IEnumerable<Transaction> FilterForBlock_Policy1(IEnumerable<Transaction> transactions)
{
int count = 0, count_free = 0;
foreach (Transaction tx in transactions.OrderByDescending(p => p.NetworkFee / p.Size).ThenByDescending(p => p.NetworkFee).ThenByDescending(p => InHighPriorityList(p)))
foreach (Transaction tx in transactions.OrderByDescending(p => p.NetworkFee / p.Size).ThenByDescending(p => p.NetworkFee).ThenByDescending(p => InHigherLowPriorityList(p)))
{
if (count++ >= Settings.Default.MaxTransactionsPerBlock - 1) break;
if (!tx.IsLowPriority || count_free++ < Settings.Default.MaxFreeTransactionsPerBlock)
Expand All @@ -66,7 +67,7 @@ private static IEnumerable<Transaction> FilterForBlock_Policy2(IEnumerable<Trans
Transaction[] free = tx_list.Where(p => p.IsLowPriority)
.OrderByDescending(p => p.NetworkFee / p.Size)
.ThenByDescending(p => p.NetworkFee)
.ThenByDescending(p => InHighPriorityList(p))
.ThenByDescending(p => InHigherLowPriorityList(p))
.Take(Settings.Default.MaxFreeTransactionsPerBlock)
.ToArray();

Expand Down Expand Up @@ -96,7 +97,7 @@ void ILogPlugin.Log(string source, LogLevel level, string message)

private bool VerifySizeLimits(Transaction tx)
{
if (InHighPriorityList(tx)) return true;
if (InHigherLowPriorityList(tx)) return true;

// Not Allow free TX bigger than MaxFreeTransactionSize
if (tx.IsLowPriority && tx.Size > Settings.Default.MaxFreeTransactionSize) return false;
Expand All @@ -112,6 +113,6 @@ private bool VerifySizeLimits(Transaction tx)
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool InHighPriorityList(Transaction tx) => Settings.Default.HighPriorityTxType.Contains(tx.Type);
private static bool InHigherLowPriorityList(Transaction tx) => Settings.Default.HighPriorityTxType.Contains(tx.Type);
vncoelho marked this conversation as resolved.
Show resolved Hide resolved
}
}