From 2c680fb03c809cadd61ba22bd50828e56495cf31 Mon Sep 17 00:00:00 2001 From: Duke Date: Sat, 20 Apr 2024 07:07:54 -0400 Subject: [PATCH] Try to deal gracefully with clients sending expired txs --- common/common.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/common/common.go b/common/common.go index 3164dc6..64ee77c 100644 --- a/common/common.go +++ b/common/common.go @@ -289,15 +289,24 @@ func CallRpcWithRetries(method string, params []json.RawMessage) (json.RawMessag break } retryCount++ - if retryCount > maxRetries { + if retryCount > maxRetries && method != "sendrawtransaction" { Log.WithFields(logrus.Fields{ "timeouts": retryCount, }).Fatal(fmt.Sprintf("unable to issue %s RPC call to hushd node", method)) } + if retryCount > maxRetries && method == "sendrawtransaction" { + // TODO: it would be better to only give up if the error is an expired tx + Log.WithFields(logrus.Fields{ + "error": err.Error(), + "retry": retryCount, + }).Warn(fmt.Sprintf("giving up on %s rpc", method)) + // TODO: return a better error + return nil, nil + } Log.WithFields(logrus.Fields{ "error": err.Error(), "retry": retryCount, - }).Warn(fmt.Sprintf("error with %s rpc, retrying..."), method) + }).Warn(fmt.Sprintf("error with %s rpc, retrying...", method)) Time.Sleep(time.Duration(10+retryCount*5) * time.Second) // backoff } return nil, nil