lnwallet: define helper func to coop close conf scaling
What changed, and why it matters
This commit adds a small helper function that decides how many blockchain confirmations LND should wait before treating a channel close as final. In production it returns at least 3 confirmations, scaling up with larger channel capacities; in integration tests it always returns 1 to keep tests fast. There is no direct security bug here—it is a defensive reorg-protection measure and a code-organization change.
No immediate action required. Reviewers should verify that future commits actually replace inline close-confirmation logic with CloseConfsForCapacity, and that the 3-confirmation minimum is appropriate for the intended threat model. Treat this commit as a preparatory refactor, not a vulnerability fix.
Security signals we found
Adds a minimum-confirmation floor (3) for close finality, which is a reorg-protection hardening measure
Uses existing ScaleNumConfs helper, so the scaling behavior itself is not new
No input validation, overflow, or panic paths are visible in the diff
No call sites are modified, so the change is purely additive
Evidence from the diff
Two new build-tagged files introduce CloseConfsForCapacity(capacity btcutil.Amount) uint32. The integration build always returns 1. The production build delegates to ScaleNumConfs(capacity, 0) and enforces a minimum of 3 confirmations. The function is intended for use before signaling cooperative and force closes. The commit only defines the helper; it does not change any call sites or consensus logic.
Changed components
lnwallet/confscale_integration.golnwallet/confscale_prod.goInspect captured patch +38 / −0
diff --git a/lnwallet/confscale_integration.go b/lnwallet/confscale_integration.go
new file mode 100644
index 0000000..4e78b96
--- /dev/null
+++ b/lnwallet/confscale_integration.go
@@ -0,0 +1,13 @@
+//go:build integration
+// +build integration
+
+package lnwallet
+
+import "github.com/btcsuite/btcd/btcutil"
+
+// CloseConfsForCapacity returns the number of confirmations to wait
+// before signaling a cooperative close. Under integration tests, we
+// always return 1 to keep tests fast and deterministic.
+func CloseConfsForCapacity(capacity btcutil.Amount) uint32 { //nolint:revive
+ return 1
+}
diff --git a/lnwallet/confscale_prod.go b/lnwallet/confscale_prod.go
new file mode 100644
index 0000000..8988107
--- /dev/null
+++ b/lnwallet/confscale_prod.go
@@ -0,0 +1,25 @@
+//go:build !integration
+// +build !integration
+
+package lnwallet
+
+import "github.com/btcsuite/btcd/btcutil"
+
+// CloseConfsForCapacity returns the number of confirmations to wait before
+// signaling a channel close, scaled by channel capacity. This is used for both
+// cooperative and force closes. We enforce a minimum of 3 confirmations to
+// provide better reorg protection, even for small channels.
+func CloseConfsForCapacity(capacity btcutil.Amount) uint32 {
+ // For cooperative closes, we don't have a push amount to consider,
+ // so we pass 0 for the pushAmt parameter.
+ scaledConfs := uint32(ScaleNumConfs(capacity, 0))
+
+ // Enforce a minimum of 3 confirmations for reorg safety.
+ // This protects against shallow reorgs which are more common.
+ const minCloseConfs = 3
+ if scaledConfs < minCloseConfs {
+ return minCloseConfs
+ }
+
+ return scaledConfs
+}
Why this scored 17/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.