From 150c0b5de8137ff8e5920daac5da56cfddfad794 Mon Sep 17 00:00:00 2001 From: priyanshiiit Date: Fri, 17 Jun 2022 21:07:17 +0530 Subject: [PATCH] lnwallet: adds RequiredReserve method --- lntest/mock/walletcontroller.go | 5 +++++ lnwallet/btcwallet/btcwallet.go | 16 ++++++++++++++++ lnwallet/interface.go | 6 ++++++ 3 files changed, 27 insertions(+) diff --git a/lntest/mock/walletcontroller.go b/lntest/mock/walletcontroller.go index 0256a3164..3cd237076 100644 --- a/lntest/mock/walletcontroller.go +++ b/lntest/mock/walletcontroller.go @@ -105,6 +105,11 @@ func (w *WalletController) ListAccounts(string, return nil, nil } +// RequiredReserve currently returns a dummy value. +func (w *WalletController) RequiredReserve(uint32) btcutil.Amount { + return 0 +} + // ImportAccount currently returns a dummy value. func (w *WalletController) ImportAccount(string, *hdkeychain.ExtendedKey, uint32, *waddrmgr.AddressType, bool) (*waddrmgr.AccountProperties, diff --git a/lnwallet/btcwallet/btcwallet.go b/lnwallet/btcwallet/btcwallet.go index 40e4a9867..c92823cb8 100644 --- a/lnwallet/btcwallet/btcwallet.go +++ b/lnwallet/btcwallet/btcwallet.go @@ -711,6 +711,22 @@ func (b *BtcWallet) ListAccounts(name string, return res, nil } +// RequiredReserve returns the minimum amount of satoshis that should be +// kept in the wallet in order to fee bump anchor channels if necessary. +// The value scales with the number of public anchor channels but is +// capped at a maximum. +func (b *BtcWallet) RequiredReserve( + numAnchorChans uint32) btcutil.Amount { + + anchorChanReservedValue := lnwallet.AnchorChanReservedValue + reserved := btcutil.Amount(numAnchorChans) * anchorChanReservedValue + if reserved > lnwallet.MaxAnchorChanReservedValue { + reserved = lnwallet.MaxAnchorChanReservedValue + } + + return reserved +} + // ImportAccount imports an account backed by an account extended public key. // The master key fingerprint denotes the fingerprint of the root key // corresponding to the account public key (also known as the key with diff --git a/lnwallet/interface.go b/lnwallet/interface.go index 71602789e..146fb8e58 100644 --- a/lnwallet/interface.go +++ b/lnwallet/interface.go @@ -244,6 +244,12 @@ type WalletController interface { ListAccounts(string, *waddrmgr.KeyScope) ([]*waddrmgr.AccountProperties, error) + // RequiredReserve returns the minimum amount of satoshis that should be + // kept in the wallet in order to fee bump anchor channels if necessary. + // The value scales with the number of public anchor channels but is + // capped at a maximum. + RequiredReserve(uint32) btcutil.Amount + // ImportAccount imports an account backed by an account extended public // key. The master key fingerprint denotes the fingerprint of the root // key corresponding to the account public key (also known as the key