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

Downtime detector module #3603

Closed
3 tasks done
ValarDragon opened this issue Dec 2, 2022 · 2 comments
Closed
3 tasks done

Downtime detector module #3603

ValarDragon opened this issue Dec 2, 2022 · 2 comments
Assignees

Comments

@ValarDragon
Copy link
Member

ValarDragon commented Dec 2, 2022

Background

For several use cases, we need a module that can detect when the chain is recovering from downtime. We want to be able to efficiently know "Has it been $RECOVERY_PERIOD minutes since the chain has been down for $DOWNTIME_PERIOD", and expose this as a query to contracts.

So for instance, you'd want to know if it has been at least 10 minutes, since the chain was down for > 30 minutes. Since you assume in such an event that it may take ~10 minutes for price oracles to be arb'd to correct.

Suggested Design

Theres a couple designs, such as:

  • Iterating over block times from the last N blocks (with a heuristic filter based on average block time)
    • Implies bounds on recovery time
    • Linear iteration if heuristic is met
    • Requires encoding expected block time
  • Restricting downtime period, and storing a state entry for last time a downtime of length $D occurred

Because this may be in the hot-loop of contracts, I think we need to go with the approach that has minimal query compute, which is the latter. So I'll explain that in more depth.

We restrict the $DOWNTIME_PERIOD options that you can query, to be say 30seconds, 1 min, 2 min, 3 min, 4 min, 5 min, 10 min, 20 min, 30 min, 40 min, 50 min, 1 hr, 1.5hr, 2 hr, 2.5 hr, 3 hr, 4 hr, 5 hr, 6 hr, 9hr, 12hr, 18hr, 24hr, 36hr, 48hr

In the downtime detector module, we store state entries for:

  • Last blocks timestamp
  • For each period, last time there was downtime

Then in every begin block:

  • Store last blocks timestamp
  • if time since last block timestamp >= 30 seconds, iterate through all $DOWNTIME_PERIODS and add a state entry for the current block time

Then our query for has it been $RECOVERY_PERIOD since $DOWNTIME_PERIOD, simply reads the state entry for that $DOWNTIME_PERIOD, and then checks if time difference between now and that block is > RECOVERY_PERIOD.

Acceptance Criteria

  • Downtime detector module exists
  • Has query for RECOVERY_SINCE_DOWNTIME_LENGTH
  • Query is efficient
@osmo-bot osmo-bot moved this to Needs Review 🔍 in Osmosis Chain Development Dec 2, 2022
@ValarDragon ValarDragon mentioned this issue Dec 2, 2022
9 tasks
@ValarDragon ValarDragon self-assigned this Dec 3, 2022
mergify bot pushed a commit that referenced this issue Dec 6, 2022
Sub-component of #3603 

## What is the purpose of the change

Adds types for the thin module intended for downtime detection

## Brief Changelog

- Add downtime detection module types

## Testing and Verifying

No tests added

## Documentation and Release Note

  - Does this pull request introduce a new feature or user-facing behavior changes? somewhat
  - Is a relevant changelog entry added to the `Unreleased` section in `CHANGELOG.md`? yes
  - How is the feature or change documented? In its spec
@ValarDragon
Copy link
Member Author

(Only remaining item for this issue is testing on localosmosis + getting CLI logs)

czarcas7ic pushed a commit that referenced this issue Jan 4, 2023
Sub-component of #3603

Adds types for the thin module intended for downtime detection

- Add downtime detection module types

No tests added

  - Does this pull request introduce a new feature or user-facing behavior changes? somewhat
  - Is a relevant changelog entry added to the `Unreleased` section in `CHANGELOG.md`? yes
  - How is the feature or change documented? In its spec
