diff --git a/services/horizon/CHANGELOG.md b/services/horizon/CHANGELOG.md index 7f96ce8c9c..a5eed12460 100644 --- a/services/horizon/CHANGELOG.md +++ b/services/horizon/CHANGELOG.md @@ -3,13 +3,19 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -## Unreleased +## v2.11.0 ### Changes -* Add a new horizon flag `--max-assets-per-path-request` (`15` by default) that sets the number of assets to consider for strict-send and strict-recieve ([4046](https://github.com/stellar/go/pull/4046)) -* Add an endpoint that allows querying for which liquidity pools an account is participating in [4043](https://github.com/stellar/go/pull/4043) +* Add a new horizon flag `--max-assets-per-path-request` (`15` by default) that sets the number of assets to consider for strict-send and strict-recieve requests ([4046](https://github.com/stellar/go/pull/4046)) +* Add an endpoint `/liquidity_pools?account={account_id}` which returns the liquidity pools an account is participating in [4043](https://github.com/stellar/go/pull/4043) * Add a new horizon command `horizon db fill-gaps` which fills any gaps in history in the horizon db. The command takes optional start and end ledger parameters. If the start and end ledger is provided then horizon will only fill the gaps found within the given ledger range [4060](https://github.com/stellar/go/pull/4060) +* Improve performance of `/liquidity_pools/{liquidity_pool_id}/effects` endpoint by optimizing the db query to fetch effects for a liquidity pool [4065](https://github.com/stellar/go/pull/4065) +* Include the captive core binary in the `stellar/horizon` Docker image [4019](https://github.com/stellar/go/pull/4019) +* Remove `--captive-core-reuse-storage-dir` horizon flag [4048](https://github.com/stellar/go/pull/4048) +* Improve performance of XDR encoding which should also improve ingestion speeds [4063](https://github.com/stellar/go/pull/4063), [4056](https://github.com/stellar/go/pull/4056), [3957](https://github.com/stellar/go/pull/3957) +* Improve detection of when the Stellar Core binary has been modified [4050](https://github.com/stellar/go/pull/4050) +* `horizon_ingest_state_verify_ledger_entries` metric was changed to gauge [4054](https://github.com/stellar/go/pull/4054) ## v2.10.0 diff --git a/services/horizon/internal/actions/effects.go b/services/horizon/internal/actions/effects.go index ccb6a7d106..a141067d25 100644 --- a/services/horizon/internal/actions/effects.go +++ b/services/horizon/internal/actions/effects.go @@ -101,7 +101,7 @@ func loadEffectRecords(ctx context.Context, hq *history.Q, qp EffectsQuery, pq d case qp.AccountID != "": effects.ForAccount(ctx, qp.AccountID) case qp.LiquidityPoolID != "": - effects.ForLiquidityPool(qp.LiquidityPoolID) + effects.ForLiquidityPool(ctx, pq, qp.LiquidityPoolID) case qp.OperationID > 0: effects.ForOperation(int64(qp.OperationID)) case qp.LedgerID > 0: diff --git a/services/horizon/internal/db2/history/effect.go b/services/horizon/internal/db2/history/effect.go index a0294870f4..c7618b019f 100644 --- a/services/horizon/internal/db2/history/effect.go +++ b/services/horizon/internal/db2/history/effect.go @@ -127,12 +127,43 @@ func (q *EffectsQ) ForOperation(id int64) *EffectsQ { return q } -// ForLiquidityPoolID filters the query to only effects in a specific liquidity pool, +// ForLiquidityPool filters the query to only effects in a specific liquidity pool, // specified by its id. -func (q *EffectsQ) ForLiquidityPool(id string) *EffectsQ { - q.sql = q.sql.InnerJoin("history_operation_liquidity_pools holp ON holp.history_operation_id = heff.history_operation_id") - q.sql = q.sql.InnerJoin("history_liquidity_pools hlp ON hlp.id = holp.history_liquidity_pool_id") - q.sql = q.sql.Where("hlp.liquidity_pool_id = ?", id) +func (q *EffectsQ) ForLiquidityPool(ctx context.Context, page db2.PageQuery, id string) *EffectsQ { + if q.Err != nil { + return q + } + + op, _, err := page.CursorInt64Pair(db2.DefaultPairSep) + if err != nil { + q.Err = err + return q + } + + query := `SELECT holp.history_operation_id + FROM history_operation_liquidity_pools holp + WHERE holp.history_liquidity_pool_id = (SELECT id FROM history_liquidity_pools WHERE liquidity_pool_id = ?) + ` + switch page.Order { + case "asc": + query += "AND holp.history_operation_id >= ? ORDER BY holp.history_operation_id asc LIMIT ?" + case "desc": + query += "AND holp.history_operation_id <= ? ORDER BY holp.history_operation_id desc LIMIT ?" + default: + q.Err = errors.Errorf("invalid paging order: %s", page.Order) + return q + } + + var liquidityPoolOperationIDs []int64 + err = q.parent.SelectRaw(ctx, &liquidityPoolOperationIDs, query, id, op, page.Limit) + if err != nil { + q.Err = err + return q + } + + q.sql = q.sql.Where(map[string]interface{}{ + "heff.history_operation_id": liquidityPoolOperationIDs, + }) return q } diff --git a/services/horizon/internal/db2/history/effect_test.go b/services/horizon/internal/db2/history/effect_test.go index ab2c407343..4cb055d34f 100644 --- a/services/horizon/internal/db2/history/effect_test.go +++ b/services/horizon/internal/db2/history/effect_test.go @@ -7,6 +7,7 @@ import ( "github.com/guregu/null" "github.com/stellar/go/protocols/horizon/effects" + "github.com/stellar/go/services/horizon/internal/db2" "github.com/stellar/go/services/horizon/internal/test" "github.com/stellar/go/services/horizon/internal/toid" ) @@ -57,7 +58,11 @@ func TestEffectsForLiquidityPool(t *testing.T) { tt.Assert.NoError(err) var result []Effect - err = q.Effects().ForLiquidityPool(liquidityPoolID).Select(tt.Ctx, &result) + err = q.Effects().ForLiquidityPool(tt.Ctx, db2.PageQuery{ + Cursor: "0-0", + Order: "asc", + Limit: 10, + }, liquidityPoolID).Select(tt.Ctx, &result) tt.Assert.NoError(err) tt.Assert.Len(result, 1)