-
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
Use (TxIn, Address)
as a unique input identifier within coin selection modules.
#3149
Use (TxIn, Address)
as a unique input identifier within coin selection modules.
#3149
Conversation
51bdf6d
to
bac063e
Compare
(TxIn, Address)
as a unique input identifier within coin selection.
bac063e
to
59c9fbe
Compare
(TxIn, Address)
as a unique input identifier within coin selection.(TxIn, Address)
as a unique input identifier within coin selection modules.
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.
Can't quite see the full picture and wondering if we might not want some output
parameters anyway down the line, but also LGTM.
-- ^ Selected inputs. | ||
, collateral | ||
:: ![(TxIn, Coin)] | ||
:: ![(InputId, Coin)] | ||
-- ^ Selected collateral inputs. | ||
, outputs | ||
:: ![(Address, TokenBundle)] |
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 are some remaining TxOut
and Address
types... Are you sure we won't end up needing a output
type-parameter anyway? Maybe this interplays with the choices in this PR
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 are some remaining
TxOut
andAddress
types... Are you sure we won't end up needing a output type-parameter anyway? Maybe this interplays with the choices in this PR
I do eventually plan to remove all of the TxOut
and Address
usages, I promise! I haven't got there yet, as I'm currently trying to do these changes one area at a time, partly in order to limit the size and complexity of each PR. But all of them will go away!
As for the outputs
field: I suspect this is one area where we might need to use an output
type parameter, simply because it's helpful to the caller to be able to link the outputs they supplied to the outputs they eventually get back in the final selection.
User-specified outputs can be changed by the algorithm (if they didn't specify any ada, then we allow ourselves to add the minimum ada quantity).
But perhaps there's a way to avoid even this, in future, if we take the responsibility for "preparing outputs" away from coin selection.
-- | ||
-- Otherwise, returns 'False'. | ||
-- | ||
isMember :: IsUTxOSelection s => TxIn -> s -> Bool | ||
isMember :: IsUTxOSelection s => InputId -> s -> Bool |
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 I found strange initially was: how would UTxOIndex.isMember
and UTxOIndex.lookup
be useful if the caller would have to provide the TxIn
and the Address
as a key? You can't lookup a output given its input anymore...
However, it seems UTxOIndex
is never used like that anyway, so I guess it's fine 🤷♂️
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 I found strange initially was: how would UTxOIndex.isMember and UTxOIndex.lookup be useful if the caller would have to provide the TxIn and the Address as a key?
UTxOIndex.lookup
and UTxO.isMember
can be used in one of two different contexts:
- When the caller is coin selection: coin selection doesn't care about the shape of keys used within the
UTxOIndex
. Coin selection views keys as opaque unique identifiers. - When the caller is the wallet: the wallet knows the mapping between
TxIn
andAddress
values, so it can easily create the(TxIn, Address)
key required for lookup.
However, it seems
UTxOIndex
is never used like that anyway, so I guess it's fine :man_shrugging
Yes, exactly.
Currently UTxOIndex
is currently only used by coin selection. (It was written specifically to make coin selection easier to implement.) So we have the luxury of being able to limit its operations to just those required by coin selection.
…ion. ADP-1448 We eventually want to change the internal coin selection library so that it: - does not depend on the following wallet-specific types: - `TxIn` - `TxOut` - `Address` - `UTxO` - produces selections of the form: ```haskell data Selection input = Selection { inputs = [(input, TokenBundle)] , collateral = [(input, Coin )] , ... } ``` (here `input` is a **_type parameter_** that **_uniquely_** identifies a selected input) However, the **_wallet_** currently expects to manipulate selections of the following form: ```haskell data Selection = Selection { inputs = [(TxIn, TxOut)] , collateral = [(TxIn, TxOut)] , ... } ``` Since (for the time being) we wish to avoid making major changes to the wallet codebase, we need a way to translate a `Selection` produced by the internal algorithm to a wallet-friendly `Selection`. One way to achieve this is to instantiate type `input` as `(TxIn, Address)`, so that our internal selection type is instantiated to: ```haskell data Selection = Selection { inputs = [((TxIn, Address), TokenBundle)] , collateral = [((TxIn, Address), Coin )] , ... } ``` With this substitution, it's trivial to convert from internal `Selection` values to wallet-friendly `Selection` values, because the choice of concrete type for `input` has all the context necessary to reconstruct a `(TxIn, TxOut)` pair. This commit **_doesn't_** introduce any new type parameters, but instead makes an evolutionary step **_towards_** the goal outlined above. This commit: - Introduces a (temporary) type synonym `InputId = (TxIn, Address)`. - Amends core coin selection modules to use `InputId` as the unique identifier for inputs. - Amends core coin selection modules so that they no longer depend on the `TxOut` and `UTxO` types. - Amends the `readWalletUTxOIndex` function to perform the translation from `UTxO` (equivalent to `Map TxIn TxOut`) to `Map InputId TokenBundle`. - Amends the wallet-facing `Cardano.Wallet.CoinSelection` module to perform the reverse translation from `(InputId, TokenBundle)` pairs to `(TxIn, TxOut)` pairs. A **future commit** will replace the `InputId` type synonym with an `input` type parameter on the following types: - `Selection` - `SelectionParams` - `UTxOIndex` - `UTxOSelection` It's important that the translations stated above do not add any performance overhead. - The translation from `(TxIn, TxOut)` to `(InputId, TokenBundle)` within function `readWalletUTxOIndex` does need to traverse the UTxO, but it only does so a single time. When estimating a fee, this function is only evaluated a single time. - The translation from `(InputId, TokenBundle)` to `(TxIn, TxOut)` is only applied to the inputs that are eventually selected.
59c9fbe
to
a269694
Compare
We use the following convention for identifier names: - `u` represents a unique identifier for an individual UTxO (unspent transaction output). - `b` represents a `TokenBundle` value. - `i` represents an index of type `UTxOIndex`.
The former field name was confusing because it overloaded the term "UTxO" (used elsewhere in the module to refer to a single UTxO) with the complete set of UTxOs in the index.
These names better reflect the types involved.
…e-parameter-for-utxo-identifier-in-utxo-index Generalize UTxO identifier type within `UTxOIndex`.
bors r+ |
3149: Use `(TxIn, Address)` as a unique input identifier within coin selection modules. r=jonathanknowles a=jonathanknowles ## Issue Number ADP-1417 ## Background We eventually want to change the internal coin selection library so that it: - does not depend on the following wallet-specific types: - `TxIn` - `TxOut` - `Address` - `UTxO` - produces selections of the form: ```haskell data Selection input = Selection { inputs = [(input, TokenBundle)] , collateral = [(input, Coin )] , ... } ``` (where `input` is a **_type parameter_** that **_uniquely_** identifies a selected input) However, the **_wallet_** currently expects to manipulate selections of the following form: ```haskell data Selection = Selection { inputs = [(TxIn, TxOut)] , collateral = [(TxIn, TxOut)] , ... } ``` Since (for the time being) we wish to avoid making major changes to the wallet codebase, we need a way to translate a `Selection` produced by the internal algorithm to a wallet-friendly `Selection`. One way to achieve this is to instantiate type `input` as `(TxIn, Address)`, so that our internal selection type is instantiated to: ```haskell data Selection = Selection { inputs = [((TxIn, Address), TokenBundle)] , collateral = [((TxIn, Address), Coin )] , ... } ``` With this substitution, it's trivial to convert from internal `Selection` values to wallet-friendly `Selection` values, because the choice of concrete type for `input` has all the context necessary to reconstruct a `(TxIn, TxOut)` pair. ## This PR This PR **_doesn't_** introduce any new type parameters, but instead makes an evolutionary step **_towards_** the goal outlined above. This PR: - [x] Introduces a (temporary) type synonym `InputId = (TxIn, Address)`. - [x] Amends core coin selection modules to use `InputId` as the unique identifier for inputs. - [x] Amends core coin selection modules so that they no longer depend on the `TxOut` and `UTxO` types. - [x] Amends the `readWalletUTxOIndex` function to perform the translation from `UTxO` (equivalent to `Map TxIn TxOut`) to `Map InputId TokenBundle`. - [x] Amends the wallet-facing `Cardano.Wallet.CoinSelection` module to perform the reverse translation from `(InputId, TokenBundle)` pairs to `(TxIn, TxOut)` pairs. ## Future Work A **future PR** will replace the `InputId` type synonym with a type parameter on the following types: - `Selection` - `SelectionParams` - `UTxOIndex` - `UTxOSelection` ## Performance Considerations It's important that the translations stated above do not add any performance overhead. - The translation from `(TxIn, TxOut)` to `(InputId, TokenBundle)` within `readWalletUTxOIndex` does need to traverse the UTxO, but it only does so a single time. It was already necessary to traverse the UTxO in order to construct the `UTxOIndex`. When estimating a fee, the function `readWalletUTxOIndex` is only evaluated a single time. - The translation from `(InputId, TokenBundle)` to `(TxIn, TxOut)` is only applied to the inputs that are eventually selected. Co-authored-by: Jonathan Knowles <jonathan.knowles@iohk.io>
Build failed: Test timed out here: Sign transaction
signTransaction adds reward account witness when necessary (AnyCardanoEra ByronEra)
+++ OK, passed 100 tests (100% feature not supported in ByronEra.).
signTransaction adds reward account witness when necessary (AnyCardanoEra ShelleyEra) (29562ms)
+++ OK, passed 100 tests.
signTransaction adds reward account witness when necessary (AnyCardanoEra AllegraEra) (29663ms)
+++ OK, passed 100 tests.
signTransaction adds reward account witness when necessary (AnyCardanoEra MaryEra) (29746ms)
+++ OK, passed 100 tests.
signTransaction adds reward account witness when necessary (AnyCardanoEra AlonzoEra) (29702ms)
+++ OK, passed 100 tests.
signTransaction adds extra key witness when necessary (AnyCardanoEra ByronEra)
+++ OK, passed 100 tests (100% feature not supported in ByronEra.).
signTransaction adds extra key witness when necessary (AnyCardanoEra ShelleyEra)
+++ OK, passed 100 tests (100% feature not supported in ShelleyEra.).
signTransaction adds extra key witness when necessary (AnyCardanoEra AllegraEra)
+++ OK, passed 100 tests (100% feature not supported in AllegraEra.).
signTransaction adds extra key witness when necessary (AnyCardanoEra MaryEra)
+++ OK, passed 100 tests (100% feature not supported in MaryEra.).
signTransaction adds extra key witness when necessary (AnyCardanoEra AlonzoEra) (69849ms)
+++ OK, passed 100 tests.
signTransaction adds tx in witnesses when necessary (AnyCardanoEra ByronEra) (1ms)
+++ OK, passed 100 tests.
signTransaction adds tx in witnesses when necessary (AnyCardanoEra ShelleyEra) (95213ms)
+++ OK, passed 100 tests.
signTransaction adds tx in witnesses when necessary (AnyCardanoEra AllegraEra) (95491ms)
+++ OK, passed 100 tests. |
bors r+ |
3149: Use `(TxIn, Address)` as a unique input identifier within coin selection modules. r=jonathanknowles a=jonathanknowles ## Issue Number ADP-1417 ## Background We eventually want to change the internal coin selection library so that it: - does not depend on the following wallet-specific types: - `TxIn` - `TxOut` - `Address` - `UTxO` - produces selections of the form: ```haskell data Selection input = Selection { inputs = [(input, TokenBundle)] , collateral = [(input, Coin )] , ... } ``` (where `input` is a **_type parameter_** that **_uniquely_** identifies a selected input) However, the **_wallet_** currently expects to manipulate selections of the following form: ```haskell data Selection = Selection { inputs = [(TxIn, TxOut)] , collateral = [(TxIn, TxOut)] , ... } ``` Since (for the time being) we wish to avoid making major changes to the wallet codebase, we need a way to translate a `Selection` produced by the internal algorithm to a wallet-friendly `Selection`. One way to achieve this is to instantiate type `input` as `(TxIn, Address)`, so that our internal selection type is instantiated to: ```haskell data Selection = Selection { inputs = [((TxIn, Address), TokenBundle)] , collateral = [((TxIn, Address), Coin )] , ... } ``` With this substitution, it's trivial to convert from internal `Selection` values to wallet-friendly `Selection` values, because the choice of concrete type for `input` has all the context necessary to reconstruct a `(TxIn, TxOut)` pair. ## This PR This PR **_doesn't_** introduce any new type parameters, but instead makes an evolutionary step **_towards_** the goal outlined above. This PR: - [x] Introduces a (temporary) type synonym `InputId = (TxIn, Address)`. - [x] Amends core coin selection modules to use `InputId` as the unique identifier for inputs. - [x] Amends core coin selection modules so that they no longer depend on the `TxOut` and `UTxO` types. - [x] Amends the `readWalletUTxOIndex` function to perform the translation from `UTxO` (equivalent to `Map TxIn TxOut`) to `Map InputId TokenBundle`. - [x] Amends the wallet-facing `Cardano.Wallet.CoinSelection` module to perform the reverse translation from `(InputId, TokenBundle)` pairs to `(TxIn, TxOut)` pairs. ## Future Work A **future PR** will replace the `InputId` type synonym with a type parameter on the following types: - `Selection` - `SelectionParams` - `UTxOIndex` - `UTxOSelection` ## Performance Considerations It's important that the translations stated above do not add any performance overhead. - The translation from `(TxIn, TxOut)` to `(InputId, TokenBundle)` within `readWalletUTxOIndex` does need to traverse the UTxO, but it only does so a single time. It was already necessary to traverse the UTxO in order to construct the `UTxOIndex`. When estimating a fee, the function `readWalletUTxOIndex` is only evaluated a single time. - The translation from `(InputId, TokenBundle)` to `(TxIn, TxOut)` is only applied to the inputs that are eventually selected. Co-authored-by: Jonathan Knowles <jonathan.knowles@iohk.io>
Build failed: Another timeout: Sign transaction
signTransaction adds reward account witness when necessary (AnyCardanoEra ByronEra)
+++ OK, passed 100 tests (100% feature not supported in ByronEra.).
signTransaction adds reward account witness when necessary (AnyCardanoEra ShelleyEra) (29438ms)
+++ OK, passed 100 tests.
signTransaction adds reward account witness when necessary (AnyCardanoEra AllegraEra) (29539ms)
+++ OK, passed 100 tests.
signTransaction adds reward account witness when necessary (AnyCardanoEra MaryEra) (29601ms)
+++ OK, passed 100 tests.
signTransaction adds reward account witness when necessary (AnyCardanoEra AlonzoEra) (29572ms)
+++ OK, passed 100 tests.
signTransaction adds extra key witness when necessary (AnyCardanoEra ByronEra)
+++ OK, passed 100 tests (100% feature not supported in ByronEra.).
signTransaction adds extra key witness when necessary (AnyCardanoEra ShelleyEra)
+++ OK, passed 100 tests (100% feature not supported in ShelleyEra.).
signTransaction adds extra key witness when necessary (AnyCardanoEra AllegraEra)
+++ OK, passed 100 tests (100% feature not supported in AllegraEra.).
signTransaction adds extra key witness when necessary (AnyCardanoEra MaryEra)
+++ OK, passed 100 tests (100% feature not supported in MaryEra.). I actually watched this test while it was running in CI. The output stops at the above point, as if something has got stuck, and then test infrastructure times out much later on. |
Time comparison of test that times out ( This branch (486.4921 seconds)Finished in 486.4921 seconds, used 487.6973 seconds of CPU time
35 examples, 0 failures
Slow spec items:
test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs:388:29: /Cardano.Wallet.Shelley.Transaction/Sign transaction/signTransaction adds collateral witnesses when necessary (AnyCardan
oEra AlonzoEra)/ (58960ms)
test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs:386:29: /Cardano.Wallet.Shelley.Transaction/Sign transaction/signTransaction adds tx in witnesses when necessary (AnyCardanoEra
ShelleyEra)/ (58924ms)
test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs:386:29: /Cardano.Wallet.Shelley.Transaction/Sign transaction/signTransaction adds tx in witnesses when necessary (AnyCardanoEra
AlonzoEra)/ (58743ms)
test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs:386:29: /Cardano.Wallet.Shelley.Transaction/Sign transaction/signTransaction adds tx in witnesses when necessary (AnyCardanoEra
AllegraEra)/ (58700ms)
test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs:386:29: /Cardano.Wallet.Shelley.Transaction/Sign transaction/signTransaction adds tx in witnesses when necessary (AnyCardanoEra
MaryEra)/ (58681ms)
test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs:384:29: /Cardano.Wallet.Shelley.Transaction/Sign transaction/signTransaction adds extra key witness when necessary (AnyCardanoEr
a AlonzoEra)/ (52162ms)
test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs:382:29: /Cardano.Wallet.Shelley.Transaction/Sign transaction/signTransaction adds reward account witness when necessary (AnyCard
anoEra MaryEra)/ (21584ms)
test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs:382:29: /Cardano.Wallet.Shelley.Transaction/Sign transaction/signTransaction adds reward account witness when necessary (AnyCard
anoEra AllegraEra)/ (21583ms)
test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs:382:29: /Cardano.Wallet.Shelley.Transaction/Sign transaction/signTransaction adds reward account witness when necessary (AnyCard
anoEra AlonzoEra)/ (21551ms)
test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs:382:29: /Cardano.Wallet.Shelley.Transaction/Sign transaction/signTransaction adds reward account witness when necessary (AnyCard
anoEra ShelleyEra)/ (21418ms)
cardano-wallet> Test suite unit passed Master branch (547.6825 seconds)Finished in 547.6825 seconds, used 549.0480 seconds of CPU time
35 examples, 0 failures
Slow spec items:
test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs:388:29: /Cardano.Wallet.Shelley.Transaction/Sign transaction/signTransaction adds collateral witnesses when necessary (AnyCardanoEra AlonzoEra)/ (71508ms)
test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs:386:29: /Cardano.Wallet.Shelley.Transaction/Sign transaction/signTransaction adds tx in witnesses when necessary (AnyCardanoEra AlonzoEra)/ (71326ms)
test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs:386:29: /Cardano.Wallet.Shelley.Transaction/Sign transaction/signTransaction adds tx in witnesses when necessary (AnyCardanoEra MaryEra)/ (71251ms)
test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs:386:29: /Cardano.Wallet.Shelley.Transaction/Sign transaction/signTransaction adds tx in witnesses when necessary (AnyCardanoEra ShelleyEra)/ (71217ms)
test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs:386:29: /Cardano.Wallet.Shelley.Transaction/Sign transaction/signTransaction adds tx in witnesses when necessary (AnyCardanoEra AllegraEra)/ (71201ms)
test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs:384:29: /Cardano.Wallet.Shelley.Transaction/Sign transaction/signTransaction adds extra key witness when necessary (AnyCardanoEra AlonzoEra)/ (49614ms)
test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs:382:29: /Cardano.Wallet.Shelley.Transaction/Sign transaction/signTransaction adds reward account witness when necessary (AnyCardanoEra AlonzoEra)/ (21273ms)
test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs:382:29: /Cardano.Wallet.Shelley.Transaction/Sign transaction/signTransaction adds reward account witness when necessary (AnyCardanoEra MaryEra)/ (21253ms)
test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs:382:29: /Cardano.Wallet.Shelley.Transaction/Sign transaction/signTransaction adds reward account witness when necessary (AnyCardanoEra AllegraEra)/ (21241ms)
test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs:382:29: /Cardano.Wallet.Shelley.Transaction/Sign transaction/signTransaction adds reward account witness when necessary (AnyCardanoEra ShelleyEra)/ (21151ms)
cardano-wallet> Test suite unit passed I've run this several times both on this branch, and on Successful runs of this branch on CI: |
bors r+ |
Build succeeded: |
3155: Generalize UTxO identifier type within `UTxOSelection`. r=jonathanknowles a=jonathanknowles ## Issue Number ADP-1450 ## Background Within coin selection modules, we are steadily replacing all uses of `TxIn`, `Address`, `TxOut` with type parameters, so that the coin selection library does not depend on these concrete wallet types. ## Summary This PR replaces all uses of `InputId` (a temporary type synonym introduced in #3149) with a type parameter within module `UTxOSelection`. We use the following convention for type parameters and identifier names: - `u` represents a unique identifier for an individual UTxO (unspent transaction output). - `s` represents a selection of type `UTxOSelection`. - `b` represents a `TokenBundle` value. - `i` represents an index of type `UTxOIndex`. Co-authored-by: Jonathan Knowles <jonathan.knowles@iohk.io>
3155: Generalize UTxO identifier type within `UTxOSelection`. r=Anviking a=jonathanknowles ## Issue Number ADP-1450 ## Background Within coin selection modules, we are steadily replacing all uses of `TxIn`, `Address`, `TxOut` with type parameters, so that the coin selection library does not depend on these concrete wallet types. ## Summary This PR replaces all uses of `InputId` (a temporary type synonym introduced in #3149) with a type parameter within module `UTxOSelection`. We use the following convention for type parameters and identifier names: - `u` represents a unique identifier for an individual UTxO (unspent transaction output). - `s` represents a selection of type `UTxOSelection`. - `b` represents a `TokenBundle` value. - `i` represents an index of type `UTxOIndex`. Co-authored-by: Jonathan Knowles <jonathan.knowles@iohk.io>
3155: Generalize UTxO identifier type within `UTxOSelection`. r=jonathanknowles a=jonathanknowles ## Issue Number ADP-1450 ## Background Within coin selection modules, we are steadily replacing all uses of `TxIn`, `Address`, `TxOut` with type parameters, so that the coin selection library does not depend on these concrete wallet types. ## Summary This PR replaces all uses of `InputId` (a temporary type synonym introduced in #3149) with a type parameter within module `UTxOSelection`. We use the following convention for type parameters and identifier names: - `u` represents a unique identifier for an individual UTxO (unspent transaction output). - `s` represents a selection of type `UTxOSelection`. - `b` represents a `TokenBundle` value. - `i` represents an index of type `UTxOIndex`. Co-authored-by: Jonathan Knowles <jonathan.knowles@iohk.io>
3155: Generalize UTxO identifier type within `UTxOSelection`. r=jonathanknowles a=jonathanknowles ## Issue Number ADP-1450 ## Background Within coin selection modules, we are steadily replacing all uses of `TxIn`, `Address`, `TxOut` with type parameters, so that the coin selection library does not depend on these concrete wallet types. ## Summary This PR replaces all uses of `InputId` (a temporary type synonym introduced in #3149) with a type parameter within module `UTxOSelection`. We use the following convention for type parameters and identifier names: - `u` represents a unique identifier for an individual UTxO (unspent transaction output). - `s` represents a selection of type `UTxOSelection`. - `b` represents a `TokenBundle` value. - `i` represents an index of type `UTxOIndex`. Co-authored-by: Jonathan Knowles <jonathan.knowles@iohk.io>
Issue Number
ADP-1417
Background
We eventually want to change the internal coin selection library so that it:
TxIn
TxOut
Address
UTxO
input
is a type parameter that uniquely identifies a selected input)However, the wallet currently expects to manipulate selections of the following form:
Since (for the time being) we wish to avoid making major changes to the wallet codebase, we need a way to translate a
Selection
produced by the internal algorithm to a wallet-friendlySelection
.One way to achieve this is to instantiate type
input
as(TxIn, Address)
, so that our internal selection type is instantiated to:With this substitution, it's trivial to convert from internal
Selection
values to wallet-friendlySelection
values, because the choice of concrete type forinput
has all the context necessary to reconstruct a(TxIn, TxOut)
pair.This PR
This PR doesn't introduce any new type parameters, but instead makes an evolutionary step towards the goal outlined above.
This PR:
InputId = (TxIn, Address)
.InputId
as the unique identifier for inputs.TxOut
andUTxO
types.readWalletUTxOIndex
function to perform the translation fromUTxO
(equivalent toMap TxIn TxOut
) toMap InputId TokenBundle
.Cardano.Wallet.CoinSelection
module to perform the reverse translation from(InputId, TokenBundle)
pairs to(TxIn, TxOut)
pairs.Future Work
A future PR will replace the
InputId
type synonym with a type parameter on the following types:Selection
SelectionParams
UTxOIndex
UTxOSelection
Performance Considerations
It's important that the translations stated above do not add any performance overhead.
(TxIn, TxOut)
to(InputId, TokenBundle)
withinreadWalletUTxOIndex
does need to traverse the UTxO, but it only does so a single time. It was already necessary to traverse the UTxO in order to construct theUTxOIndex
. When estimating a fee, the functionreadWalletUTxOIndex
is only evaluated a single time.(InputId, TokenBundle)
to(TxIn, TxOut)
is only applied to the inputs that are eventually selected.