Skip to content

Commit 041228d

Browse files
mzumsandefanquake
authored andcommitted
rpc: fix getrawtransaction segfault
The crash would happen when querying a mempool transaction with verbosity=2, while pruning. Github-Pull: #29003 Rebased-From: 494a926
1 parent b86285d commit 041228d

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ static RPCHelpMan getrawtransaction()
310310
LOCK(cs_main);
311311
blockindex = chainman.m_blockman.LookupBlockIndex(hash_block);
312312
}
313-
if (verbosity == 1) {
313+
if (verbosity == 1 || !blockindex) {
314314
TxToJSON(*tx, hash_block, result, chainman.ActiveChainstate());
315315
return result;
316316
}
@@ -319,8 +319,7 @@ static RPCHelpMan getrawtransaction()
319319
CBlock block;
320320
const bool is_block_pruned{WITH_LOCK(cs_main, return chainman.m_blockman.IsBlockPruned(blockindex))};
321321

322-
if (tx->IsCoinBase() ||
323-
!blockindex || is_block_pruned ||
322+
if (tx->IsCoinBase() || is_block_pruned ||
324323
!(UndoReadFromDisk(blockUndo, blockindex) && ReadBlockFromDisk(block, blockindex, Params().GetConsensus()))) {
325324
TxToJSON(*tx, hash_block, result, chainman.ActiveChainstate());
326325
return result;

0 commit comments

Comments
 (0)