From e860a9e23dcd665862777d972dae9150afb8b500 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 13 Aug 2020 13:01:00 -0700 Subject: [PATCH] lnwallet: ensure ConfirmedBalance holds the coin select mutex In this commit, we make a new wrapper method around the internal `WalletController` method to ensure it holds the coin select mutex while the balance is being computed. --- lnwallet/wallet.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lnwallet/wallet.go b/lnwallet/wallet.go index 2b41aedc..6126fa15 100644 --- a/lnwallet/wallet.go +++ b/lnwallet/wallet.go @@ -377,6 +377,16 @@ func (l *LightningWallet) Shutdown() error { return nil } +// ConfirmedBalance returns the current confirmed balance of the wallet. This +// methods wraps the interal WalletController method so we're able to properly +// hold the coin select mutex while we compute the balance. +func (l *LightningWallet) ConfirmedBalance(confs int32) (btcutil.Amount, error) { + l.coinSelectMtx.Lock() + defer l.coinSelectMtx.Unlock() + + return l.WalletController.ConfirmedBalance(confs) +} + // LockedOutpoints returns a list of all currently locked outpoint. func (l *LightningWallet) LockedOutpoints() []*wire.OutPoint { outPoints := make([]*wire.OutPoint, 0, len(l.lockedOutPoints))