Simplify logic in WalletRequestProcessor.
This commit is contained in:
parent
53e4070a5a
commit
aa0980bfa7
1 changed files with 39 additions and 41 deletions
56
rpcserver.go
56
rpcserver.go
|
@ -180,48 +180,46 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// WalletRequestProcessor processes client requests and btcd notifications.
|
// WalletRequestProcessor processes client requests and btcd notifications.
|
||||||
// Notifications are preferred over client requests.
|
|
||||||
func WalletRequestProcessor() {
|
func WalletRequestProcessor() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case r := <-requestQueue:
|
case r := <-requestQueue:
|
||||||
var result interface{}
|
method := r.request.Method()
|
||||||
var jsonErr *btcjson.Error
|
f, ok := rpcHandlers[method]
|
||||||
if f, ok := rpcHandlers[r.request.Method()]; ok {
|
if !ok && r.ws {
|
||||||
AcctMgr.Grab()
|
f, ok = wsHandlers[method]
|
||||||
result, jsonErr = f(r.request)
|
|
||||||
AcctMgr.Release()
|
|
||||||
} else if f, ok := wsHandlers[r.request.Method()]; r.ws && ok {
|
|
||||||
AcctMgr.Grab()
|
|
||||||
result, jsonErr = f(r.request)
|
|
||||||
AcctMgr.Release()
|
|
||||||
} else {
|
|
||||||
result, jsonErr = Unimplemented(r.request)
|
|
||||||
}
|
}
|
||||||
resp := &ClientResponse{
|
if !ok {
|
||||||
|
f = Unimplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
AcctMgr.Grab()
|
||||||
|
result, jsonErr := f(r.request)
|
||||||
|
AcctMgr.Release()
|
||||||
|
|
||||||
|
r.response <- &ClientResponse{
|
||||||
result: result,
|
result: result,
|
||||||
err: jsonErr,
|
err: jsonErr,
|
||||||
}
|
}
|
||||||
r.response <- resp
|
|
||||||
|
|
||||||
case n := <-handleNtfn:
|
case n := <-handleNtfn:
|
||||||
if f, ok := notificationHandlers[n.Method()]; ok {
|
f, ok := notificationHandlers[n.Method()]
|
||||||
|
if !ok {
|
||||||
|
// Ignore unhandled notifications.
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
AcctMgr.Grab()
|
AcctMgr.Grab()
|
||||||
err := f(n)
|
err := f(n)
|
||||||
AcctMgr.Release()
|
AcctMgr.Release()
|
||||||
switch err {
|
switch err {
|
||||||
case nil:
|
|
||||||
// ignore
|
|
||||||
|
|
||||||
case tx.ErrInconsistantStore:
|
case tx.ErrInconsistantStore:
|
||||||
log.Warn("Detected inconsistant TxStore. Reconnecting...")
|
// Assume this is a broken btcd reordered
|
||||||
// Likely due to a mis-ordered btcd notification.
|
// notifications. Restart the connection
|
||||||
// To recover, close server connection and reopen
|
// to reload accounts files from their last
|
||||||
// all accounts from their last good state saved
|
// known good state.
|
||||||
// to disk. This will trigger the handshake on
|
log.Warn("Reconnecting to recover from "+
|
||||||
// next connect, and a rescan of one or two blocks
|
"out-of-order btcd notification")
|
||||||
// to catch up rather than throwing away all tx
|
|
||||||
// history and rescanning everything.
|
|
||||||
s := CurrentServerConn()
|
s := CurrentServerConn()
|
||||||
if btcd, ok := s.(*BtcdRPCConn); ok {
|
if btcd, ok := s.(*BtcdRPCConn); ok {
|
||||||
AcctMgr.Grab()
|
AcctMgr.Grab()
|
||||||
|
@ -230,13 +228,13 @@ func WalletRequestProcessor() {
|
||||||
AcctMgr.Release()
|
AcctMgr.Release()
|
||||||
}
|
}
|
||||||
|
|
||||||
default: // other non-nil
|
case nil: // ignore
|
||||||
|
default:
|
||||||
log.Warn(err)
|
log.Warn(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Unimplemented handles an unimplemented RPC request with the
|
// Unimplemented handles an unimplemented RPC request with the
|
||||||
// appropiate error.
|
// appropiate error.
|
||||||
|
|
Loading…
Reference in a new issue