Skip to content

Conversation

@pedrobranco
Copy link
Contributor

@pedrobranco pedrobranco commented Oct 18, 2016

This PR adds a new optional JSON options for listunspent RPC call:

  • Return unspents greater or equal than a specific amount in BTC: minimumAmount (default = 0).
  • Return unspents lower or equal than a specific amount in BTC: maximumAmount (default = MAX_MONEY = 21000000.0 BTC).
  • Return unspents with a total number lower or equal than a specific number: maximumCount (default=0=unlimited).
  • Return unspents which total is greater or equal than a specific amount in BTC: minimumSumAmount (default = MAX_MONEY = 21000000.0 BTC).
> bitcoin-cli help listunspent
...
5. query options    (json, optional) JSON with query options
    {
      "minimumAmount"    (numeric or string, default=0) Minimum value of each UTXO in BTC
      "maximumAmount"    (numeric or string, default=21000000=unlimited) Maximum value of each UTXO in BTC
      "maximumCount"     (numeric or string, default=0=unlimited) Maximum number of UTXOs
      "minimumSumAmount" (numeric or string, default=21000000=unlimited) Minimum sum value all UTXOs in BTC
    }
...

When selecting unspents on client side in a wallet with a large set of small unspents makes the call listunspent slow. Using with minimumAmount option could improve the performance of the RPC call, performance which depends on the size of wallet, the distribution of the unspents and the minimumAmount selected.

Example:

> bitcoin-cli listunspent 0 9999999 '[]' true '{ "minimumAmount": 10, "maximumAmount": 80, "minimumSumAmount": 50, "maximumCount": 3 }'

Note: this PR also changes/simplifies the code in AvailableCoins to make the longest calls later in execution time, which also could improve performance in some listunspent results.

@pedrobranco pedrobranco force-pushed the enhancement/improve-rpc-listunspent branch from 57b9e76 to 3f89e80 Compare October 18, 2016 11:46
@pedrobranco pedrobranco force-pushed the enhancement/improve-rpc-listunspent branch 3 times, most recently from e1881d9 to 2e423ea Compare October 19, 2016 11:50
@laanwj
Copy link
Member

laanwj commented Oct 19, 2016

Concept ACK

@pedrobranco
Copy link
Contributor Author

WDYT of adding new options like maximumAmount (which ables to define a range with minimumAmount) or maybe sumAmount (return unspents until the respective sum is bigger than sumAmount) ?

@pedrobranco pedrobranco force-pushed the enhancement/improve-rpc-listunspent branch from 2e423ea to 5cf4057 Compare October 19, 2016 14:36
@laanwj
Copy link
Member

laanwj commented Oct 19, 2016

Yes, would make sense. Passing the JSON "query object" is a good idea.

@pedrobranco
Copy link
Contributor Author

pedrobranco commented Oct 19, 2016

I'm willing to implement I've also implemented maximumAmount, minimumSumAmount and maximumCount options.

minimumAmount and maximumAmount are options to filter unspents, but maximumCount and minimumSumAmount are grouping options which returns unspents until satisfies one of these conditions.

@pedrobranco pedrobranco force-pushed the enhancement/improve-rpc-listunspent branch from 5cf4057 to 6660c22 Compare October 19, 2016 18:06
@pedrobranco pedrobranco changed the title Add selection options to listunspent RPC call Add query options to listunspent RPC call Oct 19, 2016
@pedrobranco pedrobranco force-pushed the enhancement/improve-rpc-listunspent branch from 6660c22 to 98d0a6f Compare October 19, 2016 18:12
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Dec 21, 2016
Github-Pull: bitcoin#8952
Rebased-From: 98d0a6fb81b33a2cef429d3d6f9d56dd47508076
Copy link
Member

@luke-jr luke-jr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK code, one nit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of the dual meanings, just say default=unlimited (and make sure 0 doesn't behave in such a manner).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@pedrobranco pedrobranco force-pushed the enhancement/improve-rpc-listunspent branch from 98d0a6f to ae6a0c0 Compare February 3, 2017 18:05
@pedrobranco
Copy link
Contributor Author

pedrobranco commented Feb 7, 2017

@laanwj @luke-jr Is this PR mergeable as is?

@laanwj
Copy link
Member

laanwj commented Feb 7, 2017

Looks like it! but as we're past the feature freeze for 0.14 and this is a new feature, merging this will have to wait until 0.14 is branched off.

@pedrobranco
Copy link
Contributor Author

About tests: there aren't any tests specifically for testing listunspent options. Should we now create them?

@laanwj
Copy link
Member

laanwj commented Feb 7, 2017

Yes, tests for that would be great. They'd make it possible to automatically detect when something breaks this functionality.

nTotal += pcoin->tx->vout[i].nValue;

if (nTotal >= nMinimumSumAmount) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm misreading, but this (nMinimumSumAmount) sounds like a maximum, not a minimum. Esp. since it defaults to MAX_MONEY rather than 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no issue here since is to be used like it was a minorant set of unspents which satisfies the passed value. If It it was called maximum it should not retrieve unspents which sum are greater than the passed value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are collecting the sum of the nValue and once the total exceeds the minimum you stop. Generally speaking,

int minimumSum = 5;
int values[] = {1,2,3,2,3};
int sum = 0;
for (int i = 0; i < 5; i++) {
  sum += values[i];
  if (sum >= minimumSum) break;
}

The above looks inverted to me, and will no doubt confuse the user. If you used the word minorant, it might help, but the minorant would be the vout set not the sum, I believe?

Anyway, if I'm the only one bothered by this feel free to keep as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kallewoof Any suggestions? nTargetSumAmount?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pedrobranco I say keep it as it is if no one else complains.

" \"minimumAmount\" (numeric or string, default=0) Minimum value of each UTXO in " + CURRENCY_UNIT + "\n"
" \"maximumAmount\" (numeric or string, default=unlimited) Maximum value of each UTXO in " + CURRENCY_UNIT + "\n"
" \"maximumCount\" (numeric or string, default=unlimited) Maximum number of UTXOs\n"
" \"minimumSumAmount\" (numeric or string, default=unlimited) Minimum sum value all UTXOs in " + CURRENCY_UNIT + "\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: [...]Minimum sum value of all UTXOs in " (missing of).

"\nReturns array of unspent transaction outputs\n"
"with between minconf and maxconf (inclusive) confirmations.\n"
"Optionally filter to only include txouts paid to specified addresses.\n"
"\nArguments:\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add options to the first line, e.g.

"listunspent ( minconf maxconf  [\"addresses\",...] [include_unsafe] [options] )\n"

@pedrobranco
Copy link
Contributor Author

pedrobranco commented Mar 7, 2017

Yes, tests for that would be great. They'd make it possible to automatically detect when something breaks this functionality.

@laanwj I'm already working on it. Can I submit in another PR?

@pedrobranco pedrobranco force-pushed the enhancement/improve-rpc-listunspent branch 4 times, most recently from bba51b1 to c03488f Compare March 8, 2017 11:52
@fanquake
Copy link
Member

fanquake commented Apr 2, 2017

This needs a rebase. @pedrobranco Tests could be submitted in a follow-up PR.

@pedrobranco pedrobranco force-pushed the enhancement/improve-rpc-listunspent branch from c03488f to 4f6566d Compare April 4, 2017 19:06
@pedrobranco pedrobranco force-pushed the enhancement/improve-rpc-listunspent branch from 4f6566d to 11ee5ec Compare April 5, 2017 00:08
@laanwj
Copy link
Member

laanwj commented May 17, 2017

Merged (and rebased) via 9390845

@laanwj laanwj mentioned this pull request May 17, 2017
12 tasks
@pedrobranco
Copy link
Contributor Author

Thank you @laanwj 👍

@sipa
Copy link
Member

sipa commented May 18, 2017

@laanwj I suppose you forgot to close after merging?

@sipa sipa closed this May 18, 2017
@laanwj
Copy link
Member

laanwj commented May 18, 2017 via email

@pedrobranco pedrobranco deleted the enhancement/improve-rpc-listunspent branch June 5, 2017 15:42
@fedelcs
Copy link

fedelcs commented Jul 12, 2018

@pedrobranco I've been trying to use the minimumSumAmount along with the addresses parameter, and I keep getting fewer outputs than I should.

Looking at the code it seems that the minimumSumAmount is applied first, finding a correct set of outputs, but then when the addresses/destinations are checked, some of those are removed.

Is this the expected behavior? Shouldn't this be, first get all UTXO's that belong to addresses and then apply the filters?

@promag
Copy link
Contributor

promag commented Jul 13, 2018

Looks like a bug.

@promag
Copy link
Contributor

promag commented Jul 15, 2018

@fedelcs IIRC minimumSumAmount was added to allow early returns in the coin selection. Note that the problem only exists when both args are used.

To fix this we should either:

  • push down address filtering to CWallet::AvailableCoins
  • truncate the result once the minimumSumAmount is achieved.

@RussianSwiss
Copy link

RussianSwiss commented Jul 20, 2018

Need to have a feature show all addresses' UTXO set with non-zero balance (not only own addresses like listunspent) in Bitcoin Core as a build-in feature.

PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 26, 2019
bc63d0e Add query options to listunspent rpc call (Pedro Branco)

Tree-SHA512: 2d296eee8df4e7ac378206ac3003a300e6478502d4b814f1ed1a47614222b01cc35dba871345ced68629860c227aff2c9e4b7f0d4ed0aa7de8b04f26c983580f
Signed-off-by: Pasta <[email protected]>

# Conflicts:
#	src/rpc/client.cpp
#	src/wallet/rpcwallet.cpp
#	src/wallet/wallet.cpp
#	src/wallet/wallet.h
furszy added a commit to PIVX-Project/PIVX that referenced this pull request May 17, 2021
063abcf [Doc] Add query_options listunspent parameter to release notes (random-zebra)
602f622 [QA] Excercise query_options parameter in listunspent (random-zebra)
93d4789 [RPC] Backport RPCTypeCheckArgument function and use it inside listunspent (furszy)
c073ef2 [RPC] Add query options to listunspent rpc call. (furszy)

Pull request description:

  Adaptation of bitcoin#8952

  This PR adds a new optional JSON options for `listunspent` RPC call:

  * Return unspents greater or equal than a specific amount in PIV: minimumAmount.
  * Return unspents lower or equal than a specific amount in PIV: maximumAmount.
  * Return unspents with a total number lower or equal than a specific number: maximumCount.
  * Return unspents which total is greater or equal than a specific amount in PIV: minimumSumAmount.

  ```
  > pivx-cli help listunspent
  ...
  5. query options    (json, optional) JSON with query options
      {
        "minimumAmount"    (numeric or string, default=0) Minimum value of each UTXO in PIV
        "maximumAmount"    (numeric or string, default=unlimited) Maximum value of each UTXO in PIV
        "maximumCount"     (numeric or string, default=0=unlimited) Maximum number of UTXOs
        "minimumSumAmount" (numeric or string, default=unlimited) Minimum sum value all UTXOs in PIV
      }
  ...
  ```

ACKs for top commit:
  random-zebra:
    ACK 063abcf
  Fuzzbawls:
    ACK 063abcf

Tree-SHA512: 0a54636657be5e366ddfff374cacb2cac9e7667af99e67d96dfefc3255a06d431dfb75539c90af8727d97697933042cd19ddf968894e655a5fd20a7b6eaeb5aa
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants