mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-03 17:54:19 +02:00
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.
Rebased-From: c74332c678
This commit is contained in:
committed by
Wladimir J. van der Laan
parent
306a93b79e
commit
6d911ada83
@@ -23,7 +23,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;
|
||||
@@ -177,7 +178,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:
|
||||
@@ -194,7 +195,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:
|
||||
@@ -218,7 +219,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:
|
||||
@@ -255,7 +264,7 @@ BOOST_AUTO_TEST_CASE(DoS_checkSig)
|
||||
tx.vout[0].nValue = 1*CENT;
|
||||
tx.vout[0].scriptPubKey.SetDestination(key.GetPubKey().GetID());
|
||||
|
||||
AddOrphanTx(tx);
|
||||
AddOrphanTx(tx, 0);
|
||||
}
|
||||
|
||||
// Create a transaction that depends on orphans:
|
||||
|
||||
Reference in New Issue
Block a user