lnwallet: define helper func to coop close conf scaling

We have two versions: for itests, we just use one conf, but in prod,
we'll scale the number of confirmations.
This commit is contained in:
Olaoluwa Osuntokun committed 2026-01-15 16:22:26 -08:00
1 parent 45aa94c760
commit 09c813a61c
2 files changed
+38

No files matched your search

+13
View File
@@ -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
}
+25
View File
@@ -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
}