osmosis icon indicating copy to clipboard operation
osmosis copied to clipboard

Simulator: Property checks

Open ValarDragon opened this issue 3 years ago • 0 comments

Background

This issue discusses implementation details for "Property Checks", a suggested abstraction over the legacy SDK invariants.

The goal of a property check is to be able to verify properties of the state machine, during these complex simulation runs. There are a couple dimensions the property checks should abstract over:

  • "Memoryless" (AKA legacy invariants) - Just look at the current state, and run some consistency checks. If consistency check fails, error. E.g. "No account has a negative balance"
  • Memoried - The checker can maintain state from its prior invokations. (So it can tell that a quantity that is only increasing, is in fact only increasing)

Triggers:

  • We want to be able to trigger an event before and after certain message types are executed
    • In a first pass, we maybe just architect around before/after an action, and pass the message blob through. TBD
  • Trigger an event after any action
  • Trigger an event at beginning and end block.

Suggested Design

I suggest a "pub sub" model of for the property checks. We have the simualtor "publish" events to an "event bus" struct. We have the simulator take in property checks, that each register "subscriptions". The simualtor handles putting those subscriptions onto the "event bus" struct as well.

To be honest, I think this is the correct answer for hooks should be designed everywhere in the SDK, and I suggest we use this as a demo to showcase a much cleaner way to rewrite hooks.

Acceptance Criteria

  • [ ] Property check written into new simulator
  • [ ] Property check written for CFMM k only increasing between swaps & join pools. (And handling exit pools)
  • [ ] Property check from legacy invariant
    • [ ] We will want to amend to give more fine-grained subscription control as well, but can be later.
  • [ ] Actions trigger pre and post events

ValarDragon avatar Jul 18 '22 03:07 ValarDragon