Merge remote-tracking branch 'jgarzik/mempool'
authorPieter Wuille <pieter.wuille@gmail.com>
Tue, 17 Apr 2012 18:12:48 +0000 (20:12 +0200)
committerPieter Wuille <pieter.wuille@gmail.com>
Tue, 17 Apr 2012 18:12:48 +0000 (20:12 +0200)
1  2 
src/bitcoinrpc.cpp
src/main.cpp
src/main.h

Simple merge
diff --cc src/main.cpp
@@@ -484,9 -483,9 +483,9 @@@ bool CTxMemPool::accept(CTxDB& txdb, CT
  
      // Check for conflicts with in-memory transactions
      CTransaction* ptxOld = NULL;
-     for (unsigned int i = 0; i < vin.size(); i++)
 -    for (int i = 0; i < tx.vin.size(); i++)
++    for (unsigned int i = 0; i < tx.vin.size(); i++)
      {
-         COutPoint outpoint = vin[i].prevout;
+         COutPoint outpoint = tx.vin[i].prevout;
          if (mapNextTx.count(outpoint))
          {
              // Disable replacement feature for now
              ptxOld = mapNextTx[outpoint].ptx;
              if (ptxOld->IsFinal())
                  return false;
-             if (!IsNewerThan(*ptxOld))
+             if (!tx.IsNewerThan(*ptxOld))
                  return false;
-             for (unsigned int i = 0; i < vin.size(); i++)
 -            for (int i = 0; i < tx.vin.size(); i++)
++            for (unsigned int i = 0; i < tx.vin.size(); i++)
              {
-                 COutPoint outpoint = vin[i].prevout;
+                 COutPoint outpoint = tx.vin[i].prevout;
                  if (!mapNextTx.count(outpoint) || mapNextTx[outpoint].ptx != ptxOld)
                      return false;
              }
          // you should add code here to check that the transaction does a
          // reasonable number of ECDSA signature verifications.
  
-         int64 nFees = GetValueIn(mapInputs)-GetValueOut();
-         unsigned int nSize = ::GetSerializeSize(*this, SER_NETWORK, PROTOCOL_VERSION);
+         int64 nFees = tx.GetValueIn(mapInputs)-tx.GetValueOut();
 -        unsigned int nSize = ::GetSerializeSize(tx, SER_NETWORK);
++        unsigned int nSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
  
          // Don't accept it if it can't get into a block
-         if (nFees < GetMinFee(1000, true, GMF_RELAY))
-             return error("AcceptToMemoryPool() : not enough fees");
+         if (nFees < tx.GetMinFee(1000, true, GMF_RELAY))
+             return error("CTxMemPool::accept() : not enough fees");
  
          // Continuously rate-limit free transactions
          // This mitigates 'penny-flooding' -- sending thousands of free transactions just to
      return true;
  }
  
- uint64 nPooledTx = 0;
+ bool CTransaction::AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs, bool* pfMissingInputs)
+ {
+     return mempool.accept(txdb, *this, fCheckInputs, pfMissingInputs);
+ }
  
- bool CTransaction::AddToMemoryPoolUnchecked()
+ bool CTxMemPool::addUnchecked(CTransaction &tx)
  {
-     printf("AcceptToMemoryPoolUnchecked(): size %lu\n",  mapTransactions.size());
+     printf("addUnchecked(): 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.
+     // call CTxMemPool::accept to properly check the transaction first.
      {
-         LOCK(cs_mapTransactions);
-         uint256 hash = GetHash();
-         mapTransactions[hash] = *this;
-         for (unsigned int i = 0; i < vin.size(); i++)
-             mapNextTx[vin[i].prevout] = CInPoint(&mapTransactions[hash], i);
+         LOCK(cs);
+         uint256 hash = tx.GetHash();
+         mapTx[hash] = tx;
 -        for (int i = 0; i < tx.vin.size(); i++)
++        for (unsigned int i = 0; i < tx.vin.size(); i++)
+             mapNextTx[tx.vin[i].prevout] = CInPoint(&mapTx[hash], i);
          nTransactionsUpdated++;
-         ++nPooledTx;
      }
      return true;
  }
@@@ -1183,9 -1183,9 +1183,9 @@@ bool CTransaction::ClientConnectInputs(
  
      // Take over previous transactions' spent pointers
      {
-         LOCK(cs_mapTransactions);
+         LOCK(mempool.cs);
          int64 nValueIn = 0;
 -        for (int i = 0; i < vin.size(); i++)
 +        for (unsigned int i = 0; i < vin.size(); i++)
          {
              // Get prev tx from single transactions in memory
              COutPoint prevout = vin[i].prevout;
@@@ -2136,20 -2137,15 +2137,20 @@@ bool static AlreadyHave(CTxDB& txdb, co
      switch (inv.type)
      {
      case MSG_TX:
 -      {
 -        LOCK(mempool.cs);
 -        return mempool.exists(inv.hash) ||
 +        {
 +        bool txInMap = false;
 +            {
-             LOCK(cs_mapTransactions);
-             txInMap = (mapTransactions.count(inv.hash) != 0);
++            LOCK(mempool.cs);
++            txInMap = (mempool.exists(inv.hash));
 +            }
 +        return txInMap ||
                 mapOrphanTransactions.count(inv.hash) ||
                 txdb.ContainsTx(inv.hash);
 -      }
 +        }
  
      case MSG_BLOCK:
 -        return mapBlockIndex.count(inv.hash) || mapOrphanBlocks.count(inv.hash);
 +        return mapBlockIndex.count(inv.hash) ||
 +               mapOrphanBlocks.count(inv.hash);
      }
      // Don't know what it is, just say we already got one
      return true;
diff --cc src/main.h
Simple merge