Skip to content

Commit

Permalink
(fix) Fail fast on the nonzero code during the sync broadcast - 2
Browse files Browse the repository at this point in the history
  • Loading branch information
shibaeff committed Oct 2, 2024
1 parent ad22cb0 commit e98bbf1
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions client/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -839,8 +839,23 @@ func (c *chainClient) SyncBroadcastSignedTx(txBytes []byte) (*txtypes.BroadcastT

awaitCtx, cancelFn := context.WithTimeout(context.Background(), defaultBroadcastTimeout)
defer cancelFn()

txHash, _ := hex.DecodeString(res.TxResponse.TxHash)
resultTx, err := c.ctx.Client.Tx(awaitCtx, txHash, false)
if err != nil {
if errRes := client.CheckCometError(err, txBytes); errRes != nil {
return &txtypes.BroadcastTxResponse{TxResponse: errRes}, err
}
} else if resultTx.TxResult.Code != 0 {
resResultTx := sdk.NewResponseResultTx(resultTx, res.TxResponse.Tx, res.TxResponse.Timestamp)
res = &txtypes.BroadcastTxResponse{TxResponse: resResultTx}
panic(errors.New(fmt.Sprintf("Failed with non-zero code %d", resultTx.TxResult.Code)))
return res, errors.New(fmt.Sprintf("Failed with non-zero code %d", resultTx.TxResult.Code))
} else if resultTx.Height > 0 {
resResultTx := sdk.NewResponseResultTx(resultTx, res.TxResponse.Tx, res.TxResponse.Timestamp)
res = &txtypes.BroadcastTxResponse{TxResponse: resResultTx}
return res, err
}

t := time.NewTimer(defaultBroadcastStatusPoll)

for {
Expand All @@ -859,10 +874,14 @@ func (c *chainClient) SyncBroadcastSignedTx(txBytes []byte) (*txtypes.BroadcastT
t.Reset(defaultBroadcastStatusPoll)
continue

} else if resultTx.TxResult.Code != 0 {
resResultTx := sdk.NewResponseResultTx(resultTx, res.TxResponse.Tx, res.TxResponse.Timestamp)
res = &txtypes.BroadcastTxResponse{TxResponse: resResultTx}
panic(errors.New(fmt.Sprintf("Failed with non-zero code %d", resultTx.TxResult.Code)))
return res, errors.New(fmt.Sprintf("Failed with non-zero code %d", resultTx.TxResult.Code))
} else if resultTx.Height > 0 {
resResultTx := sdk.NewResponseResultTx(resultTx, res.TxResponse.Tx, res.TxResponse.Timestamp)
res = &txtypes.BroadcastTxResponse{TxResponse: resResultTx}
t.Stop()
return res, err
}

Expand Down

0 comments on commit e98bbf1

Please sign in to comment.