chainntnfs: add block cache to BtcdNotifier

This commit adds gives BtcdNotifier access to the block cache and wraps
its GetBlock method so that it uses the block cache.
This commit is contained in:
Elle Mouton
2021-03-18 14:54:36 +02:00
parent 8a33fbf11a
commit a0f7bf8b2d
6 changed files with 40 additions and 10 deletions

View File

@@ -6,15 +6,16 @@ import (
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/rpcclient"
"github.com/lightningnetwork/lnd/blockcache"
"github.com/lightningnetwork/lnd/chainntnfs"
)
// createNewNotifier creates a new instance of the ChainNotifier interface
// implemented by BtcdNotifier.
func createNewNotifier(args ...interface{}) (chainntnfs.ChainNotifier, error) {
if len(args) != 4 {
if len(args) != 5 {
return nil, fmt.Errorf("incorrect number of arguments to "+
".New(...), expected 4, instead passed %v", len(args))
".New(...), expected 5, instead passed %v", len(args))
}
config, ok := args[0].(*rpcclient.ConnConfig)
@@ -41,7 +42,15 @@ func createNewNotifier(args ...interface{}) (chainntnfs.ChainNotifier, error) {
"is incorrect, expected a chainntnfs.ConfirmHintCache")
}
return New(config, chainParams, spendHintCache, confirmHintCache)
blockCache, ok := args[4].(*blockcache.BlockCache)
if !ok {
return nil, errors.New("fifth argument to btcdnotify.New " +
"is incorrect, expected a *blockcache.BlockCache")
}
return New(
config, chainParams, spendHintCache, confirmHintCache, blockCache,
)
}
// init registers a driver for the BtcdNotifier concrete implementation of the