Skip to content

Insufficient broadcast txs error info returned by POST /txs  #4858

Closed
@whunmr

Description

Summary of Bug

Not consistent return value structure between success and failure result of POST /txs API.

  • when execution of tx failed with some error (e.g.: delegate without enough funds)
    the POST /txs API will return like:

    {
        "error": "[{\"msg_index\":0,\"success\":false,\"log\":\"    {\\\"codespace\\\":\\\"sdk\\\",\\\"code\\\":10,\\\"message\\\":\\\"insufficient account funds;     8999900000000cet \\u003c 9000000000000cet\\\"}\"}]"
    }
    

the problem is when we got this error result, can not know the txhash for further use

  • But the success execution through POST /txs will return like:
    {
        "events": [
            {
                "attributes": [
                    {
                        "key": "validator",
                        "value": "coinexvaloper13hkgv5f9xm3v2cxxkkzvse8t6pcjqpk974pv83"
                    },
                    {
                        "key": "amount",
                        "value": "3000000000000"
                    }
                ],
                "type": "delegate"
            },
            {
                "attributes": [
                    {
                        "key": "action",
                        "value": "delegate"
                    },
                    {
                        "key": "module",
                        "value": "staking"
                    },
                    {
                        "key": "sender",
                        "value": "coinex13hkgv5f9xm3v2cxxkkzvse8t6pcjqpk996zyf9"
                    }
                ],
                "type": "message"
            }
        ],
        "gas_used": "99076",
        "gas_wanted": "200000",
        "height": "6",
        "logs": [
            {
                "log": "",
                "msg_index": 0,
                "success": true
            }
        ],
        "raw_log": "[{\"msg_index\":0,\"success\":true,\"log\":\"\"}]",
        "txhash": "12E644C8BC21DA5B5CA87AC912AF78E8E7F355C94A5DD2B355A12999802FA47F"
    }
    

Version

$ git rev-parse HEAD
07a0a1bda6647e9f859d8206b80413b372f8feeb
$ git describe
v0.36.0-rc1

Steps to Reproduce

  • POST /txs a successful delegation tx
  • POST /txs a failed delegation tx (failure caused by not enough account funds)
  • compare two result structure
    • ACTUAL: structure not consistent (missing various fields in failed delegate scenario)
    • EXPECTED: with same structure, also contains fields(txhash, raw_logs, etc) in result of failed scenario

codes

broadcast.go:47

  • Maybe we should also return res in the rest.WriteErrorResponse.
  • Meanwhile, delegation without sufficient funds, are not feels like an InternalServerError, and maybe we should not return http code 500 here.
		res, err := cliCtx.BroadcastTx(txBytes)
		if err != nil {
			rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
			return
		}
                rest.PostProcessResponseBare(w, cliCtx, res)

For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions