simplification: removed most of CreateNewBlock
authorThomasV <thomasv@gitorious>
Sat, 16 Jun 2012 08:20:00 +0000 (12:20 +0400)
committerThomasV <thomasv@gitorious>
Sat, 16 Jun 2012 08:20:00 +0000 (12:20 +0400)
backends/abe/__init__.py
patches/bitcoin-0.6.2.diff

index 7c5ec6a..6713329 100644 (file)
@@ -380,6 +380,7 @@ class AbeStore(Datastore_class):
             else:
                 tx_id = store.import_tx(tx, False)
                 store.update_tx_cache(tx_id)
+                #print tx_hash
     
         store.commit()
 
index eaf9755..b55e8c8 100644 (file)
@@ -55,56 +55,177 @@ index 15bcf1d..1ace361 100644
  
  CRPCTable::CRPCTable()
 diff --git a/src/main.cpp b/src/main.cpp
-index 427e435..887e628 100644
+index 427e435..35a0aea 100644
 --- a/src/main.cpp
 +++ b/src/main.cpp
-@@ -3222,18 +3222,21 @@ CBlock* CreateNewBlock(CReserveKey& reservekey)
+@@ -3134,156 +3134,28 @@ CBlock* CreateNewBlock(CReserveKey& reservekey)
+     if (!pblock.get())
+         return NULL;
  
-             // Size limits
-             unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
+-    // Create coinbase tx
+-    CTransaction txNew;
+-    txNew.vin.resize(1);
+-    txNew.vin[0].prevout.SetNull();
+-    txNew.vout.resize(1);
+-    txNew.vout[0].scriptPubKey << reservekey.GetReservedKey() << OP_CHECKSIG;
+-
+-    // Add our coinbase tx as first transaction
+-    pblock->vtx.push_back(txNew);
+-
+     // Collect memory pool transactions into the block
+-    int64 nFees = 0;
+     {
+         LOCK2(cs_main, mempool.cs);
+         CTxDB txdb("r");
+-        // Priority order to process transactions
+-        list<COrphan> vOrphan; // list memory doesn't move
+-        map<uint256, vector<COrphan*> > mapDependers;
+-        multimap<double, CTransaction*> mapPriority;
+-        for (map<uint256, CTransaction>::iterator mi = mempool.mapTx.begin(); mi != mempool.mapTx.end(); ++mi)
+-        {
+-            CTransaction& tx = (*mi).second;
+-            if (tx.IsCoinBase() || !tx.IsFinal())
+-                continue;
+-
+-            COrphan* porphan = NULL;
+-            double dPriority = 0;
+-            BOOST_FOREACH(const CTxIn& txin, tx.vin)
+-            {
+-                // Read prev transaction
+-                CTransaction txPrev;
+-                CTxIndex txindex;
+-                if (!txPrev.ReadFromDisk(txdb, txin.prevout, txindex))
+-                {
+-                    // Has to wait for dependencies
+-                    if (!porphan)
+-                    {
+-                        // Use list for automatic deletion
+-                        vOrphan.push_back(COrphan(&tx));
+-                        porphan = &vOrphan.back();
+-                    }
+-                    mapDependers[txin.prevout.hash].push_back(porphan);
+-                    porphan->setDependsOn.insert(txin.prevout.hash);
+-                    continue;
+-                }
+-                int64 nValueIn = txPrev.vout[txin.prevout.n].nValue;
+-
+-                // Read block header
+-                int nConf = txindex.GetDepthInMainChain();
+-
+-                dPriority += (double)nValueIn * nConf;
+-
+-                if (fDebug && GetBoolArg("-printpriority"))
+-                    printf("priority     nValueIn=%-12I64d nConf=%-5d dPriority=%-20.1f\n", nValueIn, nConf, dPriority);
+-            }
+-
+-            // Priority is sum(valuein * age) / txsize
+-            dPriority /= ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
+-
+-            if (porphan)
+-                porphan->dPriority = dPriority;
+-            else
+-                mapPriority.insert(make_pair(-dPriority, &(*mi).second));
+-
+-            if (fDebug && GetBoolArg("-printpriority"))
+-            {
+-                printf("priority %-20.1f %s\n%s", dPriority, tx.GetHash().ToString().substr(0,10).c_str(), tx.ToString().c_str());
+-                if (porphan)
+-                    porphan->print();
+-                printf("\n");
+-            }
+-        }
+-
+-        // Collect transactions into block
+-        map<uint256, CTxIndex> mapTestPool;
+-        uint64 nBlockSize = 1000;
+         uint64 nBlockTx = 0;
+-        int nBlockSigOps = 100;
+-        while (!mapPriority.empty())
++        for (map<uint256, CTransaction>::iterator mi = mempool.mapTx.begin(); mi != mempool.mapTx.end(); ++mi)
+         {
+-            // Take highest priority transaction off priority queue
+-            double dPriority = -(*mapPriority.begin()).first;
+-            CTransaction& tx = *(*mapPriority.begin()).second;
+-            mapPriority.erase(mapPriority.begin());
+-
+-            // Size limits
+-            unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
 -            if (nBlockSize + nTxSize >= MAX_BLOCK_SIZE_GEN)
 -                continue;
-+            //if (nBlockSize + nTxSize >= MAX_BLOCK_SIZE_GEN)
-+            //    continue;
-             // Legacy limits on sigOps:
-             unsigned int nTxSigOps = tx.GetLegacySigOpCount();
+-
+-            // Legacy limits on sigOps:
+-            unsigned int nTxSigOps = tx.GetLegacySigOpCount();
 -            if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS)
 -                continue;
-+            //if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS)
-+            //    continue;
-             // Transaction fee required depends on block size
-             bool fAllowFree = (nBlockSize + nTxSize < 4000 || CTransaction::AllowFree(dPriority));
-             int64 nMinFee = tx.GetMinFee(nBlockSize, fAllowFree, GMF_BLOCK);
-+            // Electrum server: do not check fees
-+            nMinFee = 0;
-+
-             // Connecting shouldn't fail due to dependency on other memory pool transactions
-             // because we're already processing them in order of dependency
-             map<uint256, CTxIndex> mapTestPoolTmp(mapTestPool);
-@@ -3256,11 +3259,15 @@ CBlock* CreateNewBlock(CReserveKey& reservekey)
-             swap(mapTestPool, mapTestPoolTmp);
+-
+-            // Transaction fee required depends on block size
+-            bool fAllowFree = (nBlockSize + nTxSize < 4000 || CTransaction::AllowFree(dPriority));
+-            int64 nMinFee = tx.GetMinFee(nBlockSize, fAllowFree, GMF_BLOCK);
+-
+-            // Connecting shouldn't fail due to dependency on other memory pool transactions
+-            // because we're already processing them in order of dependency
+-            map<uint256, CTxIndex> mapTestPoolTmp(mapTestPool);
+-            MapPrevTx mapInputs;
+-            bool fInvalid;
+-            if (!tx.FetchInputs(txdb, mapTestPoolTmp, false, true, mapInputs, fInvalid))
+-                continue;
++        CTransaction& tx = (*mi).second;
++        if (tx.IsCoinBase() || !tx.IsFinal())
++          continue;
  
-             // Added
+-            int64 nTxFees = tx.GetValueIn(mapInputs)-tx.GetValueOut();
+-            if (nTxFees < nMinFee)
+-                continue;
+-
+-            nTxSigOps += tx.GetP2SHSigOpCount(mapInputs);
+-            if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS)
+-                continue;
+-
+-            if (!tx.ConnectInputs(mapInputs, mapTestPoolTmp, CDiskTxPos(1,1,1), pindexPrev, false, true))
+-                continue;
+-            mapTestPoolTmp[tx.GetHash()] = CTxIndex(CDiskTxPos(1,1,1), tx.vout.size());
+-            swap(mapTestPool, mapTestPoolTmp);
+-
+-            // Added
 -            pblock->vtx.push_back(tx);
 -            nBlockSize += nTxSize;
 -            ++nBlockTx;
 -            nBlockSigOps += nTxSigOps;
 -            nFees += nTxFees;
-+          if (!tx.get_electrum_flag())
-+            {
+-
+-            // Add transactions that depend on this one to the priority queue
+-            uint256 hash = tx.GetHash();
+-            if (mapDependers.count(hash))
+-            {
+-                BOOST_FOREACH(COrphan* porphan, mapDependers[hash])
+-                {
+-                    if (!porphan->setDependsOn.empty())
+-                    {
+-                        porphan->setDependsOn.erase(hash);
+-                        if (porphan->setDependsOn.empty())
+-                            mapPriority.insert(make_pair(-porphan->dPriority, porphan->ptx));
+-                    }
+-                }
+-            }
++        if (!tx.get_electrum_flag())
++          {
 +              tx.set_electrum_flag(true);
 +              pblock->vtx.push_back(tx);
-+              nBlockSize += nTxSize;
 +              ++nBlockTx;
-+              nBlockSigOps += nTxSigOps;
-+              nFees += nTxFees;
-+            }
++          }
+         }
+-        nLastBlockTx = nBlockTx;
+-        nLastBlockSize = nBlockSize;
+-        printf("CreateNewBlock(): total size %lu\n", nBlockSize);
+-
++        printf("CreateNewBlock(): transactions: %lu\n", nBlockTx);
+     }
+-    pblock->vtx[0].vout[0].nValue = GetBlockValue(pindexPrev->nHeight+1, nFees);
  
-             // Add transactions that depend on this one to the priority queue
-             uint256 hash = tx.GetHash();
+     // Fill in header
+     pblock->hashPrevBlock  = pindexPrev->GetBlockHash();
 diff --git a/src/main.h b/src/main.h
 index 262e77e..4cc9319 100644
 --- a/src/main.h