Skip to content

Commit

Permalink
Merge pull request #5522 from stellar/protocol-22
Browse files Browse the repository at this point in the history
services/horizon: Merge horizon v22.0.0 release branch into master
  • Loading branch information
tamirms authored Nov 8, 2024
2 parents 39a8d36 + a07b380 commit edf3eed
Show file tree
Hide file tree
Showing 64 changed files with 25,259 additions and 20,434 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/galexie-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
GALEXIE_INTEGRATION_TESTS_CAPTIVE_CORE_BIN: /usr/bin/stellar-core
# this pins to a version of quickstart:testing that has the same version as STELLAR_CORE_VERSION
# this is the multi-arch index sha, get it by 'docker buildx imagetools inspect stellar/quickstart:testing'
GALEXIE_INTEGRATION_TESTS_QUICKSTART_IMAGE: docker.io/stellar/quickstart:testing@sha256:03c6679f838a92b1eda4cd3a9e2bdee4c3586e278a138a0acf36a9bc99a0041f
GALEXIE_INTEGRATION_TESTS_QUICKSTART_IMAGE: docker.io/stellar/quickstart:testing@sha256:5333ec87069efd7bb61f6654a801dc093bf0aad91f43a5ba84806d3efe4a6322
GALEXIE_INTEGRATION_TESTS_QUICKSTART_IMAGE_PULL: "false"
STELLAR_CORE_VERSION: 21.3.1-2007.4ede19620.focal
STELLAR_CORE_VERSION: 22.0.0-2138.721fd0a65.focal
steps:
- name: Set VERSION
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/galexie.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ jobs:
name: Test
runs-on: ubuntu-latest
env:
CAPTIVE_CORE_DEBIAN_PKG_VERSION: 21.3.1-2007.4ede19620.focal
CAPTIVE_CORE_DEBIAN_PKG_VERSION: 22.0.0-2138.721fd0a65.focal
GALEXIE_INTEGRATION_TESTS_ENABLED: "true"
GALEXIE_INTEGRATION_TESTS_CAPTIVE_CORE_BIN: /usr/bin/stellar-core
# this pins to a version of quickstart:testing that has the same version as GALEXIE_INTEGRATION_TESTS_CAPTIVE_CORE_BIN
# this is the multi-arch index sha, get it by 'docker buildx imagetools inspect stellar/quickstart:testing'
GALEXIE_INTEGRATION_TESTS_QUICKSTART_IMAGE: docker.io/stellar/quickstart:testing@sha256:5c8186f53cc98571749054dd782dce33b0aca2d1a622a7610362f7c15b79b1bf
GALEXIE_INTEGRATION_TESTS_QUICKSTART_IMAGE: docker.io/stellar/quickstart:testing@sha256:5333ec87069efd7bb61f6654a801dc093bf0aad91f43a5ba84806d3efe4a6322
GALEXIE_INTEGRATION_TESTS_QUICKSTART_IMAGE_PULL: "false"
steps:
- name: Install captive core
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/horizon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
os: [ubuntu-20.04, ubuntu-22.04]
go: ["1.21", "1.22"]
pg: [12, 16]
protocol-version: [21]
protocol-version: [21, 22]
runs-on: ${{ matrix.os }}
services:
postgres:
Expand All @@ -36,6 +36,9 @@ jobs:
PROTOCOL_21_CORE_DEBIAN_PKG_VERSION: 21.3.1-2007.4ede19620.focal
PROTOCOL_21_CORE_DOCKER_IMG: stellar/stellar-core:21.3.1-2007.4ede19620.focal
PROTOCOL_21_SOROBAN_RPC_DOCKER_IMG: stellar/soroban-rpc:21.5.1
PROTOCOL_22_CORE_DEBIAN_PKG_VERSION: 22.0.0-2138.721fd0a65.focal
PROTOCOL_22_CORE_DOCKER_IMG: stellar/stellar-core:22.0.0-2138.721fd0a65.focal
PROTOCOL_22_SOROBAN_RPC_DOCKER_IMG: stellar/soroban-rpc:22.0.0-rc3-101
PGHOST: localhost
PGPORT: 5432
PGUSER: postgres
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/services/horizon/captive-core
/services/horizon/horizon
/services/horizon/stellar-horizon
/bucket-cache
**bucket-cache/
.vscode
.idea
debug
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ XDRS = $(DOWNLOADABLE_XDRS) xdr/Stellar-exporter.x


