Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(icq-relayer): reverse conditional pkg/runner.flush for more idiomatic Go #1685

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 52 additions & 46 deletions icq-relayer/pkg/runner/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,53 +754,59 @@
}
}

// TODO: refactor me!
func flush(chainId string, toSend []sdk.Msg, logger log.Logger, metrics prommetrics.Metrics) {
if len(toSend) > 0 {
_ = logger.Log("msg", fmt.Sprintf("Sending batch of %d messages", len(toSend)))
chainClient := globalCfg.Cl[chainId]
if chainClient == nil {
return
}
// dedupe on queryId
msgs := unique(toSend, logger)
if len(msgs) > 0 {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
defer cancel()
resp, err := chainClient.SendMsgs(ctx, msgs, VERSION)
if err != nil {
switch {
case resp != nil && resp.Code == 19 && resp.Codespace == "sdk":
_ = logger.Log("msg", "Tx already in mempool")
case resp != nil && resp.Code == 12 && resp.Codespace == "sdk":
_ = logger.Log("msg", "Not enough gas")
case strings.Contains(err.Error(), "request body too large"):
TxMsgs = TxMsgs / 2
LastReduced = time.Now()
_ = logger.Log("msg", "body too large: reduced batchsize", "size", TxMsgs)
// case err.Error() == "context deadline exceeded":
// _ = logger.Log("msg", "Failed to submit in time, retrying")
// resp, err := chainClient.SendMsgs(ctx, msgs, VERSION)
// if err != nil {
// switch {
// case resp != nil && resp.Code == 19 && resp.Codespace == "sdk":
// _ = logger.Log("msg", "Tx already in mempool")
// case resp != nil && resp.Code == 12 && resp.Codespace == "sdk":
// _ = logger.Log("msg", "Not enough gas")
// case err.Error() == "context deadline exceeded":
// _ = logger.Log("msg", "Failed to submit in time, bailing")
// default:
// _ = logger.Log("msg", "Failed to submit after retry; nevermind, we'll try again!", "err", err)
// metrics.FailedTxs.WithLabelValues("failed_txs").Inc()
// }
// }
default:
_ = logger.Log("msg", "Failed to submit; nevermind, we'll try again!", "err", err)
metrics.FailedTxs.WithLabelValues("failed_txs").Inc()
}
}
_ = logger.Log("msg", fmt.Sprintf("Sent batch of %d (deduplicated) messages", len(msgs)))
}
if len(toSend) == 0 {
return
}

_ = logger.Log("msg", fmt.Sprintf("Sending batch of %d messages", len(toSend)))
chainClient := globalCfg.Cl[chainId]
if chainClient == nil {
return
}
// dedupe on queryId
msgs := unique(toSend, logger)
if len(msgs) == 0 {
return
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
defer cancel()

resp, err := chainClient.SendMsgs(ctx, msgs, VERSION)
if err == nil {
_ = logger.Log("msg", fmt.Sprintf("Sent batch of %d (deduplicated) messages", len(msgs)))
return
}

switch {
case resp != nil && resp.Code == 19 && resp.Codespace == "sdk":
_ = logger.Log("msg", "Tx already in mempool")
case resp != nil && resp.Code == 12 && resp.Codespace == "sdk":
_ = logger.Log("msg", "Not enough gas")
case strings.Contains(err.Error(), "request body too large"):
TxMsgs = TxMsgs / 2
LastReduced = time.Now()

Check warning

Code scanning / CodeQL

Calling the system time Warning

Calling the system time may be a possible source of non-determinism
_ = logger.Log("msg", "body too large: reduced batchsize", "size", TxMsgs)
// case err.Error() == "context deadline exceeded":
// _ = logger.Log("msg", "Failed to submit in time, retrying")
// resp, err := chainClient.SendMsgs(ctx, msgs, VERSION)
// if err != nil {
// switch {
// case resp != nil && resp.Code == 19 && resp.Codespace == "sdk":
// _ = logger.Log("msg", "Tx already in mempool")
// case resp != nil && resp.Code == 12 && resp.Codespace == "sdk":
// _ = logger.Log("msg", "Not enough gas")
// case err.Error() == "context deadline exceeded":
// _ = logger.Log("msg", "Failed to submit in time, bailing")
// default:
// _ = logger.Log("msg", "Failed to submit after retry; nevermind, we'll try again!", "err", err)
// metrics.FailedTxs.WithLabelValues("failed_txs").Inc()
// }
// }
default:
_ = logger.Log("msg", "Failed to submit; nevermind, we'll try again!", "err", err)
metrics.FailedTxs.WithLabelValues("failed_txs").Inc()
}
}

Expand Down
Loading