cardano-wallet-core-2022.7.1: The Wallet Backend for a Cardano node.
Copyright © 2021 IOHK
License Apache-2.0
Safe Haskell None
Language Haskell2010

Cardano.Wallet.CoinSelection.Internal.Collateral

Description

Provides functions for selecting coins for use as collateral from a UTxO set.

See the documentation for performSelection for more details.

Synopsis

Public API

performSelection :: forall u. Ord u => PerformSelection u Source #

Selects coins for collateral.

This function tries two strategies in the following order, picking the first strategy that succeeds:

  1. Attempt to select an amount of collateral that is as small as possible.
  2. Attempt to select collateral from the largest coins available.

The first strategy, given unlimited computation time, will always produce an optimal result: the smallest possible amount of collateral. However, if the required search space is large, and if the $sel:searchSpaceLimit:SelectionConstraints parameter is set to a value that's smaller than the required search space size, then this strategy will fail without computing a result.

The second strategy sacrifices optimality and always produces a result if one is available, by looking only at the very largest coins available. This result can be computed very quickly, without using much search space.

The combination of these two strategies means that we can satisfy the following properties:

If the attempt to select collateral succeeds:

>>> sum  coinsSelected ≥ minimumSelectionAmount
>>> size coinsSelected ≤ maximumSelectionSize
>>> coinsSelected ⊆ coinsAvailable

If the attempt to select collateral fails:

>>> sum  largestCombinationAvailable < minimumSelectionAmount
>>> size largestCombinationAvailable ≤ maximumSelectionSize
>>> largestCombinationAvailable ⊆ coinsAvailable

data SelectionConstraints Source #

Specifies all constraints required for collateral selection.

Selection constraints:

  • are dependent on the current set of protocol parameters.
  • are not specific to a given selection.
  • place limits on the selection algorithm, enabling it to produce selections that are acceptable to the ledger.

Constructors

SelectionConstraints

Fields

Instances

Instances details
Eq SelectionConstraints Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal.Collateral

Show SelectionConstraints Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal.Collateral

Generic SelectionConstraints Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal.Collateral

type Rep SelectionConstraints Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal.Collateral

type Rep SelectionConstraints = D1 (' MetaData "SelectionConstraints" "Cardano.Wallet.CoinSelection.Internal.Collateral" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' False ) ( C1 (' MetaCons "SelectionConstraints" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "maximumSelectionSize") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 Int ) :*: S1 (' MetaSel (' Just "searchSpaceLimit") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 SearchSpaceLimit )))

data SelectionParams u Source #

Specifies all parameters that are specific to a given selection.

Constructors

SelectionParams

Fields

newtype SelectionResult u Source #

Represents a successful selection of collateral.

Constructors

SelectionResult

Fields

selectionResultEmpty :: SelectionResult u Source #

A completely empty result, with no inputs selected.

data SelectionCollateralError u Source #

Represents an unsuccessful attempt to select collateral.

Constructors

SelectionCollateralError

Fields

Instances

Instances details
Eq u => Eq ( SelectionCollateralError u) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal.Collateral

Show u => Show ( SelectionCollateralError u) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal.Collateral

Generic ( SelectionCollateralError u) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal.Collateral

type Rep ( SelectionCollateralError u) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal.Collateral

type Rep ( SelectionCollateralError u) = D1 (' MetaData "SelectionCollateralError" "Cardano.Wallet.CoinSelection.Internal.Collateral" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' False ) ( C1 (' MetaCons "SelectionCollateralError" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "largestCombinationAvailable") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ( Map u Coin )) :*: S1 (' MetaSel (' Just "minimumSelectionAmount") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 Coin )))

data SearchSpaceLimit Source #

Specifies an upper bound on the search space size.

Constructors

SearchSpaceLimit Int

Specifies an upper bound on the number of coin combinations that can be considered in any single step.

UnsafeNoSearchSpaceLimit

Specifies that there is no search space limit. This should only be used for testing purposes.

searchSpaceLimitDefault :: SearchSpaceLimit Source #

The default search space limit.

This constant is used by the test suite, so we can be reasonably confident that performing selections with this limit will not use inordinate amounts of time and space.

Internal API

Selecting collateral by giving priority to smallest values first

selectCollateralSmallest :: forall u. Ord u => PerformSelection u Source #

Attempts to select an amount of collateral that is as small as possible.

This function, given unlimited computation time, will always produce an optimal result: the smallest possible amount of collateral. However, if the required search space is large, and if the $sel:searchSpaceLimit:SelectionConstraints parameter is set to a value that's smaller than the required search space size, then this function will return without computing a result.

Selecting collateral by giving priority to largest values first

selectCollateralLargest :: forall u. Ord u => PerformSelection u Source #

Selects collateral from the largest coins available.

This function sacrifices optimality and always produces a result if one is available, by looking only at the very largest coins available.

This result can be computed very quickly, without using much search space.

Guarding search space size

data SearchSpaceRequirement Source #

Constructors

SearchSpaceRequirement Int

Indicates a known search space requirement.

SearchSpaceRequirementUnknown

Indicates that the search space requirement is unknown.

guardSearchSpaceSize Source #

Arguments

:: SearchSpaceRequirement

The search space requirement

-> SearchSpaceLimit

The search space limit

-> Maybe a

A computation that potentially yields a value

-> Maybe a

The guarded computation

Generating submaps

submaps :: forall a b. ( Ord a, Ord b) => Map a b -> Set ( Map a b) Source #

Generates all submaps of a given map.

This function is analogous to powerSet .

For a map m of size n , this function will generate all possible submaps, including the empty map and the original map m .

Generating subsequences

subsequencesOfSize Source #

Arguments

:: [a]

The sequence from which to generate subsequences.

-> Int

The size k of subsequences to generate.

-> [[a]]

All subsequences of size k .

Generates all subsequences of size k from a particular sequence.

Warning: this function can use an excessive amount of time and space.

To check how many results would be returned without actually generating them, use the numberOfSubsequencesOfSize function.

Properties:

>>> all (== k) (length <$> xs `subsequencesOfSize` k)
>>> length (xs `subsequencesOfSize` k) ==
>>> length xs `numberOfSubsequencesOfSize` k

numberOfSubsequencesOfSize Source #

Arguments

:: Int

Indicates the size of the sequence.

-> Int

Indicates the size of subsequences.

-> Maybe Int

Computes the number of subsequences generated by subsequencesOfSize .

This function can be used to determine whether calling subsequencesOfSize would use an excessive amount of time and space, and if so, avoid calling it.

Returns Nothing if the result is larger than 'maxBound :: Int'.

Control flow

firstRight :: NonEmpty (a -> Either e r) -> a -> Either e r Source #

Applies a sequence of functions to an argument until one succeeds.

This function iterates through the specified sequence from left to right, applying each function to the given argument, and returning the very first Right result encountered, without evaluating the subsequent functions.

If none of the given functions produces a Right result, then this function returns the Left result produced by the last function in the sequence.

takeUntil :: (a -> Bool ) -> [a] -> [a] Source #

Takes items from a list until a predicate becomes true.

The returned list is a prefix of the original list, and includes the very first item that satisfies the predicate.