Skip to content

Commit 686af03

Browse files
committed
Add -datacarriernum
1 parent c2d72ea commit 686af03

File tree

8 files changed

+23
-9
lines changed

8 files changed

+23
-9
lines changed

src/init.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ void SetupServerArgs(ArgsManager& argsman)
593593
argsman.AddArg("-acceptstalefeeestimates", strprintf("Read fee estimates even if they are stale (%sdefault: %u) fee estimates are considered stale if they are %s hours old", "regtest only; ", DEFAULT_ACCEPT_STALE_FEE_ESTIMATES, Ticks<std::chrono::hours>(MAX_FILE_AGE)), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
594594
argsman.AddArg("-bytespersigop", strprintf("Equivalent bytes per sigop in transactions for relay and mining (default: %u)", DEFAULT_BYTES_PER_SIGOP), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
595595
argsman.AddArg("-datacarrier", strprintf("Relay and mine data carrier transactions (default: %u)", DEFAULT_ACCEPT_DATACARRIER), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
596+
argsman.AddArg("-datacarriernum", strprintf("Relay and mine transacrtions with max %u data carrier outputs", DEFAULT_DATACARRIER_OUTPUTS), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
596597
argsman.AddArg("-datacarriersize",
597598
strprintf("Relay and mine transactions whose data-carrying raw scriptPubKey "
598599
"is of this size or less (default: %u)",

src/kernel/mempool_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct MemPoolOptions {
5353
* If nullopt, any size is nonstandard.
5454
*/
5555
std::optional<unsigned> max_datacarrier_bytes{DEFAULT_ACCEPT_DATACARRIER ? std::optional{MAX_OP_RETURN_RELAY} : std::nullopt};
56+
std::optional<unsigned> max_datacarrier_outputs{DEFAULT_DATACARRIER_OUTPUTS ? std::optional{MAX_DATACARRIER_OUTPUTS} : std::nullopt};
5657
bool permit_bare_multisig{DEFAULT_PERMIT_BAREMULTISIG};
5758
bool require_standard{true};
5859
bool full_rbf{DEFAULT_MEMPOOL_FULL_RBF};

src/node/mempool_args.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ util::Result<void> ApplyArgsManOptions(const ArgsManager& argsman, const CChainP
8686
mempool_opts.max_datacarrier_bytes = std::nullopt;
8787
}
8888

89+
if (argsman.GetBoolArg("-datacarrieroutputs", DEFAULT_DATACARRIER_OUTPUTS)) {
90+
mempool_opts.max_datacarrier_outputs = argsman.GetIntArg("-datacarrieroutputs", MAX_DATACARRIER_OUTPUTS);
91+
} else {
92+
mempool_opts.max_datacarrier_outputs = std::nullopt;
93+
}
94+
8995
mempool_opts.require_standard = !argsman.GetBoolArg("-acceptnonstdtxn", DEFAULT_ACCEPT_NON_STD_TXN);
9096
if (!chainparams.IsTestChain() && !mempool_opts.require_standard) {
9197
return util::Error{strprintf(Untranslated("acceptnonstdtxn is not currently supported for %s chain"), chainparams.GetChainTypeString())};

src/policy/policy.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ bool IsStandard(const CScript& scriptPubKey, const std::optional<unsigned>& max_
9191
return true;
9292
}
9393

94-
bool IsStandardTx(const CTransaction& tx, const std::optional<unsigned>& max_datacarrier_bytes, bool permit_bare_multisig, const CFeeRate& dust_relay_fee, std::string& reason)
94+
bool IsStandardTx(const CTransaction& tx, const std::optional<unsigned>& max_datacarrier_bytes, const std::optional<unsigned>& max_datacarrier_outputs, bool permit_bare_multisig, const CFeeRate& dust_relay_fee, std::string& reason)
9595
{
9696
if (tx.nVersion > TX_MAX_STANDARD_VERSION || tx.nVersion < 1) {
9797
reason = "version";
@@ -128,8 +128,8 @@ bool IsStandardTx(const CTransaction& tx, const std::optional<unsigned>& max_dat
128128
}
129129
}
130130

131-
unsigned int nDataOut = 0;
132131
TxoutType whichType;
132+
unsigned int nDataOut = 0;
133133
for (const CTxOut& txout : tx.vout) {
134134
if (!::IsStandard(txout.scriptPubKey, max_datacarrier_bytes, whichType)) {
135135
reason = "scriptpubkey";
@@ -147,11 +147,10 @@ bool IsStandardTx(const CTransaction& tx, const std::optional<unsigned>& max_dat
147147
}
148148
}
149149

150-
// only one OP_RETURN txout is permitted
151-
//if (nDataOut > 1) {
152-
// reason = "multi-op-return";
153-
// return false;
154-
//}
150+
if (nDataOut > max_datacarrier_outputs) {
151+
reason = "multi-op-return";
152+
return false;
153+
}
155154

156155
return true;
157156
}

src/policy/policy.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,16 @@ static constexpr unsigned int DEFAULT_DESCENDANT_LIMIT{25};
6565
static constexpr unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT_KVB{101};
6666
/** Default for -datacarrier */
6767
static const bool DEFAULT_ACCEPT_DATACARRIER = true;
68+
/** Default for -datacarriernum */
69+
static const bool DEFAULT_DATACARRIER_OUTPUTS = 1;
6870
/**
6971
* Default setting for -datacarriersize. 80 bytes of data, +1 for OP_RETURN,
7072
* +2 for the pushdata opcodes.
7173
*/
7274
static const unsigned int MAX_OP_RETURN_RELAY = 1000000;
75+
76+
static const unsigned int MAX_DATACARRIER_OUTPUTS = 100;
77+
7378
/**
7479
* An extra transaction can be added to a package, as long as it only has one
7580
* ancestor and is no larger than this. Not really any reason to make this
@@ -137,7 +142,7 @@ static constexpr decltype(CTransaction::nVersion) TX_MAX_STANDARD_VERSION{2};
137142
* Check for standard transaction types
138143
* @return True if all outputs (scriptPubKeys) use only standard transaction forms
139144
*/
140-
bool IsStandardTx(const CTransaction& tx, const std::optional<unsigned>& max_datacarrier_bytes, bool permit_bare_multisig, const CFeeRate& dust_relay_fee, std::string& reason);
145+
bool IsStandardTx(const CTransaction& tx, const std::optional<unsigned>& max_datacarrier_bytes, const std::optional<unsigned>& max_datacarrier_outputs, bool permit_bare_multisig, const CFeeRate& dust_relay_fee, std::string& reason);
141146
/**
142147
* Check for standard transaction types
143148
* @param[in] mapInputs Map of previous transactions that have outputs we're spending

src/txmempool.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ CTxMemPool::CTxMemPool(const Options& opts)
410410
m_dust_relay_feerate{opts.dust_relay_feerate},
411411
m_permit_bare_multisig{opts.permit_bare_multisig},
412412
m_max_datacarrier_bytes{opts.max_datacarrier_bytes},
413+
m_max_datacarrier_outputs{opts.max_datacarrier_outputs},
413414
m_require_standard{opts.require_standard},
414415
m_full_rbf{opts.full_rbf},
415416
m_limits{opts.limits}

src/txmempool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ class CTxMemPool
444444
const CFeeRate m_dust_relay_feerate;
445445
const bool m_permit_bare_multisig;
446446
const std::optional<unsigned> m_max_datacarrier_bytes;
447+
const std::optional<unsigned> m_max_datacarrier_outputs;
447448
const bool m_require_standard;
448449
const bool m_full_rbf;
449450

src/validation.cpp

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

719719
// Rather not work on nonstandard transactions (unless -testnet/-regtest)
720720
std::string reason;
721-
if (m_pool.m_require_standard && !IsStandardTx(tx, m_pool.m_max_datacarrier_bytes, m_pool.m_permit_bare_multisig, m_pool.m_dust_relay_feerate, reason)) {
721+
if (m_pool.m_require_standard && !IsStandardTx(tx, m_pool.m_max_datacarrier_bytes, m_pool.m_max_datacarrier_outputs, m_pool.m_permit_bare_multisig, m_pool.m_dust_relay_feerate, reason)) {
722722
return state.Invalid(TxValidationResult::TX_NOT_STANDARD, reason);
723723
}
724724

0 commit comments

Comments
 (0)