Skip to content

Commit

Permalink
Merge pull request #11547 from vegaprotocol/feature/metadatas
Browse files Browse the repository at this point in the history
feature: add validation on market proposals metadata
  • Loading branch information
jeremyletang authored Aug 8, 2024
2 parents 6ee7627 + 83f182a commit 750a0ef
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions commands/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
25 changes: 25 additions & 0 deletions commands/proposal_submission.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 750a0ef

Please sign in to comment.