Browse Source

Avoid calling GetSerializeSize on each tx in a block if !fTxIndex

0.16
Matt Corallo 8 years ago
parent
commit
22fdddeabb
  1. 8
      src/validation.cpp

8
src/validation.cpp

@ -1647,6 +1647,8 @@ static bool WriteUndoDataForBlock(const CBlockUndo& blockundo, CValidationState&
static bool WriteTxIndexDataForBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex) static bool WriteTxIndexDataForBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex)
{ {
if (!fTxIndex) return true;
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());
@ -1656,9 +1658,9 @@ static bool WriteTxIndexDataForBlock(const CBlock& block, CValidationState& stat
pos.nTxOffset += ::GetSerializeSize(*tx, SER_DISK, CLIENT_VERSION); pos.nTxOffset += ::GetSerializeSize(*tx, SER_DISK, CLIENT_VERSION);
} }
if (fTxIndex) if (!pblocktree->WriteTxIndex(vPos)) {
if (!pblocktree->WriteTxIndex(vPos)) return AbortNode(state, "Failed to write transaction index");
return AbortNode(state, "Failed to write transaction index"); }
return true; return true;
} }

Loading…
Cancel
Save