Skip to content

Commit e1860fc

Browse files
committed
Merge ElementsProject#304: commit genesis block transactions to txindex
d74234b commit genesis block transactions to txindex (Gregory Sanders)
2 parents d207f27 + d74234b commit e1860fc

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/validation.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2557,12 +2557,21 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
25572557
if (block.GetHash() == chainparams.GetConsensus().hashGenesisBlock) {
25582558
if (!fJustCheck) {
25592559
assert(block.nHeight == 0);
2560+
std::vector<std::pair<uint256, CDiskTxPos> > vPos;
2561+
CDiskTxPos pos(pindex->GetBlockPos(), GetSizeOfCompactSize(block.vtx.size()));
25602562
for (const auto& tx : block.vtx) {
25612563

25622564
// Directly add new coins to DB
25632565
view.ModifyNewCoins(tx->GetHash(), tx->IsCoinBase())->FromTx(*tx, pindex->nHeight);
2566+
vPos.push_back(std::make_pair(tx->GetHash(), pos));
2567+
pos.nTxOffset += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION);
25642568
}
25652569
view.SetBestBlock(pindex->GetBlockHash());
2570+
if (fTxIndex) {
2571+
if (!pblocktree->WriteTxIndex(vPos)) {
2572+
return AbortNode(state, "Failed to write transaction index");
2573+
}
2574+
}
25662575
}
25672576
return true;
25682577
}

0 commit comments

Comments
 (0)