aboutsummaryrefslogtreecommitdiff
path: root/src/test/DoS_tests.cpp
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2012-05-15 15:53:30 -0400
committerGavin Andresen <gavinandresen@gmail.com>2012-05-18 10:13:21 -0400
commit77b99cf7ad8f15f6228b07d5d01cb20c849519b8 (patch)
tree67ce38adebe3b5cd8b22a4c432d0282f40d45d54 /src/test/DoS_tests.cpp
parentf718aedd9f244ee77a40f182bf6c6737730d975c (diff)
downloadbitcoin-77b99cf7ad8f15f6228b07d5d01cb20c849519b8.tar.xz
Optimize orphan transaction handling
Changes suggested by Sergio Demian Lerner to help prevent potential DoS attacks.
Diffstat (limited to 'src/test/DoS_tests.cpp')
-rw-r--r--src/test/DoS_tests.cpp30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/test/DoS_tests.cpp b/src/test/DoS_tests.cpp
index 3a2b1d9d54..c0d414d083 100644
--- a/src/test/DoS_tests.cpp
+++ b/src/test/DoS_tests.cpp
@@ -13,10 +13,10 @@
#include <stdint.h>
// Tests this internal-to-main.cpp method:
-extern void AddOrphanTx(const CDataStream& vMsg);
+extern bool AddOrphanTx(const CDataStream& vMsg);
extern unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans);
extern std::map<uint256, CDataStream*> mapOrphanTransactions;
-extern std::multimap<uint256, CDataStream*> mapOrphanTransactionsByPrev;
+extern std::map<uint256, std::map<uint256, CDataStream*> > mapOrphanTransactionsByPrev;
CService ip(uint32_t i)
{
@@ -184,6 +184,32 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
AddOrphanTx(ds);
}
+ // This really-big orphan should be ignored:
+ for (int i = 0; i < 10; i++)
+ {
+ CTransaction txPrev = RandomOrphan();
+
+ CTransaction tx;
+ tx.vout.resize(1);
+ tx.vout[0].nValue = 1*CENT;
+ tx.vout[0].scriptPubKey.SetBitcoinAddress(key.GetPubKey());
+ tx.vin.resize(500);
+ for (int j = 0; j < tx.vin.size(); j++)
+ {
+ tx.vin[j].prevout.n = j;
+ tx.vin[j].prevout.hash = txPrev.GetHash();
+ }
+ SignSignature(keystore, txPrev, tx, 0);
+ // Re-use same signature for other inputs
+ // (they don't have to be valid for this test)
+ for (int j = 1; j < tx.vin.size(); j++)
+ tx.vin[j].scriptSig = tx.vin[0].scriptSig;
+
+ CDataStream ds(SER_DISK, CLIENT_VERSION);
+ ds << tx;
+ BOOST_CHECK(!AddOrphanTx(ds));
+ }
+
// Test LimitOrphanTxSize() function:
LimitOrphanTxSize(40);
BOOST_CHECK(mapOrphanTransactions.size() <= 40);