lnwallet: add new helper functions to scale confirmations based on amt
What changed, and why it matters
This commit adds a new helper file that calculates how many Bitcoin confirmations LND should wait before treating a channel funding transaction as settled. The number of required confirmations now scales between 1 and 6 based on the channel size and any 'pushed' amount. There is no bug fix, vulnerability patch, or security-relevant behavior change visible in the diff; it appears to be a new feature or policy refinement.
No immediate security action required. Review where these helpers will be called in follow-up commits to confirm the confirmation-scaling policy matches expected security assumptions, especially for wumbo channels and push amounts.
Security signals we found
No security-relevant signals present in the diff
Purely additive helper code with no existing callers shown
No input validation changes, no fix language, no CVE or advisory references
Evidence from the diff
The patch introduces lnwallet/confscale.go with two exported helpers: ScaleNumConfs and FundingConfsForAmounts. They compute a linearly scaled uint16 confirmation count between minRequiredConfs (1) and maxRequiredConfs (6), using maxChannelSize (0.16777215 BTC) as the scaling cap. Wumbo channels (amount > maxChannelSize) always receive maxRequiredConfs. The code is purely additive and contains no callers, no state changes, no cryptographic operations, and no obvious arithmetic flaws (the multiplication is bounded by uint64(stake) where stake is at most ~2×maxChannelSizeMsat, so overflow is not possible).
Changed components
lnwallet/confscale.go (new file)Inspect captured patch +58 / −0
diff --git a/lnwallet/confscale.go b/lnwallet/confscale.go
new file mode 100644
index 0000000..6e2b010
--- /dev/null
+++ b/lnwallet/confscale.go
@@ -0,0 +1,58 @@
+package lnwallet
+
+import (
+ "github.com/btcsuite/btcd/btcutil"
+ "github.com/lightningnetwork/lnd/lnwire"
+)
+
+const (
+ // minRequiredConfs is the minimum number of confirmations we'll
+ // require for channel operations.
+ minRequiredConfs = 1
+
+ // maxRequiredConfs is the maximum number of confirmations we'll
+ // require for channel operations.
+ maxRequiredConfs = 6
+
+ // maxChannelSize is the maximum expected channel size in satoshis.
+ // This matches MaxBtcFundingAmount (0.16777215 BTC).
+ maxChannelSize = 16777215
+)
+
+// ScaleNumConfs returns a linearly scaled number of confirmations based on the
+// provided channel amount and push amount (for funding transactions). The push
+// amount represents additional risk when receiving funds.
+func ScaleNumConfs(chanAmt btcutil.Amount, pushAmt lnwire.MilliSatoshi) uint16 {
+ // For wumbo channels, always require maximum confirmations.
+ if chanAmt > maxChannelSize {
+ return maxRequiredConfs
+ }
+
+ // Calculate total stake: channel amount + push amount. The push amount
+ // represents value at risk for the receiver.
+ maxChannelSizeMsat := lnwire.NewMSatFromSatoshis(maxChannelSize)
+ stake := lnwire.NewMSatFromSatoshis(chanAmt) + pushAmt
+
+ // Scale confirmations linearly based on stake.
+ conf := uint64(maxRequiredConfs) * uint64(stake) /
+ uint64(maxChannelSizeMsat)
+
+ // Bound the result between minRequiredConfs and maxRequiredConfs.
+ if conf < minRequiredConfs {
+ conf = minRequiredConfs
+ }
+ if conf > maxRequiredConfs {
+ conf = maxRequiredConfs
+ }
+
+ return uint16(conf)
+}
+
+// FundingConfsForAmounts returns the number of confirmations to wait for a
+// funding transaction, taking into account both the channel amount and any
+// pushed amount (which represents additional risk).
+func FundingConfsForAmounts(chanAmt btcutil.Amount,
+ pushAmt lnwire.MilliSatoshi) uint16 {
+
+ return ScaleNumConfs(chanAmt, pushAmt)
+}
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.