Skip to content

Commit 3b78b2d

Browse files
committed
Avoid calling GetSerializeSize on each tx in a block if !fTxIndex
1 parent 21ec373 commit 3b78b2d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/validation.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,8 @@ static bool WriteUndoDataForBlock(const CBlockUndo& blockundo, CValidationState&
16191619

16201620
static bool WriteTxIndexDataForBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex)
16211621
{
1622+
if (!fTxIndex) return true;
1623+
16221624
CDiskTxPos pos(pindex->GetBlockPos(), GetSizeOfCompactSize(block.vtx.size()));
16231625
std::vector<std::pair<uint256, CDiskTxPos> > vPos;
16241626
vPos.reserve(block.vtx.size());
@@ -1628,9 +1630,9 @@ static bool WriteTxIndexDataForBlock(const CBlock& block, CValidationState& stat
16281630
pos.nTxOffset += ::GetSerializeSize(*tx, SER_DISK, CLIENT_VERSION);
16291631
}
16301632

1631-
if (fTxIndex)
1632-
if (!pblocktree->WriteTxIndex(vPos))
1633-
return AbortNode(state, "Failed to write transaction index");
1633+
if (!pblocktree->WriteTxIndex(vPos)) {
1634+
return AbortNode(state, "Failed to write transaction index");
1635+
}
16341636

16351637
return true;
16361638
}

0 commit comments

Comments
 (0)