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

simplify implementation of 'estimateMaxNumberOfInputs' & increase coverage #2112

Merged
merged 3 commits into from
Sep 8, 2020

Conversation

KtorZ
Copy link
Member

@KtorZ KtorZ commented Sep 4, 2020

Issue Number

#2051

Overview

  • I've added scenarios for Byron and Icarus keys
  • I've added a 'within' clause to some scenarios in order to make sure that the properties are executed within a reasonable time.

Comments

This didn't really improve execution time significantly, but it is still useful to keep.

@KtorZ KtorZ requested a review from Anviking September 4, 2020 08:52
@KtorZ KtorZ self-assigned this Sep 4, 2020
@KtorZ KtorZ added the IMPROVEMENT Mark a PR as an improvement, for auto-generated CHANGELOG label Sep 4, 2020
@KtorZ KtorZ force-pushed the KtorZ/2051/investigate-slow-fee-estimation branch from 7c6e87e to 8df8b86 Compare September 4, 2020 08:56
Copy link
Collaborator

@Anviking Anviking left a comment

Choose a reason for hiding this comment

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

Looks good; a few comments

upperBound_ !n | isTooBig n = n
| otherwise = upperBound_ (n*growingFactor)
findMax :: Word8 -> Word8
findMax inf
Copy link
Collaborator

@Anviking Anviking Sep 4, 2020

Choose a reason for hiding this comment

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

findMax minBound first looks deceptively simple... until you start looking at it. Can we give give an overview about what is going on here? E.g. Find the largest amount of inputs that doesn't make the tx too big. Tries in sequence from 0 and upward.

Also, btw, why did you decide to remove the bisection? Just simplicity?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also I think it might make sense to take the condition explicitly (see other comment).

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, btw, why did you decide to remove the bisection? Just simplicity?

I originally suspected that the bisection could have been causing some slowness, taking to long to find a fix point. I actually measured the time and observed some very long delays until I realized I was measuring the wrong thing. In the meantime, I had changed the implementation to findMax which turned out to be slightly master but also much simpler so I kept it.

| otherwise = upperBound_ (n*growingFactor)
findMax :: Word8 -> Word8
findMax inf
| inf == maxBound = 0
Copy link
Collaborator

@Anviking Anviking Sep 4, 2020

Choose a reason for hiding this comment

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

What does inf == maxBound mean? If 1 input would be too much, findMax 0 should return 0. But it also returns 0 if all possibilities pass? That seems like an error. (If the max tx size is really big...)

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually you're right, this should just return maxBound 👍

findMax inf
| inf == maxBound = 0
| isTooBig (inf + 1) = inf
| otherwise = findMax (inf + 1)

isTooBig nInps = size > fromIntegral maxSize
Copy link
Collaborator

Choose a reason for hiding this comment

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

What would you think about

  1. Calling this txTooBig
  2. Passing it explicitly to the findMax function

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. Sounds good.
  2. Okay, but why ? What's the added benefit in this context?

Copy link
Collaborator

@Anviking Anviking Sep 4, 2020

Choose a reason for hiding this comment

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

I think findMax :: Word8 -> Word8 is a kind-of deceptive name and type-signature. It sounds abstract (at first glance), but it is not. I believe it is meant more as a helper of estimateMaxNumberOfInputs.

I think it should either be abstract, or have a more specialised name.

I think explicitly showing the dependency on the txTooBig condition might be clearer in both cases, but in particular, it would make findMax abstract (assuming no other details specific to this use-case).

Modulo, if the type-signature becomes too ugly, perhaps.

