Skip to content

Conversation

@ishaanam
Copy link
Contributor

@ishaanam ishaanam commented Jun 15, 2022

This PR adds a "minconf" option to fundrawtransaction, walletcreatefundedpsbt, and sendall.
Alternative implementation of #14641
Fixes #14542

Edit: This PR now also adds this option to send

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 15, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK Xekyo, achow101, furszy
Stale ACK w0xlt, 1440000bytes

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #26732 (wallet: tx creation, don't select outputs from txes that are being replaced by furszy)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

ACK 0f023da

Tested minconf argument on regtest with:

$ bitcoin-cli generatetoaddress 102 bcrt1qjjdvpcz3l2p4q2y7zc6ztkk3rvagke248y6ckm

$ bitcoin-cli listunspent
[
  {
    "txid": "56a91239cfcff53da811ae1969bb6e8e288f15ab58cac8fe455ea906a3b51ecb",
    "vout": 0,
    "address": "bcrt1qjjdvpcz3l2p4q2y7zc6ztkk3rvagke248y6ckm",
    "label": "",
    "scriptPubKey": "0014949ac0e051fa8350289e163425dad11b3a8b6555",
    "amount": 50.00000000,
    "confirmations": 101,
    "spendable": true,
    "solvable": true,
    "desc": "wpkh([ae30e814/84'/1'/0'/0/0]020a3db12de02b1f4bbb5e5016f7cebaa427e0c60d20b95ebc552ceb97c86f3722)#n2vukszk",
    "safe": true
  },
  {
    "txid": "f1257f379856d91401d27229dbdf797802a521edb6f958bc884e316265a48cfc",
    "vout": 0,
    "address": "bcrt1qjjdvpcz3l2p4q2y7zc6ztkk3rvagke248y6ckm",
    "label": "",
    "scriptPubKey": "0014949ac0e051fa8350289e163425dad11b3a8b6555",
    "amount": 50.00000000,
    "confirmations": 102,
    "spendable": true,
    "solvable": true,
    "desc": "wpkh([ae30e814/84'/1'/0'/0/0]020a3db12de02b1f4bbb5e5016f7cebaa427e0c60d20b95ebc552ceb97c86f3722)#n2vukszk",
    "safe": true
  }
]

$ bitcoin-cli createrawtransaction '[]' '{"data":"505220233235333735"}'

02000000000100000000000000000b6a0950522023323533373500000000


$ bitcoin-cli fundrawtransaction "02000000000100000000000000000b6a0950522023323533373500000000" "{\"minconf\": 102}"
{
  "hex": "0200000001fc8ca46562314e88bc58f9b6ed21a5027879dfdb2972d20114d95698377f25f10000000000feffffff0272f1052a010000002251209b08765d5b558137195f9b3b5b4f5ceaffddcac91590e76f904fdde08cc033bb00000000000000000b6a0950522023323533373500000000",
  "fee": 0.00000142,
  "changepos": 0
}

$ bitcoin-cli decoderawtransaction 0200000001fc8ca46562314e88bc58f9b6ed21a5027879dfdb2972d20114d95698377f25f10000000000feffffff0272f1052a010000002251209b08765d5b558137195f9b3b5b4f5ceaffddcac91590e76f904fdde08cc033bb00000000000000000b6a0950522023323533373500000000
{
  "txid": "4974082891c14f96170f2af7f381e3a6f9510cb9e42841b1e12463f09b164ad5",
  "hash": "4974082891c14f96170f2af7f381e3a6f9510cb9e42841b1e12463f09b164ad5",
  "version": 2,
  "size": 114,
  "vsize": 114,
  "weight": 456,
  "locktime": 0,
  "vin": [
    {
      "txid": "f1257f379856d91401d27229dbdf797802a521edb6f958bc884e316265a48cfc",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "sequence": 4294967294
    }
  ],
  "vout": [
    {
      "value": 49.99999858,
      "n": 0,
      "scriptPubKey": {
        "asm": "1 9b08765d5b558137195f9b3b5b4f5ceaffddcac91590e76f904fdde08cc033bb",
        "desc": "addr(bcrt1pnvy8vh2m2kqnwx2lnva4kn6uatlamjkfzkgwwmusflw7prxqxwas8y08ed)#4mpq27kr",
        "hex": "51209b08765d5b558137195f9b3b5b4f5ceaffddcac91590e76f904fdde08cc033bb",
        "address": "bcrt1pnvy8vh2m2kqnwx2lnva4kn6uatlamjkfzkgwwmusflw7prxqxwas8y08ed",
        "type": "witness_v1_taproot"
      }
    },
    {
      "value": 0.00000000,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_RETURN 505220233235333735",
        "desc": "raw(6a09505220233235333735)#wxsnvgu2",
        "hex": "6a09505220233235333735",
        "type": "nulldata"
      }
    }
  ]
}
$ bitcoin-cli fundrawtransaction "02000000000100000000000000000b6a0950522023323533373500000000" "{\"minconf\": 103}"
error code: -4
error message:
Insufficient funds

