Commit d16395c8 authored by Sergei Zubov's avatar Sergei Zubov

Modify fee validation in mempool

Transaction fee is validated before accepting transaction to mempool
parent fe545d5a
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using NBitcoin;
......@@ -186,5 +188,21 @@ namespace Stratis.Bitcoin.Features.MemoryPool
context.SetConflicts.Add(ptxConflicting.GetHash());
}
}
/// <summary>
/// Validates the transaction fee is valid.
/// </summary>
/// <param name="context">Current validation context.</param>
protected override void CheckFee(MempoolValidationContext context)
{
long expectedFee = Convert.ToInt64(context.Transaction.Outputs
.Where(p => !context.Transaction.Inputs.RemoveChangePointer()
.Select(q => context.View.Set.GetOutputFor(q).ScriptPubKey)
.Contains(p.ScriptPubKey))
.Sum(p => p.Value) * this.network.FeeRate);
if (context.ModifiedFees < expectedFee)
context.State.Fail(MempoolErrors.InsufficientFee, $" {context.Fees} < {expectedFee}").Throw();
}
}
}
\ No newline at end of file
......@@ -153,7 +153,7 @@ namespace Stratis.Bitcoin.Features.MemoryPool
// public long LastTime;
//}
private Network network;
protected Network network;
/// <summary>
/// Constructs a memory pool validator object.
......@@ -697,7 +697,7 @@ namespace Stratis.Bitcoin.Features.MemoryPool
/// and absurdly high fees.
/// </summary>
/// <param name="context">Current validation context.</param>
protected void CheckFee(MempoolValidationContext context)
protected virtual void CheckFee(MempoolValidationContext context)
{
Money mempoolRejectFee = this.memPool.GetMinFee(this.mempoolSettings.MaxMempool * 1000000).GetFee(context.EntrySize);
if (mempoolRejectFee > 0 && context.ModifiedFees < mempoolRejectFee)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment