From 969acf61458d988e74ddbec3e4fb290a00689378 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Thu, 6 Dec 2018 21:14:07 -0800 Subject: [PATCH] chainntnfs/neutrinonotify: clean up neutrinonotify.New --- chainntnfs/neutrinonotify/driver.go | 6 +++--- chainntnfs/neutrinonotify/neutrino.go | 21 ++++++++------------- chainntnfs/neutrinonotify/neutrino_dev.go | 2 -- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/chainntnfs/neutrinonotify/driver.go b/chainntnfs/neutrinonotify/driver.go index 6a6ffd8e..68a1b2f2 100644 --- a/chainntnfs/neutrinonotify/driver.go +++ b/chainntnfs/neutrinonotify/driver.go @@ -11,9 +11,9 @@ import ( // createNewNotifier creates a new instance of the ChainNotifier interface // implemented by NeutrinoNotifier. func createNewNotifier(args ...interface{}) (chainntnfs.ChainNotifier, error) { - if len(args) != 2 { + if len(args) != 3 { return nil, fmt.Errorf("incorrect number of arguments to "+ - ".New(...), expected 2, instead passed %v", len(args)) + ".New(...), expected 3, instead passed %v", len(args)) } config, ok := args[0].(*neutrino.ChainService) @@ -34,7 +34,7 @@ func createNewNotifier(args ...interface{}) (chainntnfs.ChainNotifier, error) { "is incorrect, expected a chainntfs.ConfirmHintCache") } - return New(config, spendHintCache, confirmHintCache) + return New(config, spendHintCache, confirmHintCache), nil } // init registers a driver for the NeutrinoNotify concrete implementation of diff --git a/chainntnfs/neutrinonotify/neutrino.go b/chainntnfs/neutrinonotify/neutrino.go index 3302b620..a9febf61 100644 --- a/chainntnfs/neutrinonotify/neutrino.go +++ b/chainntnfs/neutrinonotify/neutrino.go @@ -93,15 +93,16 @@ var _ chainntnfs.ChainNotifier = (*NeutrinoNotifier)(nil) // NOTE: The passed neutrino node should already be running and active before // being passed into this function. func New(node *neutrino.ChainService, spendHintCache chainntnfs.SpendHintCache, - confirmHintCache chainntnfs.ConfirmHintCache) (*NeutrinoNotifier, error) { + confirmHintCache chainntnfs.ConfirmHintCache) *NeutrinoNotifier { - notifier := &NeutrinoNotifier{ + return &NeutrinoNotifier{ notificationCancels: make(chan interface{}), notificationRegistry: make(chan interface{}), blockEpochClients: make(map[uint64]*blockEpochRegistration), - p2pNode: node, + p2pNode: node, + chainConn: &NeutrinoChainConn{node}, rescanErr: make(chan error), @@ -112,8 +113,6 @@ func New(node *neutrino.ChainService, spendHintCache chainntnfs.SpendHintCache, quit: make(chan struct{}), } - - return notifier, nil } // Start contacts the running neutrino light client and kicks off an initial @@ -132,8 +131,11 @@ func (n *NeutrinoNotifier) Start() error { if err != nil { return err } - n.bestHeight = uint32(startingPoint.Height) + n.txNotifier = chainntnfs.NewTxNotifier( + n.bestHeight, chainntnfs.ReorgSafetyLimit, n.confirmHintCache, + n.spendHintCache, + ) // Next, we'll create our set of rescan options. Currently it's // required that a user MUST set an addr/outpoint/txid when creating a @@ -152,13 +154,6 @@ func (n *NeutrinoNotifier) Start() error { neutrino.WatchInputs(zeroInput), } - n.txNotifier = chainntnfs.NewTxNotifier( - n.bestHeight, chainntnfs.ReorgSafetyLimit, n.confirmHintCache, - n.spendHintCache, - ) - - n.chainConn = &NeutrinoChainConn{n.p2pNode} - // Finally, we'll create our rescan struct, start it, and launch all // the goroutines we need to operate this ChainNotifier instance. n.chainView = n.p2pNode.NewRescan(rescanOptions...) diff --git a/chainntnfs/neutrinonotify/neutrino_dev.go b/chainntnfs/neutrinonotify/neutrino_dev.go index 2cacf2b3..f341bdf3 100644 --- a/chainntnfs/neutrinonotify/neutrino_dev.go +++ b/chainntnfs/neutrinonotify/neutrino_dev.go @@ -53,8 +53,6 @@ func (n *NeutrinoNotifier) UnsafeStart(bestHeight int32, n.confirmHintCache, n.spendHintCache, ) - n.chainConn = &NeutrinoChainConn{n.p2pNode} - // Finally, we'll create our rescan struct, start it, and launch all // the goroutines we need to operate this ChainNotifier instance. n.chainView = n.p2pNode.NewRescan(rescanOptions...)