czarcas7ic added a commit that referenced this issue Jan 5, 2023
…14 (#3925)

* Upgrade IBC to v4.2.0 (#3838)

* initial changes to migrate to ibc v4

* added checksum to proposal

* begin and end block are now being called inside nextBlock

* added changelog

* linked pr on changelog

* remove local replace

* using error acks from osmoutils

* osmoutils tagged

* go sum

* added checksum

* feat(x/twap): modify cli to add geometric option (#3812)

* feat(x/twap): geometric twap code gen query boilerplate

* revert cli change

* query gen

* wire up API

* test

* fix

* fixes

* cli

* lint

* refactor via flag

* refactor

* refactor

* fixes

* lint

* add arithmetic twap alias

* Make wasm hooks importable (#3850)

* moved ibc-hooks to its own go.mod

* updated ibc hooks version

* go sum

* add ics23 patch into x/ibc-hooks

* Fix wasm import version conflict

* Update x/ibc-hooks to osmoutils v0.0.2

* Update versions

Co-authored-by: Dev Ojha <[email protected]>

* refactor(x/twap): handle spot price error case in the context of geometric twap (#3845)

* refactor(x/twap): handle spot price error case

* supporting test cases

* table-driven log tests

* test(x/twap): add randomized geometric twap test on a balancer pool (#3844)

* test(x/twap): add randomized test with a balancer pool

* comments

* multiplicative tolerance, fewer retries and larger initial supply range

* Basic geometric twap e2e test (#3835)

* feat(x/twap): geometric twap code gen query boilerplate

* revert cli change

* query gen

* wire up API

* test

* fix

* fixes

* add geometric queries

* create pool.json

* add test

* resolve conflict

* fix: swap uosmo in

* fix problem with wallet creation

* updates

* simplify and add comments

* Update tests/e2e/e2e_test.go

* Update tests/e2e/e2e_test.go

* Update tests/e2e/configurer/chain/queries.go

Co-authored-by: Adam Tucker <[email protected]>

* Update tests/e2e/configurer/chain/queries.go

Co-authored-by: Adam Tucker <[email protected]>

* Update tests/e2e/e2e_test.go

Co-authored-by: Adam Tucker <[email protected]>

* Update tests/e2e/e2e_test.go

Co-authored-by: Adam Tucker <[email protected]>

* Update tests/e2e/e2e_test.go

Co-authored-by: Adam Tucker <[email protected]>

* Update tests/e2e/e2e_test.go

Co-authored-by: Adam Tucker <[email protected]>

Co-authored-by: Roman <[email protected]>
Co-authored-by: Roman <[email protected]>
Co-authored-by: Adam Tucker <[email protected]>

* feat(x/twap): whitelist GeometricTwap and GeometricTwapToNow (#3852)

* feat(x/twap): GeometricTwap and GeometricTwapToNow queries added to Stargate whitelist

* update docs

* fix(scripts): proto gen for osmoutils (#3854)

* fix(scripts): proto gen for osmoutils

* Update scripts/protocgen.sh

* fix(scripts): proto gen osmoutils path (#3859)

* added packet timeouts to wasm hooks (#3862)

* add negative to cli (#3888)

* Making osmoutils compile on chains that don't use our SDK fork (#3899)

* making osmoutils compile on chains that don't use osmosis' fork of the cosmos sdk

* updated imports for e2e tests

* go fumpt

* updated version everywhere

* added changelog entry

* remove deprecation from arithmetic & geometric twap to now query (#3917)

* Add types & boilerplate for the Downtime detector module (#3609)

Sub-component of #3603

Adds types for the thin module intended for downtime detection

- Add downtime detection module types

No tests added

  - Does this pull request introduce a new feature or user-facing behavior changes? somewhat
  - Is a relevant changelog entry added to the `Unreleased` section in `CHANGELOG.md`? yes
  - How is the feature or change documented? In its spec

* Add downtime detector module (#3688)

* WIP

* Switch to enum

* Remove params query

* Add query

* Add wiring, add import/export test

* Start begin block test

* Finish keeper tests

* Add CLI

* Wire downtime detector CLI + queries

* more module wiring

* add types test

* Fix state alteration test

* Fix superfluid test

* Add stargate whitelist support

* Apply code comment

* Rename folder

* Add requested godoc

* Update x/downtime-detector/genesis.go

Co-authored-by: Adam Tucker <[email protected]>

* Apply adam suggestion for having a `-`

* move genesis test to own file

Co-authored-by: Adam Tucker <[email protected]>

* Initial by hand fixes

* feat(osmomath): Exp2 function (#3708)

* feat(osmomath): exp2 function

* export exp2

* changelog

* refactor ErrTolerance to use Dec instead of Int for additive tolerance

* Update osmomath/exp2.go

* Update osmomath/exp2.go

* Update osmomath/exp2.go

* Update osmomath/exp2_test.go

* Update osmomath/exp2_test.go

* do bit shift instead of multiplication

* godoc about error bounds

* comment about bit shift equivalency

* merge conflict

* improve godoc

* typo

* remove TODOs - confirmed obsolete

* Runge's phenomenon comment

* [x/TWAP] Expose a geometric TWAP API  (#3529)

* refactored twap api.go for geometric TWAP

* added barebon docs

* romans feedback

* new

* fix

* nichola feedback

* final roman comments

* fix twap by hand

* change to gamm

* fix balancer test

* bump to v14 upgrade

* e2e fix

* add remaining diff from main to ibc-rate-limit

* update contracts test

* osmomath: `AddMut` and `QuoMut` (#3779)

* mut add

* test add mut

* quo  mut

* test quo mut/ remove want from test struct

* refactor exp

* change mutatives code

* change

* not allocaing

* exp change to quomut

* remove file

* refactor quo

* refactor ad

* refactor tests

* Modify CHANGELOG

* Whitelist EstimateSwapExactAmountOut (#3693)

* whitelist EstimateSwapExactAmountOut

* doc: changelog

* updated rate limit contract

* Fix rust checks (#3576)

* added cargo.lock

* added Cargo.lock as an artifact

* added new bytecode with lock file

Co-authored-by: Nicolas Lara <[email protected]>
Co-authored-by: Roman <[email protected]>
Co-authored-by: Dev Ojha <[email protected]>
Co-authored-by: Hieu Vu <[email protected]>
Co-authored-by: Roman <[email protected]>
Co-authored-by: Supanat <[email protected]>
Co-authored-by: Dev Ojha <[email protected]>
Co-authored-by: Sishir Giri <[email protected]>
Co-authored-by: Ruslan Akhtariev <[email protected]>
Co-authored-by: mattverse <[email protected]>
Co-authored-by: ByeongSu Hong <[email protected]>
@ValarDragon
Copy link
Member Author

This has been completed

@github-project-automation github-project-automation bot moved this from Needs Review 🔍 to Done ✅ in Osmosis Chain Development Jan 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

1 participant