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:
1 parent
45aa94c760
commit
09c813a61c
2 files changed
+38
No files matched your search
@@ -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
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
Reference in new issue
Block a user