mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
Remove ::IsStandardTx(tx, reason) alias
Apart from tests, it is only used in one place, so there is no need for an alias.
This commit is contained in:
parent
fa7a9114e5
commit
fa8a7f01fe
5 changed files with 18 additions and 17 deletions
|
@ -10,7 +10,6 @@
|
|||
#include <policy/policy.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
class CTransaction;
|
||||
|
||||
|
@ -18,11 +17,6 @@ extern CFeeRate dustRelayFee;
|
|||
extern unsigned int nBytesPerSigOp;
|
||||
extern bool fIsBareMultisigStd;
|
||||
|
||||
static inline bool IsStandardTx(const CTransaction& tx, std::string& reason)
|
||||
{
|
||||
return IsStandardTx(tx, ::fIsBareMultisigStd, ::dustRelayFee, reason);
|
||||
}
|
||||
|
||||
static inline int64_t GetVirtualTransactionSize(int64_t weight, int64_t sigop_cost)
|
||||
{
|
||||
return GetVirtualTransactionSize(weight, sigop_cost, ::nBytesPerSigOp);
|
||||
|
|
|
@ -92,7 +92,6 @@ FUZZ_TARGET_INIT(transaction, initialize_transaction)
|
|||
(void)GetTransactionWeight(tx);
|
||||
(void)GetVirtualTransactionSize(tx);
|
||||
(void)IsFinalTx(tx, /* nBlockHeight= */ 1024, /* nBlockTime= */ 1024);
|
||||
(void)IsStandardTx(tx, reason);
|
||||
(void)RecursiveDynamicUsage(tx);
|
||||
(void)SignalsOptInRBF(tx);
|
||||
|
||||
|
|
|
@ -18,6 +18,11 @@
|
|||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
// Helpers:
|
||||
bool IsStandardTx(const CTransaction& tx, std::string& reason)
|
||||
{
|
||||
return IsStandardTx(tx, DEFAULT_PERMIT_BAREMULTISIG, CFeeRate{DUST_RELAY_TX_FEE}, reason);
|
||||
}
|
||||
|
||||
static std::vector<unsigned char>
|
||||
Serialize(const CScript& s)
|
||||
{
|
||||
|
|
|
@ -40,6 +40,9 @@ typedef std::vector<unsigned char> valtype;
|
|||
// In script_tests.cpp
|
||||
UniValue read_json(const std::string& jsondata);
|
||||
|
||||
static CFeeRate g_dust{DUST_RELAY_TX_FEE};
|
||||
static bool g_bare_multi{DEFAULT_PERMIT_BAREMULTISIG};
|
||||
|
||||
static std::map<std::string, unsigned int> mapFlagNames = {
|
||||
{std::string("P2SH"), (unsigned int)SCRIPT_VERIFY_P2SH},
|
||||
{std::string("STRICTENC"), (unsigned int)SCRIPT_VERIFY_STRICTENC},
|
||||
|
@ -764,19 +767,19 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
|
|||
|
||||
constexpr auto CheckIsStandard = [](const auto& t) {
|
||||
std::string reason;
|
||||
BOOST_CHECK(IsStandardTx(CTransaction(t), reason));
|
||||
BOOST_CHECK(IsStandardTx(CTransaction{t}, g_bare_multi, g_dust, reason));
|
||||
BOOST_CHECK(reason.empty());
|
||||
};
|
||||
constexpr auto CheckIsNotStandard = [](const auto& t, const std::string& reason_in) {
|
||||
std::string reason;
|
||||
BOOST_CHECK(!IsStandardTx(CTransaction(t), reason));
|
||||
BOOST_CHECK(!IsStandardTx(CTransaction{t}, g_bare_multi, g_dust, reason));
|
||||
BOOST_CHECK_EQUAL(reason_in, reason);
|
||||
};
|
||||
|
||||
CheckIsStandard(t);
|
||||
|
||||
// Check dust with default relay fee:
|
||||
CAmount nDustThreshold = 182 * dustRelayFee.GetFeePerK() / 1000;
|
||||
CAmount nDustThreshold = 182 * g_dust.GetFeePerK() / 1000;
|
||||
BOOST_CHECK_EQUAL(nDustThreshold, 546);
|
||||
// dust:
|
||||
t.vout[0].nValue = nDustThreshold - 1;
|
||||
|
@ -804,14 +807,14 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
|
|||
|
||||
// Check dust with odd relay fee to verify rounding:
|
||||
// nDustThreshold = 182 * 3702 / 1000
|
||||
dustRelayFee = CFeeRate(3702);
|
||||
g_dust = CFeeRate(3702);
|
||||
// dust:
|
||||
t.vout[0].nValue = 674 - 1;
|
||||
CheckIsNotStandard(t, "dust");
|
||||
// not dust:
|
||||
t.vout[0].nValue = 674;
|
||||
CheckIsStandard(t);
|
||||
dustRelayFee = CFeeRate(DUST_RELAY_TX_FEE);
|
||||
g_dust = CFeeRate{DUST_RELAY_TX_FEE};
|
||||
|
||||
t.vout[0].scriptPubKey = CScript() << OP_1;
|
||||
CheckIsNotStandard(t, "scriptpubkey");
|
||||
|
@ -923,16 +926,16 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
|
|||
BOOST_CHECK_EQUAL(GetTransactionWeight(CTransaction(t)), 400004);
|
||||
CheckIsNotStandard(t, "tx-size");
|
||||
|
||||
// Check bare multisig (standard if policy flag fIsBareMultisigStd is set)
|
||||
fIsBareMultisigStd = true;
|
||||
// Check bare multisig (standard if policy flag g_bare_multi is set)
|
||||
g_bare_multi = true;
|
||||
t.vout[0].scriptPubKey = GetScriptForMultisig(1, {key.GetPubKey()}); // simple 1-of-1
|
||||
t.vin.resize(1);
|
||||
t.vin[0].scriptSig = CScript() << std::vector<unsigned char>(65, 0);
|
||||
CheckIsStandard(t);
|
||||
|
||||
fIsBareMultisigStd = false;
|
||||
g_bare_multi = false;
|
||||
CheckIsNotStandard(t, "bare-multisig");
|
||||
fIsBareMultisigStd = DEFAULT_PERMIT_BAREMULTISIG;
|
||||
g_bare_multi = DEFAULT_PERMIT_BAREMULTISIG;
|
||||
|
||||
// Check P2WPKH outputs dust threshold
|
||||
t.vout[0].scriptPubKey = CScript() << OP_0 << ParseHex("ffffffffffffffffffffffffffffffffffffffff");
|
||||
|
|
|
@ -700,7 +700,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
|
|||
|
||||
// Rather not work on nonstandard transactions (unless -testnet/-regtest)
|
||||
std::string reason;
|
||||
if (m_pool.m_require_standard && !IsStandardTx(tx, reason)) {
|
||||
if (m_pool.m_require_standard && !IsStandardTx(tx, ::fIsBareMultisigStd, ::dustRelayFee, reason)) {
|
||||
return state.Invalid(TxValidationResult::TX_NOT_STANDARD, reason);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue