Skip to content

Commit fa8a7f0

Browse files
author
MacroFake
committed
Remove ::IsStandardTx(tx, reason) alias
Apart from tests, it is only used in one place, so there is no need for an alias.
1 parent fa7a911 commit fa8a7f0

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

src/policy/settings.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,13 @@
1010
#include <policy/policy.h>
1111

1212
#include <cstdint>
13-
#include <string>
1413

1514
class CTransaction;
1615

1716
extern CFeeRate dustRelayFee;
1817
extern unsigned int nBytesPerSigOp;
1918
extern bool fIsBareMultisigStd;
2019

21-
static inline bool IsStandardTx(const CTransaction& tx, std::string& reason)
22-
{
23-
return IsStandardTx(tx, ::fIsBareMultisigStd, ::dustRelayFee, reason);
24-
}
25-
2620
static inline int64_t GetVirtualTransactionSize(int64_t weight, int64_t sigop_cost)
2721
{
2822
return GetVirtualTransactionSize(weight, sigop_cost, ::nBytesPerSigOp);

src/test/fuzz/transaction.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ FUZZ_TARGET_INIT(transaction, initialize_transaction)
9292
(void)GetTransactionWeight(tx);
9393
(void)GetVirtualTransactionSize(tx);
9494
(void)IsFinalTx(tx, /* nBlockHeight= */ 1024, /* nBlockTime= */ 1024);
95-
(void)IsStandardTx(tx, reason);
9695
(void)RecursiveDynamicUsage(tx);
9796
(void)SignalsOptInRBF(tx);
9897

src/test/script_p2sh_tests.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
#include <boost/test/unit_test.hpp>
1919

2020
// Helpers:
21+
bool IsStandardTx(const CTransaction& tx, std::string& reason)
22+
{
23+
return IsStandardTx(tx, DEFAULT_PERMIT_BAREMULTISIG, CFeeRate{DUST_RELAY_TX_FEE}, reason);
24+
}
25+
2126
static std::vector<unsigned char>
2227
Serialize(const CScript& s)
2328
{

src/test/transaction_tests.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ typedef std::vector<unsigned char> valtype;
4040
// In script_tests.cpp
4141
UniValue read_json(const std::string& jsondata);
4242

43+
static CFeeRate g_dust{DUST_RELAY_TX_FEE};
44+
static bool g_bare_multi{DEFAULT_PERMIT_BAREMULTISIG};
45+
4346
static std::map<std::string, unsigned int> mapFlagNames = {
4447
{std::string("P2SH"), (unsigned int)SCRIPT_VERIFY_P2SH},
4548
{std::string("STRICTENC"), (unsigned int)SCRIPT_VERIFY_STRICTENC},
@@ -764,19 +767,19 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
764767

765768
constexpr auto CheckIsStandard = [](const auto& t) {
766769
std::string reason;
767-
BOOST_CHECK(IsStandardTx(CTransaction(t), reason));
770+
BOOST_CHECK(IsStandardTx(CTransaction{t}, g_bare_multi, g_dust, reason));
768771
BOOST_CHECK(reason.empty());
769772
};
770773
constexpr auto CheckIsNotStandard = [](const auto& t, const std::string& reason_in) {
771774
std::string reason;
772-
BOOST_CHECK(!IsStandardTx(CTransaction(t), reason));
775+
BOOST_CHECK(!IsStandardTx(CTransaction{t}, g_bare_multi, g_dust, reason));
773776
BOOST_CHECK_EQUAL(reason_in, reason);
774777
};
775778

776779
CheckIsStandard(t);
777780

778781
// Check dust with default relay fee:
779-
CAmount nDustThreshold = 182 * dustRelayFee.GetFeePerK() / 1000;
782+
CAmount nDustThreshold = 182 * g_dust.GetFeePerK() / 1000;
780783
BOOST_CHECK_EQUAL(nDustThreshold, 546);
781784
// dust:
782785
t.vout[0].nValue = nDustThreshold - 1;
@@ -804,14 +807,14 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
804807

805808
// Check dust with odd relay fee to verify rounding:
806809
// nDustThreshold = 182 * 3702 / 1000
807-
dustRelayFee = CFeeRate(3702);
810+
g_dust = CFeeRate(3702);
808811
// dust:
809812
t.vout[0].nValue = 674 - 1;
810813
CheckIsNotStandard(t, "dust");
811814
// not dust:
812815
t.vout[0].nValue = 674;
813816
CheckIsStandard(t);
814-
dustRelayFee = CFeeRate(DUST_RELAY_TX_FEE);
817+
g_dust = CFeeRate{DUST_RELAY_TX_FEE};
815818

816819
t.vout[0].scriptPubKey = CScript() << OP_1;
817820
CheckIsNotStandard(t, "scriptpubkey");
@@ -923,16 +926,16 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
923926
BOOST_CHECK_EQUAL(GetTransactionWeight(CTransaction(t)), 400004);
924927
CheckIsNotStandard(t, "tx-size");
925928

926-
// Check bare multisig (standard if policy flag fIsBareMultisigStd is set)
927-
fIsBareMultisigStd = true;
929+
// Check bare multisig (standard if policy flag g_bare_multi is set)
930+
g_bare_multi = true;
928931
t.vout[0].scriptPubKey = GetScriptForMultisig(1, {key.GetPubKey()}); // simple 1-of-1
929932
t.vin.resize(1);
930933
t.vin[0].scriptSig = CScript() << std::vector<unsigned char>(65, 0);
931934
CheckIsStandard(t);
932935

933-
fIsBareMultisigStd = false;
936+
g_bare_multi = false;
934937
CheckIsNotStandard(t, "bare-multisig");
935-
fIsBareMultisigStd = DEFAULT_PERMIT_BAREMULTISIG;
938+
g_bare_multi = DEFAULT_PERMIT_BAREMULTISIG;
936939

937940
// Check P2WPKH outputs dust threshold
938941
t.vout[0].scriptPubKey = CScript() << OP_0 << ParseHex("ffffffffffffffffffffffffffffffffffffffff");

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
700700

701701
// Rather not work on nonstandard transactions (unless -testnet/-regtest)
702702
std::string reason;
703-
if (m_pool.m_require_standard && !IsStandardTx(tx, reason)) {
703+
if (m_pool.m_require_standard && !IsStandardTx(tx, ::fIsBareMultisigStd, ::dustRelayFee, reason)) {
704704
return state.Invalid(TxValidationResult::TX_NOT_STANDARD, reason);
705705
}
706706

0 commit comments

Comments
 (0)