Skip to content

Commit a344880

Browse files
committed
Merge pull request #7323
45b8e27 -bytespersigop option to additionally limit sigops in transactions we relay and mine (Luke Dashjr)
2 parents d513405 + 5b144b7 commit a344880

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

src/init.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ std::string HelpMessage(HelpMessageMode mode)
474474
strUsage += HelpMessageGroup(_("Node relay options:"));
475475
if (showDebug)
476476
strUsage += HelpMessageOpt("-acceptnonstdtxn", strprintf("Relay and mine \"non-standard\" transactions (%sdefault: %u)", "testnet/regtest only; ", !Params(CBaseChainParams::TESTNET).RequireStandard()));
477+
strUsage += HelpMessageOpt("-bytespersigop", strprintf(_("Minimum bytes per sigop in transactions we relay and mine (default: %u)"), DEFAULT_BYTES_PER_SIGOP));
477478
strUsage += HelpMessageOpt("-datacarrier", strprintf(_("Relay and mine data carrier transactions (default: %u)"), DEFAULT_ACCEPT_DATACARRIER));
478479
strUsage += HelpMessageOpt("-datacarriersize", strprintf(_("Maximum size of data in data carrier transactions we relay and mine (default: %u)"), MAX_OP_RETURN_RELAY));
479480

@@ -937,6 +938,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
937938
fRequireStandard = !GetBoolArg("-acceptnonstdtxn", !Params().RequireStandard());
938939
if (Params().RequireStandard() && !fRequireStandard)
939940
return InitError(strprintf("acceptnonstdtxn is not currently supported for %s chain", chainparams.NetworkIDString()));
941+
nBytesPerSigOp = GetArg("-bytespersigop", nBytesPerSigOp);
940942

941943
#ifdef ENABLE_WALLET
942944
if (mapArgs.count("-mintxfee"))

src/main.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ bool fHavePruned = false;
6969
bool fPruneMode = false;
7070
bool fIsBareMultisigStd = DEFAULT_PERMIT_BAREMULTISIG;
7171
bool fRequireStandard = true;
72+
unsigned int nBytesPerSigOp = DEFAULT_BYTES_PER_SIGOP;
7273
bool fCheckBlockIndex = false;
7374
bool fCheckpointsEnabled = DEFAULT_CHECKPOINTS_ENABLED;
7475
size_t nCoinCacheUsage = 5000 * 300;
@@ -929,16 +930,8 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState &state, const C
929930
if (fRequireStandard && !AreInputsStandard(tx, view))
930931
return state.Invalid(false, REJECT_NONSTANDARD, "bad-txns-nonstandard-inputs");
931932

932-
// Check that the transaction doesn't have an excessive number of
933-
// sigops, making it impossible to mine. Since the coinbase transaction
934-
// itself can contain sigops MAX_STANDARD_TX_SIGOPS is less than
935-
// MAX_BLOCK_SIGOPS; we still consider this an invalid rather than
936-
// merely non-standard transaction.
937933
unsigned int nSigOps = GetLegacySigOpCount(tx);
938934
nSigOps += GetP2SHSigOpCount(tx, view);
939-
if (nSigOps > MAX_STANDARD_TX_SIGOPS)
940-
return state.DoS(0, false, REJECT_NONSTANDARD, "bad-txns-too-many-sigops", false,
941-
strprintf("%d > %d", nSigOps, MAX_STANDARD_TX_SIGOPS));
942935

943936
CAmount nValueOut = tx.GetValueOut();
944937
CAmount nFees = nValueIn-nValueOut;
@@ -964,6 +957,15 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState &state, const C
964957
CTxMemPoolEntry entry(tx, nFees, GetTime(), dPriority, chainActive.Height(), pool.HasNoInputsOf(tx), inChainInputValue, fSpendsCoinbase, nSigOps);
965958
unsigned int nSize = entry.GetTxSize();
966959

960+
// Check that the transaction doesn't have an excessive number of
961+
// sigops, making it impossible to mine. Since the coinbase transaction
962+
// itself can contain sigops MAX_STANDARD_TX_SIGOPS is less than
963+
// MAX_BLOCK_SIGOPS; we still consider this an invalid rather than
964+
// merely non-standard transaction.
965+
if ((nSigOps > MAX_STANDARD_TX_SIGOPS) || (nBytesPerSigOp && nSigOps > nSize / nBytesPerSigOp))
966+
return state.DoS(0, false, REJECT_NONSTANDARD, "bad-txns-too-many-sigops", false,
967+
strprintf("%d", nSigOps));
968+
967969
CAmount mempoolRejectFee = pool.GetMinFee(GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFee(nSize);
968970
if (mempoolRejectFee > 0 && nModifiedFees < mempoolRejectFee) {
969971
return state.DoS(0, false, REJECT_INSUFFICIENTFEE, "mempool min fee not met", false, strprintf("%d < %d", nFees, mempoolRejectFee));

src/main.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ static const bool DEFAULT_RELAYPRIORITY = true;
100100

101101
/** Default for -permitbaremultisig */
102102
static const bool DEFAULT_PERMIT_BAREMULTISIG = true;
103+
static const unsigned int DEFAULT_BYTES_PER_SIGOP = 20;
103104
static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
104105
static const bool DEFAULT_TXINDEX = false;
105106
static const unsigned int DEFAULT_BANSCORE_THRESHOLD = 100;
@@ -130,6 +131,7 @@ extern int nScriptCheckThreads;
130131
extern bool fTxIndex;
131132
extern bool fIsBareMultisigStd;
132133
extern bool fRequireStandard;
134+
extern unsigned int nBytesPerSigOp;
133135
extern bool fCheckBlockIndex;
134136
extern bool fCheckpointsEnabled;
135137
extern size_t nCoinCacheUsage;

0 commit comments

Comments
 (0)