mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
staticaddr: refresh deposits before spend selection
Refresh the active static-address deposit set against lnd's wallet view before quote, loop-in, withdrawal, channel-open, and autoloop selection paths. This prevents stale persisted Deposited records from being selected after replacement, reorg, or an external spend.
This commit is contained in:
parent
1c89ff83f1
commit
dc7da41b28
13 changed files with 112 additions and 15 deletions
|
|
@ -946,6 +946,12 @@ func (s *swapClientServer) GetLoopInQuote(ctx context.Context,
|
|||
// number of deposits to quote for.
|
||||
numDeposits := 0
|
||||
if autoSelectDeposits {
|
||||
err = s.depositManager.EnsureDepositsFresh(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to refresh deposits: %w",
|
||||
err)
|
||||
}
|
||||
|
||||
deposits, err := s.depositManager.GetActiveDepositsInState(
|
||||
deposit.Deposited,
|
||||
)
|
||||
|
|
@ -980,6 +986,12 @@ func (s *swapClientServer) GetLoopInQuote(ctx context.Context,
|
|||
|
||||
numDeposits = len(selectedDeposits)
|
||||
} else if len(req.DepositOutpoints) > 0 {
|
||||
err = s.depositManager.EnsureDepositsFresh(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to refresh deposits: %w",
|
||||
err)
|
||||
}
|
||||
|
||||
// If deposits are selected, we need to retrieve them to
|
||||
// calculate the total value which we request a quote for.
|
||||
depositList, err := s.ListStaticAddressDeposits(
|
||||
|
|
@ -1798,6 +1810,12 @@ func (s *swapClientServer) WithdrawDeposits(ctx context.Context,
|
|||
return nil, fmt.Errorf("must select either all or some utxos")
|
||||
|
||||
case isAllSelected:
|
||||
err = s.depositManager.EnsureDepositsFresh(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to refresh deposits: %w",
|
||||
err)
|
||||
}
|
||||
|
||||
deposits, err := s.depositManager.GetActiveDepositsInState(
|
||||
deposit.Deposited,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
|
|
@ -13,6 +14,7 @@ import (
|
|||
"github.com/lightninglabs/loop/staticaddr/deposit"
|
||||
"github.com/lightninglabs/loop/staticaddr/script"
|
||||
mock_lnd "github.com/lightninglabs/loop/test"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
|
@ -60,6 +62,33 @@ func (s *staticAddrDepositStore) AllDeposits(context.Context) (
|
|||
return s.allDeposits, nil
|
||||
}
|
||||
|
||||
type staticAddrTestAddressManager struct{}
|
||||
|
||||
func (s *staticAddrTestAddressManager) GetStaticAddressParameters(
|
||||
context.Context) (*script.Parameters, error) {
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *staticAddrTestAddressManager) GetStaticAddress(
|
||||
context.Context) (*script.StaticAddress, error) {
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *staticAddrTestAddressManager) ListUnspent(context.Context,
|
||||
int32, int32) ([]*lnwallet.Utxo, error) {
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *staticAddrTestAddressManager) GetTaprootAddress(
|
||||
*btcec.PublicKey, *btcec.PublicKey, int64) (*btcutil.AddressTaproot,
|
||||
error) {
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// newTestDepositManager creates a deposit manager backed by seeded deposits.
|
||||
func newTestDepositManager(
|
||||
deposits ...*deposit.Deposit) *deposit.Manager {
|
||||
|
|
@ -70,6 +99,7 @@ func newTestDepositManager(
|
|||
}
|
||||
|
||||
return deposit.NewManager(&deposit.ManagerConfig{
|
||||
AddressManager: &staticAddrTestAddressManager{},
|
||||
Store: &staticAddrDepositStore{
|
||||
allDeposits: deposits,
|
||||
byOutpoint: byOutpoint,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue