diff --git a/.travis.yml b/.travis.yml index 20a2df6..8f8eada 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ before_install: install: - go install -v $(glide novendor) - go get -v golang.org/x/tools/cmd/cover - - go get -v github.com/golang/lint/golint + - go get -v golang.org/x/lint/golint - go get -v github.com/davecgh/go-spew/spew script: - export PATH=$PATH:$HOME/gopath/bin diff --git a/chain/neutrino.go b/chain/neutrino.go index 04b6f44..38a1cce 100644 --- a/chain/neutrino.go +++ b/chain/neutrino.go @@ -118,16 +118,12 @@ func (s *NeutrinoClient) GetBlock(hash *chainhash.Hash) (*wire.MsgBlock, error) // since we can't actually return a FutureGetBlockVerboseResult because the // underlying type is private to rpcclient. func (s *NeutrinoClient) GetBlockHeight(hash *chainhash.Hash) (int32, error) { - _, height, err := s.CS.BlockHeaders.FetchHeader(hash) - if err != nil { - return 0, err - } - return int32(height), nil + return s.CS.GetBlockHeight(hash) } // GetBestBlock replicates the RPC client's GetBestBlock command. func (s *NeutrinoClient) GetBestBlock() (*chainhash.Hash, int32, error) { - chainTip, err := s.CS.BestSnapshot() + chainTip, err := s.CS.BestBlock() if err != nil { return nil, 0, err } @@ -150,20 +146,14 @@ func (s *NeutrinoClient) BlockStamp() (*waddrmgr.BlockStamp, error) { // client has been shut down or the hash at the block height doesn't exist or // is unknown. func (s *NeutrinoClient) GetBlockHash(height int64) (*chainhash.Hash, error) { - header, err := s.CS.BlockHeaders.FetchHeaderByHeight(uint32(height)) - if err != nil { - return nil, err - } - hash := header.BlockHash() - return &hash, nil + return s.CS.GetBlockHash(height) } // GetBlockHeader returns the block header for the given block hash, or an error // if the client has been shut down or the hash doesn't exist or is unknown. func (s *NeutrinoClient) GetBlockHeader( blockHash *chainhash.Hash) (*wire.BlockHeader, error) { - header, _, err := s.CS.BlockHeaders.FetchHeader(blockHash) - return header, err + return s.CS.GetBlockHeader(blockHash) } // SendRawTransaction replicates the RPC client's SendRawTransaction command. @@ -351,10 +341,15 @@ func (s *NeutrinoClient) Rescan(startHash *chainhash.Hash, addrs []btcutil.Addre s.lastProgressSent = false s.isRescan = true - header, height, err := s.CS.BlockHeaders.ChainTip() + bestBlock, err := s.CS.BestBlock() if err != nil { return fmt.Errorf("Can't get chain service's best block: %s", err) } + header, err := s.CS.GetBlockHeader(&bestBlock.Hash) + if err != nil { + return fmt.Errorf("Can't get block header for hash %v: %s", + bestBlock.Hash, err) + } // If the wallet is already fully caught up, or the rescan has started // with state that indicates a "fresh" wallet, we'll send a @@ -364,7 +359,7 @@ func (s *NeutrinoClient) Rescan(startHash *chainhash.Hash, addrs []btcutil.Addre select { case s.enqueueNotification <- &RescanFinished{ Hash: startHash, - Height: int32(height), + Height: int32(bestBlock.Height), Time: header.Timestamp, }: case <-s.quit: @@ -503,7 +498,7 @@ func (s *NeutrinoClient) onFilteredBlockConnected(height int32, } // Handle RescanFinished notification if required. - bs, err := s.CS.BestSnapshot() + bs, err := s.CS.BestBlock() if err != nil { log.Errorf("Can't get chain service's best block: %s", err) return diff --git a/glide.lock b/glide.lock index 29cfc74..5de3592 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ -hash: b1db66b8a8a0efd622b44de1299cf86ed6ea9333e73c1c9b1fcdaa9d589065fa -updated: 2018-08-22T20:11:48.978564284-07:00 +hash: fd238231109616b821cfb40783aab5b96fa5d9026de065411507b5c3431166e5 +updated: 2018-10-16T18:17:51.368476548-07:00 imports: - name: github.com/aead/siphash version: 83563a290f60225eb120d724600b9690c3fb536f @@ -69,7 +69,7 @@ imports: - name: github.com/lightninglabs/gozmq version: 462a8a75388506b68f76661af8d649f0b88e5301 - name: github.com/lightninglabs/neutrino - version: 31332f9c7a241da72835ad33ff340c3998e30de8 + version: 4d60692991302a44509d1a9234ccd51373c120b4 subpackages: - cache - cache/lru diff --git a/glide.yaml b/glide.yaml index f106e73..c046ee8 100644 --- a/glide.yaml +++ b/glide.yaml @@ -18,7 +18,7 @@ import: subpackages: - hdkeychain - package: github.com/lightninglabs/neutrino - version: 31332f9c7a241da72835ad33ff340c3998e30de8 + version: 4d60692991302a44509d1a9234ccd51373c120b4 - package: github.com/btcsuite/golangcrypto subpackages: - nacl/secretbox diff --git a/wallet/wallet.go b/wallet/wallet.go index b202d69..f069e7a 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -443,36 +443,31 @@ func (w *Wallet) syncWithChain() error { return err } + // If we're using the Neutrino backend, we can check if + // it's current or not. For other backends we'll assume + // it is current if the best height has reached the + // last checkpoint. + isCurrent := func(bestHeight int32) bool { + switch c := chainClient.(type) { + case *chain.NeutrinoClient: + return c.CS.IsCurrent() + } + return bestHeight >= checkHeight + } + // If we've found the best height the backend knows - // about, but we haven't reached the last checkpoint, we - // know the backend is still synchronizing. We can give - // it a little bit of time to synchronize further before - // updating the best height based on the backend. Once - // we see that the backend has advanced, we can catch - // up to it. - for height == bestHeight && bestHeight < checkHeight { + // about, and the backend is still synchronizing, we'll + // wait. We can give it a little bit of time to + // synchronize further before updating the best height + // based on the backend. Once we see that the backend + // has advanced, we can catch up to it. + for height == bestHeight && !isCurrent(bestHeight) { time.Sleep(100 * time.Millisecond) _, bestHeight, err = chainClient.GetBestBlock() if err != nil { tx.Rollback() return err } - - // If we're using the Neutrino backend, we can - // check if it's current or not. If it's not and - // we've exceeded the original checkHeight, we - // can keep the loop going by increasing the - // checkHeight to be greater than the bestHeight - // and if it is, we can set checkHeight to the - // same as the bestHeight so the loop exits. - switch c := chainClient.(type) { - case *chain.NeutrinoClient: - if c.CS.IsCurrent() { - checkHeight = bestHeight - } else if checkHeight < bestHeight+1 { - checkHeight = bestHeight + 1 - } - } } header, err := chainClient.GetBlockHeader(hash)