aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Zumsande <mzumsande@gmail.com>2023-12-05 13:07:39 -0500
committerfanquake <fanquake@gmail.com>2024-01-04 16:21:36 +0000
commit5097bb3389fe3add504851302918692b3f05db70 (patch)
tree1a11c2481a62cc27f84defa2785128e2de297deb /src
parent81e744a9a6a55cb5c2b88cd6eeb9dd6523f3a438 (diff)
rpc: fix getrawtransaction segfault
The crash would happen when querying a mempool transaction with verbosity=2, while pruning. Github-Pull: #29003 Rebased-From: 494a926d05df44b60b3bc1145ad2a64acf96f61b
Diffstat (limited to 'src')
-rw-r--r--src/rpc/rawtransaction.cpp5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp
index 16705b3ce2..b30b0bbfeb 100644
--- a/src/rpc/rawtransaction.cpp
+++ b/src/rpc/rawtransaction.cpp
@@ -396,7 +396,7 @@ static RPCHelpMan getrawtransaction()
LOCK(cs_main);
blockindex = chainman.m_blockman.LookupBlockIndex(hash_block);
}
- if (verbosity == 1) {
+ if (verbosity == 1 || !blockindex) {
TxToJSON(*tx, hash_block, result, chainman.ActiveChainstate());
return result;
}
@@ -405,8 +405,7 @@ static RPCHelpMan getrawtransaction()
CBlock block;
const bool is_block_pruned{WITH_LOCK(cs_main, return chainman.m_blockman.IsBlockPruned(blockindex))};
- if (tx->IsCoinBase() ||
- !blockindex || is_block_pruned ||
+ if (tx->IsCoinBase() || is_block_pruned ||
!(chainman.m_blockman.UndoReadFromDisk(blockUndo, *blockindex) && chainman.m_blockman.ReadBlockFromDisk(block, *blockindex))) {
TxToJSON(*tx, hash_block, result, chainman.ActiveChainstate());
return result;