Skip to content

fix(db): order swap_states correctly#1046

Open
Einliterflasche wants to merge 1 commit into
masterfrom
fix/asb-rpc-sort-swap-states
Open

fix(db): order swap_states correctly#1046
Einliterflasche wants to merge 1 commit into
masterfrom
fix/asb-rpc-sort-swap-states

Conversation

@Einliterflasche
Copy link
Copy Markdown

@Einliterflasche Einliterflasche commented May 21, 2026

When trying to chronologically order the states of a swap we used to just do MIN(entered_at) which ordered lexicographically. But our current fn insert_latest_state produces 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 id field 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_fresh is 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.

`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.
@Einliterflasche Einliterflasche force-pushed the fix/asb-rpc-sort-swap-states branch from 4024420 to d7fa69d Compare May 21, 2026 23:03
@Einliterflasche Einliterflasche changed the title fix(db): order swap_states by id, not entered_at fix(db): order swap_states correctly May 21, 2026
@binarybaron
Copy link
Copy Markdown

Did you change this to order by date in the recent PR?

@Einliterflasche
Copy link
Copy Markdown
Author

Einliterflasche commented May 22, 2026

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants