Skip to content

Commit

Permalink
Merge pull request #3125 from stellar/release-horizon-v1.10.0
Browse files Browse the repository at this point in the history
Merge release-horizon-v1.10.0 into master
  • Loading branch information
bartekn authored Oct 14, 2020
2 parents dd35fa3 + 38cc1f6 commit 6f5b147
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 18 deletions.
11 changes: 9 additions & 2 deletions services/horizon/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
All notable changes to this project will be documented in this
file. This project adheres to [Semantic Versioning](http://semver.org/).x

## Unreleased
## v1.10.0

* Dropped support for Go 1.13.
**After upgrading Horizon will rebuild its state. During this process (which can take several minutes) it will not ingest new ledgers.**

* Fixed a bug that caused a fresh instance of Horizon to be unable to sync with testnet (Protocol 14) correctly. ([#3100](https://github.com/stellar/go/pull/3100))
* Add Golang- and process-related metrics. ([#3103](https://github.com/stellar/go/pull/3103))
* New `network_passphrase` field in History Archives (added in Stellar-Core 14.1.0) is now checked. Horizon will return error if incorrect archive is used. ([#3082](https://github.com/stellar/go/pull/3082))
* Fixed a bug that caused some errors to be logged with `info` level instead of `error` level. ([#3094](https://github.com/stellar/go/pull/3094))
* Fixed a bug in `/claimable_balances` that returned 500 error instead of 400 for some requests. ([#3088](https://github.com/stellar/go/pull/3088))
* Print a friendly message when Horizon does not support the current Stellar protocol version. ([#3093](https://github.com/stellar/go/pull/3093))

## v1.9.1

Expand Down
8 changes: 8 additions & 0 deletions services/horizon/internal/actions/claimable_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ func (handler GetClaimableBalancesHandler) GetResourcePage(
Claimant: qp.claimant(),
}

_, _, err = query.Cursor()
if err != nil {
return nil, problem.MakeInvalidFieldProblem(
"cursor",
errors.New("The first part should be a number higher than 0 and the second part should be a valid claimable balance ID"),
)
}

historyQ, err := horizonContext.HistoryQFromRequest(r)
if err != nil {
return nil, err
Expand Down
54 changes: 48 additions & 6 deletions services/horizon/internal/actions/claimable_balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,12 +524,54 @@ func TestGetClaimableBalances(t *testing.T) {

tt.Assert.NoError(err)
tt.Assert.Len(response, 2)
// for _, resource := range response {
// tt.Assert.Equal(
// "GC3C4AKRBQLHOJ45U4XG35ESVWRDECWO5XLDGYADO6DPR3L7KIDVUMML",
// resource.(protocol.ClaimableBalance).Sponsor,
// )
// }
}

func TestCursorAndOrderValidation(t *testing.T) {
tt := test.Start(t)
defer tt.Finish()
test.ResetHorizonDB(t, tt.HorizonDB)
q := &history.Q{tt.HorizonSession()}

handler := GetClaimableBalancesHandler{}
_, err := handler.GetResourcePage(httptest.NewRecorder(), makeRequest(
t,
map[string]string{
"cursor": "-1-00000043d380c38a2f2cac46ab63674064c56fdce6b977fdef1a278ad50e1a7e6a5e18",
},
map[string]string{},
q.Session,
))
p := err.(*problem.P)
tt.Assert.Equal("bad_request", p.Type)
tt.Assert.Equal("cursor", p.Extras["invalid_field"])
tt.Assert.Equal("The first part should be a number higher than 0 and the second part should be a valid claimable balance ID", p.Extras["reason"])

_, err = handler.GetResourcePage(httptest.NewRecorder(), makeRequest(
t,
map[string]string{
"cursor": "1003529-00000043d380c38a2f2cac46ab63674064c56fdce6b977fdef1a278ad50e1a7e6a5e18",
},
map[string]string{},
q.Session,
))
p = err.(*problem.P)
tt.Assert.Equal("bad_request", p.Type)
tt.Assert.Equal("cursor", p.Extras["invalid_field"])
tt.Assert.Equal("The first part should be a number higher than 0 and the second part should be a valid claimable balance ID", p.Extras["reason"])

_, err = handler.GetResourcePage(httptest.NewRecorder(), makeRequest(
t,
map[string]string{
"order": "arriba",
"cursor": "1003529-00000043d380c38a2f2cac46ab63674064c56fdce6b977fdef1a278ad50e1a7e6a5e18",
},
map[string]string{},
q.Session,
))
p = err.(*problem.P)
tt.Assert.Equal("bad_request", p.Type)
tt.Assert.Equal("order", p.Extras["invalid_field"])
tt.Assert.Equal("order: invalid value", p.Extras["reason"])
}

func TestClaimableBalancesQueryURLTemplate(t *testing.T) {
Expand Down
6 changes: 6 additions & 0 deletions services/horizon/internal/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,12 @@ func (a *App) init() error {
a.prometheusRegistry.MustRegister(meter)
}

// go metrics
initGoMetrics(a)

// process metrics
initProcessMetrics(a)

// db-metrics
initDbMetrics(a)

Expand Down
27 changes: 19 additions & 8 deletions services/horizon/internal/db2/history/claimable_balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ type ClaimableBalancesQuery struct {
Claimant *xdr.AccountId
}

// ApplyCursor applies cursor to the given sql. For performance reason the limit
// is not apply here. This allows us to hint the planner later to use the right
// indexes.
func (cbq ClaimableBalancesQuery) ApplyCursor(sql sq.SelectBuilder) (sq.SelectBuilder, error) {
// Cursor validates and returns the query page cursor
func (cbq ClaimableBalancesQuery) Cursor() (int64, *xdr.ClaimableBalanceId, error) {
p := cbq.PageQuery
var l int64
var r *xdr.ClaimableBalanceId
Expand All @@ -34,24 +32,37 @@ func (cbq ClaimableBalancesQuery) ApplyCursor(sql sq.SelectBuilder) (sq.SelectBu
if p.Cursor != "" {
parts := strings.SplitN(p.Cursor, "-", 2)
if len(parts) != 2 {
return sql, errors.New("Invalid cursor")
return l, r, errors.New("Invalid cursor")
}

l, err = strconv.ParseInt(parts[0], 10, 64)
if err != nil {
return sql, errors.Wrap(err, "Invalid cursor - first value should be higher than 0")
return l, r, errors.Wrap(err, "Invalid cursor - first value should be higher than 0")
}

var balanceID xdr.ClaimableBalanceId
if err = xdr.SafeUnmarshalHex(parts[1], &balanceID); err != nil {
return sql, errors.Wrap(err, "Invalid cursor - second value should be a valid claimable balance id")
return l, r, errors.Wrap(err, "Invalid cursor - second value should be a valid claimable balance id")
}
r = &balanceID
if l < 0 {
return sql, errors.Wrap(err, "Invalid cursor - first value should be higher than 0")
return l, r, errors.Wrap(err, "Invalid cursor - first value should be higher than 0")
}
}

return l, r, nil
}

// ApplyCursor applies cursor to the given sql. For performance reason the limit
// is not apply here. This allows us to hint the planner later to use the right
// indexes.
func (cbq ClaimableBalancesQuery) ApplyCursor(sql sq.SelectBuilder) (sq.SelectBuilder, error) {
p := cbq.PageQuery
l, r, err := cbq.Cursor()
if err != nil {
return sql, err
}

switch p.Order {
case db2.OrderAscending:
if l > 0 && r != nil {
Expand Down
1 change: 1 addition & 0 deletions services/horizon/internal/db2/history/ingestion.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ func (q *Q) TruncateExpingestStateTables() error {
"accounts",
"accounts_data",
"accounts_signers",
"claimable_balances",
"exp_asset_stats",
"offers",
"trust_lines",
Expand Down
4 changes: 3 additions & 1 deletion services/horizon/internal/expingest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ const (
// - 10: Fixes a bug in meta processing (fees are now processed before
// everything else).
// - 11: Protocol 14: CAP-23 and CAP-33.
CurrentVersion = 11
// - 12: Trigger state rebuild due to `absTime` -> `abs_time` rename
// in ClaimableBalances predicates.
CurrentVersion = 12

// MaxDBConnections is the size of the postgres connection pool dedicated to Horizon ingestion:
// * Ledger ingestion,
Expand Down
2 changes: 1 addition & 1 deletion services/horizon/internal/expingest/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const assetStatsBatchSize = 500
// check them.
// There is a test that checks it, to fix it: update the actual `verifyState`
// method instead of just updating this value!
const stateVerifierExpectedIngestionVersion = 11
const stateVerifierExpectedIngestionVersion = 12

// verifyState is called as a go routine from pipeline post hook every 64
// ledgers. It checks if the state is correct. If another go routine is already
Expand Down
15 changes: 15 additions & 0 deletions services/horizon/internal/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,21 @@ func initDbMetrics(app *App) {
app.prometheusRegistry.MustRegister(app.orderBookStream.LatestLedgerGauge)
}

// initGoMetrics registers the Go collector provided by prometheus package which
// includes Go-related metrics.
func initGoMetrics(app *App) {
app.prometheusRegistry.MustRegister(prometheus.NewGoCollector())
}

// initProcessMetrics registers the process collector provided by prometheus
// package. This is only available on operating systems with a Linux-style proc
// filesystem and on Microsoft Windows.
func initProcessMetrics(app *App) {
app.prometheusRegistry.MustRegister(
prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}),
)
}

// initIngestMetrics registers the metrics for the ingestion into the provided
// app's metrics registry.
func initIngestMetrics(app *App) {
Expand Down

0 comments on commit 6f5b147

Please sign in to comment.