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

client/core: Only check for fees when they are definitely available #2062

Merged
merged 3 commits into from Jan 30, 2023

Conversation

martonp
Copy link
Contributor

@martonp martonp commented Jan 21, 2023

The fee checks for dynamic fee assets were happening many times before the transaction was confirmed, unnecessarily slowing the ticks down.

The fee checks for dynamic fee assets were happening many times before
the transaction was confirmed, unnecessarily slowing the ticks down.
client/core/trade.go Outdated Show resolved Hide resolved
@chappjc chappjc added this to the 0.6 milestone Jan 22, 2023
@chappjc chappjc added the ETH label Jan 22, 2023
Comment on lines 1390 to 1393
return match.Status >= order.MakerSwapCast
return match.Status > order.MakerSwapCast || (match.Status == order.MakerSwapCast && mine > 1)
Copy link
Member

Choose a reason for hiding this comment

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

Why not...

return match.Status >= order.MakerSwapCast && mine > 0

Copy link
Member

Choose a reason for hiding this comment

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

Unless I'm mistaken the confirms() value is all that matters now. If it's confirmed, does it matter what the match status is?

Copy link
Contributor Author

@martonp martonp Jan 23, 2023

Choose a reason for hiding this comment

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

The reason I did it like this is the confirmation updates seemed very irregular using the MultiRPC. On Etherscan I would see many confirmations while still showing 0 in the dex client. I was worried that maybe in some case setSwapConfirms would not be called.

How about

    return match.Status > order.MakerSwapCast || mine > 0

Copy link
Member

@chappjc chappjc Jan 24, 2023

Choose a reason for hiding this comment

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

On Etherscan I would see many confirmations while still showing 0 in the dex client. I was worried that maybe in some case setSwapConfirms would not be called.

In this case, surely the dynamic fee check would also fail to find it on the chain?

EDIT: I now see your point that it might never say >0 from confirms(). #2062 (comment)

@@ -1386,10 +1386,13 @@ func (t *trackedTrade) checkSwapFeeConfirms(match *matchTracker) bool {
// Confirmed will be set in the db.
return true
}
// Waiting until the swap is definitely confirmed in order to not
// keep calling the fee checker before the swap is confirmed.
mine, _ := match.confirms()
Copy link
Member

Choose a reason for hiding this comment

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

A more descriptive variable would be nice. mySwapConfs or something.

Comment on lines 1409 to 1414
if match.Side == order.Maker {
return match.Status >= order.MakerRedeemed
}
// Checking taker redemption fees might be a bit early, but there will be
// no more ticks after the status is set to MatchConfirmed.
return match.Status >= order.MatchComplete
Copy link
Member

Choose a reason for hiding this comment

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

It's not clear what the intention is here. For maker, the difference between MakerRedeemed and MatchComplete is just a successful sendRedeemAsync, which should come immediately after the status is set to MakerRedeemed anyway, and seems unrelated to whether or not we want to check confirmations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah you're right, this change is unnecessary. For the redemption I don't think there's anything we can do due to the irregular confirmation updates I mentioned #2062 (comment) . If one updates takes us from 0 to 10, and the status is set to MatchConfirmed, tick will no longer run. Unless we update matchIsActive to take into account these fees.

Copy link
Member

@chappjc chappjc Jan 24, 2023

Choose a reason for hiding this comment

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

I believe this (keeping as-is on master for the redeem) is fine since unlike with the swap transactions, there should be no delays after the maker broadcasts their redeem txn.

if match.Side == order.Maker {
return match.Status >= order.MakerSwapCast
return match.Status > order.MakerSwapCast || mySwapConfs > 0
Copy link
Member

Choose a reason for hiding this comment

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

Why > instead of >=? Why should maker wait to see the taker's swap before checking for fees on its own swap?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not waiting, if the maker's swap has 1 confirmation, this will return true. If we put >=, then this will constantly check before it's ready, unnecessarily holding up tick.

The match.Status > order.MakerSwapCast is there just to be conservative in case the swap confirms doesn't get updated. We are not strictly tracking the confirmations on the swap transaction, and due to the irregular way the confirmations were coming in when testing on testnet, I thought this would be safer.

Copy link
Member

Choose a reason for hiding this comment

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

We are not strictly tracking the confirmations on the swap transaction, and due to the irregular way the confirmations were coming in when testing on testnet, I thought this would be safer.

Hmm, that's an interesting point. I suppose there can be a case where no tick gets your own swap's confirms before moving on to the next status, which could preclude the confs check.

OK, I think this is safest since tick does not make explicit guarantees about this.

Actually, I think the counter party could even make their transaction without waiting for a single confirmation on ours. Nothing stopping that.

@chappjc chappjc merged commit f4a0fec into decred:master Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants