Merge pull request #491 from gavinandresen/manytxfix
Optimize database writes for transactions with lots of TxIns.
This commit is contained in:
commit
e4626e94f4
1 changed files with 12 additions and 12 deletions
24
src/main.cpp
24
src/main.cpp
|
@ -813,7 +813,7 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPoo
|
||||||
// Read txindex
|
// Read txindex
|
||||||
CTxIndex txindex;
|
CTxIndex txindex;
|
||||||
bool fFound = true;
|
bool fFound = true;
|
||||||
if (fMiner && mapTestPool.count(prevout.hash))
|
if ((fBlock || fMiner) && mapTestPool.count(prevout.hash))
|
||||||
{
|
{
|
||||||
// Get txindex from current proposed changes
|
// Get txindex from current proposed changes
|
||||||
txindex = mapTestPool[prevout.hash];
|
txindex = mapTestPool[prevout.hash];
|
||||||
|
@ -873,12 +873,7 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPoo
|
||||||
txindex.vSpent[prevout.n] = posThisTx;
|
txindex.vSpent[prevout.n] = posThisTx;
|
||||||
|
|
||||||
// Write back
|
// Write back
|
||||||
if (fBlock)
|
if (fBlock || fMiner)
|
||||||
{
|
|
||||||
if (!txdb.UpdateTxIndex(prevout.hash, txindex))
|
|
||||||
return error("ConnectInputs() : UpdateTxIndex failed");
|
|
||||||
}
|
|
||||||
else if (fMiner)
|
|
||||||
{
|
{
|
||||||
mapTestPool[prevout.hash] = txindex;
|
mapTestPool[prevout.hash] = txindex;
|
||||||
}
|
}
|
||||||
|
@ -900,9 +895,8 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPoo
|
||||||
|
|
||||||
if (fBlock)
|
if (fBlock)
|
||||||
{
|
{
|
||||||
// Add transaction to disk index
|
// Add transaction to changes
|
||||||
if (!txdb.AddTxIndex(*this, posThisTx, pindexBlock->nHeight))
|
mapTestPool[GetHash()] = CTxIndex(posThisTx, vout.size());
|
||||||
return error("ConnectInputs() : AddTxPos failed");
|
|
||||||
}
|
}
|
||||||
else if (fMiner)
|
else if (fMiner)
|
||||||
{
|
{
|
||||||
|
@ -991,16 +985,22 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex)
|
||||||
//// issue here: it doesn't know the version
|
//// issue here: it doesn't know the version
|
||||||
unsigned int nTxPos = pindex->nBlockPos + ::GetSerializeSize(CBlock(), SER_DISK) - 1 + GetSizeOfCompactSize(vtx.size());
|
unsigned int nTxPos = pindex->nBlockPos + ::GetSerializeSize(CBlock(), SER_DISK) - 1 + GetSizeOfCompactSize(vtx.size());
|
||||||
|
|
||||||
map<uint256, CTxIndex> mapUnused;
|
map<uint256, CTxIndex> mapQueuedChanges;
|
||||||
int64 nFees = 0;
|
int64 nFees = 0;
|
||||||
BOOST_FOREACH(CTransaction& tx, vtx)
|
BOOST_FOREACH(CTransaction& tx, vtx)
|
||||||
{
|
{
|
||||||
CDiskTxPos posThisTx(pindex->nFile, pindex->nBlockPos, nTxPos);
|
CDiskTxPos posThisTx(pindex->nFile, pindex->nBlockPos, nTxPos);
|
||||||
nTxPos += ::GetSerializeSize(tx, SER_DISK);
|
nTxPos += ::GetSerializeSize(tx, SER_DISK);
|
||||||
|
|
||||||
if (!tx.ConnectInputs(txdb, mapUnused, posThisTx, pindex, nFees, true, false))
|
if (!tx.ConnectInputs(txdb, mapQueuedChanges, posThisTx, pindex, nFees, true, false))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// Write queued txindex changes
|
||||||
|
for (map<uint256, CTxIndex>::iterator mi = mapQueuedChanges.begin(); mi != mapQueuedChanges.end(); ++mi)
|
||||||
|
{
|
||||||
|
if (!txdb.UpdateTxIndex((*mi).first, (*mi).second))
|
||||||
|
return error("ConnectBlock() : UpdateTxIndex failed");
|
||||||
|
}
|
||||||
|
|
||||||
if (vtx[0].GetValueOut() > GetBlockValue(pindex->nHeight, nFees))
|
if (vtx[0].GetValueOut() > GetBlockValue(pindex->nHeight, nFees))
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue