Skip to content

Commit

Permalink
Merge #2680 #2692
Browse files Browse the repository at this point in the history
2680: Update cardano-node to 1.27.0. r=jonathanknowles a=jonathanknowles

# Issue Number

ADP-914

# Overview

Updates the dependencies of `cardano-wallet` to include version 1.27.0 of `cardano-node`.

2692: Test the generation of change maps for non-user-specified assets. r=jonathanknowles a=jonathanknowles

# Issue Number

ADP-346

# Overview

This PR:
- extracts out function `collateNonUserSpecifiedAssetQuantities`.
- extracts out function `makeChangeForNonUserSpecifiedAssets`.
- adds property tests to verify the expected behaviour of each function.
- adds unit tests to illustrate the expected behaviour of each function.

The `collateNonUserSpecifiedAssetQuantities` function is designed to produce a map of all assets that do **NOT** appear in the user-specified outputs of a coin selection. Each asset `a` is mapped to the complete list of discrete quantities of `a` found in the selected inputs.

The `makeChangeForNonUserSpecifiedAssets` function is designed to make a list of change maps for all assets that do **NOT** appear in the user-specified outputs of coin selection. The number of change maps is intended to be exactly equal to the number of user-specified outputs.

Co-authored-by: Jonathan Knowles <jonathan.knowles@iohk.io>
Co-authored-by: Johannes Lund <johannes.lund@iohk.io>
  • Loading branch information
3 people committed Jun 8, 2021
3 parents e426116 + 3e0622e + 8f2e54d commit 3f15d36
Show file tree
Hide file tree
Showing 65 changed files with 1,109 additions and 381 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -70,7 +70,7 @@ See **Installation Instructions** for each available [release](https://github.co
>
> | cardano-wallet | cardano-node (compatible versions) | SMASH (compatible versions)
> | --- | --- | ---
> | `master` branch | [1.26.2](https://github.com/input-output-hk/cardano-node/releases/tag/1.26.2) | [1.4.0](https://github.com/input-output-hk/smash/releases/tag/1.4.0)
> | `master` branch | [1.27.0](https://github.com/input-output-hk/cardano-node/releases/tag/1.27.0) | [1.4.0](https://github.com/input-output-hk/smash/releases/tag/1.4.0)
> | [v2021-05-26](https://github.com/input-output-hk/cardano-wallet/releases/tag/v2021-05-26) | [1.26.2](https://github.com/input-output-hk/cardano-node/releases/tag/1.26.2) | [1.4.0](https://github.com/input-output-hk/smash/releases/tag/1.4.0)
> | [v2021-04-28](https://github.com/input-output-hk/cardano-wallet/releases/tag/v2021-04-28) | [1.26.2](https://github.com/input-output-hk/cardano-node/releases/tag/1.26.2) | [1.4.0](https://github.com/input-output-hk/smash/releases/tag/1.4.0)
> | [v2021-04-08](https://github.com/input-output-hk/cardano-wallet/releases/tag/v2021-04-08) | [1.25.1](https://github.com/input-output-hk/cardano-node/releases/tag/1.25.1) | [1.3.0](https://github.com/input-output-hk/smash/releases/tag/1.3.0)
Expand Down
18 changes: 9 additions & 9 deletions cabal.project
Expand Up @@ -28,12 +28,13 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-base
tag: 101e7752cf4b23fd0b411736f523b8f6c43f6bc2
tag: 47db5b818ca4fa051f2e44cdf5e7c5c18c1fb0bf
subdir: binary
binary/test
cardano-crypto-class
cardano-crypto-praos
cardano-crypto-tests
strict-containers
slotting

source-repository-package
Expand All @@ -44,7 +45,7 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger-specs
tag: 2e0e7b625492e5e0182464247f4c26d6949ab6f7
tag: e8f19bcc9c8f405131cb95ca6ada26b2b4eac638
subdir: byron/chain/executable-spec
byron/crypto
byron/crypto/test
Expand All @@ -57,23 +58,21 @@ source-repository-package
shelley/chain-and-ledger/dependencies/non-integer
shelley/chain-and-ledger/executable-spec
shelley/chain-and-ledger/shelley-spec-ledger-test
cardano-ledger-core

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-node
tag: 3531289c9f79eab7ac5d3272ce6e6821504fec4c
tag: 8fe46140a52810b6ca456be01d652ca08fe730bf
subdir: cardano-api
cardano-api/test
cardano-cli
cardano-config
cardano-node
cardano-node-chairman
hedgehog-extras

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-prelude
tag: ee4e7b547a991876e6b05ba542f4e62909f4a571
tag: bb4ed71ba8e587f672d06edf9d2e376f4b055555
subdir: cardano-prelude
cardano-prelude-test

Expand All @@ -90,7 +89,7 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/iohk-monitoring-framework
tag: f6ab0631275d04dff1b990283bbf9671093e7505
tag: 808724ff8a19a33d0ed06f9ef59fbd900b08553c
subdir: contra-tracer
iohk-monitoring
plugins/backend-aggregation
Expand All @@ -103,7 +102,7 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/ouroboros-network
tag: 7f90c8c59ffc7d61a4e161e886d8962a9c26787a
tag: 9b279c7548ee549e1ed755cd1acb69b6e69d0c7b
subdir: cardano-client
io-sim
io-sim-classes
Expand All @@ -115,6 +114,7 @@ source-repository-package
ouroboros-consensus-mock
ouroboros-consensus-shelley
ouroboros-network
ouroboros-network-testing
ouroboros-network-framework
typed-protocols
typed-protocols-examples
Expand Down
Expand Up @@ -62,7 +62,9 @@ module Cardano.Wallet.Primitive.CoinSelection.MA.RoundRobin
, makeChangeForCoin
, makeChangeForUserSpecifiedAsset
, makeChangeForNonUserSpecifiedAsset
, makeChangeForNonUserSpecifiedAssets
, assignCoinsToChangeMaps
, collateNonUserSpecifiedAssetQuantities

-- * Splitting bundles
, splitBundleIfAssetCountExcessive
Expand Down Expand Up @@ -1083,11 +1085,8 @@ makeChange criteria
-- Change for non-user-specified assets: assets that were not present
-- in the original set of user-specified outputs ('outputsToCover').
changeForNonUserSpecifiedAssets :: NonEmpty TokenMap
changeForNonUserSpecifiedAssets = F.foldr
(NE.zipWith (<>)
. makeChangeForNonUserSpecifiedAsset outputMaps)
(TokenMap.empty <$ outputMaps)
nonUserSpecifiedAssets
changeForNonUserSpecifiedAssets = makeChangeForNonUserSpecifiedAssets
outputMaps nonUserSpecifiedAssetQuantities

totalInputValueInsufficient = error
"makeChange: not (totalOutputValue <= totalInputValue)"
Expand Down Expand Up @@ -1136,15 +1135,34 @@ makeChange criteria
--
-- Each asset is paired with the complete list of quantities of that asset
-- present in the selected inputs.
nonUserSpecifiedAssets :: [(AssetId, NonEmpty TokenQuantity)]
nonUserSpecifiedAssets = Map.toList $
F.foldr discardUserSpecifiedAssets mempty inputBundles
nonUserSpecifiedAssetQuantities :: Map AssetId (NonEmpty TokenQuantity)
nonUserSpecifiedAssetQuantities =
collateNonUserSpecifiedAssetQuantities
(view #tokens <$> inputBundles) userSpecifiedAssetIds

-- | Generates a map of all non-user-specified assets and their quantities.
--
-- Each key in the resulting map corresponds to an asset that was NOT included
-- in the original set of user-specified outputs, but that was nevertheless
-- selected during the selection process.
--
-- The value associated with each key corresponds to the complete list of all
-- discrete non-zero quantities of that asset present in the selected inputs.
--
collateNonUserSpecifiedAssetQuantities
:: NonEmpty TokenMap
-- ^ Token maps of all selected inputs.
-> Set AssetId
-- ^ Set of all assets in user-specified outputs.
-> Map AssetId (NonEmpty TokenQuantity)
collateNonUserSpecifiedAssetQuantities inputMaps userSpecifiedAssetIds =
F.foldr discardUserSpecifiedAssets mempty inputMaps
where
discardUserSpecifiedAssets
:: TokenBundle
:: TokenMap
-> Map AssetId (NonEmpty TokenQuantity)
-> Map AssetId (NonEmpty TokenQuantity)
discardUserSpecifiedAssets (TokenBundle _ tokens) m =
discardUserSpecifiedAssets tokens m =
foldr (\(k, v) -> Map.insertWith (<>) k (v :| [])) m filtered
where
filtered = filter
Expand Down Expand Up @@ -1309,15 +1327,34 @@ makeChangeForUserSpecifiedAsset targets (asset, excess) =
-- with the `leq` function.
--
makeChangeForNonUserSpecifiedAsset
:: NonEmpty TokenMap
-- ^ A list of weights for the distribution. The list is only used for
-- its number of elements.
:: NonEmpty a
-- ^ Determines the number of change maps to create.
-> (AssetId, NonEmpty TokenQuantity)
-- ^ An asset quantity to distribute.
-> NonEmpty TokenMap
-- ^ The resultant change maps.
makeChangeForNonUserSpecifiedAsset n (asset, quantities) =
TokenMap.singleton asset <$> padCoalesce quantities n

-- | Constructs change outputs for all non-user-specified assets: assets that
-- were not present in the original set of outputs.
--
-- The resultant list is sorted into ascending order when maps are compared
-- with the `leq` function.
--
makeChangeForNonUserSpecifiedAssets
:: NonEmpty a
-- ^ Determines the number of change maps to create.
-> Map AssetId (NonEmpty TokenQuantity)
-- ^ A map of asset quantities to distribute.
-> NonEmpty TokenMap
-- ^ The resultant change maps.
makeChangeForNonUserSpecifiedAssets n nonUserSpecifiedAssetQuantities =
F.foldr
(NE.zipWith (<>) . makeChangeForNonUserSpecifiedAsset n)
(TokenMap.empty <$ n)
(Map.toList nonUserSpecifiedAssetQuantities)

-- | Constructs a list of ada change outputs based on the given distribution.
--
-- If the sum of weights in given distribution is equal to zero, this function
Expand Down

0 comments on commit 3f15d36

Please sign in to comment.