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.
This commit is contained in:
2 files changed
+1
-20
No files matched your search
@@ -59,11 +59,6 @@ type BtcWallet struct {
|
|||||||
netParams *chaincfg.Params
|
netParams *chaincfg.Params
|
||||||
|
|
||||||
chainKeyScope waddrmgr.KeyScope
|
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
|
// A compile time check to ensure that BtcWallet implements the
|
||||||
@@ -130,7 +125,6 @@ func New(cfg Config) (*BtcWallet, error) {
|
|||||||
chain: cfg.ChainSource,
|
chain: cfg.ChainSource,
|
||||||
netParams: cfg.NetParams,
|
netParams: cfg.NetParams,
|
||||||
chainKeyScope: chainKeyScope,
|
chainKeyScope: chainKeyScope,
|
||||||
utxoCache: make(map[wire.OutPoint]*wire.TxOut),
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,17 +26,7 @@ func (b *BtcWallet) FetchInputInfo(prevOut *wire.OutPoint) (*wire.TxOut, error)
|
|||||||
err error
|
err error
|
||||||
output *wire.TxOut
|
output *wire.TxOut
|
||||||
)
|
)
|
||||||
|
// We manually look up the output within the tx store.
|
||||||
// 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.
|
|
||||||
txid := &prevOut.Hash
|
txid := &prevOut.Hash
|
||||||
txDetail, err := base.UnstableAPI(b.wallet).TxDetails(txid)
|
txDetail, err := base.UnstableAPI(b.wallet).TxDetails(txid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -54,9 +44,6 @@ func (b *BtcWallet) FetchInputInfo(prevOut *wire.OutPoint) (*wire.TxOut, error)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
b.cacheMtx.Lock()
|
|
||||||
b.utxoCache[*prevOut] = output
|
|
||||||
b.cacheMtx.Unlock()
|
|
||||||
|
|
||||||
return output, nil
|
return output, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user