Skip to content
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

feat(swap): persist active swap deals to db #1080

Merged
merged 1 commit into from
Aug 5, 2019

Conversation

sangaman
Copy link
Collaborator

@sangaman sangaman commented Jul 5, 2019

This commit persists the state of swap deals to the database upon each phase change once a deal has been accepted to. This is done to be able to prevent loss of funds and recover gracefully from any active swaps should xud crash unexpectedly.

This is the first step towards closing #1079.

I wound up leaving the existing phases as is, and just updated the comments instead and renamed SwapAgreed to SwapAccepted to align with our terminology elsewhere. I started adding separate phases for maker/taker but it would've required changing quite a few lines of code, and ultimately for recovery purposes we can determine the precise state by looking at both phase and role.

@sangaman sangaman added swaps database Database related issues labels Jul 5, 2019
@sangaman sangaman requested review from a user and kilrau July 5, 2019 18:25
@sangaman sangaman self-assigned this Jul 5, 2019
@sangaman sangaman force-pushed the swaps/persist-active-deals branch from c98fcdc to 7430641 Compare July 5, 2019 18:42
@sangaman sangaman force-pushed the swaps/persist-active-deals branch from 7430641 to 9352ddc Compare July 8, 2019 16:04
@kilrau
Copy link
Contributor

kilrau commented Jul 23, 2019

Test: what if writing to db fails - what's the behavior? Definitely swap should be failed.

@kilrau
Copy link
Contributor

kilrau commented Aug 1, 2019

needs your review @erkarl

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with minor nits. Also tested the swaps manually.

lib/constants/enums.ts Outdated Show resolved Hide resolved
lib/swaps/Swaps.ts Outdated Show resolved Hide resolved
@sangaman sangaman force-pushed the swaps/persist-active-deals branch from 9352ddc to 7f63743 Compare August 5, 2019 05:59
This commit persists the state of swap deals to the database upon each
phase change once a deal has been accepted to. This is done to be able
to prevent loss of funds and recover gracefully from any active swaps
should `xud` crash unexpectedly.

This is the first step towards closing #1079.
@sangaman sangaman force-pushed the swaps/persist-active-deals branch from 7f63743 to 1a0692b Compare August 5, 2019 06:05
@sangaman sangaman merged commit 3514852 into master Aug 5, 2019
@ghost ghost deleted the swaps/persist-active-deals branch August 5, 2019 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database Database related issues swaps
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants