-
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
Perform verification of SelectionCollateralError
values.
#2988
Perform verification of SelectionCollateralError
values.
#2988
Conversation
|
||
-- The subset of the largest reported combination that is suitable for | ||
-- use as collateral. This set should be exactly the same size as the | ||
-- reporte largest combination. |
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.
-- reporte largest combination. | |
-- reported largest combination. |
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.
Haha, thanks!
14571e4
to
f2165d7
Compare
bors r+ |
2988: Perform verification of `SelectionCollateralError` values. r=jonathanknowles a=jonathanknowles ## Issue Number ADP-1037 ## Summary This PR adds verification of `SelectionCollateralError` values. We verify that: - The reported `largestCombinationAvailable` value does not include any UTxO entries that are unsuitable for use as collateral. - The number of entries within `largestCombinationAvailable` is not greater than `maximumCollateralInputCount`. - The total value of entries within `largestCombinationAvailable` is not greater than the computed `minimumSelectionAmount` (as this would mean that the error was returned erroneously: we **_could_** have generated a selection). ## Example failures ### Collateral suitability If we introduce a mutation that deliberately removes the collateral suitability check: ```patch diff --git a/lib/core/src/Cardano/Wallet/Primitive/CoinSelection.hs b/lib/core/src/Cardano/Wallet/Primitive/CoinSelection.hs index 994103a68..a137cfc05 100644 --- a/lib/core/src/Cardano/Wallet/Primitive/CoinSelection.hs +++ b/lib/core/src/Cardano/Wallet/Primitive/CoinSelection.hs @@ -316,9 +316,8 @@ toCollateralConstraintsParams balanceResult (constraints, params) = } collateralParams = Collateral.SelectionParams { coinsAvailable = - Map.mapMaybeWithKey - (curry (view #utxoSuitableForCollateral constraints)) - (unUTxO (view #utxoAvailableForCollateral params)) + view (#tokens . #coin) <$> unUTxO + (view #utxoAvailableForCollateral params) , minimumSelectionAmount = computeMinimumCollateral ComputeMinimumCollateralParams { minimumCollateralPercentage = ``` Then we see a verification failure similar to: ![collateralErrorVerificationFailure](https://user-images.githubusercontent.com/206319/138395759-2cc8d652-6a8e-4f96-a852-3c82734efb2b.png) ### Maximum number of collateral inputs If we introduce a mutation that deliberately passes an incorrect maximum number of collateral inputs to the collateral selection algorithm: ```patch diff --git a/lib/core/src/Cardano/Wallet/Primitive/CoinSelection.hs b/lib/core/src/Cardano/Wallet/Primitive/CoinSelection.hs index 6fc4d4f5d..1b18e0360 100644 --- a/lib/core/src/Cardano/Wallet/Primitive/CoinSelection.hs +++ b/lib/core/src/Cardano/Wallet/Primitive/CoinSelection.hs @@ -305,7 +305,7 @@ toCollateralConstraintsParams balanceResult (constraints, params) = where collateralConstraints = Collateral.SelectionConstraints { maximumSelectionSize = - view #maximumCollateralInputCount constraints + view #maximumCollateralInputCount constraints + 1 , searchSpaceLimit = -- We use the default search space limit here, as this value is -- used in the test suite for 'Collateral.performSelection'. We ``` Then we see a verification failure similar to: ![collateralErrorVerificationFailure2](https://user-images.githubusercontent.com/206319/138395037-ee779897-bafe-411e-9fdc-b30de41aba89.png) Co-authored-by: Jonathan Knowles <[email protected]>
Build failed: Another cached failure. The cause seems to be from a completely unrelated PR that had several jobs that failed because of resource limitatons on hydra, and these job failures have propagated to the merge attempt for this PR. I've restarted all the failed jobs manually, and cleared the errors. |
bors r+ |
Build succeeded: |
Issue Number
ADP-1037
Summary
This PR adds verification of
SelectionCollateralError
values.We verify that:
largestCombinationAvailable
value does not include any UTxO entries that are unsuitable for use as collateral.largestCombinationAvailable
is not greater thanmaximumCollateralInputCount
.largestCombinationAvailable
is not greater than the computedminimumSelectionAmount
(as this would mean that the error was returned erroneously: we could have generated a selection).Example failures
Collateral suitability
If we introduce a mutation that deliberately removes the collateral suitability check:
Then we see a verification failure similar to:
Maximum number of collateral inputs
If we introduce a mutation that deliberately passes an incorrect maximum number of collateral inputs to the collateral selection algorithm:
Then we see a verification failure similar to: