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

Use tx max size & estimator to figure out the right input upper-bound in coin selection #536

Merged
merged 2 commits into from
Jul 15, 2019

Conversation

KtorZ
Copy link
Member

@KtorZ KtorZ commented Jul 12, 2019

Issue Number

#462

Overview

  • I have added a new parameter txMaxSize to BlockchainParameter
  • I have used this and estimateMaxNumberOfInputs from the transaction layer to replace the hard-coded max number of inputs with a number that's actually relevant.

Comments

@KtorZ KtorZ requested a review from paweljakubas July 12, 2019 14:41
@KtorZ KtorZ self-assigned this Jul 12, 2019
| otherwise =
return (opt, inps, utxo)
return (maxN, inps, utxo)

Copy link
Member Author

Choose a reason for hiding this comment

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

Note that most of the changes in this file are because the type for the maxN in the coin selection options was changed from Word64 to Word8 -> Word8. Therefore, the actual maxN is now computed in the root random (or largestFirst function, and passed down to the iteration function as a Word64 to be depleted.

coinSelOpts :: CoinSelectionOptions (ErrValidateSelection t)
coinSelOpts = CoinSelectionOptions
{ maximumNumberOfInputs = 10
{ maximumNumberOfInputs = estimateMaxNumberOfInputs tl txMaxSize
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

let n = fromIntegral $ maximumNumberOfInputs opt
let nLargest = take n . L.sortBy (flip $ comparing (coin . snd)) . Map.toList . getUTxO
let nOuts = fromIntegral $ NE.length outs
let maxN = fromIntegral $ maximumNumberOfInputs opt (fromIntegral nOuts)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

-- there's also a soft-limit of 8kb which results in much smaller transactions
-- in the end.
softTxMaxSize :: Quantity "byte" Word16
softTxMaxSize = Quantity 8192
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@paweljakubas paweljakubas merged commit 1d6a19c into master Jul 15, 2019
@paweljakubas paweljakubas deleted the KtorZ/462/enable-max-input branch July 15, 2019 08:11
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 this pull request may close these issues.

3 participants