Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order spam #2188

Open
wants to merge 25 commits into
base: colosseo_II
Choose a base branch
from
Open

Order spam #2188

wants to merge 25 commits into from

Conversation

davidsiska-vega
Copy link
Contributor

@davidsiska-vega davidsiska-vega commented Feb 26, 2024

Aims to address comments from @ze97286 that got missed (by me) on the previous PR here #2180:

  1. "this seems to focus on order submission, what about order amendment?"
  2. "what about pegged orders?"
  3. "maybe I've missed it but I don't see what should happen for a batch transaction?"

close #2097

@davidsiska-vega davidsiska-vega changed the base branch from master to colosseo February 26, 2024 21:50
@@ -89,6 +89,9 @@ Network parameter: `spam.order.MinimalMarginQuantumMultiple` (between 0 and infi

If the maintenance margin for a given transaction is smaller than the parameter `spam.order.MinimalMarginSizeQuantumMultiple`, then the transaction is pre-block rejected.
I.e. if `(rf + linear slippage param) x size x price < spam.order.MinimalMarginSizeQuantumMultiple x asset quantum amount` then the order is rejected. Here `rf` is the risk factor (and will be different for long and for short) `linear slippage param` is a market parameter and `size` and `price` are assumed to be correctly scaled by, PDPs and MDPs respectively.
- For peg orders we check the `price` implied by the peg and the book at submission time.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if the peg doesn't exist?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and during an auction.

@davidsiska-vega davidsiska-vega marked this pull request as ready for review February 27, 2024 12:43
Copy link
Contributor Author

@davidsiska-vega davidsiska-vega left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check that `general + margin > 0' (after checking pow) but before any of these more fancy checks.

protocol/0062-SPAM-spam_protection.md Outdated Show resolved Hide resolved
protocol/0062-SPAM-spam_protection.md Outdated Show resolved Hide resolved
davidsiska-vega and others added 4 commits February 28, 2024 17:52
Co-authored-by: Charlie <99198652+cdummett@users.noreply.github.com>
Co-authored-by: Charlie <99198652+cdummett@users.noreply.github.com>
@@ -85,19 +85,28 @@ Further, each party is allowed to submit up to `n` transactions per epoch where

### Transaction Spam

Before any order or liquidity commitment is accepted for a perpetual futures or expiring futures check that the party has `margin + general > 0` with `margin` being the balance in the margin account for the relevant market and `general` the balance in the general account for the relevant asset. Orders from parties that don't meet this criteria are rejected. This is to be done after the PoW check.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to account for order margin I'd imagine too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please have a look again after the recent edit.

@davidsiska-vega davidsiska-vega changed the base branch from colosseo to colosseo_II May 1, 2024 09:52
@davidsiska-vega davidsiska-vega marked this pull request as ready for review May 1, 2024 09:59
@davidsiska-vega davidsiska-vega marked this pull request as draft May 1, 2024 09:59
@davidsiska-vega davidsiska-vega changed the title Fix/order spam amendments etc Order spam May 1, 2024
@cdummett cdummett force-pushed the fix/order-spam-amendments-etc branch from 7e014c5 to 0e11ca0 Compare May 10, 2024 10:37
@cdummett cdummett marked this pull request as ready for review May 10, 2024 10:38
@cdummett cdummett dismissed their stale review May 10, 2024 10:39

Dismissing previous approval as content added for spot markets.


The following points apply generally to both derivative and spot markets:

- Non-persistent orders are not blocked by the mechanisms described above as long as the market exists.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly do we mean by this? Is it that market orders are not subject to the minimum size checks? @cdummett

ze97286
ze97286 previously approved these changes May 14, 2024

Further, given the network parameter: `spam.order.minimalMarginQuantumMultiple` (between 0 and infinite)

If the maintenance margin for a given transaction is smaller than the parameter `spam.order.minimalMarginQuantumMultiple`, then the transaction is pre-block rejected.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there will be cases where margin + order margin could be 0, but the transaction should still be accepted. I'm thinking, especially, about cases where a party has a general balance of 0, and margin balance < initial margin, but >= maintenance level (ie they're close to getting closed out). They might want to submit a transaction closing their current position. In that case the maintenance level for the given transaction == 0.

As per an exceptionally long thread on slack, there are also cases, specifically when dealing with capped futures, where the margin requirement for an order can be 0. This will, most likely cause such orders to be rejected as a rule.

To this end, I think it makes more sense for the markets themselves to receive a call to a function like OrderAcceptanceLikelihood, which the order spam component keeps track of over time. Should a given party submit N orders that are below 50% likely to get accepted over the course of N blocks, any order transaction that is less than 50% likely to get accepted should get rejected.

The benefits are that individual markets can determine whether or not, in the context of that market, an order makes more or less sense, and therefore should or should not be accepted, without relying on a single network parameter. Because we can keep a tally of these transaction types over time, we could also adjust the threshold for rejection/acceptance of any given transaction on a per-party basis, based on their behaviour. A party that submits, say, a zero-margin order to a capped market once isn't a worry as such. A party doing so every block, or several times per block, may see their order acceptance threshold increased to 75%, or even 100% (effectively timing them out for N blocks).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Order spam: margin required for an order is checked to be greater than a network parameter
6 participants