routing: add block cache to BitcoindFilteredChainView
This commit adds the block cache to the BitcoindFilteredChainView struct and wraps its GetBlock function so that block cache is used.
This commit is contained in:
parent
106f93a1b4
commit
0193669ed8
@ -418,7 +418,9 @@ func NewChainControl(cfg *Config) (*ChainControl, func(), error) {
|
||||
cc.ChainNotifier = bitcoindnotify.New(
|
||||
bitcoindConn, cfg.ActiveNetParams.Params, hintCache, hintCache,
|
||||
)
|
||||
cc.ChainView = chainview.NewBitcoindFilteredChainView(bitcoindConn)
|
||||
cc.ChainView = chainview.NewBitcoindFilteredChainView(
|
||||
bitcoindConn, blockCache,
|
||||
)
|
||||
walletConfig.ChainSource = bitcoindConn.NewBitcoindClient()
|
||||
|
||||
// If we're not in regtest mode, then we'll attempt to use a
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcwallet/chain"
|
||||
"github.com/btcsuite/btcwallet/wtxmgr"
|
||||
"github.com/lightningnetwork/lnd/blockcache"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
)
|
||||
|
||||
@ -37,6 +38,9 @@ type BitcoindFilteredChainView struct {
|
||||
// chainView.
|
||||
blockQueue *blockEventQueue
|
||||
|
||||
// blockCache is an LRU block cache.
|
||||
blockCache *blockcache.BlockCache
|
||||
|
||||
// filterUpdates is a channel in which updates to the utxo filter
|
||||
// attached to this instance are sent over.
|
||||
filterUpdates chan filterUpdate
|
||||
@ -61,12 +65,14 @@ var _ FilteredChainView = (*BitcoindFilteredChainView)(nil)
|
||||
// NewBitcoindFilteredChainView creates a new instance of a FilteredChainView
|
||||
// from RPC credentials and a ZMQ socket address for a bitcoind instance.
|
||||
func NewBitcoindFilteredChainView(
|
||||
chainConn *chain.BitcoindConn) *BitcoindFilteredChainView {
|
||||
chainConn *chain.BitcoindConn,
|
||||
blockCache *blockcache.BlockCache) *BitcoindFilteredChainView {
|
||||
|
||||
chainView := &BitcoindFilteredChainView{
|
||||
chainFilter: make(map[wire.OutPoint]struct{}),
|
||||
filterUpdates: make(chan filterUpdate),
|
||||
filterBlockReqs: make(chan *filterBlockReq),
|
||||
blockCache: blockCache,
|
||||
quit: make(chan struct{}),
|
||||
}
|
||||
|
||||
@ -390,7 +396,7 @@ func (b *BitcoindFilteredChainView) chainFilterer() {
|
||||
case req := <-b.filterBlockReqs:
|
||||
// First we'll fetch the block itself as well as some
|
||||
// additional information including its height.
|
||||
block, err := b.chainClient.GetBlock(req.blockHash)
|
||||
block, err := b.GetBlock(req.blockHash)
|
||||
if err != nil {
|
||||
req.err <- err
|
||||
req.resp <- nil
|
||||
@ -479,3 +485,11 @@ func (b *BitcoindFilteredChainView) FilteredBlocks() <-chan *FilteredBlock {
|
||||
func (b *BitcoindFilteredChainView) DisconnectedBlocks() <-chan *FilteredBlock {
|
||||
return b.blockQueue.staleBlocks
|
||||
}
|
||||
|
||||
// GetBlock is used to retrieve the block with the given hash. This function
|
||||
// wraps the blockCache's GetBlock function.
|
||||
func (b *BitcoindFilteredChainView) GetBlock(hash *chainhash.Hash) (
|
||||
*wire.MsgBlock, error) {
|
||||
|
||||
return b.blockCache.GetBlock(hash, b.chainClient.GetBlock)
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import (
|
||||
_ "github.com/btcsuite/btcwallet/walletdb/bdb" // Required to register the boltdb walletdb implementation.
|
||||
|
||||
"github.com/lightninglabs/neutrino"
|
||||
"github.com/lightningnetwork/lnd/blockcache"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||
)
|
||||
@ -844,7 +845,11 @@ var interfaceImpls = []struct {
|
||||
cleanUp2()
|
||||
}
|
||||
|
||||
chainView := NewBitcoindFilteredChainView(chainConn)
|
||||
blockCache := blockcache.NewBlockCache(10000)
|
||||
|
||||
chainView := NewBitcoindFilteredChainView(
|
||||
chainConn, blockCache,
|
||||
)
|
||||
|
||||
return cleanUp3, chainView, nil
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user