nit: If no UTXO available in wallet with minconf confirmations, the error could be specific to help the user. Example: Insufficient funds with required confirmations

@achow101
Copy link
Member

nit: If no UTXO available in wallet with minconf confirmations, the error could be specific to help the user. Example: Insufficient funds with required confirmations

It's actually quite difficult currently to get more specific errors out of coin selection. There's quite a bit of plumbing needed that does not currently exist. #25218 and #24845 add a lot of what is needed to get such errors, but there's still an additional issue where it is hard to tell whether the insufficient funds is due to this particular filter or something else in coin selection.

Copy link
Contributor

@w0xlt w0xlt left a comment

Choose a reason for hiding this comment

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

Code Review ACK 0f023da

@w0xlt
Copy link
Contributor

w0xlt commented Jun 18, 2022

Perhaps this same option could be included in send() RPC ?
This also creates a CCoinControl object and passes it to FundTransaction(), just like the other methods covered in this PR.

@luke-jr
Copy link
Member

luke-jr commented Jun 18, 2022

This seems like a subset of #22049

@ishaanam ishaanam force-pushed the fundrawtransaction_minconf branch from 0f023da to 1e14aea Compare June 20, 2022 16:47
@ishaanam
Copy link
Contributor Author

Changes made since last push:

  • refactored sendall tests based on feedback from @xekyo
  • moved minconf help text to FundTxDoc
  • added minconf option to send as suggested by @w0xlt and added a test for that
  • added check that minconf is not negative and added tests to ensure that an error is raised when minconf is negative

@ishaanam
Copy link
Contributor Author

This seems like a subset of #22049

Yes, I didn't see that one since it didn't mention the issue I was looking at. I took a look at the other PR and it looks like the main differences, disregarding the tests, are that this one doesn't implement maxconf, but does implement the minconf option for sendall as well.

@ishaanam
Copy link
Contributor Author

I'm closing this PR as it is quite similar to #22049

@ishaanam ishaanam closed this Aug 15, 2022
@luke-jr
Copy link
Member

luke-jr commented Sep 28, 2022

@ishaanam As #22049 has been abandoned, perhaps copy and rebase it here?

P.S. I still have a rebased version at master...luke-jr:rpc_fundtx_minmaxconf

@ghost
Copy link

ghost commented Sep 29, 2022

@ishaanam As #22049 has been abandoned, perhaps copy and rebase it here?

P.S. I still have a rebased version at master...luke-jr:rpc_fundtx_minmaxconf

I agree with @luke-jr , its important to fix the issue not the author or pr and #22049 is abandoned

@ishaanam ishaanam reopened this Sep 29, 2022
@ishaanam ishaanam force-pushed the fundrawtransaction_minconf branch 3 times, most recently from 7e24831 to 3f0f67c Compare September 29, 2022 20:47
@ishaanam
Copy link
Contributor Author

@ishaanam As #22049 has been abandoned, perhaps copy and rebase it here?

P.S. I still have a rebased version at master...luke-jr:rpc_fundtx_minmaxconf

I have reopened this PR, thanks for rebasing #22049!

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

reACK 3f0f67c

@ishaanam ishaanam changed the title rpc: add minconf option to sendall and fund transaction calls rpc: add minconf/maxconf options to sendall and fund transaction calls Oct 1, 2022
@ishaanam ishaanam force-pushed the fundrawtransaction_minconf branch from 3f0f67c to a7ab096 Compare October 21, 2022 17:17
@ishaanam
Copy link
Contributor Author

Rebased

@ishaanam ishaanam force-pushed the fundrawtransaction_minconf branch from f38eb81 to 18e277f Compare December 4, 2022 20:01
@ishaanam ishaanam force-pushed the fundrawtransaction_minconf branch from 18e277f to b3a3cb1 Compare December 10, 2022 16:10
Copy link
Member

@furszy furszy left a comment

Choose a reason for hiding this comment

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

Almost there, code reviewed b3a3cb14.
Left a last finding and it's ready to go.

@ishaanam ishaanam force-pushed the fundrawtransaction_minconf branch from b3a3cb1 to 24c906b Compare December 20, 2022 19:31
Copy link
Member

@furszy furszy left a comment

Choose a reason for hiding this comment

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

ACK 24c906b

@achow101
Copy link
Member

ACK 24c906b3311336ccaf5ea9c70da5ebde6f1cd041

