Skip to content

Commit

Permalink
Avoid calling GetSerializeSize on each tx in a block if !fTxIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueMatt committed Dec 4, 2017
1 parent 2862aca commit 22fddde
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,8 @@ static bool WriteUndoDataForBlock(const CBlockUndo& blockundo, CValidationState&

static bool WriteTxIndexDataForBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex)
{
if (!fTxIndex) return true;

CDiskTxPos pos(pindex->GetBlockPos(), GetSizeOfCompactSize(block.vtx.size()));
std::vector<std::pair<uint256, CDiskTxPos> > vPos;
vPos.reserve(block.vtx.size());
Expand All @@ -1656,9 +1658,9 @@ static bool WriteTxIndexDataForBlock(const CBlock& block, CValidationState& stat
pos.nTxOffset += ::GetSerializeSize(*tx, SER_DISK, CLIENT_VERSION);
}

if (fTxIndex)
if (!pblocktree->WriteTxIndex(vPos))
return AbortNode(state, "Failed to write transaction index");
if (!pblocktree->WriteTxIndex(vPos)) {
return AbortNode(state, "Failed to write transaction index");
}

return true;
}
Expand Down

0 comments on commit 22fddde

Please sign in to comment.