aboutsummaryrefslogtreecommitdiff
path: root/src/test/DoS_tests.cpp
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2014-08-28 13:23:24 -0400
committerGavin Andresen <gavinandresen@gmail.com>2014-09-10 14:09:40 -0400
commitc74332c67806ed92e6e18de174671a7c30608780 (patch)
tree635d923bc891518c366dfb651304326a59b704df /src/test/DoS_tests.cpp
parentdef2fdb4b9b52fa908c11fe2f5a42ea04f8e9f11 (diff)
Stricter handling of orphan transactions
Prevent denial-of-service attacks by banning peers that send us invalid orphan transactions and only storing orphan transactions given to us by a peer while the peer is connected.
Diffstat (limited to 'src/test/DoS_tests.cpp')
-rw-r--r--src/test/DoS_tests.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/test/DoS_tests.cpp b/src/test/DoS_tests.cpp
index fa4edff63f..e019674816 100644
--- a/src/test/DoS_tests.cpp
+++ b/src/test/DoS_tests.cpp
@@ -24,7 +24,8 @@
#include <boost/test/unit_test.hpp>
// Tests this internal-to-main.cpp method:
-extern bool AddOrphanTx(const CTransaction& tx);
+extern bool AddOrphanTx(const CTransaction& tx, NodeId peer);
+extern void EraseOrphansFor(NodeId peer);
extern unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans);
extern std::map<uint256, CTransaction> mapOrphanTransactions;
extern std::map<uint256, std::set<uint256> > mapOrphanTransactionsByPrev;
@@ -174,7 +175,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
tx.vout[0].nValue = 1*CENT;
tx.vout[0].scriptPubKey.SetDestination(key.GetPubKey().GetID());
- AddOrphanTx(tx);
+ AddOrphanTx(tx, i);
}
// ... and 50 that depend on other orphans:
@@ -191,7 +192,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
tx.vout[0].scriptPubKey.SetDestination(key.GetPubKey().GetID());
SignSignature(keystore, txPrev, tx, 0);
- AddOrphanTx(tx);
+ AddOrphanTx(tx, i);
}
// This really-big orphan should be ignored:
@@ -215,7 +216,15 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
for (unsigned int j = 1; j < tx.vin.size(); j++)
tx.vin[j].scriptSig = tx.vin[0].scriptSig;
- BOOST_CHECK(!AddOrphanTx(tx));
+ BOOST_CHECK(!AddOrphanTx(tx, i));
+ }
+
+ // Test EraseOrphansFor:
+ for (NodeId i = 0; i < 3; i++)
+ {
+ size_t sizeBefore = mapOrphanTransactions.size();
+ EraseOrphansFor(i);
+ BOOST_CHECK(mapOrphanTransactions.size() < sizeBefore);
}
// Test LimitOrphanTxSize() function: