Batch block connection during IBD

During the initial block download (or -loadblock), delay connection
of new blocks a bit, and perform them in a single action. This reduces
the load on the database engine, as subsequent blocks often update an
earlier block's transaction already.
This commit is contained in:
Pieter Wuille
2012-07-06 16:33:34 +02:00
parent 450cbb0944
commit ae8bfd12da
10 changed files with 183 additions and 171 deletions

View File

@@ -583,7 +583,7 @@ public:
bool CheckTransaction() const;
// Try to accept this transaction into the memory pool
bool AcceptToMemoryPool(CCoinsDB& coinsdb, bool fCheckInputs=true, bool* pfMissingInputs=NULL);
bool AcceptToMemoryPool(bool fCheckInputs=true, bool* pfMissingInputs=NULL);
protected:
static CTxOut GetOutputFor(const CTxIn& input, CCoinsView& mapInputs);
@@ -682,6 +682,7 @@ public:
bool WriteToDisk(CDiskBlockPos &pos)
{
// Open history file to append
CAutoFile fileout = CAutoFile(OpenUndoFile(pos), SER_DISK, CLIENT_VERSION);
if (!fileout)
@@ -995,8 +996,7 @@ public:
int GetDepthInMainChain() const { CBlockIndex *pindexRet; return GetDepthInMainChain(pindexRet); }
bool IsInMainChain() const { return GetDepthInMainChain() > 0; }
int GetBlocksToMaturity() const;
bool AcceptToMemoryPool(CCoinsDB& coinsdb, bool fCheckInputs=true);
bool AcceptToMemoryPool();
bool AcceptToMemoryPool(bool fCheckInputs=true);
};
@@ -1676,8 +1676,7 @@ public:
std::map<uint256, CTransaction> mapTx;
std::map<COutPoint, CInPoint> mapNextTx;
bool accept(CCoinsDB& coinsdb, CTransaction &tx,
bool fCheckInputs, bool* pfMissingInputs);
bool accept(CTransaction &tx, bool fCheckInputs, bool* pfMissingInputs);
bool addUnchecked(const uint256& hash, CTransaction &tx);
bool remove(CTransaction &tx);
void clear();
@@ -1722,6 +1721,7 @@ public:
// Modify the currently active block index
virtual bool SetBestBlock(CBlockIndex *pindex);
virtual bool BatchWrite(const std::map<uint256, CCoins> &mapCoins, CBlockIndex *pindex);
};
/** CCoinsView backed by another CCoinsView */
@@ -1738,21 +1738,7 @@ public:
CBlockIndex *GetBestBlock();
bool SetBestBlock(CBlockIndex *pindex);
void SetBackend(CCoinsView &viewIn);
};
/** CCoinsView backed by a CCoinsDB */
class CCoinsViewDB : public CCoinsView
{
protected:
CCoinsDB &db;
public:
CCoinsViewDB(CCoinsDB &dbIn);
bool GetCoins(uint256 txid, CCoins &coins);
bool SetCoins(uint256 txid, const CCoins &coins);
bool HaveCoins(uint256 txid);
CBlockIndex *GetBestBlock();
bool SetBestBlock(CBlockIndex *pindex);
bool BatchWrite(const std::map<uint256, CCoins> &mapCoins, CBlockIndex *pindex);
};
/** CCoinsView that adds a memory cache for transactions to another CCoinsView */
@@ -1769,7 +1755,9 @@ public:
bool HaveCoins(uint256 txid);
CBlockIndex *GetBestBlock();
bool SetBestBlock(CBlockIndex *pindex);
bool BatchWrite(const std::map<uint256, CCoins> &mapCoins, CBlockIndex *pindex);
bool Flush();
unsigned int GetCacheSize();
};
/** CCoinsView that brings transactions from a memorypool into view.
@@ -1785,4 +1773,6 @@ public:
bool HaveCoins(uint256 txid);
};
extern CCoinsViewCache *pcoinsTip;
#endif