feat(twap): precise polling hints for watch towers#3
Draft
brunota20 wants to merge 1 commit into
Draft
Conversation
`TWAP.getTradeableOrder` now reverts with the precise polling errors
already defined on `IConditionalOrder` instead of the generic
`OrderNotValid("not within span")` / `"before twap start"` /
`"after twap finish"`:
- Pre-`t0`: `PollTryAtEpoch(t0, "before first part")`
- Post total span: `PollNever("all parts settled")`
- Between parts of an in-progress TWAP:
`PollTryAtEpoch(nextPartStart, "between parts")`
`validate()` is invoked up-front so invalid configurations still revert
with their original `OrderNotValid(...)` reasons. `OrderNotValid(NOT_WITHIN_SPAN)`
is kept as a defensive fallback (should be unreachable).
Watch towers gain the ability to:
- Stop polling between parts (retry exactly at the next part's start).
- Drop finished TWAPs from their watch set without trial-and-error.
- Skip pre-`t0` polling and wake up only when needed.
Addresses M2 grant deliverable "enhanced polling interfaces" for the
TWAP handler.
35efd03 to
5b0c15d
Compare
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
TWAP.getTradeableOrdernow reverts with the precise polling errors fromIConditionalOrderinstead of the genericOrderNotValid("not within span")(and the transitiveOrderNotValid("before twap start")/"after twap finish"raised insideTWAPOrderMathLib.calculateValidTo):t0(before the first part starts):PollTryAtEpoch(t0, "before first part")PollNever("all parts settled")PollTryAtEpoch(nextPartStart, "between parts")validate()is invoked up-front so invalid bundle configurations still revert with their originalOrderNotValid(INVALID_*)reasons (no taxonomy change there).OrderNotValid(NOT_WITHIN_SPAN)is kept as a defensive fallback (should be unreachable).Why
The
PollTryAtEpoch/PollNevererrors exist inIConditionalOrderspecifically for watch towers to optimise polling, butTWAP.solnever used them. Watch towers (CoW DAO WatchTower + our Shepherd implementation) currently have to either poll every block (wasteful) or build out-of-band logic to know when the next part starts (e.g. our COW-1077_twap_calldata.pyhelper that pinst0 = now-60).With the precise hints, watch towers stop polling between parts entirely and remove finished TWAPs from their watch set without trial-and-error.
Backward compatibility
PollTryAtEpochandPollNeverare pre-existing errors already on theIConditionalOrderinterface — no interface change.OrderNotValidcontinue to function: they will see an unknown revert and treat it as "skip this watch this block", same defensive behavior as today (no order is silently surfaced as valid).test_getTradeableOrder_FuzzRevertIfBeforeStart,_FuzzRevertIfExpired,_FuzzRevertIfOutsideSpan, the cabinet-based variants, and thetest_simulate_fuzzcatch block were updated to expect the new (more informative) errors — these are internal regression tests, not downstream consumers.Tests
4 new tests in
ComposableCoW.twap.t.solcovering the three new branches plus a regression for the in-window case:test_twap_reverts_with_PollTryAtEpoch_before_t0test_twap_reverts_with_PollNever_after_total_spantest_twap_reverts_with_PollTryAtEpoch_between_partstest_twap_existing_within_span_behavior_unchangedFull suite: 78/78 pass (excluding the pre-existing
_invariantandtest_simulate_fuzzflake — the latter is an OOG counterexample present onmainbefore this PR, unrelated to polling-hint changes; passes with reduced fuzz runs).Closes
Addresses the "enhanced polling interfaces" for the TWAP handler.