Commit da2827b5 authored by Sergei Zubov's avatar Sergei Zubov

Fix input checking in mempool

parent 5da6b37b
......@@ -2,18 +2,16 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using NBitcoin;
using Stratis.Bitcoin.Base.Deployments;
using Stratis.Bitcoin.Configuration;
using Stratis.Bitcoin.Consensus.Rules;
using Stratis.Bitcoin.Features.Consensus.CoinViews;
using Stratis.Bitcoin.Features.Consensus.Rules.CommonRules;
using Stratis.Bitcoin.Features.MemoryPool.Interfaces;
using Stratis.Bitcoin.Utilities;
namespace Stratis.Bitcoin.Features.MemoryPool
{
/// <summary>
/// Creates <see cref="DeStreamMempoolCoinView"/> and prevents verifing ChangePointer input
/// Creates <see cref="DeStreamMempoolCoinView" /> and prevents verifing ChangePointer input
/// </summary>
public class DeStreamMempoolValidator : MempoolValidator
{
......@@ -123,5 +121,27 @@ namespace Stratis.Bitcoin.Features.MemoryPool
if (!context.View.HaveInputs(context.Transaction))
context.State.Invalid(MempoolErrors.BadInputsSpent).Throw();
}
/// <inheritdoc />
protected override bool AreInputsStandard(Transaction tx, MempoolCoinView mapInputs)
{
if (tx.IsCoinBase)
return true; // Coinbases don't use vin normally
foreach (TxIn txin in tx.Inputs.RemoveChangePointer())
{
TxOut prev = mapInputs.GetOutputFor(txin);
ScriptTemplate template = StandardScripts.GetTemplateFromScriptPubKey(prev.ScriptPubKey);
if (template == null)
return false;
if (template.Type != TxOutType.TX_SCRIPTHASH) continue;
if (prev.ScriptPubKey.GetSigOpCount(true) > 15) //MAX_P2SH_SIGOPS
return false;
}
return true;
}
}
}
\ No newline at end of file
......@@ -1110,7 +1110,7 @@ namespace Stratis.Bitcoin.Features.MemoryPool
/// <param name="tx">Transaction to verify.</param>
/// <param name="mapInputs">Map of previous transactions that have outputs we're spending.</param>
/// <returns>Whether all inputs (scriptSigs) use only standard transaction forms.</returns>
private bool AreInputsStandard(Transaction tx, MempoolCoinView mapInputs)
protected virtual bool AreInputsStandard(Transaction tx, MempoolCoinView mapInputs)
{
if (tx.IsCoinBase)
return true; // Coinbases don't use vin normally
......
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