Skip to content

Commit

Permalink
Merge pull request #10474 from vegaprotocol/fix/10456
Browse files Browse the repository at this point in the history
fix: expose proper value for graphql dispatch metrics
  • Loading branch information
jeremyletang authored Jan 24, 2024
2 parents 30a1f42 + b79afef commit 2d98a38
Show file tree
Hide file tree
Showing 10 changed files with 1,372 additions and 1,332 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
- [10431](https://github.com/vegaprotocol/vega/issues/10431) - Fix source staleness validation.
- [10419](https://github.com/vegaprotocol/vega/issues/10419) - Block explorer database migration is slow.
- [10470](https://github.com/vegaprotocol/vega/issues/10470) - Mark non-optional parameters as required and update documentation strings.
- [10456](https://github.com/vegaprotocol/vega/issues/10456) - Expose proper enum for `GraphQL` dispatch metric.

## 0.73.0

Expand Down
32 changes: 32 additions & 0 deletions datanode/entities/enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,38 @@ import (
"github.com/jackc/pgtype"
)

type DispatchMetric vega.DispatchMetric

const (
DispatchMetricUnspecified DispatchMetric = DispatchMetric(vega.DispatchMetric_DISPATCH_METRIC_UNSPECIFIED)
DispatchMetricMakerFeePaid = DispatchMetric(vega.DispatchMetric_DISPATCH_METRIC_MAKER_FEES_PAID)
DispatchMetricMakerFeesReceived = DispatchMetric(vega.DispatchMetric_DISPATCH_METRIC_MAKER_FEES_RECEIVED)
DispatchMetricLPFeesReceived = DispatchMetric(vega.DispatchMetric_DISPATCH_METRIC_LP_FEES_RECEIVED)
DispatchMetricMarketValue = DispatchMetric(vega.DispatchMetric_DISPATCH_METRIC_MARKET_VALUE)
DispatchMetricAveragePosition = DispatchMetric(vega.DispatchMetric_DISPATCH_METRIC_AVERAGE_POSITION)
DispatchMetricRelativeReturn = DispatchMetric(vega.DispatchMetric_DISPATCH_METRIC_RELATIVE_RETURN)
DispatchMetricReturnVolatility = DispatchMetric(vega.DispatchMetric_DISPATCH_METRIC_RETURN_VOLATILITY)
DispatchMetricValidatorRanking = DispatchMetric(vega.DispatchMetric_DISPATCH_METRIC_VALIDATOR_RANKING)
)

func (m DispatchMetric) EncodeText(_ *pgtype.ConnInfo, buf []byte) ([]byte, error) {
mode, ok := vega.DispatchMetric_name[int32(m)]
if !ok {
return buf, fmt.Errorf("unknown dispatch metric: %s", mode)
}
return append(buf, []byte(mode)...), nil
}

func (m *DispatchMetric) DecodeText(_ *pgtype.ConnInfo, src []byte) error {
val, ok := vega.DispatchMetric_value[string(src)]
if !ok {
return fmt.Errorf("unknown dispatch metric: %s", src)
}

*m = DispatchMetric(val)
return nil
}

type Side = vega.Side

const (
Expand Down
5 changes: 3 additions & 2 deletions datanode/entities/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"code.vegaprotocol.io/vega/libs/num"
v2 "code.vegaprotocol.io/vega/protos/data-node/api/v2"
"code.vegaprotocol.io/vega/protos/vega"
)

type _Game struct{}
Expand Down Expand Up @@ -93,7 +94,7 @@ type TeamGameEntity struct {
Team TeamGameParticipation
Rank uint64
Volume num.Decimal
RewardMetric string
RewardMetric vega.DispatchMetric
RewardEarned *num.Uint
TotalRewardsEarned *num.Uint
}
Expand All @@ -114,7 +115,7 @@ type IndividualGameEntity struct {
Individual string
Rank uint64
Volume num.Decimal
RewardMetric string
RewardMetric vega.DispatchMetric
RewardEarned *num.Uint
TotalRewardsEarned *num.Uint
}
Expand Down
12 changes: 6 additions & 6 deletions datanode/gateway/graphql/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions datanode/gateway/graphql/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions datanode/gateway/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -7055,7 +7055,7 @@ type IndividualGameEntity {
"The volume traded by the individual"
volume: String!
"The reward metric applied to the game"
rewardMetric: String!
rewardMetric: DispatchMetric!
"The rewards earned by the individual during the epoch"
rewardEarned: String!
"Total rewards earned by the individual during the game"
Expand All @@ -7079,7 +7079,7 @@ type TeamGameEntity {
"Total volume traded by the team"
volume: String!
"Reward metric applied to the game."
rewardMetric: String!
rewardMetric: DispatchMetric!
"Total rewards earned by the team during the epoch"
rewardEarned: String!
"Total rewards earned by the team for the game"
Expand Down
6 changes: 3 additions & 3 deletions datanode/sqlstore/games.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func parseGameRewards(rewards []GameReward) ([]entities.Game, error) {
Individual: rewards[i].PartyID.String(),
Rank: uint64(rewards[i].MemberRank),
Volume: num.DecimalZero(),
RewardMetric: rewards[i].DispatchStrategy.Metric.String(),
RewardMetric: rewards[i].DispatchStrategy.Metric,
RewardEarned: rewardEarned,
TotalRewardsEarned: totalRewardsEarned,
}
Expand Down Expand Up @@ -291,9 +291,9 @@ func parseGameRewards(rewards []GameReward) ([]entities.Game, error) {
teamVolume := num.DecimalZero()
teamRewardEarned := num.NewUint(0)
teamTotalRewardsEarned := num.NewUint(0)
rewardMetric := ""
rewardMetric := vega.DispatchMetric_DISPATCH_METRIC_UNSPECIFIED
for _, individual := range individuals {
if rewardMetric == "" {
if rewardMetric == vega.DispatchMetric_DISPATCH_METRIC_UNSPECIFIED {
rewardMetric = individual.RewardMetric
}
teamVolume = teamVolume.Add(individual.Volume)
Expand Down
6 changes: 3 additions & 3 deletions datanode/sqlstore/games_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ func setupGamesData(ctx context.Context, t *testing.T, stores gameStores, block
Individual: member.ID.String(),
Rank: 0,
Volume: num.DecimalZero(),
RewardMetric: "DISPATCH_METRIC_MAKER_FEES_PAID",
RewardMetric: vega.DispatchMetric_DISPATCH_METRIC_MAKER_FEES_PAID,
RewardEarned: rewardEarned,
}
teamRewards = teamRewards.Add(teamRewards, individualEntity.RewardEarned)
Expand Down Expand Up @@ -451,7 +451,7 @@ func setupGamesData(ctx context.Context, t *testing.T, stores gameStores, block
},
Rank: 0,
Volume: teamVolume,
RewardMetric: "DISPATCH_METRIC_MAKER_FEES_PAID",
RewardMetric: vega.DispatchMetric_DISPATCH_METRIC_MAKER_FEES_PAID,
RewardEarned: teamRewards,
}
if teamTotalRewards[gk][team] == nil {
Expand Down Expand Up @@ -511,7 +511,7 @@ func setupGamesData(ctx context.Context, t *testing.T, stores gameStores, block
Individual: individual.ID.String(),
Rank: uint64(i + 1),
Volume: num.DecimalZero(),
RewardMetric: "DISPATCH_METRIC_MAKER_FEES_PAID",
RewardMetric: vega.DispatchMetric_DISPATCH_METRIC_MAKER_FEES_PAID,
RewardEarned: rewardEarned,
}
individualEntities = append(individualEntities, &individualEntity)
Expand Down
Loading

0 comments on commit 2d98a38

Please sign in to comment.