From aa181b35d0da99161edfbfc0fc15bdbce0999edf Mon Sep 17 00:00:00 2001 From: Aditya Vyas Date: Fri, 31 May 2024 13:59:56 -0400 Subject: [PATCH 1/2] Change the txsub timeout response --- .../horizon/internal/actions/submit_transaction.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/services/horizon/internal/actions/submit_transaction.go b/services/horizon/internal/actions/submit_transaction.go index 00049a9172..6a5a65ae6e 100644 --- a/services/horizon/internal/actions/submit_transaction.go +++ b/services/horizon/internal/actions/submit_transaction.go @@ -191,6 +191,17 @@ func (handler SubmitTransactionHandler) GetResource(w HeaderWriter, r *http.Requ if r.Context().Err() == context.Canceled { return nil, hProblem.ClientDisconnected } - return nil, hProblem.Timeout + return nil, &problem.P{ + Type: "transaction_submission_timeout", + Title: "Transaction Submission Timeout", + Status: http.StatusGatewayTimeout, + Detail: "Your transaction submission request has timed out. This does not necessarily mean the submission has failed. " + + "Before resubmitting, please use the transaction hash provided in `extras.hash` to poll the GET /transactions endpoint for sometime and " + + "check if it was included in a ledger.", + Extras: map[string]interface{}{ + "hash": info.hash, + "envelope_xdr": raw, + }, + } } } From 69d1923ecd18e213260b5220e46cb5fe794e4f50 Mon Sep 17 00:00:00 2001 From: Aditya Vyas Date: Fri, 31 May 2024 14:39:32 -0400 Subject: [PATCH 2/2] Fix timeout test --- .../internal/actions/submit_transaction.go | 13 ++++++++++++- .../internal/actions/submit_transaction_test.go | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/services/horizon/internal/actions/submit_transaction.go b/services/horizon/internal/actions/submit_transaction.go index 6a5a65ae6e..703e7a554d 100644 --- a/services/horizon/internal/actions/submit_transaction.go +++ b/services/horizon/internal/actions/submit_transaction.go @@ -92,7 +92,18 @@ func (handler SubmitTransactionHandler) response(r *http.Request, info envelopeI } if result.Err == txsub.ErrTimeout { - return nil, &hProblem.Timeout + return nil, &problem.P{ + Type: "transaction_submission_timeout", + Title: "Transaction Submission Timeout", + Status: http.StatusGatewayTimeout, + Detail: "Your transaction submission request has timed out. This does not necessarily mean the submission has failed. " + + "Before resubmitting, please use the transaction hash provided in `extras.hash` to poll the GET /transactions endpoint for sometime and " + + "check if it was included in a ledger.", + Extras: map[string]interface{}{ + "hash": info.hash, + "envelope_xdr": info.raw, + }, + } } if result.Err == txsub.ErrCanceled { diff --git a/services/horizon/internal/actions/submit_transaction_test.go b/services/horizon/internal/actions/submit_transaction_test.go index eb1987bdea..8d9979ae4b 100644 --- a/services/horizon/internal/actions/submit_transaction_test.go +++ b/services/horizon/internal/actions/submit_transaction_test.go @@ -100,6 +100,19 @@ func TestTimeoutSubmission(t *testing.T) { form := url.Values{} form.Set("tx", "AAAAAAGUcmKO5465JxTSLQOQljwk2SfqAJmZSG6JH6wtqpwhAAABLAAAAAAAAAABAAAAAAAAAAEAAAALaGVsbG8gd29ybGQAAAAAAwAAAAAAAAAAAAAAABbxCy3mLg3hiTqX4VUEEp60pFOrJNxYM1JtxXTwXhY2AAAAAAvrwgAAAAAAAAAAAQAAAAAW8Qst5i4N4Yk6l+FVBBKetKRTqyTcWDNSbcV08F4WNgAAAAAN4Lazj4x61AAAAAAAAAAFAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABLaqcIQAAAEBKwqWy3TaOxoGnfm9eUjfTRBvPf34dvDA0Nf+B8z4zBob90UXtuCqmQqwMCyH+okOI3c05br3khkH0yP4kCwcE") + expectedTimeoutResponse := &problem.P{ + Type: "transaction_submission_timeout", + Title: "Transaction Submission Timeout", + Status: http.StatusGatewayTimeout, + Detail: "Your transaction submission request has timed out. This does not necessarily mean the submission has failed. " + + "Before resubmitting, please use the transaction hash provided in `extras.hash` to poll the GET /transactions endpoint for sometime and " + + "check if it was included in a ledger.", + Extras: map[string]interface{}{ + "hash": "3389e9f0f1a65f19736cacf544c2e825313e8447f569233bb8db39aa607c8889", + "envelope_xdr": "AAAAAAGUcmKO5465JxTSLQOQljwk2SfqAJmZSG6JH6wtqpwhAAABLAAAAAAAAAABAAAAAAAAAAEAAAALaGVsbG8gd29ybGQAAAAAAwAAAAAAAAAAAAAAABbxCy3mLg3hiTqX4VUEEp60pFOrJNxYM1JtxXTwXhY2AAAAAAvrwgAAAAAAAAAAAQAAAAAW8Qst5i4N4Yk6l+FVBBKetKRTqyTcWDNSbcV08F4WNgAAAAAN4Lazj4x61AAAAAAAAAAFAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABLaqcIQAAAEBKwqWy3TaOxoGnfm9eUjfTRBvPf34dvDA0Nf+B8z4zBob90UXtuCqmQqwMCyH+okOI3c05br3khkH0yP4kCwcE", + }, + } + request, err := http.NewRequest( "POST", "https://horizon.stellar.org/transactions", @@ -115,7 +128,7 @@ func TestTimeoutSubmission(t *testing.T) { w := httptest.NewRecorder() _, err = handler.GetResource(w, request) assert.Error(t, err) - assert.Equal(t, hProblem.Timeout, err) + assert.Equal(t, expectedTimeoutResponse, err) } func TestClientDisconnectSubmission(t *testing.T) {