From ce888ed941af9f614d506da3c72d1456f2dd4268 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Wed, 13 May 2020 08:54:23 -0700 Subject: [PATCH 1/2] wallet: use GetBlockHeaderVerbose to retrieve block heights in GetTransactions There's no need to retrieve the full block as we're only interesting in retrieve its corresponding height, which can be done with GetBlockHeaderVerbose. --- wallet/wallet.go | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/wallet/wallet.go b/wallet/wallet.go index cf2990f..ad16ab9 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -20,7 +20,6 @@ import ( "github.com/btcsuite/btcd/btcjson" "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg/chainhash" - "github.com/btcsuite/btcd/rpcclient" "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" @@ -2202,7 +2201,6 @@ func (w *Wallet) GetTransactions(startBlock, endBlock *BlockIdentifier, cancel < // TODO: Fetching block heights by their hashes is inherently racy // because not all block headers are saved but when they are for SPV the // db can be queried directly without this. - var startResp, endResp rpcclient.FutureGetBlockVerboseResult if startBlock != nil { if startBlock.hash == nil { start = startBlock.height @@ -2212,7 +2210,13 @@ func (w *Wallet) GetTransactions(startBlock, endBlock *BlockIdentifier, cancel < } switch client := chainClient.(type) { case *chain.RPCClient: - startResp = client.GetBlockVerboseTxAsync(startBlock.hash) + startHeader, err := client.GetBlockHeaderVerbose( + startBlock.hash, + ) + if err != nil { + return nil, err + } + start = startHeader.Height case *chain.BitcoindClient: var err error start, err = client.GetBlockHeight(startBlock.hash) @@ -2237,7 +2241,19 @@ func (w *Wallet) GetTransactions(startBlock, endBlock *BlockIdentifier, cancel < } switch client := chainClient.(type) { case *chain.RPCClient: - endResp = client.GetBlockVerboseTxAsync(endBlock.hash) + endHeader, err := client.GetBlockHeaderVerbose( + endBlock.hash, + ) + if err != nil { + return nil, err + } + end = endHeader.Height + case *chain.BitcoindClient: + var err error + start, err = client.GetBlockHeight(endBlock.hash) + if err != nil { + return nil, err + } case *chain.NeutrinoClient: var err error end, err = client.GetBlockHeight(endBlock.hash) @@ -2247,20 +2263,6 @@ func (w *Wallet) GetTransactions(startBlock, endBlock *BlockIdentifier, cancel < } } } - if startResp != nil { - resp, err := startResp.Receive() - if err != nil { - return nil, err - } - start = int32(resp.Height) - } - if endResp != nil { - resp, err := endResp.Receive() - if err != nil { - return nil, err - } - end = int32(resp.Height) - } var res GetTransactionsResult err := walletdb.View(w.db, func(dbtx walletdb.ReadTx) error { From 17c23a92669959771fe93095536d000a74f501d0 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Wed, 13 May 2020 08:57:18 -0700 Subject: [PATCH 2/2] build: update to latest btcd version --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index a20589c..f55c89f 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module github.com/btcsuite/btcwallet require ( - github.com/btcsuite/btcd v0.20.1-beta + github.com/btcsuite/btcd v0.20.1-beta.0.20200513120220-b470eee47728 github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d github.com/btcsuite/btcwallet/wallet/txauthor v1.0.0 diff --git a/go.sum b/go.sum index 3f267ec..7c1715a 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,8 @@ github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3 h1:A/EVblehb75cUgXA5 github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= github.com/btcsuite/btcd v0.20.1-beta h1:Ik4hyJqN8Jfyv3S4AGBOmyouMsYE3EdYODkMbQjwPGw= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= +github.com/btcsuite/btcd v0.20.1-beta.0.20200513120220-b470eee47728 h1:kF1MN22IdIZ1I7VMgS5WuihFuYaWOoP69Btm4bLUBxY= +github.com/btcsuite/btcd v0.20.1-beta.0.20200513120220-b470eee47728/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d h1:yJzD/yFppdVCf6ApMkVy8cUxV0XrxdP9rVf6D87/Mng=