Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

PARTIAL: switch to a single CPendingRelayBlock

  • Loading branch information...
commit 9387855b23e0c074edeb4e2dd35cf481494feaf0 1 parent 6528a2b
@TheBlueMatt authored
Showing with 20 additions and 29 deletions.
  1. +14 −24 src/main.cpp
  2. +6 −5 src/main.h
View
38 src/main.cpp
@@ -24,7 +24,7 @@ set<CWallet*> setpwalletRegistered;
CCriticalSection cs_main;
-CPendingRelayBlockPool mempoolBlocks;
+CPendingRelayBlock mempoolBlocks;
CTxMemPool mempool;
unsigned int nTransactionsUpdated = 0;
@@ -2069,33 +2069,23 @@ uint256 CRelayBlock::GetBlockHash()
-bool CPendingRelayBlockPool::ProvideTransaction(const CTransaction& tx, const uint256& hash)
+bool CPendingRelayBlock::ProvideTransaction(const CTransaction& tx, const uint256& hash)
{
- bool fRet = false;
- for (list<RelayedBlockTupleType>::iterator it = listUnfilledBlocks.begin(); it != listUnfilledBlocks.end(); it++)
+ set<uint256>& setMissingTxes = get<0>(blockUnfilled);
+ set<uint256>::iterator itHash = setMissingTxes.find(hash);
+ if (itHash != setMissingTxes.end())
{
- set<uint256>& setMissingTxes = get<0>(*it);
- set<uint256>::iterator itHash = setMissingTxes.find(hash);
- if (itHash != setMissingTxes.end())
- {
- fRet = true;
- CRelayBlock& block = get<1>(*it);
- block.ProvideTransaction(tx);
- block.GetMissingTransactions(setMissingTxes);
- if (setMissingTxes.empty())
- {
- listFilledBlocks.push_back(make_pair(block, get<2>(*it)));
- list<RelayedBlockTupleType>::iterator it2 = it;
- it++;
- listUnfilledBlocks.erase(it2);
- it--;
- }
- }
+ CRelayBlock& block = get<1>(blockUnfilled);
+ block.ProvideTransaction(tx);
+ block.GetMissingTransactions(setMissingTxes);
+ if (setMissingTxes.empty())
+ listFilledBlocks.push_back(make_pair(block, get<2>(blockUnfilled)));
+ return true;
}
- return fRet;
+ return false;
}
-bool CPendingRelayBlockPool::ProcessBlocks(bool fActuallyProcess)
+bool CPendingRelayBlock::ProcessBlocks(bool fActuallyProcess)
{
bool fRet = false;
for (list<pair<CRelayBlock, CNode*> >::iterator it = listFilledBlocks.begin(); it != listFilledBlocks.end(); it++)
@@ -2114,7 +2104,7 @@ bool CPendingRelayBlockPool::ProcessBlocks(bool fActuallyProcess)
return fRet;
}
-bool CPendingRelayBlockPool::AddBlock(CRelayBlock& block, CNode* pfrom, vector<CInv>& missingInvsRet)
+bool CPendingRelayBlock::AddBlock(CRelayBlock& block, CNode* pfrom, vector<CInv>& missingInvsRet)
{
set<uint256> setMissingTxes;
block.GetMissingTransactions(setMissingTxes);
View
11 src/main.h
@@ -1711,14 +1711,15 @@ class CRelayBlock
-/** Used to keep a list of pending CRelayBlocks, and the txes they are missing
+/** Used to keep track of a pending CRelayBlock, the txes it is missing
+ * and to request full blocks if a block is not filled before the next one.
+ * Primarily abstracted for testing.
* Note that this structure is NOT thread-safe
*/
-class CPendingRelayBlockPool
+class CPendingRelayBlock
{
private:
- typedef boost::tuple<std::set<uint256>, CRelayBlock, CNode*> RelayedBlockTupleType;
- std::list<RelayedBlockTupleType> listUnfilledBlocks;
+ boost::tuple<std::set<uint256>, CRelayBlock, CNode*> blockUnfilled;
std::list<std::pair<CRelayBlock, CNode*> > listFilledBlocks;
public:
@@ -1726,7 +1727,7 @@ class CPendingRelayBlockPool
bool ProvideTransaction(const CTransaction& tx, const uint256& hash);
// Call ProcessBlock for every block for which we aren't missing txes
- // Separated out to make testing more thorough
+ // Separated out to make testing easier
// Returns true if any blocks were processed
bool ProcessBlocks(bool fActuallyProcess=true);
Please sign in to comment.
Something went wrong with that request. Please try again.