diff options
author | Jeff Garzik <jeff@garzik.org> | 2012-04-13 16:28:07 -0400 |
---|---|---|
committer | Jeff Garzik <jgarzik@redhat.com> | 2012-04-15 14:42:52 -0400 |
commit | 8e45ed66dde5d5eb5fde0fc1eba64b26bd48bfb0 (patch) | |
tree | a14ee478db4d23b7aa3b258db990f3df596583f9 /src | |
parent | 235507ae48718ee8ce5289b2791b4b449090dabc (diff) |
CTxMemPool: encapsulate AddToMemoryPoolUnchecked(), RemoveFromMemoryPool(),
and nPooledTx
Diffstat (limited to 'src')
-rw-r--r-- | src/bitcoinrpc.cpp | 2 | ||||
-rw-r--r-- | src/main.cpp | 42 | ||||
-rw-r--r-- | src/main.h | 15 |
3 files changed, 31 insertions, 28 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 63c51ada8d..b8ef5275f8 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -363,7 +363,7 @@ Value getmininginfo(const Array& params, bool fHelp) obj.push_back(Pair("generate", GetBoolArg("-gen"))); obj.push_back(Pair("genproclimit", (int)GetArg("-genproclimit", -1))); obj.push_back(Pair("hashespersec", gethashespersec(params, false))); - obj.push_back(Pair("pooledtx", (uint64_t)nPooledTx)); + obj.push_back(Pair("pooledtx", (uint64_t)mempool.size())); obj.push_back(Pair("testnet", fTestNet)); return obj; } diff --git a/src/main.cpp b/src/main.cpp index 9e2fbe99e7..ba20af0550 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,7 +23,7 @@ set<CWallet*> setpwalletRegistered; CCriticalSection cs_main; -static CTxMemPool mempool; +CTxMemPool mempool; unsigned int nTransactionsUpdated = 0; map<uint256, CBlockIndex*> mapBlockIndex; @@ -576,9 +576,9 @@ bool CTransaction::AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs, bool* pfMi if (ptxOld) { printf("AcceptToMemoryPool() : replacing tx %s with new version\n", ptxOld->GetHash().ToString().c_str()); - ptxOld->RemoveFromMemoryPool(); + mempool.remove(*ptxOld); } - AddToMemoryPoolUnchecked(); + mempool.addUnchecked(*this); } ///// are we sure this is ok when loading transactions or restoring block txes @@ -590,39 +590,35 @@ bool CTransaction::AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs, bool* pfMi return true; } -uint64 nPooledTx = 0; - -bool CTransaction::AddToMemoryPoolUnchecked() +bool CTxMemPool::addUnchecked(CTransaction &tx) { - printf("AcceptToMemoryPoolUnchecked(): size %lu\n", mempool.mapTx.size()); + printf("AcceptToMemoryPoolUnchecked(): size %lu\n", mapTx.size()); // Add to memory pool without checking anything. Don't call this directly, // call AcceptToMemoryPool to properly check the transaction first. { - LOCK(mempool.cs); - uint256 hash = GetHash(); - mempool.mapTx[hash] = *this; - for (int i = 0; i < vin.size(); i++) - mempool.mapNextTx[vin[i].prevout] = CInPoint(&mempool.mapTx[hash], i); + LOCK(cs); + uint256 hash = tx.GetHash(); + mapTx[hash] = tx; + for (int i = 0; i < tx.vin.size(); i++) + mapNextTx[tx.vin[i].prevout] = CInPoint(&mapTx[hash], i); nTransactionsUpdated++; - ++nPooledTx; } return true; } -bool CTransaction::RemoveFromMemoryPool() +bool CTxMemPool::remove(CTransaction &tx) { // Remove transaction from memory pool { - LOCK(mempool.cs); - uint256 hash = GetHash(); - if (mempool.mapTx.count(hash)) + LOCK(cs); + uint256 hash = tx.GetHash(); + if (mapTx.count(hash)) { - BOOST_FOREACH(const CTxIn& txin, vin) - mempool.mapNextTx.erase(txin.prevout); - mempool.mapTx.erase(hash); + BOOST_FOREACH(const CTxIn& txin, tx.vin) + mapNextTx.erase(txin.prevout); + mapTx.erase(hash); nTransactionsUpdated++; - --nPooledTx; } } return true; @@ -1435,7 +1431,7 @@ bool static Reorganize(CTxDB& txdb, CBlockIndex* pindexNew) // Delete redundant memory transactions that are in the connected branch BOOST_FOREACH(CTransaction& tx, vDelete) - tx.RemoveFromMemoryPool(); + mempool.remove(tx); printf("REORGANIZE: done\n"); @@ -1471,7 +1467,7 @@ bool CBlock::SetBestChainInner(CTxDB& txdb, CBlockIndex *pindexNew) // Delete redundant memory transactions BOOST_FOREACH(CTransaction& tx, vtx) - tx.RemoveFromMemoryPool(); + mempool.remove(tx); return true; } diff --git a/src/main.h b/src/main.h index ef4ee137b6..bf24944ce2 100644 --- a/src/main.h +++ b/src/main.h @@ -67,7 +67,6 @@ extern CBigNum bnBestChainWork; extern CBigNum bnBestInvalidWork; extern uint256 hashBestChain; extern CBlockIndex* pindexBest; -extern uint64 nPooledTx; extern unsigned int nTransactionsUpdated; extern uint64 nLastBlockTx; extern uint64 nLastBlockSize; @@ -689,9 +688,6 @@ public: protected: const CTxOut& GetOutputFor(const CTxIn& input, const MapPrevTx& inputs) const; - bool AddToMemoryPoolUnchecked(); -public: - bool RemoveFromMemoryPool(); }; @@ -1614,6 +1610,17 @@ public: mutable CCriticalSection cs; std::map<uint256, CTransaction> mapTx; std::map<COutPoint, CInPoint> mapNextTx; + + bool addUnchecked(CTransaction &tx); + bool remove(CTransaction &tx); + + unsigned long size() + { + LOCK(cs); + return mapTx.size(); + } }; +extern CTxMemPool mempool; + #endif |