Skip to content

Commit

Permalink
Narrow cs_poll_registry locking in getpollresults and votedetails
Browse files Browse the repository at this point in the history
The holding of the cs_poll_registry lock is only required to
retrieve the reference.
  • Loading branch information
jamescowens committed Jan 26, 2023
1 parent 2e93908 commit 4651af0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/rpc/voting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 4651af0

Please sign in to comment.