Skip to content

Commit 22fddde

Browse files
committed
Avoid calling GetSerializeSize on each tx in a block if !fTxIndex
1 parent 2862aca commit 22fddde

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
@@ -1647,6 +1647,8 @@ static bool WriteUndoDataForBlock(const CBlockUndo& blockundo, CValidationState&
16471647

16481648
static bool WriteTxIndexDataForBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex)
16491649
{
1650+
if (!fTxIndex) return true;
1651+
16501652
CDiskTxPos pos(pindex->GetBlockPos(), GetSizeOfCompactSize(block.vtx.size()));
16511653
std::vector<std::pair<uint256, CDiskTxPos> > vPos;
16521654
vPos.reserve(block.vtx.size());
@@ -1656,9 +1658,9 @@ static bool WriteTxIndexDataForBlock(const CBlock& block, CValidationState& stat
16561658
pos.nTxOffset += ::GetSerializeSize(*tx, SER_DISK, CLIENT_VERSION);
16571659
}
16581660

1659-
if (fTxIndex)
1660-
if (!pblocktree->WriteTxIndex(vPos))
1661-
return AbortNode(state, "Failed to write transaction index");
1661+
if (!pblocktree->WriteTxIndex(vPos)) {
1662+
return AbortNode(state, "Failed to write transaction index");
1663+
}
16621664

16631665
return true;
16641666
}

0 commit comments

Comments
 (0)