XDRGEN_COMMIT=e2cac557162d99b12ae73b846cf3d5bfe16636de
XDR_COMMIT=70180d5e8d9caee9e8645ed8a38c36a8cf403cd9
XDR_COMMIT=529d5176f24c73eeccfa5eba481d4e89c19b1181

.PHONY: xdr xdr-clean xdr-update

Expand Down
48 changes: 44 additions & 4 deletions clients/horizonclient/internal.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package horizonclient

import (
"bytes"
"encoding/json"
"io"
"net/http"
"net/url"
"strconv"
"strings"
"time"

"github.com/stellar/go/protocols/horizon"
"github.com/stellar/go/support/clock"
"github.com/stellar/go/support/errors"
)
Expand All @@ -27,10 +30,11 @@ func decodeResponse(resp *http.Response, object interface{}, horizonUrl string,
}
setCurrentServerTime(u.Hostname(), resp.Header["Date"], clock)

// While this part of code assumes that any error < 200 or error >= 300 is a Horizon problem, it is not
// true for the response from /transactions_async endpoint which does give these codes for certain responses
// from core.
if !(resp.StatusCode >= 200 && resp.StatusCode < 300) && (resp.Request == nil || resp.Request.URL == nil || resp.Request.URL.Path != "/transactions_async") {
if isStatusCodeAnError(resp.StatusCode) {
if isAsyncTxSubRequest(resp) {
return decodeAsyncTxSubResponse(resp, object)
}

horizonError := &Error{
Response: resp,
}
Expand All @@ -47,6 +51,42 @@ func decodeResponse(resp *http.Response, object interface{}, horizonUrl string,
return
}

func isStatusCodeAnError(statusCode int) bool {
return !(statusCode >= 200 && statusCode < 300)
}

func isAsyncTxSubRequest(resp *http.Response) bool {
return resp.Request != nil && resp.Request.URL != nil && resp.Request.URL.Path == "/transactions_async"
}

func decodeAsyncTxSubResponse(resp *http.Response, object interface{}) error {
// We need to read the entire body in order to create 2 decoders later.
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return errors.Wrap(err, "error reading response body")
}

// The first decoder converts the response to AsyncTransactionSubmissionResponse and checks
// the hash of the transaction. If the response was not a valid AsyncTransactionSubmissionResponse object,
// the hash of the converted object will be empty.
asyncRespDecoder := json.NewDecoder(bytes.NewReader(bodyBytes))
err = asyncRespDecoder.Decode(&object)
if asyncResp, ok := object.(*horizon.AsyncTransactionSubmissionResponse); err == nil && ok && asyncResp.Hash != "" {
return nil
}

// Create a new reader for the second decoding. The second decoder decodes to Horizon.Problem object.
problemDecoder := json.NewDecoder(bytes.NewReader(bodyBytes))
horizonError := Error{
Response: resp,
}
err = problemDecoder.Decode(&horizonError.Problem)
if err != nil {
return errors.Wrap(err, "error decoding horizon error")
}
return horizonError
}

// countParams counts the number of parameters provided
func countParams(params ...interface{}) int {
counter := 0
Expand Down
2 changes: 0 additions & 2 deletions clients/horizonclient/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,6 @@ func TestAssetsRequest(t *testing.T) {
assert.Equal(t, record.Asset.Code, "ABC")
assert.Equal(t, record.Asset.Issuer, "GCLWGQPMKXQSPF776IU33AH4PZNOOWNAWGGKVTBQMIC5IMKUNP3E6NVU")
assert.Equal(t, record.PT, "1")
assert.Equal(t, record.NumAccounts, int32(3))
assert.Equal(t, record.Amount, "105.0000000")
assert.Equal(t, record.Flags.AuthRevocable, false)
assert.Equal(t, record.Flags.AuthRequired, true)
assert.Equal(t, record.Flags.AuthImmutable, false)
Expand Down
Loading

0 comments on commit edf3eed

Please sign in to comment.