:: Cardano.NetworkId
:: forall k. (TxWitnessTagFor k, Typeable k)
=> Cardano.NetworkId
-> [(Word8, Word8)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doc comment? 🙏

I think a name like estimateMaxInputsGivenOutputsTests would make the call-site tuples more easy to understand too.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think a name like estimateMaxInputsGivenOutputsTests would make the call-site tuples more easy to understand too.

Ok, I see estimateMaxInputsTests is not only goldens. Then I'm less sure...

Copy link
Member Author

Choose a reason for hiding this comment

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

estimateMaxInputsGivenOutputsTests

Estimating max inputs is always given some outputs though.

Copy link
Collaborator

@Anviking Anviking Sep 4, 2020

Choose a reason for hiding this comment

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

Yes, but I think these tests should be easily understood without being 100% sure about that.

Adding a doc comment to [(Word8, Word8)] definitely helps.

But my idea with estimateMaxInputsGivenOutputsTests was to hint the same, already at the call-site, similar to the impossible [(outputs: 1, maxInputs: 2)], or the perhaps overkill EstimateMaxInputsGolden { outputs, maxInputs :: Word8 }.

@@ -162,23 +183,25 @@ spec = do
res `shouldBe` Right (FeeEstimation 165413 165413)

estimateMaxInputsTests
:: Cardano.NetworkId
:: forall k. (TxWitnessTagFor k, Typeable k)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

_estimateMaxNumberOfInputs @ShelleyKey net size Nothing nOuts
prop_moreOutputsMeansLessInputs net size nOuts
= withMaxSuccess 1000
$ within 100000
Copy link
Collaborator

Choose a reason for hiding this comment

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

👌 👍

Copy link
Member Author

@KtorZ KtorZ Sep 4, 2020

Choose a reason for hiding this comment

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

I am slightly worried about Windows here which it notably slower. I can go down to 50000 on my machine without issue, so I took an order of magnitude higher just to be sure.

@KtorZ KtorZ force-pushed the KtorZ/2051/investigate-slow-fee-estimation branch from 8df8b86 to 2427e60 Compare September 7, 2020 12:48
@KtorZ
Copy link
Member Author

KtorZ commented Sep 7, 2020

bors r+

iohk-bors bot added a commit that referenced this pull request Sep 7, 2020
2112: simplify implementation of 'estimateMaxNumberOfInputs' & increase coverage r=KtorZ a=KtorZ

# Issue Number

<!-- Put here a reference to the issue this PR relates to and which requirements it tackles -->

#2051 

# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->

- I've added scenarios for Byron and Icarus keys
- I've added a 'within' clause to some scenarios in order to make sure that the properties are executed within a reasonable time.

# Comments

<!-- Additional comments or screenshots to attach if any -->

This didn't really improve execution time significantly, but it is still useful to keep.

<!-- 
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Once created, link this PR to its corresponding ticket
 ✓ Assign the PR to a corresponding milestone
 ✓ Acknowledge any changes required to the Wiki
-->


Co-authored-by: KtorZ <matthias.benkort@gmail.com>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Sep 7, 2020

Canceled.

@KtorZ
Copy link
Member Author

KtorZ commented Sep 7, 2020

bors r+

iohk-bors bot added a commit that referenced this pull request Sep 7, 2020
2112: simplify implementation of 'estimateMaxNumberOfInputs' & increase coverage r=KtorZ a=KtorZ

# Issue Number

<!-- Put here a reference to the issue this PR relates to and which requirements it tackles -->

#2051 

# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->

- I've added scenarios for Byron and Icarus keys
- I've added a 'within' clause to some scenarios in order to make sure that the properties are executed within a reasonable time.

# Comments

<!-- Additional comments or screenshots to attach if any -->

This didn't really improve execution time significantly, but it is still useful to keep.

<!-- 
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Once created, link this PR to its corresponding ticket
 ✓ Assign the PR to a corresponding milestone
 ✓ Acknowledge any changes required to the Wiki
-->


Co-authored-by: KtorZ <matthias.benkort@gmail.com>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Sep 7, 2020

Build failed:

@KtorZ KtorZ force-pushed the KtorZ/2051/investigate-slow-fee-estimation branch from 692d376 to dba03b6 Compare September 7, 2020 16:02
@KtorZ
Copy link
Member Author

KtorZ commented Sep 7, 2020

bors r+

iohk-bors bot added a commit that referenced this pull request Sep 7, 2020
2112: simplify implementation of 'estimateMaxNumberOfInputs' & increase coverage r=KtorZ a=KtorZ

# Issue Number

<!-- Put here a reference to the issue this PR relates to and which requirements it tackles -->

#2051 

# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->

- I've added scenarios for Byron and Icarus keys
- I've added a 'within' clause to some scenarios in order to make sure that the properties are executed within a reasonable time.

# Comments

<!-- Additional comments or screenshots to attach if any -->

This didn't really improve execution time significantly, but it is still useful to keep.

<!-- 
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Once created, link this PR to its corresponding ticket
 ✓ Assign the PR to a corresponding milestone
 ✓ Acknowledge any changes required to the Wiki
-->


Co-authored-by: KtorZ <matthias.benkort@gmail.com>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Sep 7, 2020

Build failed:

…erage

  - I've added scenarios for Byron and Icarus keys
  - I've added a 'within' clause to some scenarios in order to make sure that the properties are executed within a reasonable time.
@KtorZ KtorZ force-pushed the KtorZ/2051/investigate-slow-fee-estimation branch from dba03b6 to 5d7e3c6 Compare September 8, 2020 07:46
@KtorZ KtorZ force-pushed the KtorZ/2051/investigate-slow-fee-estimation branch from 5d7e3c6 to 0b58616 Compare September 8, 2020 08:38
@KtorZ
Copy link
Member Author

KtorZ commented Sep 8, 2020

bors r+

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Sep 8, 2020

Build succeeded:

@iohk-bors iohk-bors bot merged commit 3feb1d0 into master Sep 8, 2020
@iohk-bors iohk-bors bot deleted the KtorZ/2051/investigate-slow-fee-estimation branch September 8, 2020 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IMPROVEMENT Mark a PR as an improvement, for auto-generated CHANGELOG
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants