Skip to content

Commit 3f65ba2

Browse files
sipadexX7
authored andcommitted
Treat high-sigop transactions as larger rather than rejecting them
1 parent ced6c94 commit 3f65ba2

File tree

6 files changed

+15
-12
lines changed

6 files changed

+15
-12
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ std::string HelpMessage(HelpMessageMode mode)
446446
strUsage += HelpMessageGroup(_("Node relay options:"));
447447
if (showDebug)
448448
strUsage += HelpMessageOpt("-acceptnonstdtxn", strprintf("Relay and mine \"non-standard\" transactions (%sdefault: %u)", "testnet/regtest only; ", !Params(CBaseChainParams::TESTNET).RequireStandard()));
449-
strUsage += HelpMessageOpt("-bytespersigop", strprintf(_("Minimum bytes per sigop in transactions we relay and mine (default: %u)"), DEFAULT_BYTES_PER_SIGOP));
449+
strUsage += HelpMessageOpt("-bytespersigop", strprintf(_("Equivalent bytes per sigop in transactions for relay and mining (default: %u)"), DEFAULT_BYTES_PER_SIGOP));
450450
strUsage += HelpMessageOpt("-datacarrier", strprintf(_("Relay and mine data carrier transactions (default: %u)"), DEFAULT_ACCEPT_DATACARRIER));
451451
strUsage += HelpMessageOpt("-datacarriersize", strprintf(_("Maximum size of data in data carrier transactions we relay and mine (default: %u)"), MAX_OP_RETURN_RELAY));
452452
strUsage += HelpMessageOpt("-mempoolreplacement", strprintf(_("Enable transaction replacement in the memory pool (default: %u)"), DEFAULT_ENABLE_REPLACEMENT));

src/main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ bool fHavePruned = false;
7474
bool fPruneMode = false;
7575
bool fIsBareMultisigStd = DEFAULT_PERMIT_BAREMULTISIG;
7676
bool fRequireStandard = true;
77-
unsigned int nBytesPerSigOp = DEFAULT_BYTES_PER_SIGOP;
7877
bool fCheckBlockIndex = false;
7978
bool fCheckpointsEnabled = DEFAULT_CHECKPOINTS_ENABLED;
8079
size_t nCoinCacheUsage = 5000 * 300;
@@ -1297,7 +1296,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
12971296
// itself can contain sigops MAX_STANDARD_TX_SIGOPS is less than
12981297
// MAX_BLOCK_SIGOPS; we still consider this an invalid rather than
12991298
// merely non-standard transaction.
1300-
if ((nSigOpsCost > MAX_STANDARD_TX_SIGOPS_COST) || (nBytesPerSigOp && nSigOpsCost > nSize * WITNESS_SCALE_FACTOR / nBytesPerSigOp))
1299+
if (nSigOpsCost > MAX_STANDARD_TX_SIGOPS_COST)
13011300
return state.DoS(0, false, REJECT_NONSTANDARD, "bad-txns-too-many-sigops", false,
13021301
strprintf("%d", nSigOpsCost));
13031302

src/main.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;
124124

125125
/** Default for -permitbaremultisig */
126126
static const bool DEFAULT_PERMIT_BAREMULTISIG = true;
127-
static const unsigned int DEFAULT_BYTES_PER_SIGOP = 20;
128127
static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
129128
static const bool DEFAULT_TXINDEX = false;
130129
static const unsigned int DEFAULT_BANSCORE_THRESHOLD = 100;
@@ -165,7 +164,6 @@ extern int nScriptCheckThreads;
165164
extern bool fTxIndex;
166165
extern bool fIsBareMultisigStd;
167166
extern bool fRequireStandard;
168-
extern unsigned int nBytesPerSigOp;
169167
extern bool fCheckBlockIndex;
170168
extern bool fCheckpointsEnabled;
171169
extern size_t nCoinCacheUsage;

src/policy/policy.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,14 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
154154
return true;
155155
}
156156

157-
int64_t GetVirtualTransactionSize(int64_t nWeight)
157+
unsigned int nBytesPerSigOp = DEFAULT_BYTES_PER_SIGOP;
158+
159+
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost)
158160
{
159-
return (nWeight + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR;
161+
return (std::max(nWeight, nSigOpCost * nBytesPerSigOp) + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR;
160162
}
161163

162-
int64_t GetVirtualTransactionSize(const CTransaction& tx)
164+
int64_t GetVirtualTransactionSize(const CTransaction& tx, int64_t nSigOpCost)
163165
{
164-
return GetVirtualTransactionSize(GetTransactionWeight(tx));
166+
return GetVirtualTransactionSize(GetTransactionWeight(tx), nSigOpCost);
165167
}

src/policy/policy.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ static const unsigned int MAX_P2SH_SIGOPS = 15;
2828
static const unsigned int MAX_STANDARD_TX_SIGOPS_COST = MAX_BLOCK_SIGOPS_COST/5;
2929
/** Default for -maxmempool, maximum megabytes of mempool memory usage */
3030
static const unsigned int DEFAULT_MAX_MEMPOOL_SIZE = 300;
31+
/** Default for -bytespersigop */
32+
static const unsigned int DEFAULT_BYTES_PER_SIGOP = 20;
3133
/**
3234
* Standard script verification flags that standard transactions will comply
3335
* with. However scripts violating these flags may still be present in valid
@@ -66,8 +68,10 @@ bool IsStandardTx(const CTransaction& tx, std::string& reason, const bool witnes
6668
*/
6769
bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs);
6870

71+
extern unsigned int nBytesPerSigOp;
72+
6973
/** Compute the virtual transaction size (weight reinterpreted as bytes). */
70-
int64_t GetVirtualTransactionSize(int64_t nWeight);
71-
int64_t GetVirtualTransactionSize(const CTransaction& tx);
74+
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost);
75+
int64_t GetVirtualTransactionSize(const CTransaction& tx, int64_t nSigOpCost = 0);
7276

7377
#endif // BITCOIN_POLICY_POLICY_H

src/txmempool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void CTxMemPoolEntry::UpdateLockPoints(const LockPoints& lp)
7575

7676
size_t CTxMemPoolEntry::GetTxSize() const
7777
{
78-
return GetVirtualTransactionSize(nTxWeight);
78+
return GetVirtualTransactionSize(nTxWeight, sigOpCost);
7979
}
8080

8181
// Update the given tx for any in-mempool descendants.

0 commit comments

Comments
 (0)