diff --git a/client/chain/chain.go b/client/chain/chain.go index e5340eba..e32e70f1 100644 --- a/client/chain/chain.go +++ b/client/chain/chain.go @@ -554,7 +554,7 @@ func (c *chainClient) SyncBroadcastMsg(msgs ...sdk.Msg) (*txtypes.BroadcastTxRes res, err := c.broadcastTx(c.ctx, c.txFactory, true, msgs...) if err != nil { - if strings.Contains(err.Error(), "account sequence mismatch") { + if c.opts.FixSeqMismatch && strings.Contains(err.Error(), "account sequence mismatch") { c.syncNonce() sequence := c.getAccSeq() c.txFactory = c.txFactory.WithSequence(sequence) @@ -617,7 +617,7 @@ func (c *chainClient) AsyncBroadcastMsg(msgs ...sdk.Msg) (*txtypes.BroadcastTxRe c.txFactory = c.txFactory.WithAccountNumber(c.accNum) res, err := c.broadcastTx(c.ctx, c.txFactory, false, msgs...) if err != nil { - if strings.Contains(err.Error(), "account sequence mismatch") { + if c.opts.FixSeqMismatch && strings.Contains(err.Error(), "account sequence mismatch") { c.syncNonce() sequence := c.getAccSeq() c.txFactory = c.txFactory.WithSequence(sequence) @@ -631,7 +631,6 @@ func (c *chainClient) AsyncBroadcastMsg(msgs ...sdk.Msg) (*txtypes.BroadcastTxRe return nil, err } } - return res, nil } @@ -874,7 +873,7 @@ func (c *chainClient) runBatchBroadcast() { log.Debugln("broadcastTx with nonce", sequence) res, err := c.broadcastTx(c.ctx, c.txFactory, true, toSubmit...) if err != nil { - if strings.Contains(err.Error(), "account sequence mismatch") { + if c.opts.FixSeqMismatch && strings.Contains(err.Error(), "account sequence mismatch") { c.syncNonce() sequence := c.getAccSeq() c.txFactory = c.txFactory.WithSequence(sequence) diff --git a/client/common/options.go b/client/common/options.go index 59706cd1..c9bbb0a6 100644 --- a/client/common/options.go +++ b/client/common/options.go @@ -19,15 +19,18 @@ func init() { } type ClientOptions struct { - GasPrices string - TLSCert credentials.TransportCredentials - TxFactory *tx.Factory + GasPrices string + TLSCert credentials.TransportCredentials + TxFactory *tx.Factory + FixSeqMismatch bool } type ClientOption func(opts *ClientOptions) error func DefaultClientOptions() *ClientOptions { - return &ClientOptions{} + return &ClientOptions{ + FixSeqMismatch: true, + } } func OptionGasPrices(gasPrices string) ClientOption { @@ -61,3 +64,10 @@ func OptionTxFactory(txFactory *tx.Factory) ClientOption { return nil } } + +func OptionFixSeqMismatch(fixSeqMismatch bool) ClientOption { + return func(opts *ClientOptions) error { + opts.FixSeqMismatch = fixSeqMismatch + return nil + } +}