-
Notifications
You must be signed in to change notification settings - Fork 95
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
swapper resume from db #856
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made a lot of orders and swaps, suspending and just closing the server at different steps, then comparing the orderbooks and matches returned by the admin console, all returns with expected values. Am able to continue trading. Matches completed while the market is down are updated when it comes back online. Can't find anything wrong. And wow is the webserver ui easy to use now. Holy crap. DEX is legit.
Just a comment that the second commit (0e5c64b) is only touching on a mostly-unrelated can of worms. That is, the init and redeem requests sent by the client are synchronous, blocking in |
0e5c64b
to
7c5ea7b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+803 −1,237
Nice. So much cleaner now and roles are much clearer.
server/swap/swap.go
Outdated
// Load the maker's order.LimitOrder and taker's order.Order. | ||
taker, _, err := s.storage.Order(sd.MatchData.Taker, sd.Base, sd.Quote) | ||
if err != nil { | ||
log.Errorf("Failed to load taker order: %v", err) | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noting that this is a departure from normal because the Order
we'll be tracking in Swapper
is not backed by the same underlying being tracked in Market
. Is that okay? I think the only thing we'd need to worry about is if we were somehow relying on the Filled/Remaining
quantities to remain accurate, and a quick scan seems to say that we are not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, good catch and it's part of why it's better that market is back in charge of order status fully again. I will certainly make a note about the caveat you identified and have a scan myself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turned out that (*Market).SwapDone
was calling Remaining()
. Fortunately since it's in Market, we don't have to infer based on type/force/fill because we can just do Book.HaveOrder(oid)
, so that was an easy fix.
Probably safest would be not to have an order.Order
as an argument, and instead pass a whole bunch of separate data (ID, type, force, base, quote, user), but we'd need to hack together an Order anyway to use the coin unlocking and storage functions and I think that's even more error prone. We're returning to the idea of a FilledOrder
that adds the annoying Filled/Remaining stuff so that the order.Order type can be immutable.. Maybe in the future. It's a big change to do right.
31246ba
to
28390e3
Compare
I reverted the commit "client/comms: expire response handlers on reconnect" because it was only appropriate for reconnects where the server had restarted, not for when a reconnect was just a connection issue. This is because authenticated requests handlers (or their child goroutines) will respond via So instead of expiring response handlers client-side, I just changed the request timeout used for the |
This reverts commit 8740139.
491cbad
to
72ba04f
Compare
This removes the swap state gob files, loading necessary from DB on Swapper startup.
server/db
Add
SwapArchiver.ActiveSwaps
(impl. by(*Archiver).ActiveSwaps
) to retrieve full details of all active swaps across all markets.Swapper
's constructor uses this to resume active swaps.Remove all the swap state hash get/set functions.
The
meta
table and it'sstate_hash
column still exist, but I think I'm going to entirely drop this table and follow up with a PR that re-adds the meta table with a versioning scheme.server/swap
Rip out:
orderSwapTracker
, which was used to infer order "completion" for the cancellation rate computations. The market now has these order fill/settlement/success responsibilities. AswapDone
callback is provided to theSwapper
from the consumer (DEX manager) to do this.offBook
argument ofNegotiate
, which was used with theorderSwapTracker
junk.The Swapper constructor now loads all active matches from the DB and reconstructs all of the
matchTrackers
. This uses the newBackend.CoinConfTime
method for theSwapConfirmTime
, which is not stored in the DB. The match request time field ofmatchTracker
is also not recorded, so this is guessed on resume as the epoch close time plus a minute, which at worst gives the maker a little extra breathing room when resuming inNewlyMatched
status.server/market
Assume the responsibility of deciding when an order is successfully "completed" as per the cancellation rate definition. This is facilitated by the
SwapDone
method that the DEX manager bridges with theSwapper
.The
SwapDone
method also performs the same unbooking that the Swapper previous requested via theunbookHook
, now removed.server/dex
Remove the unbook hook, replacing it with a
swapDone
dispatcher.server/auth
Sign
no longer returns an error since the secp256k1 changes recently eliminated the error return.