diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2012-05-17 10:12:04 -0400 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2012-06-20 17:53:18 +0000 |
commit | 01473c3f40cea8209186e737ae20289eebcb8898 (patch) | |
tree | 9dd1cac26e49412d0d581c0ab6a6dbdbba93ca3e /src | |
parent | ce1a071f6d6d1548974796c4327399659415b489 (diff) | |
download | bitcoin-01473c3f40cea8209186e737ae20289eebcb8898.tar.xz |
Remove invalid dependent orphans from memory
Remove orphan transactions from memory once
all of their parent transactions are received
and they're still not valid.
Thanks to Sergio Demian Lerner for suggesting this fix.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp index 00f0633431..432ec871f5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2378,6 +2378,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) else if (strCommand == "tx") { vector<uint256> vWorkQueue; + vector<uint256> vEraseQueue; CDataStream vMsg(vRecv); CTransaction tx; vRecv >> tx; @@ -2392,6 +2393,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) RelayMessage(inv, vMsg); mapAlreadyAskedFor.erase(inv); vWorkQueue.push_back(inv.hash); + vEraseQueue.push_back(inv.hash); // Recursively process any orphan transactions that depended on this one for (unsigned int i = 0; i < vWorkQueue.size(); i++) @@ -2405,19 +2407,27 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) CTransaction tx; CDataStream(vMsg) >> tx; CInv inv(MSG_TX, tx.GetHash()); + bool fMissingInputs2 = false; - if (tx.AcceptToMemoryPool(true)) + if (tx.AcceptToMemoryPool(true, &fMissingInputs2)) { printf(" accepted orphan tx %s\n", inv.hash.ToString().substr(0,10).c_str()); SyncWithWallets(tx, NULL, true); RelayMessage(inv, vMsg); mapAlreadyAskedFor.erase(inv); vWorkQueue.push_back(inv.hash); + vEraseQueue.push_back(inv.hash); + } + else if (!fMissingInputs2) + { + // invalid orphan + vEraseQueue.push_back(inv.hash); + printf(" removed invalid orphan tx %s\n", inv.hash.ToString().substr(0,10).c_str()); } } } - BOOST_FOREACH(uint256 hash, vWorkQueue) + BOOST_FOREACH(uint256 hash, vEraseQueue) EraseOrphanTx(hash); } else if (fMissingInputs) |