在 Conflux 网络,通过 cfx_sendRawTransaction 办法发送交易时,如果交易结构不对,发送将会失败。其中一些谬误比拟常见比方:

  • 应用了已被执行过的 nonce
  • 应用了曾经被发送到交易池中的 nonce

另外还有几种发送失败的状况:

  • chainId 应用不匹配
  • epochHeight 太大
  • gas 超过 1500w (half of block gas limit)
  • gas 小余 21000
  • data 过大 (超过 200K)
  • gasPrice 设置为 0
  • 签名谬误
  • 交易池满

如下是交易发送失败时 cfx_sendRawTransaction 办法返回的 RPC 谬误

nonce 应用谬误

应用了曾经被执行的 nonce

{    "jsonrpc": "2.0",    "id": "15922956697249514502",    "error": {        "code": -32602,        "message": "Invalid parameters: tx",        "data": "\"Transaction 0x4a2cfa73267139d965ab86d41f2af16db09e62ff92a5abffd7f8e743f36f327c is discarded due to a too stale nonce\""    }}

此种状况需改为以后能够用的(未用的) nonce

应用了曾经被发送到交易池中的 nonce

{    "jsonrpc": "2.0",    "id": "15922956697249514502",    "error": {        "code": -32602,        "message": "Invalid parameters: tx",        "data": "\"tx already exist\""    }  }

{    "jsonrpc": "2.0",    "id": "15922956697249514502",    "error": {        "code": -32602,        "message": "Invalid parameters: tx",        "data": "Tx with same nonce already inserted. To replace it, you need to specify a gas price > {}"    }}

对于这两种状况代表交易曾经被发到交易池中了,如果想更新或替换交易的话,能够应用同样的 nonce, 批改对应的字段,并进步 gasPrice 从新发送

应用了过大的 nonce

发送交易的 nonce 不能币用户以后 nonce 过大,如果超过 2000 将遇到如下谬误:

{    "jsonrpc": "2.0",    "id": "15922956697249514502",    "error": {        "code": -32602,        "message": "Invalid parameters: tx",        "data": "\"Transaction 0xc875a03e1ce01268931a1a428d8f8313714ab5eb9c2b626bd327af7e5c3e8c03 is discarded due to in too distant future\""    }  }

gas

如果交易的 gas 太小(<21000)或太大(>1500w)会返回如下谬误:

{    "jsonrpc": "2.0",    "id": "15922956697249514502",    "error": {        "code": -32602,        "message": "Invalid parameters: tx",        "data": "\"NotEnoughBaseGas { required: 21000, got: 2000 }\""    }}
{    "jsonrpc": "2.0",    "id": "15922956697249514502",    "error": {        "code": -32602,        "message": "Invalid parameters: tx",        "data": "\"transaction gas 20000000 exceeds the maximum value 15000000, the half of pivot block gas limit\""    }}

gasPrice

交易的 gasPrice 不能设置为 0:

{    "jsonrpc": "2.0",    "id": "15922956697249514502",    "error": {        "code": -32602,        "message": "Invalid parameters: tx",        "data": "\"ZeroGasPrice\""    }}

data

交易有大小限度,最大不能超过 200k

epochHeight

如果交易的 epochHeight 跟以后网络的 epochNumber 相比小余超过 10w 会遇到如下谬误:

{    "jsonrpc": "2.0",    "id": "15922956697249514502",    "error": {        "code": -32602,        "message": "Invalid parameters: tx",        "data": "\"EpochHeightOutOfBound { block_height: 53800739, set: 0, transaction_epoch_bound: 100000 }\""    }}

chainId 应用谬误

{    "jsonrpc": "2.0",    "id": "15922956697249514502",    "error": {        "code": -32602,        "message": "Invalid parameters: tx",        "data": "\"ChainIdMismatch { expected: 1, got: 2 }\""    }}

编码或签名谬误

{    "jsonrpc": "2.0",    "id": "15922956697249514502",    "error": {        "code": -32602,        "message": "Invalid parameters: raw",        "data": "\"RlpIncorrectListLen\""    }}
{    "jsonrpc": "2.0",    "id": "15922956697249514502",    "error": {        "code": -32602,        "message": "Invalid parameters: tx",        "data": "Can not recover pubkey for Ethereum like tx"    }}

交易池满

{    "jsonrpc": "2.0",    "id": "15922956697249514502",    "error": {        "code": -32602,        "message": "Invalid parameters: tx",        "data": "txpool is full"    }}

{    "jsonrpc": "2.0",    "id": "15922956697249514502",    "error": {        "code": -32602,        "message": "Invalid parameters: tx",        "data": "Failed imported to deferred pool: Transaction Pool is full"    }}

对于此种状况,可期待一会从新发送交易,进步交易的 gasPrice 有助于进步发送的几率

其余

节点处于 catch-up mode

{    "jsonrpc": "2.0",    "id": "15922956697249514502",    "error": {        "code": -32077,        "message": "Request rejected due to still in the catch up mode.",        "data": null    }}

等节点数据同步到最新之后再发送

外部谬误

{    "jsonrpc": "2.0",    "id": "15922956697249514502",    "error": {        "code": -32602,        "message": "Invalid parameters: tx",        "data": "Failed to read account_cache from storage: {}"    }}