Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

services/horizon: Add hash to the txsub timeout response #5328

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions services/horizon/internal/actions/submit_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -191,6 +202,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{
aditya1702 marked this conversation as resolved.
Show resolved Hide resolved
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,
aditya1702 marked this conversation as resolved.
Show resolved Hide resolved
},
}
}
}
15 changes: 14 additions & 1 deletion services/horizon/internal/actions/submit_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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) {
Expand Down
Loading