Skip to content

plugins: nwc: sync with spec, fix some bugs#10505

Merged
SomberNight merged 6 commits intospesmilo:masterfrom
f321x:nwc_improvement
Mar 3, 2026
Merged

plugins: nwc: sync with spec, fix some bugs#10505
SomberNight merged 6 commits intospesmilo:masterfrom
f321x:nwc_improvement

Conversation

@f321x
Copy link
Member

@f321x f321x commented Mar 3, 2026

Syncs the NWC plugin with changes to the NIP-47 specification and makes the handling of payment budgets more reliable.

f321x added 2 commits March 3, 2026 11:22
It got removed from the spec so we don't need to support it anymore.
nostr-protocol/nips#2210
NIP-47 now defines how client/server should communicate their supported
encryption schemes. For backwards compatibility its not strictly
neccessary to implement this but it seems cleaner to explicitly handle
it.
@f321x f321x added bug 🐞 topic-plugins related to plugin system labels Mar 3, 2026
f321x added 4 commits March 3, 2026 18:04
Keep track of the spent amount in msat instead of sat to prevent
issues due to rounding.
The budget is still specified in sat.
Increase the payment budget before attempting the payment
and decrease again if the payment fails. This prevents a race
where multiple concurrent payments could pass the budget check
before the budget is incremented through any of the other payments.

A lock around the budget is not suitable either as then one long
stuck payment (hold invoice) would render the budget inaccessible for
all other payment attempts.
NIP-47 got extended to include an optional 'state' field in responses.
Implementing this acutally fixes an issue of Alby Go showing succeeded
payments as failed that appeared recently.
these changes deserve a new version
@f321x f321x force-pushed the nwc_improvement branch from 731e275 to 835ab39 Compare March 3, 2026 17:14
Copy link
Member

@SomberNight SomberNight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks!

@SomberNight SomberNight merged commit fd52b97 into spesmilo:master Mar 3, 2026
10 of 16 checks passed
Comment on lines +819 to +821
if not self.budget_allows_spend(request_pub, msat_requested=amount_msat or invoice.get_amount_msat()):
return self.get_error_response("QUOTA_EXCEEDED", "Payment exceeds daily limit")
budget_item = self.add_to_budget(request_pub, amount_msat=amount_msat or invoice.get_amount_msat())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: I think it would be a safer API if budget_allows_spend and add_to_budget were combined to a single method. could be done in a follow-up if you agree

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but as long as there is no await between the two calls, and no multi-threading here, it does not functionally matter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐞 topic-plugins related to plugin system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants