diff --git a/src/bench/rpc_mempool.cpp b/src/bench/rpc_mempool.cpp new file mode 100644 index 00000000000..67c827d0d33 --- /dev/null +++ b/src/bench/rpc_mempool.cpp @@ -0,0 +1,40 @@ +// Copyright (c) 2011-2020 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include +#include + +#include + + +static void AddTx(const CTransactionRef& tx, const CAmount& fee, CTxMemPool& pool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, pool.cs) +{ + LockPoints lp; + pool.addUnchecked(CTxMemPoolEntry(tx, fee, /*time=*/0, /*entry_height=*/1, /*spends_coinbase=*/false, /*sigops_cost=*/4, lp)); +} + +static void RpcMempool(benchmark::Bench& bench) +{ + CTxMemPool pool; + LOCK2(cs_main, pool.cs); + + for (int i = 0; i < 1000; ++i) { + CMutableTransaction tx = CMutableTransaction(); + tx.vin.resize(1); + tx.vin[0].scriptSig = CScript() << OP_1; + tx.vin[0].scriptWitness.stack.push_back({1}); + tx.vout.resize(1); + tx.vout[0].scriptPubKey = CScript() << OP_1 << OP_EQUAL; + tx.vout[0].nValue = i; + const CTransactionRef tx_r{MakeTransactionRef(tx)}; + AddTx(tx_r, /* fee */ i, pool); + } + + bench.run([&] { + (void)MempoolToJSON(pool, /*verbose*/ true); + }); +} + +BENCHMARK(RpcMempool); diff --git a/src/qt/test/test_main.cpp b/src/qt/test/test_main.cpp index 3d846b4a83c..e7abfc91b37 100644 --- a/src/qt/test/test_main.cpp +++ b/src/qt/test/test_main.cpp @@ -66,7 +66,7 @@ int main(int argc, char *argv[]) #if defined(WIN32) _putenv_s("QT_QPA_PLATFORM", "minimal"); #else - setenv("QT_QPA_PLATFORM", "minimal", 0); + setenv("QT_QPA_PLATFORM", "minimal", 0 /* overwrite */); #endif // Don't remove this, it's needed to access diff --git a/src/test/denialofservice_tests.cpp b/src/test/denialofservice_tests.cpp new file mode 100644 index 00000000000..765663e0ef2 --- /dev/null +++ b/src/test/denialofservice_tests.cpp @@ -0,0 +1,432 @@ +// Copyright (c) 2011-2020 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +// Unit tests for denial-of-service detection/prevention code + +#include +#include +#include +#include +#include +#include +#include