chainntnfs: add height hint caches to chain notifiers

This commit is contained in:
Wilmer Paulino committed 2018-08-21 12:55:51 -04:00
1 parent 6be642a033
commit 30fd219b1c
10 files changed
+138 -30

No files matched your search

+18 -2
View File
@@ -76,6 +76,16 @@ type BitcoindNotifier struct {
bestBlock chainntnfs.BlockEpoch
// spendHintCache is a cache used to query and update the latest height
// hints for an outpoint. Each height hint represents the earliest
// height at which the outpoint could have been spent within the chain.
spendHintCache chainntnfs.SpendHintCache
// confirmHintCache is a cache used to query the latest height hints for
// a transaction. Each height hint represents the earliest height at
// which the transaction could have confirmed within the chain.
confirmHintCache chainntnfs.ConfirmHintCache
wg sync.WaitGroup
quit chan struct{}
}
@@ -87,7 +97,9 @@ var _ chainntnfs.ChainNotifier = (*BitcoindNotifier)(nil)
// New returns a new BitcoindNotifier instance. This function assumes the
// bitcoind node detailed in the passed configuration is already running, and
// willing to accept RPC requests and new zmq clients.
func New(chainConn *chain.BitcoindConn) *BitcoindNotifier {
func New(chainConn *chain.BitcoindConn, spendHintCache chainntnfs.SpendHintCache,
confirmHintCache chainntnfs.ConfirmHintCache) *BitcoindNotifier {
notifier := &BitcoindNotifier{
notificationCancels: make(chan interface{}),
notificationRegistry: make(chan interface{}),
@@ -96,6 +108,9 @@ func New(chainConn *chain.BitcoindConn) *BitcoindNotifier {
spendNotifications: make(map[wire.OutPoint]map[uint64]*spendNotification),
spendHintCache: spendHintCache,
confirmHintCache: confirmHintCache,
quit: make(chan struct{}),
}
@@ -127,7 +142,8 @@ func (b *BitcoindNotifier) Start() error {
}
b.txConfNotifier = chainntnfs.NewTxConfNotifier(
uint32(currentHeight), reorgSafetyLimit)
uint32(currentHeight), reorgSafetyLimit, b.confirmHintCache,
)
b.bestBlock = chainntnfs.BlockEpoch{
Height: currentHeight,
+2 -1
View File
@@ -29,7 +29,8 @@ func (b *BitcoindNotifier) UnsafeStart(bestHeight int32, bestHash *chainhash.Has
}
b.txConfNotifier = chainntnfs.NewTxConfNotifier(
uint32(bestHeight), reorgSafetyLimit)
uint32(bestHeight), reorgSafetyLimit, b.confirmHintCache,
)
if generateBlocks != nil {
// Ensure no block notifications are pending when we start the
+17 -4
View File
@@ -1,6 +1,7 @@
package bitcoindnotify
import (
"errors"
"fmt"
"github.com/btcsuite/btcwallet/chain"
@@ -10,18 +11,30 @@ import (
// createNewNotifier creates a new instance of the ChainNotifier interface
// implemented by BitcoindNotifier.
func createNewNotifier(args ...interface{}) (chainntnfs.ChainNotifier, error) {
if len(args) != 1 {
if len(args) != 3 {
return nil, fmt.Errorf("incorrect number of arguments to "+
".New(...), expected 1, instead passed %v", len(args))
".New(...), expected 2, instead passed %v", len(args))
}
chainConn, ok := args[0].(*chain.BitcoindConn)
if !ok {
return nil, fmt.Errorf("first argument to bitcoindnotify.New " +
return nil, errors.New("first argument to bitcoindnotify.New " +
"is incorrect, expected a *chain.BitcoindConn")
}
return New(chainConn), nil
spendHintCache, ok := args[1].(chainntnfs.SpendHintCache)
if !ok {
return nil, errors.New("second argument to bitcoindnotify.New " +
"is incorrect, expected a chainntnfs.SpendHintCache")
}
confirmHintCache, ok := args[2].(chainntnfs.ConfirmHintCache)
if !ok {
return nil, errors.New("third argument to bitcoindnotify.New " +
"is incorrect, expected a chainntnfs.ConfirmHintCache")
}
return New(chainConn, spendHintCache, confirmHintCache), nil
}
// init registers a driver for the BtcdNotifier concrete implementation of the