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

Multi-Asset Migration Algorithm #2618

Merged
merged 31 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2c58d7d
Add `TxConstraints` type to `Primitive.Types.Tx`.
jonathanknowles Apr 19, 2021
3618076
Add module `Migration.Selection`.
jonathanknowles Apr 19, 2021
c9ecdab
Add module `Migration.Planning`.
jonathanknowles Apr 19, 2021
87c58c4
Add module `Migration`.
jonathanknowles Apr 19, 2021
d31d1ec
Clarify the control flow of `Selection.verify`.
jonathanknowles Apr 20, 2021
5413f6d
Add support for pretty-printing arbitrary `Show` instances.
jonathanknowles Apr 20, 2021
559272c
Make generator for `MockInputId` more collision-resistant.
jonathanknowles Apr 20, 2021
cd78eae
Add property test for `categorizeUTxOEntries`.
jonathanknowles Apr 20, 2021
c3651da
Generate fewer examples in `prop_createPlan`.
jonathanknowles Apr 20, 2021
b2186bd
Use `tabulate` instead of `label` in `prop_createPlan`.
jonathanknowles Apr 20, 2021
152d957
Add further input preservation test within `prop_createPlan`.
jonathanknowles Apr 20, 2021
f45fdbb
Fix typos of "outputs" in comments.
jonathanknowles Apr 20, 2021
eee3f2e
Test that the public and private interfaces are equivalent.
jonathanknowles Apr 20, 2021
2a2f17d
Use more descriptive type variables.
jonathanknowles Apr 21, 2021
f9de1b4
Remove unnecessary reversals from `minimizeFee`.
jonathanknowles Apr 21, 2021
7a3912d
Add documentation comments to functions in `Planning` and `Selection`.
jonathanknowles Apr 21, 2021
522a895
Relax the ada-only restriction when testing giant migrations.
jonathanknowles Apr 21, 2021
300f6a0
Explicitly test the creation of empty migration plans.
jonathanknowles Apr 21, 2021
4a43cee
Use `forAll` to simplify `PlanningSpec`.
jonathanknowles Apr 21, 2021
05501f6
Use `forAll` to simplify `SelectionSpec`.
jonathanknowles Apr 21, 2021
257abb0
Use `forAll` to simplify `MigrationSpec`.
jonathanknowles Apr 21, 2021
6584790
Provide a shared definition for `genRewardWithdrawal`.
jonathanknowles Apr 21, 2021
ab1729f
Improve the output of test failures.
jonathanknowles Apr 22, 2021
7bd4436
Remove link to `verify` function from `Selection` module documentation.
jonathanknowles Apr 22, 2021
ec6970e
Emphasise that `Selection.verify` is provided as a convenience for te…
jonathanknowles Apr 22, 2021
97f5c26
Rename `extendSelection` to `extendSelectionUntilFull`.
jonathanknowles Apr 22, 2021
a95d51b
Clarify the assumptions of `txInputCost` and `txInputSize`.
jonathanknowles Apr 22, 2021
5c2b38d
Make the order consistent for module `Migration.Selection`.
jonathanknowles Apr 22, 2021
adf7dd0
Check that `Selection.create` and `Selection.extend` minimize the fee.
jonathanknowles Apr 22, 2021
5d3c959
Strengthen the `totalFee` check within `Planning.prop_createPlan`.
jonathanknowles Apr 22, 2021
2445551
Check that `createPlan` preserves the total non-ada token balance.
jonathanknowles Apr 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/core/cardano-wallet-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ library
, persistent
, persistent-sqlite
, persistent-template
, pretty-simple
, profunctors
, quiet
, random
Expand Down Expand Up @@ -175,6 +176,9 @@ library
Cardano.Wallet.Primitive.AddressDiscovery.SharedState
Cardano.Wallet.Primitive.SyncProgress
Cardano.Wallet.Primitive.CoinSelection.MA.RoundRobin
Cardano.Wallet.Primitive.Migration
Cardano.Wallet.Primitive.Migration.Planning
Cardano.Wallet.Primitive.Migration.Selection
Cardano.Wallet.Primitive.Model
Cardano.Wallet.Primitive.Types
Cardano.Wallet.Primitive.Types.Address
Expand Down Expand Up @@ -283,6 +287,7 @@ test-suite unit
, network
, network-uri
, persistent
, pretty-simple
, regex-pcre-builtin
, OddWord
, ouroboros-consensus
Expand Down Expand Up @@ -356,6 +361,9 @@ test-suite unit
Cardano.Wallet.Primitive.AddressDiscovery.SharedStateSpec
Cardano.Wallet.Primitive.AddressDiscoverySpec
Cardano.Wallet.Primitive.CoinSelection.MA.RoundRobinSpec
Cardano.Wallet.Primitive.MigrationSpec
Cardano.Wallet.Primitive.Migration.PlanningSpec
Cardano.Wallet.Primitive.Migration.SelectionSpec
Cardano.Wallet.Primitive.ModelSpec
Cardano.Wallet.Primitive.Slotting.Legacy
Cardano.Wallet.Primitive.SlottingSpec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ data SelectionResult change = SelectionResult
-- ^ An optional extra source of ada.
, outputsCovered
:: ![TxOut]
-- ^ A list of ouputs covered.
-- ^ A list of outputs covered.
-- FIXME: Left as a list to allow to work-around the limitation of
-- 'performSelection' which cannot run for no output targets (e.g. in
-- the context of a delegation transaction). This allows callers to
Expand Down
77 changes: 77 additions & 0 deletions lib/core/src/Cardano/Wallet/Primitive/Migration.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedLabels #-}

-- |
-- Copyright: © 2021 IOHK
-- License: Apache-2.0
--
-- This module provides a public API for planning wallet migrations.
--
-- Use 'createPlan' to create a migration plan.
--
module Cardano.Wallet.Primitive.Migration
(
-- * Creating a migration plan
createPlan
, MigrationPlan (..)
, RewardWithdrawal (..)
, Selection (..)
, TxSize (..)

) where

import Prelude

import Cardano.Wallet.Primitive.Migration.Selection
( RewardWithdrawal (..), Selection (..), TxSize (..) )
import Cardano.Wallet.Primitive.Types.Coin
( Coin )
import Cardano.Wallet.Primitive.Types.Tx
( TxConstraints (..), TxIn, TxOut )
import Cardano.Wallet.Primitive.Types.UTxO
( UTxO )
import Data.Generics.Internal.VL.Lens
( view )
import Data.Generics.Labels
()
import GHC.Generics
( Generic )

import qualified Cardano.Wallet.Primitive.Migration.Planning as Planning

-- | Represents a plan for migrating a 'UTxO' set.
--
-- See 'createPlan' to create a migration plan.
--
data MigrationPlan size = MigrationPlan
{ selections :: ![Selection (TxIn, TxOut) size]
-- ^ A list of generated selections: each selection is the basis for a
-- single transaction.
, unselected :: !UTxO
-- ^ The portion of the UTxO that was not selected.
, totalFee :: !Coin
-- ^ The total fee payable: equal to the sum of the fees of the
-- individual selections.
}
deriving (Eq, Generic, Show)

-- | Creates a migration plan for the given UTxO set and reward withdrawal
-- amount.
--
-- See 'MigrationPlan'.
--
createPlan
:: TxSize size
=> TxConstraints size
-> UTxO
-> RewardWithdrawal
-> MigrationPlan size
createPlan constraints utxo reward = MigrationPlan
{ selections = view #selections plan
, unselected = Planning.uncategorizeUTxO (view #unselected plan)
, totalFee = view #totalFee plan
}
where
plan = Planning.createPlan
constraints (Planning.categorizeUTxO constraints utxo) reward
Loading