From c7bdfe149a603f4d89978b81514eb5c20cc537c0 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Mon, 19 Aug 2019 14:25:50 -0700 Subject: [PATCH] lnwallet/btcwallet: remove internal utxoCache The cache wasn't really serving a purpose as FetchInputInfo isn't known to be a hot path. Also, with a planned addition of returning the confirmation status of an output within FetchInputInfo in a later commit, caching won't be useful as we'll have to go to disk anyway to determine the confirmation status. --- lnwallet/btcwallet/btcwallet.go | 6 ------ lnwallet/btcwallet/signer.go | 15 +-------------- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/lnwallet/btcwallet/btcwallet.go b/lnwallet/btcwallet/btcwallet.go index 420760e86..9e2cab9e6 100644 --- a/lnwallet/btcwallet/btcwallet.go +++ b/lnwallet/btcwallet/btcwallet.go @@ -59,11 +59,6 @@ type BtcWallet struct { netParams *chaincfg.Params chainKeyScope waddrmgr.KeyScope - - // utxoCache is a cache used to speed up repeated calls to - // FetchInputInfo. - utxoCache map[wire.OutPoint]*wire.TxOut - cacheMtx sync.RWMutex } // A compile time check to ensure that BtcWallet implements the @@ -130,7 +125,6 @@ func New(cfg Config) (*BtcWallet, error) { chain: cfg.ChainSource, netParams: cfg.NetParams, chainKeyScope: chainKeyScope, - utxoCache: make(map[wire.OutPoint]*wire.TxOut), }, nil } diff --git a/lnwallet/btcwallet/signer.go b/lnwallet/btcwallet/signer.go index ddc45f3bf..c32c64e3f 100644 --- a/lnwallet/btcwallet/signer.go +++ b/lnwallet/btcwallet/signer.go @@ -26,17 +26,7 @@ func (b *BtcWallet) FetchInputInfo(prevOut *wire.OutPoint) (*wire.TxOut, error) err error output *wire.TxOut ) - - // First check to see if the output is already within the utxo cache. - // If so we can return directly saving a disk access. - b.cacheMtx.RLock() - if output, ok := b.utxoCache[*prevOut]; ok { - b.cacheMtx.RUnlock() - return output, nil - } - b.cacheMtx.RUnlock() - - // Otherwise, we manually look up the output within the tx store. + // We manually look up the output within the tx store. txid := &prevOut.Hash txDetail, err := base.UnstableAPI(b.wallet).TxDetails(txid) if err != nil { @@ -54,9 +44,6 @@ func (b *BtcWallet) FetchInputInfo(prevOut *wire.OutPoint) (*wire.TxOut, error) return nil, err } - b.cacheMtx.Lock() - b.utxoCache[*prevOut] = output - b.cacheMtx.Unlock() return output, nil }