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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coin Selection Better Coverage + Fix Fee Calculation #196

Merged
merged 4 commits into from
Apr 30, 2019

Conversation

KtorZ
Copy link
Member

@KtorZ KtorZ commented Apr 29, 2019

Issue Number

Overview

  • I have improved coin selection unit tests by also specifying and checking other parts of a coin selection result (i.e. outputs and change)
  • I have added some edge-case unit tests to test coin overflow in some cases
  • I have fixed a wrong strict inequality sign (caught by updated tests)
  • I have fixed a bug in the fee estimation were we were counting the same bytes twice.

Comments

@piotr-iohk This is the best I can do in terms of coverage in a reasonable amount of time. There's still one particular overflow case that is hard to instrument in practice (impossible to meet 馃 ?) but that is there in the code as a safe "gatekeeper" I suppose.

@KtorZ KtorZ requested a review from piotr-iohk April 29, 2019 16:47
+ BS.length bytes
+ sizeOf (CBOR.encodeWord32 $ crc32 bytes)
+ sizeOfCoin c
1 + BS.length bytes + sizeOfCoin c
Copy link
Member Author

Choose a reason for hiding this comment

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

So, turns out those 5 bytes + the crc are already part of the bytes payload! So we don't need to count them twice!

-- We always go for the higher bound for change address payload's size,
-- so, we may end up with up to 4 extra bytes per change address in our
-- estimation.
margin = 4 * fromIntegral (length $ CS.change sel)
realFeeSup = ceiling (a + b*(fromIntegral size + margin))
realFeeInf = ceiling (a + b*(fromIntegral size))
in
property (calcFee >= realFeeInf && calcFee <= realFeeSup)
(calcFee >= realFeeInf && calcFee <= realFeeSup, encodedTx)
=== (True, encodedTx)
Copy link
Member Author

Choose a reason for hiding this comment

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

No change in the test logic here, but we'll now display the full transaction binary representation upon failure which is quite handy for debugging!

mainnetA <- genAddress (39, 43)
testnetA <- genAddress (46, 50)
mainnetA <- genAddress (33, 33)
testnetA <- genAddress (40, 40)
Copy link
Member Author

Choose a reason for hiding this comment

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

This ought to be only the internal payload of the address. So, same confusion as within the fee calculation but, on the generation this time. The error was hard to catch because this one actually compensate for the previous one in the implementation. So, only in rare cases (1 tests out of 33k!), the double-counting would not be compensated by the wrong generation here and trigger an error!

@KtorZ KtorZ self-assigned this Apr 29, 2019
@@ -299,7 +300,7 @@ spec = do

describe "Fee Estimation properties" $ do
it "Estimated fee is the same as taken by encodeSignedTx"
(withMaxSuccess 1000 $ property propFeeEstimation)
(withMaxSuccess 2500 $ property propFeeEstimation)
Copy link
Contributor

Choose a reason for hiding this comment

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

more the merrier :) 馃憤

@KtorZ KtorZ force-pushed the KtorZ/coin-selection-better-coverage branch from 2fea66c to 6f4155b Compare April 30, 2019 06:52
Copy link
Contributor

@piotr-iohk piotr-iohk left a comment

Choose a reason for hiding this comment

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

lgtm 馃憤

@KtorZ KtorZ merged commit 896499e into master Apr 30, 2019
@KtorZ KtorZ deleted the KtorZ/coin-selection-better-coverage branch April 30, 2019 07:43
@paweljakubas paweljakubas mentioned this pull request Apr 30, 2019
parsonsmatt pushed a commit to parsonsmatt/cardano-sl that referenced this pull request May 14, 2019
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.

None yet

2 participants