mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
Avoid copying undo data
This commit is contained in:
parent
438c7e4cd2
commit
ab15b2ec71
19
src/main.cpp
19
src/main.cpp
@ -1351,12 +1351,13 @@ void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCach
|
|||||||
bool ret;
|
bool ret;
|
||||||
// mark inputs spent
|
// mark inputs spent
|
||||||
if (!tx.IsCoinBase()) {
|
if (!tx.IsCoinBase()) {
|
||||||
BOOST_FOREACH(const CTxIn &txin, tx.vin) {
|
txundo.vprevout.reserve(tx.vin.size());
|
||||||
|
for (unsigned int i = 0; i < tx.vin.size(); i++) {
|
||||||
|
const CTxIn &txin = tx.vin[i];
|
||||||
CCoins &coins = inputs.GetCoins(txin.prevout.hash);
|
CCoins &coins = inputs.GetCoins(txin.prevout.hash);
|
||||||
CTxInUndo undo;
|
txundo.vprevout.push_back(CTxInUndo());
|
||||||
ret = coins.Spend(txin.prevout, undo);
|
ret = coins.Spend(txin.prevout, txundo.vprevout.back());
|
||||||
assert(ret);
|
assert(ret);
|
||||||
txundo.vprevout.push_back(undo);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1663,6 +1664,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
|
|||||||
CDiskTxPos pos(pindex->GetBlockPos(), GetSizeOfCompactSize(block.vtx.size()));
|
CDiskTxPos pos(pindex->GetBlockPos(), GetSizeOfCompactSize(block.vtx.size()));
|
||||||
std::vector<std::pair<uint256, CDiskTxPos> > vPos;
|
std::vector<std::pair<uint256, CDiskTxPos> > vPos;
|
||||||
vPos.reserve(block.vtx.size());
|
vPos.reserve(block.vtx.size());
|
||||||
|
blockundo.vtxundo.reserve(block.vtx.size() - 1);
|
||||||
for (unsigned int i = 0; i < block.vtx.size(); i++)
|
for (unsigned int i = 0; i < block.vtx.size(); i++)
|
||||||
{
|
{
|
||||||
const CTransaction &tx = block.vtx[i];
|
const CTransaction &tx = block.vtx[i];
|
||||||
@ -1698,10 +1700,11 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
|
|||||||
control.Add(vChecks);
|
control.Add(vChecks);
|
||||||
}
|
}
|
||||||
|
|
||||||
CTxUndo txundo;
|
CTxUndo undoDummy;
|
||||||
UpdateCoins(tx, state, view, txundo, pindex->nHeight);
|
if (i > 0) {
|
||||||
if (!tx.IsCoinBase())
|
blockundo.vtxundo.push_back(CTxUndo());
|
||||||
blockundo.vtxundo.push_back(txundo);
|
}
|
||||||
|
UpdateCoins(tx, state, view, i == 0 ? undoDummy : blockundo.vtxundo.back(), pindex->nHeight);
|
||||||
|
|
||||||
vPos.push_back(std::make_pair(tx.GetHash(), pos));
|
vPos.push_back(std::make_pair(tx.GetHash(), pos));
|
||||||
pos.nTxOffset += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION);
|
pos.nTxOffset += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION);
|
||||||
|
Loading…
Reference in New Issue
Block a user