Skip to content

Commit fa2a6b8

Browse files
author
MacroFake
committed
Combine datacarrier globals into one
1 parent fa477d3 commit fa2a6b8

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

src/init.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -975,8 +975,11 @@ bool AppInitParameterInteraction(const ArgsManager& args, bool use_syscall_sandb
975975

976976
if (!g_wallet_init_interface.ParameterInteraction()) return false;
977977

978-
fAcceptDatacarrier = args.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER);
979-
nMaxDatacarrierBytes = args.GetIntArg("-datacarriersize", nMaxDatacarrierBytes);
978+
if (args.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER)) {
979+
g_max_datacarrier_bytes = args.GetIntArg("-datacarriersize", MAX_OP_RETURN_RELAY);
980+
} else {
981+
g_max_datacarrier_bytes = std::nullopt;
982+
}
980983

981984
// Option to startup with mocktime set (used for regression testing):
982985
SetMockTime(args.GetIntArg("-mocktime", 0)); // SetMockTime(0) is a no-op

src/policy/policy.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ bool IsStandard(const CScript& scriptPubKey, TxoutType& whichType)
8282
return false;
8383
if (m < 1 || m > n)
8484
return false;
85-
} else if (whichType == TxoutType::NULL_DATA &&
86-
(!fAcceptDatacarrier || scriptPubKey.size() > nMaxDatacarrierBytes)) {
87-
return false;
85+
} else if (whichType == TxoutType::NULL_DATA) {
86+
if (!g_max_datacarrier_bytes || scriptPubKey.size() > *g_max_datacarrier_bytes) {
87+
return false;
88+
}
8889
}
8990

9091
return true;

src/script/standard.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
typedef std::vector<unsigned char> valtype;
1818

19-
bool fAcceptDatacarrier = DEFAULT_ACCEPT_DATACARRIER;
20-
unsigned nMaxDatacarrierBytes = MAX_OP_RETURN_RELAY;
19+
std::optional<unsigned> g_max_datacarrier_bytes{DEFAULT_ACCEPT_DATACARRIER ? std::optional{MAX_OP_RETURN_RELAY} : std::nullopt};
2120

2221
CScriptID::CScriptID(const CScript& in) : BaseHash(Hash160(in)) {}
2322
CScriptID::CScriptID(const ScriptHash& in) : BaseHash(static_cast<uint160>(in)) {}

src/script/standard.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <util/hash_type.h>
1414

1515
#include <map>
16+
#include <optional>
1617
#include <string>
1718
#include <variant>
1819

@@ -33,19 +34,19 @@ class CScriptID : public BaseHash<uint160>
3334
};
3435

3536
/**
36-
* Default setting for nMaxDatacarrierBytes. 80 bytes of data, +1 for OP_RETURN,
37+
* Default setting for -datacarriersize. 80 bytes of data, +1 for OP_RETURN,
3738
* +2 for the pushdata opcodes.
3839
*/
3940
static const unsigned int MAX_OP_RETURN_RELAY = 83;
4041

4142
/**
4243
* A data carrying output is an unspendable output containing data. The script
4344
* type is designated as TxoutType::NULL_DATA.
45+
*
46+
* Maximum size of TxoutType::NULL_DATA scripts that this node considers standard.
47+
* If nullopt, any size is nonstandard.
4448
*/
45-
extern bool fAcceptDatacarrier;
46-
47-
/** Maximum size of TxoutType::NULL_DATA scripts that this node considers standard. */
48-
extern unsigned nMaxDatacarrierBytes;
49+
extern std::optional<unsigned> g_max_datacarrier_bytes;
4950

5051
/**
5152
* Mandatory script verification flags that all new blocks must comply with for

0 commit comments

Comments
 (0)