aboutsummaryrefslogtreecommitdiff
path: root/src/validation.cpp
diff options
context:
space:
mode:
authorJohnson Lau <jl2012@xbt.hk>2018-04-27 03:31:36 +0800
committerMarcoFalke <falke.marco@gmail.com>2018-05-24 14:03:05 -0400
commit0a000b9b73a7d7bb4086aeefc86841d0fc33e652 (patch)
tree6568d7a99f18892716c3befdef3892af3c5fbded /src/validation.cpp
parent1fffc2b346b2d2e129db5c9f5cad00e820c85c45 (diff)
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. Github-Pull: #11423 Rebased-From: 7485488e907e236133a016ba7064c89bf9ab6da3
Diffstat (limited to 'src/validation.cpp')
-rw-r--r--src/validation.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/validation.cpp b/src/validation.cpp
index 7c4c84c3f9..2c5b5a1a31 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -576,6 +576,12 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
if (fRequireStandard && !IsStandardTx(tx, reason, witnessEnabled))
return state.DoS(0, false, REJECT_NONSTANDARD, reason);
+ // Do not work on transactions that are too small.
+ // A transaction with 1 segwit input and 1 P2WPHK output has non-witness size of 82 bytes.
+ // Transactions smaller than this are not relayed to reduce unnecessary malloc overhead.
+ if (::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) < MIN_STANDARD_TX_NONWITNESS_SIZE)
+ return state.DoS(0, false, REJECT_NONSTANDARD, "tx-size-small");
+
// Only accept nLockTime-using transactions that can be mined in the next
// block; we don't want our mempool filled up with transactions that can't
// be mined yet.