From cbf7cd48f57eb3cb6ed1e4c3f93bfa25bba8865a Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sun, 4 Jun 2017 21:06:52 -0700 Subject: [PATCH] multi: update to latest neutrino API changes --- chainntnfs/neutrinonotify/neutrino.go | 6 +++--- chainregistry.go | 2 +- lnwallet/btcwallet/blockchain.go | 13 +++++++------ lnwallet/btcwallet/btcwallet.go | 10 +++++----- routing/chainview/neutrino.go | 4 ++-- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/chainntnfs/neutrinonotify/neutrino.go b/chainntnfs/neutrinonotify/neutrino.go index c7e1c986..e5f90d27 100644 --- a/chainntnfs/neutrinonotify/neutrino.go +++ b/chainntnfs/neutrinonotify/neutrino.go @@ -116,7 +116,7 @@ func (n *NeutrinoNotifier) Start() error { // start the auto-rescan from this point. Once a caller actually wishes // to register a chain view, the rescan state will be rewound // accordingly. - bestHeader, bestHeight, err := n.p2pNode.LatestBlock() + bestHeader, bestHeight, err := n.p2pNode.BlockHeaders.ChainTip() if err != nil { return err } @@ -406,7 +406,7 @@ chainScan: for scanHeight := heightHint; scanHeight <= currentHeight; scanHeight++ { // First, we'll fetch the block header for this height so we // can compute the current block hash. - header, err := n.p2pNode.GetBlockByHeight(scanHeight) + header, err := n.p2pNode.BlockHeaders.FetchHeaderByHeight(scanHeight) if err != nil { chainntnfs.Log.Errorf("unable to get header for "+ "height=%v: %v", scanHeight, err) @@ -416,7 +416,7 @@ chainScan: // With the hash computed, we can now fetch the extended filter // for this height. - extFilter, err := n.p2pNode.GetExtFilter(blockHash) + extFilter, err := n.p2pNode.GetCFilter(blockHash, true) if err != nil { chainntnfs.Log.Errorf("unable to retrieve extended "+ "filter for height=%v: %v", scanHeight, err) diff --git a/chainregistry.go b/chainregistry.go index 203df871..6b38b8b6 100644 --- a/chainregistry.go +++ b/chainregistry.go @@ -143,7 +143,7 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB) (*chainControl // Finally, we'll set the chain source for btcwallet, and // create our clean up function which simply closes the // database. - walletConfig.ChainSource = chain.NewSPVChain(svc) + walletConfig.ChainSource = chain.NewNeutrinoClient(svc) cleanUp = func() { defer nodeDatabase.Close() } diff --git a/lnwallet/btcwallet/blockchain.go b/lnwallet/btcwallet/blockchain.go index 93f6549e..4b4f84dc 100644 --- a/lnwallet/btcwallet/blockchain.go +++ b/lnwallet/btcwallet/blockchain.go @@ -29,8 +29,8 @@ var ( func (b *BtcWallet) GetBestBlock() (*chainhash.Hash, int32, error) { switch backend := b.chain.(type) { - case *chain.SPVChain: - header, height, err := backend.CS.LatestBlock() + case *chain.NeutrinoClient: + header, height, err := backend.CS.BlockHeaders.ChainTip() if err != nil { return nil, -1, err } @@ -52,7 +52,7 @@ func (b *BtcWallet) GetBestBlock() (*chainhash.Hash, int32, error) { func (b *BtcWallet) GetUtxo(op *wire.OutPoint, heightHint uint32) (*wire.TxOut, error) { switch backend := b.chain.(type) { - case *chain.SPVChain: + case *chain.NeutrinoClient: spendReport, err := backend.CS.GetUtxo( neutrino.WatchOutPoints(*op), neutrino.StartBlock(&waddrmgr.BlockStamp{ @@ -100,7 +100,7 @@ func (b *BtcWallet) GetUtxo(op *wire.OutPoint, heightHint uint32) (*wire.TxOut, func (b *BtcWallet) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error) { switch backend := b.chain.(type) { - case *chain.SPVChain: + case *chain.NeutrinoClient: block, err := backend.CS.GetBlockFromNetwork(*blockHash) if err != nil { return nil, err @@ -128,8 +128,9 @@ func (b *BtcWallet) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error) func (b *BtcWallet) GetBlockHash(blockHeight int64) (*chainhash.Hash, error) { switch backend := b.chain.(type) { - case *chain.SPVChain: - blockHeader, err := backend.CS.GetBlockByHeight(uint32(blockHeight)) + case *chain.NeutrinoClient: + height := uint32(blockHeight) + blockHeader, err := backend.CS.BlockHeaders.FetchHeaderByHeight(height) if err != nil { return nil, err } diff --git a/lnwallet/btcwallet/btcwallet.go b/lnwallet/btcwallet/btcwallet.go index 3e06f5f5..81c7d342 100644 --- a/lnwallet/btcwallet/btcwallet.go +++ b/lnwallet/btcwallet/btcwallet.go @@ -623,8 +623,8 @@ func (b *BtcWallet) IsSynced() (bool, error) { // Next, query the chain backend to grab the info about the tip of the // main chain. switch backend := b.cfg.ChainSource.(type) { - case *chain.SPVChain: - header, height, err := backend.CS.LatestBlock() + case *chain.NeutrinoClient: + header, height, err := backend.CS.BlockHeaders.ChainTip() if err != nil { return false, err } @@ -653,12 +653,12 @@ func (b *BtcWallet) IsSynced() (bool, error) { var blockHeader *wire.BlockHeader switch backend := b.cfg.ChainSource.(type) { - case *chain.SPVChain: - bh, _, err := backend.CS.GetBlockByHash(*bestHash) + case *chain.NeutrinoClient: + bh, _, err := backend.CS.BlockHeaders.FetchHeader(bestHash) if err != nil { return false, err } - blockHeader = &bh + blockHeader = bh case *chain.RPCClient: blockHeader, err = backend.GetBlockHeader(bestHash) diff --git a/routing/chainview/neutrino.go b/routing/chainview/neutrino.go index c2a98559..09f303eb 100644 --- a/routing/chainview/neutrino.go +++ b/routing/chainview/neutrino.go @@ -90,7 +90,7 @@ func (c *CfFilteredChainView) Start() error { // start the auto-rescan from this point. Once a caller actually wishes // to register a chain view, the rescan state will be rewound // accordingly. - bestHeader, bestHeight, err := c.p2pNode.LatestBlock() + bestHeader, bestHeight, err := c.p2pNode.BlockHeaders.ChainTip() if err != nil { return err } @@ -246,7 +246,7 @@ func (c *CfFilteredChainView) FilterBlock(blockHash *chainhash.Hash) (*FilteredB // Along with the block, we'll also need the height of the block in // order to complete the notification. - _, blockHeight, err := c.p2pNode.GetBlockByHash(*blockHash) + _, blockHeight, err := c.p2pNode.BlockHeaders.FetchHeader(blockHash) if err != nil { return nil, err }