-
Notifications
You must be signed in to change notification settings - Fork 43
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
(feat) Added a new config option to disable the auto fix of sequence … #220
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -675,7 +675,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.ShouldFixSequenceMismatch && strings.Contains(err.Error(), "account sequence mismatch") { | ||
c.syncNonce() | ||
sequence := c.getAccSeq() | ||
c.txFactory = c.txFactory.WithSequence(sequence) | ||
|
@@ -741,7 +741,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.ShouldFixSequenceMismatch && strings.Contains(err.Error(), "account sequence mismatch") { | ||
c.syncNonce() | ||
sequence := c.getAccSeq() | ||
c.txFactory = c.txFactory.WithSequence(sequence) | ||
|
@@ -761,7 +761,10 @@ func (c *chainClient) AsyncBroadcastMsg(msgs ...sdk.Msg) (*txtypes.BroadcastTxRe | |
|
||
func (c *chainClient) BuildSignedTx(clientCtx client.Context, accNum, accSeq, initialGas uint64, msgs ...sdk.Msg) ([]byte, error) { | ||
txf := NewTxFactory(clientCtx).WithSequence(accSeq).WithAccountNumber(accNum).WithGas(initialGas) | ||
return c.buildSignedTx(clientCtx, txf, msgs...) | ||
} | ||
|
||
func (c *chainClient) buildSignedTx(clientCtx client.Context, txf tx.Factory, msgs ...sdk.Msg) ([]byte, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactor The |
||
if clientCtx.Simulate { | ||
simTxBytes, err := txf.BuildSimTx(msgs...) | ||
if err != nil { | ||
|
@@ -873,49 +876,9 @@ func (c *chainClient) broadcastTx( | |
await bool, | ||
msgs ...sdk.Msg, | ||
) (*txtypes.BroadcastTxResponse, error) { | ||
txf, err := c.prepareFactory(clientCtx, txf) | ||
if err != nil { | ||
err = errors.Wrap(err, "failed to prepareFactory") | ||
return nil, err | ||
} | ||
ctx := context.Background() | ||
if clientCtx.Simulate { | ||
simTxBytes, err := txf.BuildSimTx(msgs...) | ||
if err != nil { | ||
err = errors.Wrap(err, "failed to build sim tx bytes") | ||
return nil, err | ||
} | ||
|
||
req := &txtypes.SimulateRequest{TxBytes: simTxBytes} | ||
simRes, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.txClient.Simulate, req) | ||
if err != nil { | ||
err = errors.Wrap(err, "failed to CalculateGas") | ||
return nil, err | ||
} | ||
|
||
adjustedGas := uint64(txf.GasAdjustment() * float64(simRes.GasInfo.GasUsed)) | ||
txf = txf.WithGas(adjustedGas) | ||
|
||
c.gasWanted = adjustedGas | ||
} | ||
|
||
txn, err := txf.BuildUnsignedTx(msgs...) | ||
|
||
txBytes, err := c.buildSignedTx(clientCtx, txf, msgs...) | ||
if err != nil { | ||
err = errors.Wrap(err, "failed to BuildUnsignedTx") | ||
return nil, err | ||
} | ||
|
||
txn.SetFeeGranter(clientCtx.GetFeeGranterAddress()) | ||
err = tx.Sign(txf, clientCtx.GetFromName(), txn, true) | ||
if err != nil { | ||
err = errors.Wrap(err, "failed to Sign Tx") | ||
return nil, err | ||
} | ||
|
||
txBytes, err := clientCtx.TxConfig.TxEncoder()(txn.GetTx()) | ||
if err != nil { | ||
err = errors.Wrap(err, "failed TxEncoder to encode Tx") | ||
err = errors.Wrap(err, "failed to build signed Tx") | ||
Comment on lines
+879
to
+881
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve error handling in The error handling in |
||
return nil, err | ||
} | ||
|
||
|
@@ -924,7 +887,7 @@ func (c *chainClient) broadcastTx( | |
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC, | ||
} | ||
|
||
res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.txClient.BroadcastTx, &req) | ||
res, err := common.ExecuteCall(context.Background(), c.network.ChainCookieAssistant, c.txClient.BroadcastTx, &req) | ||
if !await || err != nil { | ||
return res, err | ||
} | ||
|
@@ -998,7 +961,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.ShouldFixSequenceMismatch && strings.Contains(err.Error(), "account sequence mismatch") { | ||
c.syncNonce() | ||
sequence := c.getAccSeq() | ||
c.txFactory = c.txFactory.WithSequence(sequence) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add documentation for
BuildSignedTx
.This method is public and complex enough to warrant a detailed comment explaining its parameters, return type, and usage. Would you like me to draft a suggested doc comment?