[neo-project/neo] Prioritize verification of higher fee TXs and do not starve RpcServer w/ Large mempool (#356)

jsolman commented on this pull request.

> Transaction[] transactions;
lock (temp_pool)
{
if (temp_pool.Count == 0) continue;
— transactions = temp_pool.ToArray();
— temp_pool.Clear();
+ if (temp_pool.Count < 1000) I should make the 1000 here a constant to make it more easily configurable > Transaction[] transactions;
lock (temp_pool)
{
if (temp_pool.Count == 0) continue;
— transactions = temp_pool.ToArray();
— temp_pool.Clear();
+ if (temp_pool.Count < 1000) + { + transactions = temp_pool.ToArray(); + temp_pool.Clear(); + } + else + { + // Attempt verifying large fee transactions first. + transactions = temp_pool + .OrderBy(p => p.NetworkFee / p.Size)
+ .ThenBy(p => p.NetworkFee)
+ .ThenBy(p => new BigInteger(p.Hash.ToArray()))
+ .Take(1000)

Ditto, this should be the same constant mentioned above.

> Transaction[] transactions;
lock (temp_pool)
{
if (temp_pool.Count == 0) continue;
— transactions = temp_pool.ToArray();
— temp_pool.Clear();
+ if (temp_pool.Count < 1000) would be a bit more accurate actually if the condition were <= instead of <, but it doesn't make much of a difference just optimizes for the case that temp_pool.Count is exactly 1000. > @@ -217,8 +253,10 @@ private void Blockchain_PersistCompleted(object sender, Block block)

remain = mem_pool.Values.ToArray();
mem_pool.Clear();

— if (millisSinceLastBlock > 10000)
+
+ // Use normal AddTransactionLoop to verify if there is a large mem_pool to avoid
+ // starvation of RpcSerer with large mem_pool.
+ if (millisSinceLastBlock > 10000 && remain.Length < 1000) I should probably make these numbers constants also.