diff options
author | Martin Zumsande <mzumsande@gmail.com> | 2023-12-05 13:07:39 -0500 |
---|---|---|
committer | Martin Zumsande <mzumsande@gmail.com> | 2023-12-05 13:11:02 -0500 |
commit | 494a926d05df44b60b3bc1145ad2a64acf96f61b (patch) | |
tree | a0ccf06dc461653f4c96fa052cef90ff36f917b3 /src/rpc/rawtransaction.cpp | |
parent | 6d5790956f45e3de5c6c4ee6fda21878b0d1287b (diff) |
rpc: fix getrawtransaction segfault
The crash would happen when querying a mempool transaction with verbosity=2, while pruning.
Diffstat (limited to 'src/rpc/rawtransaction.cpp')
-rw-r--r-- | src/rpc/rawtransaction.cpp | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 2df2999523..5f68e7832c 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; |