Closed erikd closed 4 years ago
Maybe we could improve error messages for some cases, below examples for review:
For empty file I got an error with info that file was hex encoded:
$ curl -X POST --header "Content-Type:application/cbor" --data-binary @empty.tx http://localhost:8101/api/submit/tx
{"status":"fail","errorMsg":"Provided data was hex encoded and this webapi expects raw binary"}
and:
[cardano-tx-submit:Info:79] [2020-02-11 11:05:40.90 UTC] txSubmitPost: received 0 bytes [cardano-tx-submit:Info:79] [2020-02-11 11:05:40.90 UTC] txSubmitPost: Decoding of transaction failed: DecoderErrorDeserialiseFailure "Cardano.Chain.UTxO.TxAux.fromCborTxAux" (DeserialiseFailure 0 "end of input")
I think we can skip the second error message about file being hex encoded.
$ curl -X POST --header "Content-Type:application/cbor" --data-binary @genesis_transaction_file_1.bin http://localhost:8101/api/submit/tx
Warning: Couldn't read data from file "genesis_transaction_file_1.bin", this makes an empty POST.
{"status":"fail","errorMsg":"Provided data was hex encoded and this webapi expects raw binary"}
and:
[cardano-tx-submit:Info:77] [2020-02-11 11:03:33.22 UTC] txSubmitPost: received 0 bytes [cardano-tx-submit:Info:77] [2020-02-11 11:03:33.22 UTC] txSubmitPost: Decoding of transaction failed: DecoderErrorDeserialiseFailure "Cardano.Chain.UTxO.TxAux.fromCborTxAux" (DeserialiseFailure 0 "end of input")
This looks good.
curl -X POST --header "Content-Type:application/cbor" --data-binary @tx.hex http://localhost:8101/api/submit/tx
{"status":"fail","errorMsg":"Provided data was hex encoded and this webapi expects raw binary"}
and:
[cardano-tx-submit:Info:81] [2020-02-11 11:07:34.25 UTC] txSubmitPost: received 499 bytes [cardano-tx-submit:Info:81] [2020-02-11 11:07:34.25 UTC] txSubmitPost: Decoding of transaction failed: DecoderErrorDeserialiseFailure "Cardano.Chain.UTxO.TxAux.fromCborTxAux" (DeserialiseFailure 0 "expected list len")
I am not sure about this - should we just stick to info about tx file not being in raw binary or do we want all those details DeserialiseFailure 0 \"expected list len\
curl -X POST --header "Content-Type:application/cbor" --data-binary @tx_b64 http://localhost:8101/api/submit/tx
{"status":"fail","errorMsg":"Deserialisation failure while decoding Cardano.Chain.UTxO.TxAux.fromCborTxAux.\nCBOR failed with error: DeserialiseFailure 0 \"expected list len\""}
Are we okay with no logged output for such cases ?
$ curl -X POST --data-binary @genesis_transaction_file.bin http://localhost:8101/api/submit/tx
curl -X POST --header "Content-Type:application/json" --data-binary @tx.hex http://localhost:8101/api/submit/tx
{ NO output from curl for both cases }
No output from running API service:
[cardano-tx-submit:Info:10] [2020-02-11 10:16:54.12 UTC] Running tx-submit web server on http://localhost:8101/
curl -X POST --header "Content-Type:application/cbor" --data-binary @genesis_transaction_file.bin http://localhost:8101/api/submit/tx
{"status":"fail","errorMsg":"MempoolTxErr (UTxOValidationUTxOError (UTxOMissingInput (TxInUtxo (AbstractHash a8386f9e2b6ac7699dc78d8a0d345b0f6f0b843c7ee35e0e1327c139cfc221f8) 0)))"}
Empty TX File:
{"status":"fail","message":"Provided transaction has zero length"}
and in the logs:
[cardano-tx-submit:Info:22] [2020-02-17 01:21:40.84 UTC] txSubmitPost: received 0 bytes
[cardano-tx-submit:Info:22] [2020-02-17 01:21:40.84 UTC] txSubmitPost: Provided transaction has zero length
Speicified fle does not exist:
IN this case curl
posts a zero length file so the result is same as above.
Hex data:
> curl -X POST --header "Content-Type:application/cbor" --data-binary @hex.bin http://localhost:8101/api/submit/tx
{"status":"fail","message":"Provided data was hex encoded and this webapi expects raw binary"}
log:
[cardano-tx-submit:Info:26] [2020-02-17 01:24:12.77 UTC] txSubmitPost: received 24 bytes
[cardano-tx-submit:Info:26] [2020-02-17 01:24:12.77 UTC] txSubmitPost: Provided data was hex encoded and this webapi expects raw binary
Other unsupported encoding Used for TX File (Base64):
> curl -X POST --header "Content-Type:application/cbor" --data-binary @base64.bin http://localhost:8101/api/submit/tx
{"status":"fail","message":"Deserialisation failure while decoding Cardano.Chain.UTxO.TxAux.fromCborTxAux.\nCBOR failed with error: DeserialiseFailure 0 \"expected list len\""}
there are an infinite number of ways this could go wrong. Not sure if we can do much better than this.
No Content-Type specified or used the wrong one: By default, curl does not report HTTP errors, but an error is reported in the HTTP headers:
> curl -v -X POST --header "Content-Type:application/json" --data-binary @genesis_transaction.bin http://localhost:8101/api/submit/tx
Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying ::1:8101...
* TCP_NODELAY set
* connect to ::1 port 8101 failed: Connection refused
* Trying 127.0.0.1:8101...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8101 (#0)
> POST /api/submit/tx HTTP/1.1
> Host: localhost:8101
> User-Agent: curl/7.67.0
> Accept: */*
> Content-Type:application/json
> Content-Length: 249
>
* upload completely sent off: 249 out of 249 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 415 Unsupported Media Type
< Transfer-Encoding: chunked
< Date: Mon, 17 Feb 2020 01:41:26 GMT
< Server: Warp/3.3.9
<
* Connection #0 to host localhost left intact
The "415 Unsupported Media Type" is exactly the correct response here.
Submitting the same TX File (already POSTed) second time: First time:
> curl -X POST --header "Content-Type:application/cbor" --data-binary @genesis_transaction.bin http://localhost:8101/api/submit/tx
{"status":"success","message":"Tx 6875a2f9e27d625b submited successfully"}
and the second time:
> curl -X POST --header "Content-Type:application/cbor" --data-binary @genesis_transaction.bin http://localhost:8101/api/submit/tx
{"status":"fail","message":"UTxOError: Lookup of tx TxInUtxo a8386f9e #0 failed"}
This error message is not great, but difficult to make better.
The tx submit API should return an error message when it receives a bad request instead of only responding with an exit code. Also, the tx submit api should log requests when they come in.