aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/rawtransaction.cpp
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2021-04-12 21:34:42 -0400
committerCarl Dong <contact@carldong.me>2021-04-14 11:17:31 -0400
commit586190f0b4740457cb86cba632e3d64e6dfe9b0c (patch)
tree667f7c58a4c5c3d844fe22c279252010575d81da /src/rpc/rawtransaction.cpp
parentbc3bd369027273278a0541f3b991eb71de831aa2 (diff)
downloadbitcoin-586190f0b4740457cb86cba632e3d64e6dfe9b0c.tar.xz
rpc/rest: Take and reuse local Chain/ChainState obj
In all rest/rpc-related modules, if there are multiple calls to ActiveChain{,State}(), and the calls fall under the same ::cs_main lock, we can simply take a local reference and use/reuse it instead of calling ActiveChain{,State}() again and again.
Diffstat (limited to 'src/rpc/rawtransaction.cpp')
-rw-r--r--src/rpc/rawtransaction.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp
index 5947755819..19e9c75e32 100644
--- a/src/rpc/rawtransaction.cpp
+++ b/src/rpc/rawtransaction.cpp
@@ -268,12 +268,13 @@ static RPCHelpMan gettxoutproof()
}
} else {
LOCK(cs_main);
+ CChainState& active_chainstate = chainman.ActiveChainstate();
// Loop through txids and try to find which block they're in. Exit loop once a block is found.
for (const auto& tx : setTxids) {
- const Coin& coin = AccessByTxid(chainman.ActiveChainstate().CoinsTip(), tx);
+ const Coin& coin = AccessByTxid(active_chainstate.CoinsTip(), tx);
if (!coin.IsSpent()) {
- pblockindex = chainman.ActiveChain()[coin.nHeight];
+ pblockindex = active_chainstate.m_chain[coin.nHeight];
break;
}
}