upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/rpc.cpp
diff options
context:
space:
mode:
authorbitflash-maintainer <noreply@bitflash.invalid>2026-08-23 11:48:56 +0000
committerbitflash-maintainer <noreply@bitflash.invalid>2026-08-23 11:48:56 +0000
commita5300386813937e38810a86153811941047ea578 (patch)
tree41255bb7e92794bc0f94f13f31936823e6edd098 /src/rpc.cpp
parentc7ada00eeed8ef689b976c7201db2d9c076c17d1 (diff)
payout: take the mutex that guards the in-flight list while loading it
LoadPaying appends to gPaying and increments gPayingNextId, and both are annotated as guarded by gPayoutExecMutex. It took neither. Nothing is racing it today: it is called from the pool startup path before the payout thread is spawned, and the self-test calls it on one thread. But that is a fact about its callers, not about the function, and the annotation is what the next person to add a caller will read. The lock is uncontended here by construction, so there is nothing to weigh against taking it. Property: every mutation of gPaying and gPayingNextId in this file happens under the mutex they are documented to be guarded by.
Diffstat (limited to 'src/rpc.cpp')
-rw-r--r--src/rpc.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/rpc.cpp b/src/rpc.cpp
index c382926..a9eca8a 100644
--- a/src/rpc.cpp
+++ b/src/rpc.cpp
@@ -962,6 +962,14 @@ static void LoadPaying()
962 fclose(f); 962 fclose(f);
963 try { 963 try {
964 nlohmann::json arr = nlohmann::json::parse(s); 964 nlohmann::json arr = nlohmann::json::parse(s);
965 // gPaying and gPayingNextId are both annotated as guarded by
966 // gPayoutExecMutex and this was mutating them without it. Safe today
967 // -- LoadPaying only runs at startup, before the payout thread is
968 // spawned -- but "safe because of where it is called from" is a fact
969 // about the caller, not about this function, and the annotation is
970 // what every other reader will trust. The mutex is uncontended here by
971 // construction, so taking it costs nothing.
972 std::lock_guard<std::mutex> lk(gPayoutExecMutex);
965 for (const auto& obj : arr) { 973 for (const auto& obj : arr) {
966 PayingRecord r; 974 PayingRecord r;
967 r.address = obj["address"].get<std::string>(); 975 r.address = obj["address"].get<std::string>();