Skip to content

Commit

Permalink
Merge pull request #359 from stellar/horizon-v0.12.1-fixes
Browse files Browse the repository at this point in the history
Horizon v0.12.1 fixes
  • Loading branch information
nullstyle authored Mar 13, 2018
2 parents 07636e0 + 4f00bd7 commit f8a5cca
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 21 deletions.
13 changes: 11 additions & 2 deletions services/horizon/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ file. This project adheres to [Semantic Versioning](http://semver.org/).
As this project is pre 1.0, breaking changes may happen for minor version
bumps. A breaking change will get clearly notified in this log.

## [v0.12.0] - 2017-03-08
## v0.12.1 - 2017-03-13

This release is a bug fix release for v0.12.0. *Please see the upgrade notes below if you did not already migrate your db for v0.12.0*

### Bug fixes

- Fixed an issue caused by un-migrated trade rows. (https://github.com/stellar/go/issues/357)
- Command line flags are now useable for subcommands of horizon.


## v0.12.0 - 2017-03-08

Big release this time for horizon: We've made a number of breaking changes since v0.11.0 and have revised both our database schema as well as our data ingestion system. We recommend that you take a backup of your horizon database prior to upgrading, just in case.

Expand Down Expand Up @@ -223,7 +233,6 @@ This release contains the initial implementation of the "Abridged History System
### Added
- Github releases are created from tagged travis builds automatically

[Unreleased]: https://github.com/stellar/horizon/compare/v0.11.0...master
[v0.11.0]: https://github.com/stellar/horizon/compare/v0.10.1...v0.11.0
[v0.10.1]: https://github.com/stellar/horizon/compare/v0.10.0...v0.10.1
[v0.10.0]: https://github.com/stellar/horizon/compare/v0.9.1...v0.10.0
Expand Down
34 changes: 23 additions & 11 deletions services/horizon/internal/actions_trade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ func TestTradeActions_Aggregation(t *testing.T) {
q.Add("end_time", strconv.FormatInt(start+hour, 10))
q.Add("order", "asc")


//test illegal resolution
q.Add("resolution", strconv.FormatInt(hour/2, 10))
w := ht.GetWithParams(aggregationPath, q)
Expand Down Expand Up @@ -253,19 +252,32 @@ func TestTradeActions_Aggregation(t *testing.T) {
}

func TestTradeActions_IndexRegressions(t *testing.T) {
ht := StartHTTPTest(t, "trades")
defer ht.Finish()
t.Run("Regression: https://github.com/stellar/go/services/horizon/internal/issues/318", func(t *testing.T) {
ht := StartHTTPTest(t, "trades")
defer ht.Finish()

// Regression: https://github.com/stellar/go/services/horizon/internal/issues/318
var q = make(url.Values)
q.Add("base_asset_type", "credit_alphanum4")
q.Add("base_asset_code", "EUR")
q.Add("base_asset_issuer", "GCQPYGH4K57XBDENKKX55KDTWOTK5WDWRQOH2LHEDX3EKVIQRLMESGBG")
q.Add("counter_asset_type", "native")
var q = make(url.Values)
q.Add("base_asset_type", "credit_alphanum4")
q.Add("base_asset_code", "EUR")
q.Add("base_asset_issuer", "GCQPYGH4K57XBDENKKX55KDTWOTK5WDWRQOH2LHEDX3EKVIQRLMESGBG")
q.Add("counter_asset_type", "native")

w := ht.Get("/trades?" + q.Encode())

ht.Assert.Equal(404, w.Code) //This used to be 200 with length 0
})

t.Run("Regression for nil prices: https://github.com/stellar/go/issues/357", func(t *testing.T) {
ht := StartHTTPTest(t, "trades")
defer ht.Finish()

w := ht.Get("/trades?" + q.Encode())
w := ht.Get("/trades")
ht.Require.Equal(200, w.Code)

ht.Assert.Equal(404, w.Code) //This used to be 200 with length 0
_ = ht.HorizonDB.MustExec("UPDATE history_trades SET price_n = NULL, price_d = NULL")
w = ht.Get("/trades")
ht.Assert.Equal(200, w.Code, "nil-price trades failed")
})
}

// TestTradeActions_AggregationOrdering checks that open/close aggregation
Expand Down
4 changes: 2 additions & 2 deletions services/horizon/internal/db2/history/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ type Trade struct {
CounterAssetIssuer string `db:"counter_asset_issuer"`
CounterAmount xdr.Int64 `db:"counter_amount"`
BaseIsSeller bool `db:"base_is_seller"`
PriceN xdr.Int32 `db:"price_n"`
PriceD xdr.Int32 `db:"price_d"`
PriceN null.Int `db:"price_n"`
PriceD null.Int `db:"price_d"`
}

// TradesQ is a helper struct to aid in configuring queries that loads
Expand Down
5 changes: 5 additions & 0 deletions services/horizon/internal/db2/history/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ func (r *Trade) PagingToken() string {
return fmt.Sprintf("%d-%d", r.HistoryOperationID, r.Order)
}

// HasPrice returns true if the trade has non-null price data
func (r *Trade) HasPrice() bool {
return r.PriceN.Valid && r.PriceD.Valid
}

// Trades provides a helper to filter rows from the `history_trades` table
// with pre-defined filters. See `TradesQ` methods for the available filters.
func (q *Q) Trades() *TradesQ {
Expand Down
4 changes: 2 additions & 2 deletions services/horizon/internal/resource/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"time"

"github.com/stellar/go/services/horizon/internal/db2/history"
"github.com/stellar/go/services/horizon/internal/render/hal"
"github.com/stellar/go/services/horizon/internal/resource/base"
"github.com/stellar/go/services/horizon/internal/resource/effects"
"github.com/stellar/go/services/horizon/internal/resource/operations"
"github.com/stellar/go/services/horizon/internal/render/hal"
"github.com/stellar/go/strkey"
"github.com/stellar/go/support/errors"
"github.com/stellar/go/xdr"
Expand Down Expand Up @@ -224,7 +224,7 @@ type Trade struct {
CounterAssetCode string `json:"counter_asset_code,omitempty"`
CounterAssetIssuer string `json:"counter_asset_issuer,omitempty"`
BaseIsSeller bool `json:"base_is_seller"`
Price xdr.Price `json:"price"`
Price *Price `json:"price"`
}

// TradeEffect represents a trade effect resource. NOTE (scott, 2017-12-08):
Expand Down
10 changes: 8 additions & 2 deletions services/horizon/internal/resource/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/stellar/go/services/horizon/internal/httpx"
"github.com/stellar/go/services/horizon/internal/render/hal"
"golang.org/x/net/context"
"github.com/stellar/go/xdr"
)

// Populate fills out the details of a trade using a row from the history_trades
Expand All @@ -32,7 +31,14 @@ func (res *Trade) Populate(
res.CounterAmount = amount.String(row.CounterAmount)
res.LedgerCloseTime = row.LedgerCloseTime
res.BaseIsSeller = row.BaseIsSeller
res.Price = xdr.Price{row.PriceN, row.PriceD}

if row.HasPrice() {
res.Price = &Price{
N: int32(row.PriceN.Int64),
D: int32(row.PriceD.Int64),
}
}

res.populateLinks(ctx, row.HistoryOperationID)
return
}
Expand Down
6 changes: 4 additions & 2 deletions services/horizon/internal/test/trades/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ func IngestTestTrade(
trade.AssetBought = assetBought
trade.AssetSold = assetSold

price := xdr.Price{xdr.Int32(int32(amountBought)), xdr.Int32(int32(amountSold))}
price := xdr.Price{
N: xdr.Int32(amountBought),
D: xdr.Int32(amountSold),
}

return q.InsertTrade(opCounter, 0, buyer, trade, price, timestamp)
}
Expand Down Expand Up @@ -72,4 +75,3 @@ func PopulateTestTrades(
}
return
}

0 comments on commit f8a5cca

Please sign in to comment.