From 4651af04a25d4833f0dd7575db0b09eb368df642 Mon Sep 17 00:00:00 2001 From: "James C. Owens" Date: Thu, 26 Jan 2023 15:00:21 -0500 Subject: [PATCH] Narrow cs_poll_registry locking in getpollresults and votedetails The holding of the cs_poll_registry lock is only required to retrieve the reference. --- src/rpc/voting.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/rpc/voting.cpp b/src/rpc/voting.cpp index eaef4e5c61..57cf2811c2 100644 --- a/src/rpc/voting.cpp +++ b/src/rpc/voting.cpp @@ -551,9 +551,9 @@ UniValue getpollresults(const UniValue& params, bool fHelp) const std::string title_or_id = params[0].get_str(); - LOCK(GetPollRegistry().cs_poll_registry); - - if (const PollReference* ref = TryPollByTitleOrId(title_or_id)) { + // We only need to lock the registry to retrieve the reference. If there is a reorg during the PollResultToJson, it will + // throw. + if (const PollReference* ref = WITH_LOCK(GetPollRegistry().cs_poll_registry, return TryPollByTitleOrId(title_or_id))) { return PollResultToJson(*ref); } @@ -704,9 +704,9 @@ UniValue votedetails(const UniValue& params, bool fHelp) const std::string title_or_id = params[0].get_str(); - LOCK(GetPollRegistry().cs_poll_registry); - - if (const PollReference* ref = TryPollByTitleOrId(title_or_id)) { + // We only need to lock the registry to retrieve the reference. If there is a reorg during the PollResultToJson, it will + // throw. + if (const PollReference* ref = WITH_LOCK(GetPollRegistry().cs_poll_registry, return TryPollByTitleOrId(title_or_id))) { return VoteDetailsToJson(*ref); }