Skip to content

Commit 45b8e27

Browse files
committed
-bytespersigop option to additionally limit sigops in transactions we relay and mine
1 parent 4077ad2 commit 45b8e27

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;
@@ -937,16 +938,8 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
937938
if (fRequireStandard && !AreInputsStandard(tx, view))
938939
return state.Invalid(false, REJECT_NONSTANDARD, "bad-txns-nonstandard-inputs");
939940

940-
// Check that the transaction doesn't have an excessive number of
941-
// sigops, making it impossible to mine. Since the coinbase transaction
942-
// itself can contain sigops MAX_STANDARD_TX_SIGOPS is less than
943-
// MAX_BLOCK_SIGOPS; we still consider this an invalid rather than
944-
// merely non-standard transaction.
945941
unsigned int nSigOps = GetLegacySigOpCount(tx);
946942
nSigOps += GetP2SHSigOpCount(tx, view);
947-
if (nSigOps > MAX_STANDARD_TX_SIGOPS)
948-
return state.DoS(0, false, REJECT_NONSTANDARD, "bad-txns-too-many-sigops", false,
949-
strprintf("%d > %d", nSigOps, MAX_STANDARD_TX_SIGOPS));
950943

951944
CAmount nValueOut = tx.GetValueOut();
952945
CAmount nFees = nValueIn-nValueOut;
@@ -967,6 +960,15 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
967960
CTxMemPoolEntry entry(tx, nFees, GetTime(), dPriority, chainActive.Height(), pool.HasNoInputsOf(tx), inChainInputValue, fSpendsCoinbase, nSigOps);
968961
unsigned int nSize = entry.GetTxSize();
969962

963+
// Check that the transaction doesn't have an excessive number of
964+
// sigops, making it impossible to mine. Since the coinbase transaction
965+
// itself can contain sigops MAX_STANDARD_TX_SIGOPS is less than
966+
// MAX_BLOCK_SIGOPS; we still consider this an invalid rather than
967+
// merely non-standard transaction.
968+
if ((nSigOps > MAX_STANDARD_TX_SIGOPS) || (nBytesPerSigOp && nSigOps > nSize / nBytesPerSigOp))
969+
return state.DoS(0, false, REJECT_NONSTANDARD, "bad-txns-too-many-sigops", false,
970+
strprintf("%d", nSigOps));
971+
970972
// Don't accept it if it can't get into a block
971973
CAmount txMinFee = GetMinRelayFee(tx, pool, nSize, true);
972974
if (fLimitFree && nFees < txMinFee)

src/main.h

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

9393
/** Default for -permitbaremultisig */
9494
static const bool DEFAULT_PERMIT_BAREMULTISIG = true;
95+
static const unsigned int DEFAULT_BYTES_PER_SIGOP = 20;
9596
static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
9697
static const bool DEFAULT_TXINDEX = false;
9798
static const unsigned int DEFAULT_BANSCORE_THRESHOLD = 100;
@@ -122,6 +123,7 @@ extern int nScriptCheckThreads;
122123
extern bool fTxIndex;
123124
extern bool fIsBareMultisigStd;
124125
extern bool fRequireStandard;
126+
extern unsigned int nBytesPerSigOp;
125127
extern bool fCheckBlockIndex;
126128
extern bool fCheckpointsEnabled;
127129
extern size_t nCoinCacheUsage;

0 commit comments

Comments
 (0)