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/{dcr,btc}: maxOrder loop needs to be a binary search #2589

Closed
buck54321 opened this issue Nov 2, 2023 · 0 comments · Fixed by #2634
Closed

client/{dcr,btc}: maxOrder loop needs to be a binary search #2589

buck54321 opened this issue Nov 2, 2023 · 0 comments · Fixed by #2634

Comments

@buck54321
Copy link
Member

With the new trade limits implementation, lot sizes can be thousands of times smaller than what we're used to dealing with. Our current maxOrder implementation does some rough estimation, and then zones in on the exact max order by looping with a lots-- until it finds the value. This is a bad idea if lot sizes are really small. Instead, we should do a binary search.

dcrdex/client/asset/btc/btc.go

Lines 1874 to 1885 in 6a12553

for lots > 0 {
est, _, _, err := btc.estimateSwap(lots, lotSize, feeSuggestion, maxFeeRate,
utxos, true, 1.0)
// The only failure mode of estimateSwap -> btc.fund is when there is
// not enough funds, so if an error is encountered, count down the lots
// and repeat until we have enough.
if err != nil {
lots--
continue
}
return utxos, est, nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant