Auto merge of #2342 - bitcartel:1081__mempoolpatch, r=str4d
Add ability for node to reject tx from mempool by number of tx inputs Implement short-term solution described in #2343 so that users can respond promptly to critical short-term problems caused by quadratic validation scaling, such as the getblocktemplate latency, block propagation latency, and mempool size inflation issues described in #2333.
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <gtest/gtest-spi.h>
|
||||
|
||||
#include "consensus/validation.h"
|
||||
#include "core_io.h"
|
||||
#include "main.h"
|
||||
#include "primitives/transaction.h"
|
||||
#include "txmempool.h"
|
||||
#include "policy/fees.h"
|
||||
#include "util.h"
|
||||
|
||||
// Fake the input of transaction 5295156213414ed77f6e538e7e8ebe14492156906b9fe995b242477818789364
|
||||
// - 532639cc6bebed47c1c69ae36dd498c68a012e74ad12729adbd3dbb56f8f3f4a, 0
|
||||
@@ -87,3 +90,49 @@ TEST(Mempool, PriorityStatsDoNotCrash) {
|
||||
|
||||
EXPECT_EQ(dPriority, MAX_PRIORITY);
|
||||
}
|
||||
|
||||
TEST(Mempool, TxInputLimit) {
|
||||
CTxMemPool pool(::minRelayTxFee);
|
||||
bool missingInputs;
|
||||
|
||||
// Create an obviously-invalid transaction
|
||||
// We intentionally set tx.nVersion = 0 to reliably trigger an error, as
|
||||
// it's the first check that occurs after the -mempooltxinputlimit check,
|
||||
// and it means that we don't have to mock out a lot of global state.
|
||||
CMutableTransaction mtx;
|
||||
mtx.nVersion = 0;
|
||||
mtx.vin.resize(10);
|
||||
|
||||
// Check it fails as expected
|
||||
CValidationState state1;
|
||||
CTransaction tx1(mtx);
|
||||
EXPECT_FALSE(AcceptToMemoryPool(pool, state1, tx1, false, &missingInputs));
|
||||
EXPECT_EQ(state1.GetRejectReason(), "bad-txns-version-too-low");
|
||||
|
||||
// Set a limit
|
||||
mapArgs["-mempooltxinputlimit"] = "10";
|
||||
|
||||
// Check it stil fails as expected
|
||||
CValidationState state2;
|
||||
EXPECT_FALSE(AcceptToMemoryPool(pool, state2, tx1, false, &missingInputs));
|
||||
EXPECT_EQ(state2.GetRejectReason(), "bad-txns-version-too-low");
|
||||
|
||||
// Resize the transaction
|
||||
mtx.vin.resize(11);
|
||||
|
||||
// Check it now fails due to exceeding the limit
|
||||
CValidationState state3;
|
||||
CTransaction tx3(mtx);
|
||||
EXPECT_FALSE(AcceptToMemoryPool(pool, state3, tx3, false, &missingInputs));
|
||||
// The -mempooltxinputlimit check doesn't set a reason
|
||||
EXPECT_EQ(state3.GetRejectReason(), "");
|
||||
|
||||
// Clear the limit
|
||||
mapArgs.erase("-mempooltxinputlimit");
|
||||
|
||||
// Check it no longer fails due to exceeding the limit
|
||||
CValidationState state4;
|
||||
EXPECT_FALSE(AcceptToMemoryPool(pool, state4, tx3, false, &missingInputs));
|
||||
EXPECT_EQ(state4.GetRejectReason(), "bad-txns-version-too-low");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user