Skip to content

Commit bb62699

Browse files
committed
Backport chainparams and validation fRequireStandard flags functionality + init 'acceptnonstdtxn' option to skip (most) "non-standard transaction" checks, for testnet/regtest only.
1 parent 0280c39 commit bb62699

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

src/chainparams.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ class CMainParams : public CChainParams
241241

242242
vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_main, pnSeed6_main + ARRAYLEN(pnSeed6_main));
243243

244+
// Reject non-standard transactions by default
245+
fRequireStandard = true;
246+
244247
// Sapling
245248
bech32HRPs[SAPLING_PAYMENT_ADDRESS] = "ps";
246249
bech32HRPs[SAPLING_FULL_VIEWING_KEY] = "pviews";
@@ -364,6 +367,8 @@ class CTestNetParams : public CChainParams
364367

365368
vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_test, pnSeed6_test + ARRAYLEN(pnSeed6_test));
366369

370+
fRequireStandard = false;
371+
367372
// Sapling
368373
bech32HRPs[SAPLING_PAYMENT_ADDRESS] = "ptestsapling";
369374
bech32HRPs[SAPLING_FULL_VIEWING_KEY] = "pviewtestsapling";
@@ -486,6 +491,9 @@ class CRegTestParams : public CChainParams
486491
// Testnet pivx BIP44 coin type is '1' (All coin's testnet default)
487492
base58Prefixes[EXT_COIN_TYPE] = {0x80, 0x00, 0x00, 0x01};
488493

494+
// Reject non-standard transactions by default
495+
fRequireStandard = true;
496+
489497
// Sapling
490498
bech32HRPs[SAPLING_PAYMENT_ADDRESS] = "ptestsapling";
491499
bech32HRPs[SAPLING_FULL_VIEWING_KEY] = "pviewtestsapling";

src/chainparams.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ class CChainParams
6767
int GetDefaultPort() const { return nDefaultPort; }
6868

6969
const CBlock& GenesisBlock() const { return genesis; }
70-
70+
/** Policy: Filter transactions that do not match well-defined patterns */
71+
bool RequireStandard() const { return fRequireStandard; }
72+
/** If this chain is exclusively used for testing */
73+
bool IsTestChain() const { return IsTestnet() || IsRegTestNet(); }
7174
/** Make miner wait to have peers to avoid wasting work */
7275
bool MiningRequiresPeers() const { return !IsRegTestNet(); }
7376
/** Headers first syncing is disabled */
@@ -99,6 +102,7 @@ class CChainParams
99102
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
100103
std::string bech32HRPs[MAX_BECH32_TYPES];
101104
std::vector<SeedSpec6> vFixedSeeds;
105+
bool fRequireStandard;
102106
};
103107

104108
/**

src/init.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,12 @@ std::string HelpMessage(HelpMessageMode mode)
558558
strUsage += HelpMessageOpt("-budgetvotemode=<mode>", _("Change automatic finalized budget voting behavior. mode=auto: Vote for only exact finalized budget match to my generated budget. (string, default: auto)"));
559559

560560
strUsage += HelpMessageGroup(_("Node relay options:"));
561+
if (showDebug) {
562+
strUsage += HelpMessageOpt("-acceptnonstdtxn",
563+
strprintf("Relay and mine \"non-standard\" transactions (%sdefault: %u)",
564+
"testnet/regtest only; ",
565+
!CreateChainParams(CBaseChainParams::TESTNET)->RequireStandard()));
566+
}
561567
strUsage += HelpMessageOpt("-datacarrier", strprintf(_("Relay and mine data carrier transactions (default: %u)"), DEFAULT_ACCEPT_DATACARRIER));
562568
strUsage += HelpMessageOpt("-datacarriersize", strprintf(_("Maximum size of data in data carrier transactions we relay and mine (default: %u)"), MAX_OP_RETURN_RELAY));
563569
if (showDebug) {
@@ -1135,6 +1141,11 @@ bool AppInitParameterInteraction()
11351141
return UIError(AmountErrMsg("minrelaytxfee", gArgs.GetArg("-minrelaytxfee", "")));
11361142
}
11371143

1144+
const CChainParams& chainparams = Params();
1145+
fRequireStandard = !gArgs.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard());
1146+
if (!chainparams.IsTestChain() && !fRequireStandard)
1147+
return UIError(strprintf("acceptnonstdtxn is not currently supported for %s chain", chainparams.NetworkIDString()));
1148+
11381149
#ifdef ENABLE_WALLET
11391150
strWalletFile = gArgs.GetArg("-wallet", DEFAULT_WALLET_DAT);
11401151
if (!CWallet::ParameterInteraction())

src/validation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ int nScriptCheckThreads = 0;
9898
std::atomic<bool> fImporting{false};
9999
std::atomic<bool> fReindex{false};
100100
bool fTxIndex = true;
101+
bool fRequireStandard = true;
101102
bool fCheckBlockIndex = false;
102103
bool fVerifyingBlocks = false;
103104
size_t nCoinCacheUsage = 5000 * 300;
@@ -440,7 +441,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState &state, const C
440441

441442
// Rather not work on nonstandard transactions
442443
std::string reason;
443-
if (!IsStandardTx(_tx, nextBlockHeight, reason))
444+
if (fRequireStandard && !IsStandardTx(_tx, nextBlockHeight, reason))
444445
return state.DoS(0, false, REJECT_NONSTANDARD, reason);
445446
// is it already in the memory pool?
446447
const uint256& hash = tx.GetHash();
@@ -518,7 +519,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState &state, const C
518519
view.SetBackend(dummy);
519520

520521
// Check for non-standard pay-to-script-hash in inputs
521-
if (!Params().IsRegTestNet() && !AreInputsStandard(tx, view))
522+
if (fRequireStandard && !AreInputsStandard(tx, view))
522523
return state.Invalid(false, REJECT_NONSTANDARD, "bad-txns-nonstandard-inputs");
523524

524525
// Check that the transaction doesn't have an excessive number of

src/validation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ extern std::atomic<bool> fImporting;
142142
extern std::atomic<bool> fReindex;
143143
extern int nScriptCheckThreads;
144144
extern bool fTxIndex;
145+
extern bool fRequireStandard;
145146
extern bool fCheckBlockIndex;
146147
extern size_t nCoinCacheUsage;
147148
extern CFeeRate minRelayTxFee;

0 commit comments

Comments
 (0)