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

Fix claim #34

Merged
merged 21 commits into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from 10 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
8 changes: 4 additions & 4 deletions SimplePolicy.UnitTests/SimplePolicy.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="4.19.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
<PackageReference Include="FluentAssertions" Version="5.5.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 6 additions & 2 deletions SimplePolicy/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Microsoft.Extensions.Configuration;
using Neo.Wallets;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Configuration;
using Neo.Network.P2P.Payloads;
using Neo.Wallets;

namespace Neo.Plugins
{
Expand All @@ -13,6 +14,7 @@ internal class Settings
public int MaxFreeTransactionSize { get; }
public Fixed8 FeePerExtraByte { get; }
public BlockedAccounts BlockedAccounts { get; }
public HashSet<TransactionType> HighPriorityTxType { get; set; }

public static Settings Default { get; private set; }

Expand All @@ -23,6 +25,8 @@ private Settings(IConfigurationSection section)
this.MaxFreeTransactionSize = GetValueOrDefault(section.GetSection("MaxFreeTransactionSize"), 1024, p => int.Parse(p));
this.FeePerExtraByte = GetValueOrDefault(section.GetSection("FeePerExtraByte"), Fixed8.FromDecimal(0.00001M), p => Fixed8.Parse(p));
this.BlockedAccounts = new BlockedAccounts(section.GetSection("BlockedAccounts"));
this.HighPriorityTxType = new HashSet<TransactionType>(section.GetSection("HighPriorityTxType").GetChildren()
.Select(p => (TransactionType)Enum.Parse(typeof(TransactionType), p.Value)));
}

public T GetValueOrDefault<T>(IConfigurationSection section, T defaultValue, Func<string, T> selector)
Expand Down
6 changes: 5 additions & 1 deletion SimplePolicy/SimplePolicy/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
"MaxFreeTransactionsPerBlock": 20,
"MaxFreeTransactionSize": 1024,
"FeePerExtraByte": 0.00001,
"HighPriorityTxType":
[
"ClaimTransaction"
],
"BlockedAccounts": {
"Type": "AllowAll",
"List": []
}
}
}
}
15 changes: 11 additions & 4 deletions SimplePolicy/SimplePolicyPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static IEnumerable<Transaction> FilterForBlock_Policy1(IEnumerable<Trans
foreach (Transaction tx in transactions.OrderByDescending(p => p.NetworkFee / p.Size).ThenByDescending(p => p.NetworkFee))
{
if (count++ >= Settings.Default.MaxTransactionsPerBlock - 1) break;
if (!tx.IsLowPriority || count_free++ < Settings.Default.MaxFreeTransactionsPerBlock)
if (!IsLowPriority(tx) || count_free++ < Settings.Default.MaxFreeTransactionsPerBlock)
yield return tx;
}
}
Expand All @@ -60,13 +60,13 @@ private static IEnumerable<Transaction> FilterForBlock_Policy2(IEnumerable<Trans
if (!(transactions is IReadOnlyList<Transaction> tx_list))
tx_list = transactions.ToArray();

Transaction[] free = tx_list.Where(p => p.IsLowPriority)
Transaction[] free = tx_list.Where(p => IsLowPriority(p))
.OrderByDescending(p => p.NetworkFee / p.Size)
.ThenByDescending(p => p.NetworkFee)
.Take(Settings.Default.MaxFreeTransactionsPerBlock)
.ToArray();

Transaction[] non_free = tx_list.Where(p => !p.IsLowPriority)
Transaction[] non_free = tx_list.Where(p => !IsLowPriority(p))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, ClaimTx will enter here because its not LowPriority, correct? This is the part Im trying to.test (but will only be able to finish tomorrow). If ClaimTx netfee is always zero, wouldnt it be sent forever to the end of the queue?
I guess Peter mentioned this situation... so if thats the case, we will need to insert it together with the free tx (20 maximum), with bigger priority than all other free tx, and not subject to maxfreetxsizelimit. Please confirm if Im mistaken here.

.OrderByDescending(p => p.NetworkFee / p.Size)
.ThenByDescending(p => p.NetworkFee)
.Take(Settings.Default.MaxTransactionsPerBlock - free.Length - 1)
Expand All @@ -93,7 +93,7 @@ void ILogPlugin.Log(string source, LogLevel level, string message)
private bool VerifySizeLimits(Transaction tx)
{
// Not Allow free TX bigger than MaxFreeTransactionSize
if (tx.IsLowPriority && tx.Size > Settings.Default.MaxFreeTransactionSize) return false;
if (IsLowPriority(tx) && tx.Size > Settings.Default.MaxFreeTransactionSize) return false;
Copy link
Contributor

@igormcoelho igormcoelho Dec 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok ClaimTx wont enter here, because its not LowPriority, right? So its not limited to MaxFreeTransactionSize right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to enable and disable this in the config, but yes


// Require proportional fee for TX bigger than MaxFreeTransactionSize
if (tx.Size > Settings.Default.MaxFreeTransactionSize)
Expand All @@ -104,5 +104,12 @@ private bool VerifySizeLimits(Transaction tx)
}
return true;
}

private static bool IsLowPriority(Transaction tx)
{
if (Settings.Default.HighPriorityTxType.Contains(tx.Type)) return false;

return tx.IsLowPriority;
}
}
}