From 83f182ab3fc18635a4ae1e326362b5ad58ada7e3 Mon Sep 17 00:00:00 2001 From: Jeremy Letang Date: Thu, 8 Aug 2024 13:44:27 +0100 Subject: [PATCH] feat: add validation on market proposals metadata Signed-off-by: Jeremy Letang --- CHANGELOG.md | 3 ++- commands/errors.go | 1 + commands/proposal_submission.go | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8d0837744c..52672be85f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,13 +21,14 @@ - [11372](https://github.com/vegaprotocol/vega/issues/11372) - Support combined filters for the `AMM` API. - [11535](https://github.com/vegaprotocol/vega/issues/11535) - Added support for lottery rank distribution strategy. - [11536](https://github.com/vegaprotocol/vega/issues/11536) - Make the batch market instructions errors programmatically usable. +- [11546](https://github.com/vegaprotocol/vega/issues/11546) - Add validation to market proposals metadata. ### 🐛 Fixes - [11521](https://github.com/vegaprotocol/vega/issues/11521) - Restore `AMM` position factor when loading from a snapshot. - [11526](https://github.com/vegaprotocol/vega/issues/11526) - `EstimateAMMBounds` now respects the market's decimal places. - [11540](https://github.com/vegaprotocol/vega/issues/11540) - Fix spam check for spots to use not double count quantum. -- [11542](https://github.com/vegaprotocol/vega/issues/11542) - Fix non determinism in lottery ranking. +- [11542](https://github.com/vegaprotocol/vega/issues/11542) - Fix non determinism in lottery ranking. ## 0.77.5 diff --git a/commands/errors.go b/commands/errors.go index dfdb3fb1174..4ce8df2508d 100644 --- a/commands/errors.go +++ b/commands/errors.go @@ -33,6 +33,7 @@ var ( ErrMustBeLessThan150 = errors.New("must be less than 150") ErrMustBeAtMost1M = errors.New("must be at most 1000000") ErrMustBeAtMost100 = errors.New("must be at most 100") + ErrMustBeAtMost2048 = errors.New("must be at most 2048") ErrMustBeWithinRange7 = errors.New("must be between -7 and 7") ErrIsNotValid = errors.New("is not a valid value") ErrIsNotValidWithOCO = errors.New("is not a valid with one cancel other") diff --git a/commands/proposal_submission.go b/commands/proposal_submission.go index c1abb356d4e..2936dc9a9b0 100644 --- a/commands/proposal_submission.go +++ b/commands/proposal_submission.go @@ -950,6 +950,8 @@ func checkNewSpotMarketConfiguration(changes *vegapb.NewSpotMarketConfiguration) isCorrectProduct := false + errs.Merge(checkMetadata(changes, "new_market.changes")) + if changes.Instrument == nil { return errs.FinalAddForProperty("new_spot_market.changes.instrument", ErrIsRequired) } @@ -1000,9 +1002,32 @@ func checkNewMarketChanges(change *protoTypes.ProposalTerms_NewMarket) Errors { return checkNewMarketChangesConfiguration(change.NewMarket.Changes).AddPrefix("proposal_submission.terms.change.") } +func checkMetadata( + m interface{ GetMetadata() []string }, + pre string, +) Errors { + errs := NewErrors() + + meta := m.GetMetadata() + + if len(meta) > 100 { + errs.AddForProperty(fmt.Sprintf("%s.metadata", pre), ErrMustBeAtMost100) + } + + for i, v := range meta { + if len(v) > 2048 { + errs.AddForProperty(fmt.Sprintf("%s.metadata.%d", pre, i), ErrMustBeAtMost2048) + } + } + + return errs +} + func checkNewMarketChangesConfiguration(changes *vegapb.NewMarketConfiguration) Errors { errs := NewErrors() + errs.Merge(checkMetadata(changes, "new_market.changes")) + if changes.DecimalPlaces >= 150 { errs.AddForProperty("new_market.changes.decimal_places", ErrMustBeLessThan150) }