Spend a hashcash stamp only when the request succeeds (closes #158)
check / check (push) Waiting to run

A session request refused with 400 or 409, or a +H channel message
refused for membership, a ban or +m, used to spend its stamp, so a
retry with the same stamp was refused as already used.

hashcash.Validator.Validate is split into Check, which spends
nothing, and Claim, which records the stamp; Release undoes a claim.
Session creation checks the stamp first, claims it just before
CreateSession and releases it if CreateSession fails.
SendChannelMessage checks the stamp after the membership, ban and +m
checks.

Model: opus-5-5
This commit is contained in:
2026-10-21 01:39:03 +00:00
parent e7e408c93e
commit 1436d4e409
8 changed files with 393 additions and 51 deletions
+1 -1
View File
@@ -207,7 +207,7 @@ func TestCreateSessionSendsNickAndStamp(t *testing.T) {
return
}
err = validator.Validate(payload.Hashcash, stampBits)
err = validator.Claim(payload.Hashcash, stampBits)
if err != nil {
writer.WriteHeader(http.StatusPaymentRequired)