diff options
author | furszy <matiasfurszyfer@protonmail.com> | 2022-08-02 11:54:20 -0300 |
---|---|---|
committer | furszy <matiasfurszyfer@protonmail.com> | 2023-03-06 09:45:40 -0300 |
commit | bd91ed1cb2cc804f824d1b204513ac2afb7d5e28 (patch) | |
tree | 9956b147f73c622e5f895337fb27c1c3a0098613 /src/wallet/coinselection.h | |
parent | 55962001da4f8467e52da502b05f5c0a85128fb0 (diff) |
wallet: unify outputs grouping process
The 'GroupOutputs()' function performs the same
calculations for only-positive and mixed groups,
the only difference is that when we look for
only-positive groups, we discard negative utxos.
So, instead of wasting resources calling GroupOutputs()
for positive-only first, then call it again to include
the negative ones in the result, we can execute
GroupOutputs() only once, including in the response
both group types (positive-only and mixed).
Diffstat (limited to 'src/wallet/coinselection.h')
-rw-r--r-- | src/wallet/coinselection.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/wallet/coinselection.h b/src/wallet/coinselection.h index 6443bc3087..420892e06e 100644 --- a/src/wallet/coinselection.h +++ b/src/wallet/coinselection.h @@ -7,6 +7,7 @@ #include <consensus/amount.h> #include <consensus/consensus.h> +#include <outputtype.h> #include <policy/feerate.h> #include <primitives/transaction.h> #include <random.h> @@ -249,6 +250,21 @@ struct Groups { std::vector<OutputGroup> mixed_group; }; +/** Stores several 'Groups' whose were mapped by output type. */ +struct OutputGroupTypeMap +{ + // Maps output type to output groups. + std::map<OutputType, Groups> groups_by_type; + // All inserted groups, no type distinction. + Groups all_groups; + + // Based on the insert flag; appends group to the 'mixed_group' and, if value > 0, to the 'positive_group'. + // This affects both; the groups filtered by type and the overall groups container. + void Push(const OutputGroup& group, OutputType type, bool insert_positive, bool insert_mixed); + // Retrieves 'Groups' filtered by type + std::optional<Groups> Find(OutputType type); +}; + /** Compute the waste for this result given the cost of change * and the opportunity cost of spending these inputs now vs in the future. * If change exists, waste = change_cost + inputs * (effective_feerate - long_term_feerate) |