aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-11-25 09:25:18 -0700
committerAdam Soltys <[email protected]>2026-11-25 09:25:18 -0700
commit9225b8ddea10c15487271a7e4a4c9b26598fc45b (patch)
tree624050dcfd53cfb8105194195871cbad11a4eb99 /lib
parent43b6d2a4e16f1991a02a77f2198bc83bb71deb04 (diff)
downloadcoinos-server-9225b8ddea10c15487271a7e4a4c9b26598fc45b.tar.gz
coinos-server-9225b8ddea10c15487271a7e4a4c9b26598fc45b.zip
nwc: floor the default routing fee cap at 5 sats
1% rounds to zero below 50 sats, which rejected small zaps whose route costs a sat. Unused fee is refunded. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VMan6SEnsbshZrUDtTsxAX
Diffstat (limited to 'lib')
-rw-r--r--lib/nwc.ts10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/nwc.ts b/lib/nwc.ts
index 21bab0a7..1b306e1b 100644
--- a/lib/nwc.ts
+++ b/lib/nwc.ts
@@ -59,6 +59,12 @@ const methods = [
];
const week = 7 * 24 * 60 * 60;
+
+// Fee cap for a connection with no max fee of its own: 1% of the amount, but
+// never under 5 sats. Plain 1% rounds to 0 below 50 sats, and a 0 cap rejects
+// any zap whose route costs a single sat. Unused fee is refunded.
+const defaultMaxFee = (amount: number) =>
+ Math.max(5, Math.ceil(amount * 0.01));
const nwcEventMaxAgeSeconds = 5 * 60;
// Tolerated clock skew for future-dated events. Events further ahead than this
// are rejected so a captured, future-dated signed event can't be replayed later.
@@ -704,7 +710,7 @@ const handle = (method, params, ev, app, user) =>
// payment had settled; see issue #80).
const p = await sendLightning({
amount,
- fee: max_fee || Math.round(amount * 0.01),
+ fee: max_fee || defaultMaxFee(amount),
user,
pr,
memo: JSON.stringify(metadata),
@@ -877,7 +883,7 @@ const handle = (method, params, ev, app, user) =>
try {
const p = await sendLightning({
amount,
- fee: app.max_fee || Math.round(amount * 0.01),
+ fee: app.max_fee || defaultMaxFee(amount),
user,
pr,
memo: metadata ? JSON.stringify(metadata) : undefined,