From 4ac778d72a5d400d9d013b309e95c944e08aff5f Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 11 Jun 2014 13:23:21 -0500 Subject: [PATCH] Do not reissue rescan requests on reconnect. --- infrastructure.go | 21 +++++++++++++++++++-- notify.go | 12 ++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/infrastructure.go b/infrastructure.go index c56dc398..ee58b9d6 100644 --- a/infrastructure.go +++ b/infrastructure.go @@ -474,6 +474,12 @@ func (c *Client) reregisterNtfns() error { return nil } +// ignoreResends is a set of all methods for requests that are "long running" +// are not be reissued by the client on reconnect. +var ignoreResends = map[string]struct{}{ + "rescan": struct{}{}, +} + // resendCmds resends any commands that had not completed when the client // disconnected. It is intended to be called once the client has reconnected as // a separate goroutine. @@ -492,9 +498,20 @@ func (c *Client) resendCmds() { // also allows the lock to be released quickly. c.requestLock.Lock() resendCmds := make([]*jsonRequest, 0, c.requestList.Len()) - for e := c.requestList.Front(); e != nil; e = e.Next() { + var nextElem *list.Element + for e := c.requestList.Front(); e != nil; e = nextElem { + nextElem = e.Next() + req := e.Value.(*jsonRequest) - resendCmds = append(resendCmds, req) + if _, ok := ignoreResends[req.cmd.Method()]; ok { + // If a request is not sent on reconnect, remove it + // from the request structures, since no reply is + // expected. + delete(c.requestMap, req.cmd.Id().(uint64)) + c.requestList.Remove(e) + } else { + resendCmds = append(resendCmds, req) + } } c.requestLock.Unlock() diff --git a/notify.go b/notify.go index 198abb84..28c7e686 100644 --- a/notify.go +++ b/notify.go @@ -897,6 +897,12 @@ func (r FutureRescanResult) Receive() error { // // See Rescan for the blocking version and more details. // +// NOTE: Rescan requests are not issued on client reconnect and must be +// performed manually (ideally with a new start height based on the last +// rescan progress notification). See the OnClientConnected notification +// callback for a good callsite to reissue rescan requests on connect and +// reconnect. +// // NOTE: This is a btcd extension and requires a websocket connection. func (c *Client) RescanAsync(startHeight int32, addresses []btcutil.Address, outpoints []*btcwire.OutPoint) FutureRescanResult { @@ -952,6 +958,12 @@ func (c *Client) RescanAsync(startHeight int32, addresses []btcutil.Address, // See RescanEndHeight to also specify a block height at which to stop the // rescan if a bounded rescan is desired instead. // +// NOTE: Rescan requests are not issued on client reconnect and must be +// performed manually (ideally with a new start height based on the last +// rescan progress notification). See the OnClientConnected notification +// callback for a good callsite to reissue rescan requests on connect and +// reconnect. +// // NOTE: This is a btcd extension and requires a websocket connection. func (c *Client) Rescan(startHeight int32, addresses []btcutil.Address, outpoints []*btcwire.OutPoint) error {