fix(db): order swap_states correctly#1046
Open
Einliterflasche wants to merge 1 commit into
Open
Conversation
`entered_at` is stored via `OffsetDateTime::Display`, whose `Time` format string does not zero-pad the hour. Timestamps with a single-digit hour (`9:43:54...`) therefore lex-sort *after* same-day two-digit-hour timestamps (`16:04:20...`), corrupting `MIN`/`MAX(entered_at)` for any swap that crosses 10:00. Switch `all_paginated` and `get_swap_start_date` to use the monotonic `id` column for ordering. `entered_at` is still returned as the display value via SQLite's bare-column-with-aggregate rule. Symptom: `get_swaps` RPC logs "Skipping swap with unexpected state history" once per poll for any Alice swap whose first persisted state landed before 10:00 UTC.
4024420 to
d7fa69d
Compare
|
Did you change this to order by date in the recent PR? |
Author
|
Yes. We did not do any ordering before then. The wormhole freshness calulcation uses order by datetime too, which I changed to order by ID as well. |
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.
When trying to chronologically order the states of a swap we used to just do
MIN(entered_at)which ordered lexicographically. But our currentfn insert_latest_stateproduces a format where the lexical order does not equal the chronological order. Thus this leads to confusion and swaps not being shown in get_swaps.This PR changes this to use the monotically increasing
idfield instead. Migrating the old format to a better one (like RFC3339) is not possible without string formatting magic which I do not feel comfortable with.As an extension of this
fn all_freshis buggy as well. The actual format doesn't zero-pad the hour slot, so the length isn't always 19 but only 18 when the time is before noon.