From fa2a6b8516b24d7e9ca11926a49cf2b07f661e81 Mon Sep 17 00:00:00 2001 From: MacroFake Date: Thu, 21 Jul 2022 17:55:49 +0200 Subject: [PATCH] Combine datacarrier globals into one --- src/init.cpp | 7 +++++-- src/policy/policy.cpp | 7 ++++--- src/script/standard.cpp | 3 +-- src/script/standard.h | 11 ++++++----- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 49c7de78163..04873d1c29f 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -975,8 +975,11 @@ bool AppInitParameterInteraction(const ArgsManager& args, bool use_syscall_sandb if (!g_wallet_init_interface.ParameterInteraction()) return false; - fAcceptDatacarrier = args.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER); - nMaxDatacarrierBytes = args.GetIntArg("-datacarriersize", nMaxDatacarrierBytes); + if (args.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER)) { + g_max_datacarrier_bytes = args.GetIntArg("-datacarriersize", MAX_OP_RETURN_RELAY); + } else { + g_max_datacarrier_bytes = std::nullopt; + } // Option to startup with mocktime set (used for regression testing): SetMockTime(args.GetIntArg("-mocktime", 0)); // SetMockTime(0) is a no-op diff --git a/src/policy/policy.cpp b/src/policy/policy.cpp index f6452266b7f..0a79c0a1d8d 100644 --- a/src/policy/policy.cpp +++ b/src/policy/policy.cpp @@ -82,9 +82,10 @@ bool IsStandard(const CScript& scriptPubKey, TxoutType& whichType) return false; if (m < 1 || m > n) return false; - } else if (whichType == TxoutType::NULL_DATA && - (!fAcceptDatacarrier || scriptPubKey.size() > nMaxDatacarrierBytes)) { - return false; + } else if (whichType == TxoutType::NULL_DATA) { + if (!g_max_datacarrier_bytes || scriptPubKey.size() > *g_max_datacarrier_bytes) { + return false; + } } return true; diff --git a/src/script/standard.cpp b/src/script/standard.cpp index b3f6a1b6698..47e9e89c941 100644 --- a/src/script/standard.cpp +++ b/src/script/standard.cpp @@ -16,8 +16,7 @@ typedef std::vector valtype; -bool fAcceptDatacarrier = DEFAULT_ACCEPT_DATACARRIER; -unsigned nMaxDatacarrierBytes = MAX_OP_RETURN_RELAY; +std::optional g_max_datacarrier_bytes{DEFAULT_ACCEPT_DATACARRIER ? std::optional{MAX_OP_RETURN_RELAY} : std::nullopt}; CScriptID::CScriptID(const CScript& in) : BaseHash(Hash160(in)) {} CScriptID::CScriptID(const ScriptHash& in) : BaseHash(static_cast(in)) {} diff --git a/src/script/standard.h b/src/script/standard.h index 448fdff0109..c1c4cf4a39f 100644 --- a/src/script/standard.h +++ b/src/script/standard.h @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -33,7 +34,7 @@ public: }; /** - * Default setting for nMaxDatacarrierBytes. 80 bytes of data, +1 for OP_RETURN, + * Default setting for -datacarriersize. 80 bytes of data, +1 for OP_RETURN, * +2 for the pushdata opcodes. */ static const unsigned int MAX_OP_RETURN_RELAY = 83; @@ -41,11 +42,11 @@ static const unsigned int MAX_OP_RETURN_RELAY = 83; /** * A data carrying output is an unspendable output containing data. The script * type is designated as TxoutType::NULL_DATA. + * + * Maximum size of TxoutType::NULL_DATA scripts that this node considers standard. + * If nullopt, any size is nonstandard. */ -extern bool fAcceptDatacarrier; - -/** Maximum size of TxoutType::NULL_DATA scripts that this node considers standard. */ -extern unsigned nMaxDatacarrierBytes; +extern std::optional g_max_datacarrier_bytes; /** * Mandatory script verification flags that all new blocks must comply with for