Skip to content

Commit 7485488

Browse files
committed
Policy to reject extremely small transactions
A transaction with 1 segwit input and 1 P2WPHK output has non-witness size of 82 bytes. Anything smaller than this have unnecessary malloc overhead and are not relayed/mined.
1 parent 0f8719b commit 7485488

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/policy/policy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ static const unsigned int DEFAULT_BLOCK_MAX_WEIGHT = MAX_BLOCK_WEIGHT - 4000;
2222
static const unsigned int DEFAULT_BLOCK_MIN_TX_FEE = 1000;
2323
/** The maximum weight for transactions we're willing to relay/mine */
2424
static const unsigned int MAX_STANDARD_TX_WEIGHT = 400000;
25+
/** The minimum non-witness size for transactions we're willing to relay/mine (1 segwit input + 1 P2WPKH output = 82 bytes) */
26+
static const unsigned int MIN_STANDARD_TX_NONWITNESS_SIZE = 82;
2527
/** Maximum number of signature check operations in an IsStandard() P2SH script */
2628
static const unsigned int MAX_P2SH_SIGOPS = 15;
2729
/** The maximum number of sigops we're willing to relay/mine in a single tx */

src/validation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,12 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
582582
if (fRequireStandard && !IsStandardTx(tx, reason, witnessEnabled))
583583
return state.DoS(0, false, REJECT_NONSTANDARD, reason);
584584

585+
// Do not work on transactions that are too small.
586+
// A transaction with 1 segwit input and 1 P2WPHK output has non-witness size of 82 bytes.
587+
// Transactions smaller than this are not relayed to reduce unnecessary malloc overhead.
588+
if (::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) < MIN_STANDARD_TX_NONWITNESS_SIZE)
589+
return state.DoS(0, false, REJECT_NONSTANDARD, "tx-size-small");
590+
585591
// Only accept nLockTime-using transactions that can be mined in the next
586592
// block; we don't want our mempool filled up with transactions that can't
587593
// be mined yet.

0 commit comments

Comments
 (0)