From 4b1a8c55124caedca3b84b3fa99b7e197c2cc18c Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 2 Jun 2021 14:27:26 +0700 Subject: [PATCH] Merge pull request #91 from bandprotocol/nathachai/yoda-fix-account-attempt Yoda Fix No-Reuse Account Information --- yoda/execute.go | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/yoda/execute.go b/yoda/execute.go index c71122a0c..8f23798d3 100644 --- a/yoda/execute.go +++ b/yoda/execute.go @@ -25,7 +25,7 @@ var ( ) func signAndBroadcast( - c *Context, key keyring.Info, msgs []sdk.Msg, acc client.Account, gasLimit uint64, memo string, + c *Context, key keyring.Info, msgs []sdk.Msg, gasLimit uint64, memo string, ) (string, error) { clientCtx := client.Context{ Client: c.client, @@ -33,6 +33,10 @@ func signAndBroadcast( BroadcastMode: "async", InterfaceRegistry: band.MakeEncodingConfig().InterfaceRegistry, } + acc, err := queryAccount(clientCtx, key) + if err != nil { + return "", fmt.Errorf("unable to get account: %w", err) + } txf := tx.Factory{}. WithAccountNumber(acc.GetAccountNumber()). @@ -72,6 +76,16 @@ func signAndBroadcast( return res.TxHash, nil } +func queryAccount(clientCtx client.Context, key keyring.Info) (client.Account, error) { + accountRetriever := authtypes.AccountRetriever{} + acc, err := accountRetriever.GetAccount(clientCtx, key.GetAddress()) + if err != nil { + return nil, err + } + + return acc, nil +} + func SubmitReport(c *Context, l *Logger, keyIndex int64, reports []ReportMsgWithKey) { // Return key and update pending metric when done with SubmitReport whether successfully or not. defer func() { @@ -111,11 +125,9 @@ func SubmitReport(c *Context, l *Logger, keyIndex int64, reports []ReportMsgWith TxConfig: band.MakeEncodingConfig().TxConfig, InterfaceRegistry: band.MakeEncodingConfig().InterfaceRegistry, } - - accountRetriever := authtypes.AccountRetriever{} - acc, err := accountRetriever.GetAccount(clientCtx, key.GetAddress()) + acc, err := queryAccount(clientCtx, key) if err != nil { - l.Debug(":warning: Failed to query account with error: %s", err.Error()) + l.Error(":warning: Failed to query account with error: %s", c, err.Error()) return } @@ -126,7 +138,7 @@ func SubmitReport(c *Context, l *Logger, keyIndex int64, reports []ReportMsgWith l.Info(":e-mail: Sending report transaction attempt: (%d/%d)", sendAttempt, c.maxTry) for broadcastTry := uint64(1); broadcastTry <= c.maxTry; broadcastTry++ { l.Info(":writing_hand: Try to sign and broadcast report transaction(%d/%d)", broadcastTry, c.maxTry) - hash, err := signAndBroadcast(c, key, msgs, acc, gasLimit, memo) + hash, err := signAndBroadcast(c, key, msgs, gasLimit, memo) if err != nil { // Use info level because this error can happen and retry process can solve this error. l.Info(":warning: %s", err.Error())