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
client/assets: add feeRate sanity check for swaps and minor refactoring #2060
Conversation
bd49a32
to
e7da7c9
Compare
if swaps.FeeRate == 0 { | ||
return nil, nil, 0, fmt.Errorf("cannot send swap with with zero fee rate") | ||
} |
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.
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.
Yes, we can do that and save a few LOC. I initially assumed the check would be better at the asset level.
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.
I don't have a problem with it in both places TBH, but core also shouldn't request impossible swaps.
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.
I don't have a problem with it in both places TBH
I left the check at the asset level as an extra precaution, since it is very crucial to the swap process. Or do we really want to remove the check from the asset level? @chappjc
It seems the new check is effective. https://github.com/decred/dcrdex/actions/runs/3988636125/jobs/6840053009
2023-01-23 16:54:39.188 [ERR] TCORE: somedex.tld:7232 tick error: somedex.tld:7232 tick: {swapMatches order b2c0e3807fc2b2819a125b672c7bea91c991b2f8d5cf74e338332fd72f6415d9 - {swap cannot proceed with a zero fee rate}}
[1547](https://github.com/decred/dcrdex/actions/runs/3988636125/jobs/6840053009#step:5:1548)
2023-01-23 16:54:39.188 [ERR] TCORE: Error fetching fee rate for btc: no handler for route "fee_rate"
[1548](https://github.com/decred/dcrdex/actions/runs/3988636125/jobs/6840053009#step:5:1549)
panic: test timed out after 10m0s
[1549](https://github.com/decred/dcrdex/actions/runs/3988636125/jobs/6840053009#step:5:1550)
1550 |
Haha, yes it seems. But let's fix the tests that neglect to set a fee rate to use for these fake swaps. Changing the product code to use MaxFeeRate if the server prescribes zero and the wallet gives zero doesn't feel right. |
But does it mean we don't need to set the fee rate to MaxFeeRate if the server and wallet returned zero? |
Not sure, but it's rather questionable to fall back to MaxFeeRate. If we're getting no informed fee rate from any source, what does that mean? Is the server working? Is the swap even going to negotiate? Will the BTC swap cost a fortune? Will the problem clear up after retrying after some time? Backing up further, when we first get the I'm not positive what's best right now, but the red flag can be seen much earlier. |
Right, this is one thing am not so sure about but It makes sense to reject swaps with a zero fee rate atm if defaulting to MaxFeeRate in this scenario is questionable. Input from others would be valuable @buck54321, @martonp.
Removed in db40c8d |
If we are unable to get a fee rate from either of the sources, I say we shouldn't be proceeding. The server is clearly malfunctioning, and we also don't have a good connection to the network. |
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.
Ok, but I think in the future we'll just wanna block acceptance of such matches early on in (*dexConnection).parseMatches
. With this PR we won't make an impossible swap txn, but we may retry until revoke as @JoeGruffins pointed out, or we'll use our own rates in a situation where we know the server is misconfigured / match data is invalid.
@ukane-philemon To merge, will you prep this branch by squashing the review fixes into the "sanity check" commit, keeping the |
dc8e957
to
24d309d
Compare
Resolves #1585.