Commit 23a3d2f
fix: prevent double withdrawal of community earnings (#835)
* fix: prevent double withdrawal of community earnings
Atomically claim community earnings before scheduling a payout by
zeroing them with a conditional compare-and-set. Concurrent withdrawal
attempts now race on this update so only one wins, preventing the node
from paying out the same earnings more than once.
If the payout later fails permanently (invoice expired or payment
attempts exhausted), the pending-payments job restores the earnings so
the community creator can withdraw again without losing funds.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix: address review feedback on earnings claim accounting
- Roll back the atomic earnings claim if creating the PendingPayment
fails (user lookup or save throws). Without a persisted pending
payment the retry job can never restore the claimed earnings, so they
would be stranded.
- Restore earnings before any notification can abort the run: wrap the
expired-invoice notification in try/catch so a failed sendMessage no
longer skips the restore and leaves funds locked.
- Stop re-zeroing community.earnings on a successful payout; the
earnings were already claimed at scheduling time, and resetting them
again would wipe out earnings accrued in the meantime.
- Use an atomic $inc to restore earnings on permanent failure instead
of a stale read-modify-write, so the update applies against the
current DB value.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* chore: sync package-lock.json version to 0.15.2
package.json was bumped to 0.15.2 (commit 056284a) but package-lock.json
still declared 0.15.1. The CI 'Run prettier' step runs 'npm install'
followed by 'git diff --exit-code', and npm rewrites the lockfile
version to match package.json, producing an uncommitted diff that fails
the check. Sync the lockfile version so the working tree stays clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 056284a commit 23a3d2f
3 files changed
Lines changed: 87 additions & 34 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1004 | 1004 | | |
1005 | 1005 | | |
1006 | 1006 | | |
1007 | | - | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
1008 | 1010 | | |
1009 | 1011 | | |
1010 | 1012 | | |
| |||
1019 | 1021 | | |
1020 | 1022 | | |
1021 | 1023 | | |
1022 | | - | |
1023 | | - | |
1024 | | - | |
1025 | | - | |
1026 | | - | |
1027 | | - | |
1028 | | - | |
1029 | | - | |
1030 | | - | |
1031 | | - | |
1032 | | - | |
1033 | | - | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
1034 | 1060 | | |
1035 | 1061 | | |
1036 | 1062 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
231 | 237 | | |
232 | | - | |
| 238 | + | |
233 | 239 | | |
234 | | - | |
235 | | - | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
236 | 246 | | |
237 | 247 | | |
238 | 248 | | |
| |||
241 | 251 | | |
242 | 252 | | |
243 | 253 | | |
244 | | - | |
245 | | - | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
246 | 258 | | |
247 | 259 | | |
248 | 260 | | |
| |||
270 | 282 | | |
271 | 283 | | |
272 | 284 | | |
273 | | - | |
| 285 | + | |
274 | 286 | | |
275 | | - | |
276 | | - | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
277 | 304 | | |
278 | 305 | | |
279 | 306 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments