-
Notifications
You must be signed in to change notification settings - Fork 217
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
Conversation
7c6e87e
to
8df8b86
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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...)
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
- Calling this
txTooBig
- Passing it explicitly to the
findMax
function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Sounds good.
- Okay, but why ? What's the added benefit in this context?
There was a problem hiding this comment.
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)] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌 👍
There was a problem hiding this comment.
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.
8df8b86
to
2427e60
Compare
bors r+ |
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 <[email protected]>
Canceled. |
bors r+ |
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 <[email protected]>
Build failed: |
692d376
to
dba03b6
Compare
bors r+ |
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 <[email protected]>
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.
dba03b6
to
5d7e3c6
Compare
5d7e3c6
to
0b58616
Compare
bors r+ |
Build succeeded: |
Issue Number
#2051
Overview
Comments
This didn't really improve execution time significantly, but it is still useful to keep.