rpc: skip rescan if client has no addresses or UTXOs
In this commit, we implement an optimization that will speed up clients that attempt to perform a rescan in the past with no addresses. If the client doesn't have any thing to search for, then we simply exit early and send them a rescan finished notification with the final block in our chain.
This commit is contained in:
parent
594e2ab48a
commit
18c37d2eb7
1 changed files with 21 additions and 0 deletions
|
@ -2588,6 +2588,11 @@ func handleRescan(wsc *wsClient, icmd interface{}) (interface{}, error) {
|
|||
}
|
||||
}
|
||||
|
||||
var (
|
||||
lastBlock *btcutil.Block
|
||||
lastBlockHash *chainhash.Hash
|
||||
)
|
||||
if len(lookups.addrs) != 0 || len(lookups.unspent) != 0 {
|
||||
// With all the arguments parsed, we'll execute our chunked rescan
|
||||
// which will notify the clients of any address deposits or output
|
||||
// spends.
|
||||
|
@ -2597,6 +2602,22 @@ func handleRescan(wsc *wsClient, icmd interface{}) (interface{}, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
rpcsLog.Infof("Skipping rescan as client has no addrs/utxos")
|
||||
|
||||
// If we didn't actually do a rescan, then we'll give the
|
||||
// client our best known block within the final rescan finished
|
||||
// notification.
|
||||
chainTip := chain.BestSnapshot()
|
||||
lastBlockHash = &chainTip.Hash
|
||||
lastBlock, err = chain.BlockByHash(lastBlockHash)
|
||||
if err != nil {
|
||||
return nil, &btcjson.RPCError{
|
||||
Code: btcjson.ErrRPCBlockNotFound,
|
||||
Message: "Error getting block: " + err.Error(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Notify websocket client of the finished rescan. Due to how btcd
|
||||
// asynchronously queues notifications to not block calling code,
|
||||
|
|
Loading…
Reference in a new issue