Skip to content

rpc: bugfix, 'add_inputs' default value is true unless 'inputs' are provided - #26053

Merged
achow101 merged 2 commits into
bitcoin:masterfrom
furszy:2022_rpc_wallet_fix_help_add_inputs
Sep 14, 2022
Merged

achow101 merged 2 commits into
bitcoin:masterfrom
furszy:2022_rpc_wallet_fix_help_add_inputs

Conversation

@furszy

@furszy furszy commented Sep 9, 2022

Copy link
Copy Markdown
Member

This bugfix was meant to be in #25685, but decoupled it to try to make it part of 24.0 release.
It's a truly misleading functionality.

This PR doesn't change behavior in any way. Just fixes two invalid RPC help messages and adds test
coverage for the current behavior.

Description

In both RPC commands send() and walletcreatefundedpsbt the help message says
that add_inputs default value is false when it's actually dynamically set by the following statement:

coin_control.m_allow_other_inputs = rawTx.vin.size() == 0;

Which means that, by default, add_inputs is true unless there is any pre-set input, in which
case, the default is false.

@amovfx amovfx left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I appreciated how well your test was commented. That really helps someone new like me read whats going on.

@DrahtBot

DrahtBot commented Sep 9, 2022

Copy link
Copy Markdown
Contributor

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #25685 (wallet: Faster transaction creation by removing pre-set-inputs fetching responsibility from Coin Selection 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.

@maflcko maflcko added this to the 24.0 milestone Sep 10, 2022
Comment thread src/wallet/rpc/spend.cpp Resolved
@maflcko maflcko added the Docs label Sep 10, 2022
@furszy
furszy force-pushed the 2022_rpc_wallet_fix_help_add_inputs branch from 2e37f0a to 1350349 Compare September 10, 2022 12:36
@furszy

furszy commented Sep 10, 2022

Copy link
Copy Markdown
Member Author

Thanks MarkoFalke, feedback tackled.

Changed RPCArg::Default to RPCArg::DefaultHint.

@aureleoules aureleoules left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK 1350349f5951a4e1fdc7d92018cb5be6c014e99a.
Verified that m_allow_other_inputs is overridden when inputs are passed.

nit if you retouch: use .empty() instead of .size() == 0.

coin_control.m_allow_other_inputs = rawTx.vin.size() == 0;

@w0xlt w0xlt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK 1350349

@S3RK

S3RK commented Sep 13, 2022

Copy link
Copy Markdown
Contributor

Code Review ACK 1350349f5951a4e1fdc7d92018cb5be6c014e99a

Verified that the new help text is consistent with the behaviour. I agree that the new help text is less confusing.

@fanquake
fanquake requested a review from achow101 September 13, 2022 16:25
Comment thread src/wallet/rpc/spend.cpp Resolved
…rovided

In both RPC commands `send()` and `walletcreatefundedpsbt` the RPC help was saying
that `add_inputs` default value was false when it's actually dynamically set
by the following statement:

`coin_control.m_allow_other_inputs = rawTx.vin.size() == 0;`

Which means that, by default, `add_inputs` is true unless there
was any pre-set input, in which case, the default is false.
@furszy
furszy force-pushed the 2022_rpc_wallet_fix_help_add_inputs branch from 1350349 to 40b2010 Compare September 13, 2022 19:15
@furszy

furszy commented Sep 13, 2022

Copy link
Copy Markdown
Member Author

Thanks achow101, feedback tackled (and a bit more).

Added two new test scenarios:

  1. Explicit add_inputs=true and preset inputs (with preset inputs not-covering the target amount).
           Expect: include inputs from the wallet.

  2. Explicit add_inputs=true and preset inputs (with preset inputs covering the target amount).
           Expect: only preset inputs are used.

@achow101

Copy link
Copy Markdown
Member

ACK 40b20102371d9fa6ae3dcdcb32a678a940e1130a

Covered cases for send() and walletcreatefundedpsbt() RPC commands:

1. Default add_inputs value with no preset inputs (add_inputs=true):
       Expect: automatically add coins from the wallet to the tx.

2. Default add_inputs value with preset inputs (add_inputs=false):
       Expect: disallow automatic coin selection.

3. Explicit add_inputs=true and preset inputs (with preset inputs not-covering the target amount).
       Expect: include inputs from the wallet.

4. Explicit add_inputs=true and preset inputs (with preset inputs covering the target amount).
       Expect: only preset inputs are used.

5. Explicit add_inputs=true, no preset inputs (same as (1) but with an explicit set):
       Expect: include inputs from the wallet.
@furszy
furszy force-pushed the 2022_rpc_wallet_fix_help_add_inputs branch from 40b2010 to b00fc44 Compare September 14, 2022 14:14
@furszy

furszy commented Sep 14, 2022

Copy link
Copy Markdown
Member Author

Thanks @S3RK, review tackled.
Only made a small modification to one of the test comments: diff

@achow101

Copy link
Copy Markdown
Member

ACK b00fc44

1 similar comment
@S3RK

S3RK commented Sep 14, 2022

Copy link
Copy Markdown
Contributor

ACK b00fc44

@achow101
achow101 merged commit 2e3cd26 into bitcoin:master Sep 14, 2022
@furszy
furszy deleted the 2022_rpc_wallet_fix_help_add_inputs branch May 27, 2023 01:47
@bitcoin bitcoin locked and limited conversation to collaborators May 26, 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.

8 participants