mirror of
https://github.com/LBRYFoundation/lbcwallet.git
synced 2025-08-23 17:47:29 +00:00
Merge pull request #541 from halseth/neutrino-recovery
Wait for neutrino filter headers
This commit is contained in:
commit
c4dd27e481
5 changed files with 35 additions and 45 deletions
|
@ -12,7 +12,7 @@ before_install:
|
||||||
install:
|
install:
|
||||||
- go install -v $(glide novendor)
|
- go install -v $(glide novendor)
|
||||||
- go get -v golang.org/x/tools/cmd/cover
|
- 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
|
- go get -v github.com/davecgh/go-spew/spew
|
||||||
script:
|
script:
|
||||||
- export PATH=$PATH:$HOME/gopath/bin
|
- export PATH=$PATH:$HOME/gopath/bin
|
||||||
|
|
|
@ -118,16 +118,12 @@ func (s *NeutrinoClient) GetBlock(hash *chainhash.Hash) (*wire.MsgBlock, error)
|
||||||
// since we can't actually return a FutureGetBlockVerboseResult because the
|
// since we can't actually return a FutureGetBlockVerboseResult because the
|
||||||
// underlying type is private to rpcclient.
|
// underlying type is private to rpcclient.
|
||||||
func (s *NeutrinoClient) GetBlockHeight(hash *chainhash.Hash) (int32, error) {
|
func (s *NeutrinoClient) GetBlockHeight(hash *chainhash.Hash) (int32, error) {
|
||||||
_, height, err := s.CS.BlockHeaders.FetchHeader(hash)
|
return s.CS.GetBlockHeight(hash)
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return int32(height), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBestBlock replicates the RPC client's GetBestBlock command.
|
// GetBestBlock replicates the RPC client's GetBestBlock command.
|
||||||
func (s *NeutrinoClient) GetBestBlock() (*chainhash.Hash, int32, error) {
|
func (s *NeutrinoClient) GetBestBlock() (*chainhash.Hash, int32, error) {
|
||||||
chainTip, err := s.CS.BestSnapshot()
|
chainTip, err := s.CS.BestBlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
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
|
// client has been shut down or the hash at the block height doesn't exist or
|
||||||
// is unknown.
|
// is unknown.
|
||||||
func (s *NeutrinoClient) GetBlockHash(height int64) (*chainhash.Hash, error) {
|
func (s *NeutrinoClient) GetBlockHash(height int64) (*chainhash.Hash, error) {
|
||||||
header, err := s.CS.BlockHeaders.FetchHeaderByHeight(uint32(height))
|
return s.CS.GetBlockHash(height)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
hash := header.BlockHash()
|
|
||||||
return &hash, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBlockHeader returns the block header for the given block hash, or an error
|
// 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.
|
// if the client has been shut down or the hash doesn't exist or is unknown.
|
||||||
func (s *NeutrinoClient) GetBlockHeader(
|
func (s *NeutrinoClient) GetBlockHeader(
|
||||||
blockHash *chainhash.Hash) (*wire.BlockHeader, error) {
|
blockHash *chainhash.Hash) (*wire.BlockHeader, error) {
|
||||||
header, _, err := s.CS.BlockHeaders.FetchHeader(blockHash)
|
return s.CS.GetBlockHeader(blockHash)
|
||||||
return header, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendRawTransaction replicates the RPC client's SendRawTransaction command.
|
// 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.lastProgressSent = false
|
||||||
s.isRescan = true
|
s.isRescan = true
|
||||||
|
|
||||||
header, height, err := s.CS.BlockHeaders.ChainTip()
|
bestBlock, err := s.CS.BestBlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Can't get chain service's best block: %s", err)
|
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
|
// If the wallet is already fully caught up, or the rescan has started
|
||||||
// with state that indicates a "fresh" wallet, we'll send a
|
// 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 {
|
select {
|
||||||
case s.enqueueNotification <- &RescanFinished{
|
case s.enqueueNotification <- &RescanFinished{
|
||||||
Hash: startHash,
|
Hash: startHash,
|
||||||
Height: int32(height),
|
Height: int32(bestBlock.Height),
|
||||||
Time: header.Timestamp,
|
Time: header.Timestamp,
|
||||||
}:
|
}:
|
||||||
case <-s.quit:
|
case <-s.quit:
|
||||||
|
@ -503,7 +498,7 @@ func (s *NeutrinoClient) onFilteredBlockConnected(height int32,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle RescanFinished notification if required.
|
// Handle RescanFinished notification if required.
|
||||||
bs, err := s.CS.BestSnapshot()
|
bs, err := s.CS.BestBlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Can't get chain service's best block: %s", err)
|
log.Errorf("Can't get chain service's best block: %s", err)
|
||||||
return
|
return
|
||||||
|
|
6
glide.lock
generated
6
glide.lock
generated
|
@ -1,5 +1,5 @@
|
||||||
hash: b1db66b8a8a0efd622b44de1299cf86ed6ea9333e73c1c9b1fcdaa9d589065fa
|
hash: fd238231109616b821cfb40783aab5b96fa5d9026de065411507b5c3431166e5
|
||||||
updated: 2018-08-22T20:11:48.978564284-07:00
|
updated: 2018-10-16T18:17:51.368476548-07:00
|
||||||
imports:
|
imports:
|
||||||
- name: github.com/aead/siphash
|
- name: github.com/aead/siphash
|
||||||
version: 83563a290f60225eb120d724600b9690c3fb536f
|
version: 83563a290f60225eb120d724600b9690c3fb536f
|
||||||
|
@ -69,7 +69,7 @@ imports:
|
||||||
- name: github.com/lightninglabs/gozmq
|
- name: github.com/lightninglabs/gozmq
|
||||||
version: 462a8a75388506b68f76661af8d649f0b88e5301
|
version: 462a8a75388506b68f76661af8d649f0b88e5301
|
||||||
- name: github.com/lightninglabs/neutrino
|
- name: github.com/lightninglabs/neutrino
|
||||||
version: 31332f9c7a241da72835ad33ff340c3998e30de8
|
version: 4d60692991302a44509d1a9234ccd51373c120b4
|
||||||
subpackages:
|
subpackages:
|
||||||
- cache
|
- cache
|
||||||
- cache/lru
|
- cache/lru
|
||||||
|
|
|
@ -18,7 +18,7 @@ import:
|
||||||
subpackages:
|
subpackages:
|
||||||
- hdkeychain
|
- hdkeychain
|
||||||
- package: github.com/lightninglabs/neutrino
|
- package: github.com/lightninglabs/neutrino
|
||||||
version: 31332f9c7a241da72835ad33ff340c3998e30de8
|
version: 4d60692991302a44509d1a9234ccd51373c120b4
|
||||||
- package: github.com/btcsuite/golangcrypto
|
- package: github.com/btcsuite/golangcrypto
|
||||||
subpackages:
|
subpackages:
|
||||||
- nacl/secretbox
|
- nacl/secretbox
|
||||||
|
|
|
@ -443,36 +443,31 @@ func (w *Wallet) syncWithChain() error {
|
||||||
return err
|
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
|
// If we've found the best height the backend knows
|
||||||
// about, but we haven't reached the last checkpoint, we
|
// about, and the backend is still synchronizing, we'll
|
||||||
// know the backend is still synchronizing. We can give
|
// wait. We can give it a little bit of time to
|
||||||
// it a little bit of time to synchronize further before
|
// synchronize further before updating the best height
|
||||||
// updating the best height based on the backend. Once
|
// based on the backend. Once we see that the backend
|
||||||
// we see that the backend has advanced, we can catch
|
// has advanced, we can catch up to it.
|
||||||
// up to it.
|
for height == bestHeight && !isCurrent(bestHeight) {
|
||||||
for height == bestHeight && bestHeight < checkHeight {
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
_, bestHeight, err = chainClient.GetBestBlock()
|
_, bestHeight, err = chainClient.GetBestBlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return err
|
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)
|
header, err := chainClient.GetBlockHeader(hash)
|
||||||
|
|
Loading…
Add table
Reference in a new issue