The sequence number, on chain
Every market account storeslast_seqno, the sequence number of the most
recent accepted update_mid call. Each update_mid instruction carries its
own incoming sequence number, and the program only accepts it if that number
is strictly greater than the one already stored.
This matters because a maker’s reprice transactions are not guaranteed to
land in the order they were sent. A transaction can be dropped and retried,
or simply arrive late. Without a check, a late transaction carrying an old
mid price could land after a newer one and silently roll the book back to a
stale price, which is exactly the opening a sniping bot would want. With the
check, that late transaction is rejected instead: the book’s price can only
ever move forward in sequence, never backward.
This check is cheap enough to live entirely in the hand-written assembly
behind update_mid, alongside checks that the new mid is non-zero and that
the caller is the market’s authority. The whole instruction, including the
sequence number check, runs in 33 compute units.
The sequence number also marks time for the same-slot flow protection
described on the Matching Engine page: the
amount of flow that curve has seen is only ever counted since the current
sequence number, so it resets to zero the instant a maker reprices.

