From 82418f7fc15e930541c259a301ceeb5851534d01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Trinqu=C3=A9?= Date: Thu, 7 Dec 2023 19:13:47 +0100 Subject: [PATCH 1/3] Merge pull request #10232 from vegaprotocol/feat/10812-volume-stats-show-all-volume feat: volume discount stats api shows volume for all participants --- CHANGELOG.md | 6 ++++++ core/volumediscount/engine.go | 10 ++++++++++ core/volumediscount/engine_test.go | 4 ++-- core/volumediscount/helpers_for_test.go | 19 +++++++++++++++++++ .../sqlstore/volume_discount_stats_test.go | 19 ++++++++++++++----- 5 files changed, 51 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0eda54d275..9d6e4622add 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.73.9 + +### 🐛 Fixes + +- [10218](https://github.com/vegaprotocol/vega/issues/10218) - Volume discount stats shows volumes even if party doesn't qualify for a discount tier. + ## 0.73.8 ### 🐛 Fixes diff --git a/core/volumediscount/engine.go b/core/volumediscount/engine.go index 575d1f62f70..5fdd1b3ac22 100644 --- a/core/volumediscount/engine.go +++ b/core/volumediscount/engine.go @@ -191,6 +191,7 @@ func (e *Engine) computeFactorsByParty(ctx context.Context, epoch uint64) { for _, party := range parties { notionalVolume := e.avgVolumePerParty[party] + qualifiedForTier := false for i := tiersLen - 1; i >= 0; i-- { tier := e.currentProgram.VolumeBenefitTiers[i] if notionalVolume.GreaterThanOrEqual(tier.MinimumRunningNotionalTakerVolume.ToDecimal()) { @@ -202,9 +203,18 @@ func (e *Engine) computeFactorsByParty(ctx context.Context, epoch uint64) { DiscountFactor: tier.VolumeDiscountFactor.String(), RunningVolume: notionalVolume.Round(0).String(), }) + qualifiedForTier = true break } } + // if the party hasn't qualified, then still send the stats but with a zero factor + if !qualifiedForTier { + evt.Stats = append(evt.Stats, &eventspb.PartyVolumeDiscountStats{ + PartyId: party.String(), + DiscountFactor: "0", + RunningVolume: notionalVolume.Round(0).String(), + }) + } } e.broker.Send(events.NewVolumeDiscountStatsUpdatedEvent(ctx, evt)) diff --git a/core/volumediscount/engine_test.go b/core/volumediscount/engine_test.go index ff6fe76efb8..da15eeffc99 100644 --- a/core/volumediscount/engine_test.go +++ b/core/volumediscount/engine_test.go @@ -176,7 +176,7 @@ func TestDiscountFactor(t *testing.T) { }).Times(1) // end the epoch to get the market activity recorded - expectStatsUpdated(t, broker) + expectStatsUpdatedWithUnqualifiedParties(t, broker) currentTime = currentTime.Add(1 * time.Minute) endEpoch(t, engine, currentEpoch, currentTime.Add(1*time.Minute)) @@ -278,7 +278,7 @@ func TestDiscountFactorWithWindow(t *testing.T) { "p7": num.NewUint(5000), }).Times(1) - expectStatsUpdated(t, broker) + expectStatsUpdatedWithUnqualifiedParties(t, broker) currentTime = currentTime.Add(1 * time.Minute) endEpoch(t, engine, currentEpoch, currentTime) // start a new epoch for the discount factors to be in place diff --git a/core/volumediscount/helpers_for_test.go b/core/volumediscount/helpers_for_test.go index d7a10ab9736..c3e1fe69c8b 100644 --- a/core/volumediscount/helpers_for_test.go +++ b/core/volumediscount/helpers_for_test.go @@ -67,6 +67,25 @@ func expectStatsUpdated(t *testing.T, broker *mocks.MockBroker) { }).Times(1) } +func expectStatsUpdatedWithUnqualifiedParties(t *testing.T, broker *mocks.MockBroker) { + t.Helper() + + broker.EXPECT().Send(gomock.Any()).Do(func(evt events.Event) { + update, ok := evt.(*events.VolumeDiscountStatsUpdated) + require.Truef(t, ok, "expecting event of type *events.VolumeDiscountStatsUpdated but got %T", evt) + stats := update.VolumeDiscountStatsUpdated() + foundUnqualifiedParty := false + for _, s := range stats.Stats { + if s.PartyId == "p1" { + foundUnqualifiedParty = true + require.Equal(t, "0", s.DiscountFactor) + require.Equal(t, "900", s.RunningVolume) + } + } + require.True(t, foundUnqualifiedParty) + }).Times(1) +} + func expectProgramStarted(t *testing.T, broker *mocks.MockBroker, p1 *types.VolumeDiscountProgram) { t.Helper() diff --git a/datanode/sqlstore/volume_discount_stats_test.go b/datanode/sqlstore/volume_discount_stats_test.go index c3271ef11d5..b47bbcd7c8c 100644 --- a/datanode/sqlstore/volume_discount_stats_test.go +++ b/datanode/sqlstore/volume_discount_stats_test.go @@ -85,8 +85,8 @@ func TestVolumeDiscountStats_GetVolumeDiscountStats(t *testing.T) { ps := sqlstore.NewParties(connectionSource) vds := sqlstore.NewVolumeDiscountStats(connectionSource) - parties := make([]entities.Party, 0, 5) - for i := 0; i < 5; i++ { + parties := make([]entities.Party, 0, 6) + for i := 0; i < 6; i++ { block := addTestBlockForTime(t, ctx, bs, time.Now().Add(time.Duration(i-10)*time.Minute)) parties = append(parties, addTestParty(t, ctx, ps, block)) } @@ -231,8 +231,8 @@ func flattenVolumeDiscountStatsForParty(flattenStats []entities.FlattenVolumeDis func setupPartyVolumeDiscountStats(t *testing.T, ctx context.Context, ps *sqlstore.Parties, bs *sqlstore.Blocks) []*eventspb.PartyVolumeDiscountStats { t.Helper() - parties := make([]entities.Party, 0, 5) - for i := 0; i < 5; i++ { + parties := make([]entities.Party, 0, 6) + for i := 0; i < 6; i++ { block := addTestBlockForTime(t, ctx, bs, time.Now().Add(time.Duration(i-10)*time.Minute)) parties = append(parties, addTestParty(t, ctx, ps, block)) } @@ -249,8 +249,17 @@ func setupPartyVolumeDiscountStats(t *testing.T, ctx context.Context, ps *sqlsto func setupPartyVolumeDiscountStatsMod(t *testing.T, parties []entities.Party, f func(i int, party entities.Party) *eventspb.PartyVolumeDiscountStats) []*eventspb.PartyVolumeDiscountStats { t.Helper() - partiesStats := make([]*eventspb.PartyVolumeDiscountStats, 0, 5) + partiesStats := make([]*eventspb.PartyVolumeDiscountStats, 0, 6) for i, p := range parties { + // make the last party an unqualified party + if i == len(parties)-1 { + partiesStats = append(partiesStats, &eventspb.PartyVolumeDiscountStats{ + PartyId: p.ID.String(), + DiscountFactor: "0", + RunningVolume: "99", + }) + continue + } partiesStats = append(partiesStats, f(i, p)) } From 5b6f9f965cbe5c3df097078751061a27f0333ef9 Mon Sep 17 00:00:00 2001 From: Jeremy Letang Date: Fri, 8 Dec 2023 10:49:30 +0000 Subject: [PATCH 2/3] Merge pull request #10234 from vegaprotocol/stop_orders_logging fix: expiring stop orders fixed --- CHANGELOG.md | 1 + core/execution/future/market.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d6e4622add..8bcd0ca5476 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### 🐛 Fixes - [10218](https://github.com/vegaprotocol/vega/issues/10218) - Volume discount stats shows volumes even if party doesn't qualify for a discount tier. +- [10233](https://github.com/vegaprotocol/vega/issues/10233) - Fix expiring stop orders panic. ## 0.73.8 diff --git a/core/execution/future/market.go b/core/execution/future/market.go index 1701e877fe2..cacf37e3069 100644 --- a/core/execution/future/market.go +++ b/core/execution/future/market.go @@ -999,7 +999,7 @@ func (m *Market) removeAllStopOrders( sos, _ := m.stopOrders.Cancel(v.Party(), "") for _, so := range sos { if so.Expiry.Expires() { - _ = m.expiringOrders.RemoveOrder(so.Expiry.ExpiresAt.UnixNano(), so.ID) + _ = m.expiringStopOrders.RemoveOrder(so.Expiry.ExpiresAt.UnixNano(), so.ID) } evts = append(evts, events.NewStopOrderEvent(ctx, so)) } From 6b97a1266117fded6005d25201a98f80fbb7c745 Mon Sep 17 00:00:00 2001 From: Jeremy Letang Date: Fri, 8 Dec 2023 11:06:33 +0000 Subject: [PATCH 3/3] chore: release v0.73.9 Signed-off-by: Jeremy Letang --- protos/blockexplorer/api/v1/blockexplorer.pb.go | 2 +- protos/data-node/api/v2/trading_data.pb.go | 2 +- protos/sources/blockexplorer/api/v1/blockexplorer.proto | 2 +- protos/sources/data-node/api/v2/trading_data.proto | 2 +- protos/sources/vega/api/v1/core.proto | 2 +- protos/sources/vega/api/v1/corestate.proto | 2 +- protos/vega/api/v1/core.pb.go | 2 +- protos/vega/api/v1/corestate.pb.go | 2 +- version/version.go | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/protos/blockexplorer/api/v1/blockexplorer.pb.go b/protos/blockexplorer/api/v1/blockexplorer.pb.go index 5e6790ae214..8a8f6561547 100644 --- a/protos/blockexplorer/api/v1/blockexplorer.pb.go +++ b/protos/blockexplorer/api/v1/blockexplorer.pb.go @@ -665,7 +665,7 @@ var file_blockexplorer_api_v1_blockexplorer_proto_rawDesc = []byte{ 0x65, 0x72, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x92, 0x41, 0x3e, 0x12, 0x23, 0x0a, 0x18, 0x56, 0x65, 0x67, 0x61, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x20, 0x65, 0x78, 0x70, 0x6c, 0x6f, 0x72, 0x65, 0x72, 0x20, 0x41, 0x50, 0x49, 0x73, 0x32, 0x07, 0x76, 0x30, 0x2e, 0x37, 0x33, 0x2e, - 0x38, 0x1a, 0x13, 0x6c, 0x62, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x6e, 0x65, 0x74, 0x2e, 0x76, 0x65, + 0x39, 0x1a, 0x13, 0x6c, 0x62, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x6e, 0x65, 0x74, 0x2e, 0x76, 0x65, 0x67, 0x61, 0x2e, 0x78, 0x79, 0x7a, 0x2a, 0x02, 0x01, 0x02, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } diff --git a/protos/data-node/api/v2/trading_data.pb.go b/protos/data-node/api/v2/trading_data.pb.go index b1315833cc3..57ea966256e 100644 --- a/protos/data-node/api/v2/trading_data.pb.go +++ b/protos/data-node/api/v2/trading_data.pb.go @@ -26853,7 +26853,7 @@ var file_data_node_api_v2_trading_data_proto_rawDesc = []byte{ 0x67, 0x61, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x64, 0x61, 0x74, 0x61, 0x2d, 0x6e, 0x6f, 0x64, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x32, 0x92, 0x41, 0x8f, 0x01, 0x12, 0x1e, 0x0a, 0x13, 0x56, 0x65, 0x67, 0x61, 0x20, 0x64, 0x61, 0x74, 0x61, 0x20, 0x6e, 0x6f, 0x64, 0x65, - 0x20, 0x41, 0x50, 0x49, 0x73, 0x32, 0x07, 0x76, 0x30, 0x2e, 0x37, 0x33, 0x2e, 0x38, 0x1a, 0x1c, + 0x20, 0x41, 0x50, 0x49, 0x73, 0x32, 0x07, 0x76, 0x30, 0x2e, 0x37, 0x33, 0x2e, 0x39, 0x1a, 0x1c, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x61, 0x70, 0x69, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x6e, 0x65, 0x74, 0x2e, 0x76, 0x65, 0x67, 0x61, 0x2e, 0x78, 0x79, 0x7a, 0x2a, 0x02, 0x01, 0x02, 0x32, 0x10, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6a, 0x73, diff --git a/protos/sources/blockexplorer/api/v1/blockexplorer.proto b/protos/sources/blockexplorer/api/v1/blockexplorer.proto index c8eca3a2213..3df79710b7d 100644 --- a/protos/sources/blockexplorer/api/v1/blockexplorer.proto +++ b/protos/sources/blockexplorer/api/v1/blockexplorer.proto @@ -11,7 +11,7 @@ option go_package = "code.vegaprotocol.io/vega/protos/blockexplorer/api/v1"; option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { info: { title: "Vega block explorer APIs"; - version: "v0.73.8"; + version: "v0.73.9"; } schemes: [ HTTP, diff --git a/protos/sources/data-node/api/v2/trading_data.proto b/protos/sources/data-node/api/v2/trading_data.proto index c76ee695c81..7aee26ee2a6 100644 --- a/protos/sources/data-node/api/v2/trading_data.proto +++ b/protos/sources/data-node/api/v2/trading_data.proto @@ -17,7 +17,7 @@ option go_package = "code.vegaprotocol.io/vega/protos/data-node/api/v2"; option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { info: { title: "Vega data node APIs"; - version: "v0.73.8"; + version: "v0.73.9"; } schemes: [ HTTP, diff --git a/protos/sources/vega/api/v1/core.proto b/protos/sources/vega/api/v1/core.proto index 2cf781174c8..59b48efe4a8 100644 --- a/protos/sources/vega/api/v1/core.proto +++ b/protos/sources/vega/api/v1/core.proto @@ -12,7 +12,7 @@ option go_package = "code.vegaprotocol.io/vega/protos/vega/api/v1"; option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { info: { title: "Vega core APIs"; - version: "v0.73.8"; + version: "v0.73.9"; } schemes: [ HTTP, diff --git a/protos/sources/vega/api/v1/corestate.proto b/protos/sources/vega/api/v1/corestate.proto index c122a58625e..4e79fc82185 100644 --- a/protos/sources/vega/api/v1/corestate.proto +++ b/protos/sources/vega/api/v1/corestate.proto @@ -13,7 +13,7 @@ option go_package = "code.vegaprotocol.io/vega/protos/vega/api/v1"; option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { info: { title: "Vega core state APIs"; - version: "v0.73.8"; + version: "v0.73.9"; } schemes: [ HTTP, diff --git a/protos/vega/api/v1/core.pb.go b/protos/vega/api/v1/core.pb.go index 7e5d5fa2a26..7bf8ad5df79 100644 --- a/protos/vega/api/v1/core.pb.go +++ b/protos/vega/api/v1/core.pb.go @@ -2796,7 +2796,7 @@ var file_vega_api_v1_core_proto_rawDesc = []byte{ 0x6f, 0x6c, 0x2e, 0x69, 0x6f, 0x2f, 0x76, 0x65, 0x67, 0x61, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x76, 0x65, 0x67, 0x61, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x92, 0x41, 0x34, 0x12, 0x19, 0x0a, 0x0e, 0x56, 0x65, 0x67, 0x61, 0x20, 0x63, 0x6f, 0x72, 0x65, 0x20, 0x41, 0x50, - 0x49, 0x73, 0x32, 0x07, 0x76, 0x30, 0x2e, 0x37, 0x33, 0x2e, 0x38, 0x1a, 0x13, 0x6c, 0x62, 0x2e, + 0x49, 0x73, 0x32, 0x07, 0x76, 0x30, 0x2e, 0x37, 0x33, 0x2e, 0x39, 0x1a, 0x13, 0x6c, 0x62, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x6e, 0x65, 0x74, 0x2e, 0x76, 0x65, 0x67, 0x61, 0x2e, 0x78, 0x79, 0x7a, 0x2a, 0x02, 0x01, 0x02, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } diff --git a/protos/vega/api/v1/corestate.pb.go b/protos/vega/api/v1/corestate.pb.go index 8429fa0fa0d..6b826cd745e 100644 --- a/protos/vega/api/v1/corestate.pb.go +++ b/protos/vega/api/v1/corestate.pb.go @@ -1512,7 +1512,7 @@ var file_vega_api_v1_corestate_proto_rawDesc = []byte{ 0x6f, 0x73, 0x2f, 0x76, 0x65, 0x67, 0x61, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x92, 0x41, 0x3a, 0x12, 0x1f, 0x0a, 0x14, 0x56, 0x65, 0x67, 0x61, 0x20, 0x63, 0x6f, 0x72, 0x65, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x41, 0x50, 0x49, 0x73, 0x32, 0x07, 0x76, 0x30, 0x2e, 0x37, 0x33, - 0x2e, 0x38, 0x1a, 0x13, 0x6c, 0x62, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x6e, 0x65, 0x74, 0x2e, 0x76, + 0x2e, 0x39, 0x1a, 0x13, 0x6c, 0x62, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x6e, 0x65, 0x74, 0x2e, 0x76, 0x65, 0x67, 0x61, 0x2e, 0x78, 0x79, 0x7a, 0x2a, 0x02, 0x01, 0x02, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } diff --git a/version/version.go b/version/version.go index b0a10c97e8d..c0042efef82 100644 --- a/version/version.go +++ b/version/version.go @@ -22,7 +22,7 @@ import ( var ( cliVersionHash = "" - cliVersion = "v0.73.8" + cliVersion = "v0.73.9" ) func init() {