Copy link
Contributor

@murchandamus murchandamus left a comment

Choose a reason for hiding this comment

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

I noticed that 1e14aea added a test for send in test/functional/wallet_send.py, but that test does not seem to be part of the latest change set. Is it possible that the send test got lost accidentally or did I miss the reasoning why it got removed?

@ishaanam
Copy link
Contributor Author

ishaanam commented Jan 11, 2023

@xekyo good catch. I replaced some of my commits with those from #22049 and it looks like that didn't include a test for send. I'll add that back soon.

@ishaanam ishaanam force-pushed the fundrawtransaction_minconf branch from 24c906b to 41ebc2b Compare January 11, 2023 20:37
Copy link
Contributor

@murchandamus murchandamus left a comment

Choose a reason for hiding this comment

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

ACK 41ebc2b0294941d12980e19307bd991f9ff85301

champo and others added 2 commits January 11, 2023 17:08
… fund calls

Enables users to craft BIP-125 replacements with changes to the output
list, ensuring that if additional funds are needed they will be added.
@ishaanam ishaanam force-pushed the fundrawtransaction_minconf branch from 41ebc2b to cfe5aeb Compare January 11, 2023 22:10
@ishaanam
Copy link
Contributor Author

ishaanam commented Jan 11, 2023

Rebased for silent merge conflict.

Copy link
Contributor

@murchandamus murchandamus left a comment

Choose a reason for hiding this comment

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

ACK cfe5aeb

Comment on lines +1398 to +1399
if (coin_control.m_max_depth < coin_control.m_min_depth) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("maxconf can't be lower than minconf: %d < %d", coin_control.m_max_depth, coin_control.m_min_depth));
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to myself/other reviewers . m_min_depth is initialized to DEFAULT_MIN_DEPTH = 0 in coincontrol.h, which is why this check of m_max_depth will always be defined and weed out negative numbers.

@achow101
Copy link
Member

ACK cfe5aeb

Copy link
Member

@furszy furszy left a comment

Choose a reason for hiding this comment

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

diff ACK cfe5aeb, only a non-blocking nit.


self.log.info("Minconf")
self.nodes[1].createwallet(wallet_name="minconfw")
minconfw= self.nodes[1].get_wallet_rpc("minconfw")
Copy link
Member

Choose a reason for hiding this comment

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

nit:
missing space

Suggested change
minconfw= self.nodes[1].get_wallet_rpc("minconfw")
minconfw = self.nodes[1].get_wallet_rpc("minconfw")

@achow101 achow101 merged commit b55b11f into bitcoin:master Jan 16, 2023
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 17, 2023
"Warning: the resulting transaction may become invalid if one of the unsafe inputs disappears.\n"
"If that happens, you will need to fund the transaction with different inputs and republish it."},
{"minconf", RPCArg::Type::NUM, RPCArg::Default{0}, "If add_inputs is specified, require inputs with at least this many confirmations."},
{"maxconf", RPCArg::Type::NUM, RPCArg::Optional::OMITTED, "If add_inputs is specified, require inputs with at most this many confirmations."},
Copy link
Member

Choose a reason for hiding this comment

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

nit: Looks like this should be documented as (optional) in the RPC doc output. In theory this instance can be fixed by replacing OMITTED with OMITTED_NAMED_ARG, however a more complete fix is in #26706

(Same for other "maxconf" in this pull)

@harding
Copy link
Contributor

harding commented Jan 23, 2023

What was the motivation for the maxconf parameter? I'm guessing it's was the result of @achow101's comment, but I'm having trouble imagining a situation where someone might want to skip using UTXOs older than x blocks.

@ishaanam
Copy link
Contributor Author

@harding
It could be useful in the scenario in which someone doesn't want to reveal the age of their wallet (Eg. specify maxconf as 2016 confirmations so that the recipient doesn't know that the wallet dates all the way back to 10 years ago).

luke-jr pushed a commit to luke-jr/bitcoin that referenced this pull request Jul 5, 2023
… fund calls

Enables users to craft BIP-125 replacements with changes to the output
list, ensuring that if additional funds are needed they will be added.

Github-Pull: bitcoin#25375
Rebased-From: 3e14de57e0c1bd7692deadfde9f99b1683e5becd
luke-jr pushed a commit to luke-jr/bitcoin that referenced this pull request Jul 5, 2023
Github-Pull: bitcoin#25375
Rebased-From: 18e277fcf261ebb66cf7e8a25b380e4d6da9111f
@ishaanam ishaanam deleted the fundrawtransaction_minconf branch November 30, 2023 03:18
@bitcoin bitcoin locked and limited conversation to collaborators Nov 29, 2024
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.

fundrawtransaction - select input transaction with minimum confirmations