diff -uNr a/bitcoin/src/main.cpp b/bitcoin/src/main.cpp --- a/bitcoin/src/main.cpp fe5dcf6804d4fdaa80f20ebdcd4fdfeafe0fa4108818a6574b5a6123790e7cdb38ccb612078af5ac8ee42e5f3c3e525e62e29a041f5ab5ebebaf929950ae5aac +++ b/bitcoin/src/main.cpp 18a4b9a7abccac46895c8eeb0c14cc502f3743958654444c87d5192a51073980858750daa9c8bd67f4d4d2ec8a7117aea8fc75a4acf73cc1a2cab996aea324b1 @@ -40,8 +40,6 @@ CMedianFilter cPeerBlockCounts(5, 0); // Amount of blocks that other nodes claim to have -map mapOrphanTransactions; -multimap mapOrphanTransactionsByPrev; double dHashesPerSec; @@ -148,75 +146,6 @@ } - - - - - -////////////////////////////////////////////////////////////////////////////// -// -// mapOrphanTransactions -// - -void AddOrphanTx(const CDataStream& vMsg) -{ - CTransaction tx; - CDataStream(vMsg) >> tx; - uint256 hash = tx.GetHash(); - if (mapOrphanTransactions.count(hash)) - return; - - CDataStream* pvMsg = mapOrphanTransactions[hash] = new CDataStream(vMsg); - BOOST_FOREACH(const CTxIn& txin, tx.vin) - mapOrphanTransactionsByPrev.insert(make_pair(txin.prevout.hash, pvMsg)); -} - -void static EraseOrphanTx(uint256 hash) -{ - if (!mapOrphanTransactions.count(hash)) - return; - const CDataStream* pvMsg = mapOrphanTransactions[hash]; - CTransaction tx; - CDataStream(*pvMsg) >> tx; - BOOST_FOREACH(const CTxIn& txin, tx.vin) - { - for (multimap::iterator mi = mapOrphanTransactionsByPrev.lower_bound(txin.prevout.hash); - mi != mapOrphanTransactionsByPrev.upper_bound(txin.prevout.hash);) - { - if ((*mi).second == pvMsg) - mapOrphanTransactionsByPrev.erase(mi++); - else - mi++; - } - } - delete pvMsg; - mapOrphanTransactions.erase(hash); -} - -int LimitOrphanTxSize(int nMaxOrphans) -{ - int nEvicted = 0; - while (mapOrphanTransactions.size() > nMaxOrphans) - { - // Evict a random orphan: - std::vector randbytes(32); - RAND_bytes(&randbytes[0], 32); - uint256 randomhash(randbytes); - map::iterator it = mapOrphanTransactions.lower_bound(randomhash); - if (it == mapOrphanTransactions.end()) - it = mapOrphanTransactions.begin(); - EraseOrphanTx(it->first); - ++nEvicted; - } - return nEvicted; -} - - - - - - - ////////////////////////////////////////////////////////////////////////////// // // CTransaction and CTxIndex @@ -1731,7 +1660,7 @@ { switch (inv.type) { - case MSG_TX: return mapTransactions.count(inv.hash) || mapOrphanTransactions.count(inv.hash) || txdb.ContainsTx(inv.hash); + case MSG_TX: return mapTransactions.count(inv.hash) || txdb.ContainsTx(inv.hash); case MSG_BLOCK: return mapBlockIndex.count(inv.hash); } // Don't know what it is, just say we already got one @@ -2108,43 +2037,10 @@ RelayMessage(inv, vMsg); mapAlreadyAskedFor.erase(inv); vWorkQueue.push_back(inv.hash); - - // Recursively process any orphan transactions that depended on this one - for (int i = 0; i < vWorkQueue.size(); i++) - { - uint256 hashPrev = vWorkQueue[i]; - for (multimap::iterator mi = mapOrphanTransactionsByPrev.lower_bound(hashPrev); - mi != mapOrphanTransactionsByPrev.upper_bound(hashPrev); - ++mi) - { - const CDataStream& vMsg = *((*mi).second); - CTransaction tx; - CDataStream(vMsg) >> tx; - CInv inv(MSG_TX, tx.GetHash()); - - if (tx.AcceptToMemoryPool(true)) - { - 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); - } - } - } - - BOOST_FOREACH(uint256 hash, vWorkQueue) - EraseOrphanTx(hash); } else if (fMissingInputs) { - printf("storing orphan tx %s\n", inv.hash.ToString().substr(0,10).c_str()); - AddOrphanTx(vMsg); - - // DoS prevention: do not allow mapOrphanTransactions to grow unbounded - int nEvicted = LimitOrphanTxSize(MAX_ORPHAN_TRANSACTIONS); - if (nEvicted > 0) - printf("mapOrphan overflow, removed %d tx\n", nEvicted); + printf("REJECTED orphan tx %s\n", inv.hash.ToString().substr(0,10).c_str()); } if (tx.nDoS) pfrom->Misbehaving(tx.nDoS); } diff -uNr a/bitcoin/src/main.h b/bitcoin/src/main.h --- a/bitcoin/src/main.h 8cfdda6fd46e07e50ab42e4f4652274c324b6020f30a340b6bb9ee3fd620c497473c8480102218d48261646d7adfecff7ff987f8a798997b4d3ebd032066d78d +++ b/bitcoin/src/main.h ff2bf8f8147dd8df5e1ef1bcea9b0159d3f83c1e30befef56415b99305aa99161ac1c05efb48be87a383ffb6d621fd3761bfb3e4952ca244a6e1398ca3c71dc6 @@ -30,7 +30,6 @@ static const unsigned int MAX_BLOCK_SIZE = 1000000; static const unsigned int MAX_BLOCK_SIZE_GEN = MAX_BLOCK_SIZE/2; static const int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50; -static const int MAX_ORPHAN_TRANSACTIONS = MAX_BLOCK_SIZE/100; static const int64 COIN = 100000000; static const int64 CENT = 1000000; static const int64 MIN_TX_FEE = 50000;