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

fix(swapclients): check capacity up front #901

Merged
merged 3 commits into from
Apr 24, 2019
Merged

Conversation

sangaman
Copy link
Collaborator

Fixes #900.

This fixes a bug where the capacity for swap clients is thought to be 0 upon initialization. The checks to update the capacity happen on an interval but not right away. This adds logic to check the capacity immediately.

This disables the nosanitychecks flag for the simulation tests, which will catch this bug should it regress.

I also refactored some of the logic for setting and clearing the reconnection timer since some of that code overlapped with the fix.

This fixes a bug where the capacity for swap clients is thought to be 0
upon initialization. The checks to update the capacity happen on an
interval but not right away. This adds logic to check the capacity
immediately.

Fixes #900.
@sangaman sangaman added bug Something isn't working automated tests swaps labels Apr 18, 2019
@sangaman sangaman requested review from a user, offerm and moshababo April 18, 2019 20:51
@ghost ghost assigned sangaman Apr 18, 2019
@ghost ghost added the in progress label Apr 18, 2019
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.

Thank you for taking care of this bug. Also very excited to have our simulation tests run with sanity checks/swaps enabled. Looks good in general - left some comments/thoughts.

@@ -321,6 +311,7 @@ class RaidenClient extends BaseClient {
* Returns the total balance available across all channels.
*/
public channelBalance = async (): Promise<ChannelBalance> => {
// TODO: refine logic to determine balance per token rather than all combined
Copy link

Choose a reason for hiding this comment

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

Ugh... this is a nice catch.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah just thought I'd make note of it. It's OK for now but eventually we'd want to know the breakdown.

INSUFFICIENT_OUTBOUND_BALANCE: (currency: string, amount: number) => ({
message: `${currency} does not have sufficient outbound balance of: ${amount}`,
INSUFFICIENT_OUTBOUND_BALANCE: (currency: string, amount: number, availableAmount: number) => ({
message: `${currency} outbound balance of ${availableAmount} is not sufficient for order amount of ${amount}`,
Copy link

Choose a reason for hiding this comment

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

Really like the more detailed error message :)

@@ -50,7 +51,6 @@ func (cfg nodeConfig) genArgs() []string {
var args []string

args = append(args, "--initdb=false")
args = append(args, "--nosanitychecks=true")
Copy link

Choose a reason for hiding this comment

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

It's great that we get to test sanity checks and swaps now with simulation tests.

@sangaman sangaman force-pushed the fix/capacity-checks branch from 912a2d5 to 41833e3 Compare April 19, 2019 13:13
This moves the logic to enable or clear the reconnection timer for
swap clients to the `setStatus` method. This ensures we enable the timer
any time we are disconnected and disable the timer when our connection
is verified.
@sangaman sangaman force-pushed the fix/capacity-checks branch from 41833e3 to 87f257b Compare April 20, 2019 00:19
if (!this.reconnectionTimer) {
this.reconnectionTimer = setTimeout(this.verifyConnection, BaseClient.RECONNECT_TIMER);
} else {
this.reconnectionTimer.refresh();
Copy link

Choose a reason for hiding this comment

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

If we decide to use the refresh API we'll also have to update the:
mininum required nodejs version to >=v10.2.0 and make sure we also update our simnet etc. machines. Using an older version of nodejs will crash my xud process. Otherwise the fix is working fine.

Copy link

Choose a reason for hiding this comment

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

Alternative solution (uglier, but less work) would be to just clear the timeout before setting a new one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right although I'm OK with going to node 10 as the minimum version, given that 8 is only going to be maintained through the end of the year. I'll open another PR to update the minimum version in package.json.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I actually just went ahead and put it in this PR.

This raises the minimum Node.js version to support the `timeout.refresh`
function.
@sangaman sangaman merged commit a5354df into master Apr 24, 2019
@ghost ghost removed the in progress label Apr 24, 2019
@sangaman sangaman deleted the fix/capacity-checks branch April 24, 2019 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automated tests bug Something isn't working swaps
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong verification
1 participant