Commit 621e54c5 authored by Sergei Zubov's avatar Sergei Zubov

Fix checking mempool conflicts

parent 00923bd6
......@@ -143,5 +143,48 @@ namespace Stratis.Bitcoin.Features.MemoryPool
return true;
}
/// <inheritdoc />
protected override void CheckConflicts(MempoolValidationContext context)
{
context.SetConflicts = new List<uint256>();
foreach (TxIn txin in context.Transaction.Inputs.RemoveChangePointer())
{
TxMempool.NextTxPair itConflicting = this.memPool.MapNextTx.Find(f => f.OutPoint == txin.PrevOut);
if (itConflicting == null) continue;
Transaction ptxConflicting = itConflicting.Transaction;
if (context.SetConflicts.Contains(ptxConflicting.GetHash())) continue;
// Allow opt-out of transaction replacement by setting
// nSequence >= maxint-1 on all inputs.
//
// maxint-1 is picked to still allow use of nLockTime by
// non-replaceable transactions. All inputs rather than just one
// is for the sake of multi-party protocols, where we don't
// want a single party to be able to disable replacement.
//
// The opt-out ignores descendants as anyone relying on
// first-seen mempool behavior should be checking all
// unconfirmed ancestors anyway; doing otherwise is hopelessly
// insecure.
bool replacementOptOut = true;
if (this.mempoolSettings.EnableReplacement)
{
foreach (TxIn txiner in ptxConflicting.Inputs)
{
if (txiner.Sequence >= Sequence.Final - 1) continue;
replacementOptOut = false;
break;
}
}
if (replacementOptOut)
context.State.Invalid(MempoolErrors.Conflict).Throw();
context.SetConflicts.Add(ptxConflicting.GetHash());
}
}
}
}
\ No newline at end of file
......@@ -499,7 +499,7 @@ namespace Stratis.Bitcoin.Features.MemoryPool
/// If a conflict is found it is added to the validation context.
/// </summary>
/// <param name="context">Current validation context.</param>
protected void CheckConflicts(MempoolValidationContext context)
protected virtual void CheckConflicts(MempoolValidationContext context)
{
context.SetConflicts = new List<uint256>();
foreach (TxIn txin in context.Transaction.Inputs)
......
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