diff --git a/src/Makefile.am b/src/Makefile.am index 77820c6add..1807c2bc4f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -204,6 +204,7 @@ BITCOIN_CORE_H = \ miner.h \ mweb/mweb_db.h \ mweb/mweb_models.h \ + mweb/mweb_policy.h \ net.h \ net_permissions.h \ net_processing.h \ @@ -547,6 +548,7 @@ libbitcoin_common_a_SOURCES = \ key.cpp \ key_io.cpp \ merkleblock.cpp \ + mweb/mweb_policy.cpp \ netaddress.cpp \ netbase.cpp \ net_permissions.cpp \ diff --git a/src/mweb/mweb_policy.cpp b/src/mweb/mweb_policy.cpp new file mode 100644 index 0000000000..f299d5d983 --- /dev/null +++ b/src/mweb/mweb_policy.cpp @@ -0,0 +1,33 @@ +#include + +#include + +using namespace MWEB; + +bool Policy::IsStandardTx(const CTransaction& tx, std::string& reason) +{ + // MWEB: To help avoid mempool bugs, we don't yet allow transaction aggregation + // for transactions with canonical LTC data. + if (!tx.IsMWEBOnly()) { + std::set pegin_kernels; + for (const CTxOut& txout : tx.vout) { + mw::Hash kernel_id; + if (txout.scriptPubKey.IsMWEBPegin(&kernel_id)) { + pegin_kernels.insert(std::move(kernel_id)); + } + } + + if (pegin_kernels != tx.mweb_tx.GetKernelIDs()) { + reason = "kernel-mismatch"; + return false; + } + } + + // MWEB: Check MWEB transaction for non-standard kernel features + if (tx.HasMWEBTx() && !tx.mweb_tx.m_transaction->IsStandard()) { + reason = "non-standard-mweb-tx"; + return false; + } + + return true; +} \ No newline at end of file diff --git a/src/mweb/mweb_policy.h b/src/mweb/mweb_policy.h new file mode 100644 index 0000000000..ac8d0e4d5d --- /dev/null +++ b/src/mweb/mweb_policy.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +// Forward Declarations +class CTransaction; + +namespace MWEB { + +class Policy +{ +public: + /// + /// Checks the transaction for violation of any MWEB-specific standard tx policies. + /// + /// The transaction to check. + /// The reason it's non-standard, if any. + /// True if the transaction is standard. + static bool IsStandardTx(const CTransaction& tx, std::string& reason); +}; + +} \ No newline at end of file diff --git a/src/policy/policy.cpp b/src/policy/policy.cpp index 91997aa883..a110bf2315 100644 --- a/src/policy/policy.cpp +++ b/src/policy/policy.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -109,6 +110,12 @@ bool IsStandardTx(const CTransaction& tx, bool permit_bare_multisig, const CFeeR } } + // MWEB: Also check pegout scripts + std::vector txouts = tx.vout; + for (const PegOutCoin& pegout : tx.mweb_tx.GetPegOuts()) { + txouts.push_back(CTxOut(pegout.GetAmount(), pegout.GetScriptPubKey())); + } + unsigned int nDataOut = 0; TxoutType whichType; for (const CTxOut& txout : tx.vout) { @@ -134,6 +141,11 @@ bool IsStandardTx(const CTransaction& tx, bool permit_bare_multisig, const CFeeR return false; } + // MWEB: Check MWEB standard transaction policies + if (!MWEB::Policy::IsStandardTx(tx, reason)) { + return false; + } + return true; }