Skip to content

Conversation

@furszy
Copy link
Member

@furszy furszy commented May 12, 2022

Built on top of #23662, coming from comment #23662 (review).

If wallet.GetLabelAddresses() returns an empty vector (the wallet does not have stored destinations with that label in the addressbook) or if none of the returned destinations are from the wallet, we can return the function right away.
Otherwise, we are walking through all the wallet txs + outputs for no reason (output_scripts is empty).

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

Concept ACK

Thanks for following up!
As expressed in #23662 (comment), I think users should be notified with an error if a label is passed that doesn't exist in the wallet address book. Not sure yet if it's worth the effort, but one could even go one step further and throw two different error messages for the cases

  • there is no such label in the address book (i.e. wallet.GetLabelAddresses returns an empty set)
  • there is a label, but it doesn't apply to any address that is ours (i.e. after IsMine filtering, output_scripts is empty)

As of the current state of the PR, I think the simplest (minimal-diff) solution would be to move that part

    if (output_scripts.empty()) {
        throw JSONRPCError(RPC_WALLET_ERROR, "Address/es not found in wallet");
    }

to the end of the if (by_label) { ... } block. Then you could also be more specific with the message and say, e.g. "Label not found in wallet" (as you outlined in #23662 (comment)). Note also that the CI indicates that the functional test wallet_listreceivedby.py needs to be adapted.

@furszy
Copy link
Member Author

furszy commented May 13, 2022

yep pushed. Tests passing now. Will rebase it once your PR gets merged.

@DrahtBot
Copy link
Contributor

DrahtBot commented May 13, 2022

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

Conflicts

No conflicts as of last run.

@furszy furszy force-pushed the 2022_RPC_getreceivedbylabel_return_early branch from 6482941 to 73aea8c Compare May 17, 2022 12:45
@achow101
Copy link
Member

ACK 73aea8c65e4810f3e41c8351f80ae43e276fc1d5

@maflcko maflcko changed the title rpc: getreceivedbylabel, return early if no addresses were found in the address book. rpc: getreceivedbylabel, return early if no addresses were found in the address book May 18, 2022
@kristapsk
Copy link
Contributor

This needs release notes, as API is changed for cases when specified label does not exist in wallet.

@furszy
Copy link
Member Author

furszy commented May 19, 2022

This needs release notes, as API is changed for cases when specified label does not exist in wallet.

pushed 👍🏼.

@achow101
Copy link
Member

re-ACK 77915c1c21b7041c8e8ab76760bfd7e85e18fbab

Copy link
Contributor

@theStack theStack 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 77915c1c21b7041c8e8ab76760bfd7e85e18fbab

@furszy furszy force-pushed the 2022_RPC_getreceivedbylabel_return_early branch from 77915c1 to 8a72297 Compare May 20, 2022 13:21
@furszy
Copy link
Member Author

furszy commented May 20, 2022

nit: IIRC, we usually describe the concrete error code in the release notes for RPC changes (also in general, the PR number in parantheses).

pushed 👍🏼.

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

re-ACK 8a722974b2b9e54fcc0139dd795023a0f8ef3f6c

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

Approach ACK

Copy link
Member

Choose a reason for hiding this comment

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

Just a thought, and not necessarily in this PR, but by moving this line back to the top the entire section touched here can be bracket-scoped or extracted out to a function that returns std::set<CScript> output_scripts

Copy link
Member Author

Choose a reason for hiding this comment

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

yep, I structured it do some further decoupling but didn't find a good reason to add it here.

@furszy furszy force-pushed the 2022_RPC_getreceivedbylabel_return_early branch from 8a72297 to a13b8a0 Compare May 20, 2022 19:28
… no destinations were found for the input label.

If wallet.GetLabelAddresses() returns an empty vector (the wallet does not have addresses with that label in the addressbook) or if none of the returned destinations are from the wallet, we can return the function right away.
@furszy furszy force-pushed the 2022_RPC_getreceivedbylabel_return_early branch from a13b8a0 to da8be10 Compare May 20, 2022 19:32
@furszy
Copy link
Member Author

furszy commented May 20, 2022

Updated per feedback 👍🏼.

  • Release-notes text.
  • Moved the test line inside the "getreceivedbylabel Test" section + reworded the comment.

@jonatack
Copy link
Member

ACK da8be104cdaa2bef955bfea2909ce75af9992a2b

@kristapsk
Copy link
Contributor

Squash commits into one?

Copy link
Member

Choose a reason for hiding this comment

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

nit, just saw the release note might be in the wrong section

--- a/doc/release-notes.md
+++ b/doc/release-notes.md
@@ -57,9 +57,6 @@ Updated RPCs
 
 Changes to wallet related RPCs can be found in the Wallet section below.
 
-- RPC `getreceivedbylabel` now returns an error, "Label not found
-  in wallet" (-4), if the label is not in the address book. (#25122)
-
 New RPCs
 --------
 
@@ -81,6 +78,9 @@ Tools and Utilities
 Wallet
 ------
 
+- RPC `getreceivedbylabel` now returns an error, "Label not found
+  in wallet" (-4), if the label is not in the address book. (#25122)
+
 GUI changes
 -----------

Copy link
Member Author

Choose a reason for hiding this comment

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

pushed

@furszy furszy force-pushed the 2022_RPC_getreceivedbylabel_return_early branch from da8be10 to baa3ddc Compare May 21, 2022 02:24
Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

re-ACK baa3ddc

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.

ACK baa3ddc

@achow101
Copy link
Member

ACK baa3ddc

@achow101 achow101 merged commit 5ebff43 into bitcoin:master May 23, 2022
@jonatack
Copy link
Member

Posthumous ACK

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 28, 2022
…esses were found in the address book

baa3ddc doc: add release notes about `getreceivedbylabel` returning an error if the label is not in the address book. (furszy)
8897a21 rpc: getreceivedbylabel, don't loop over the entire wallet txs map if no destinations were found for the input label. (furszy)

Pull request description:

  Built on top of bitcoin#23662, coming from comment bitcoin#23662 (review).

  If `wallet.GetLabelAddresses()` returns an empty vector (the wallet does not have stored destinations with that label in the addressbook) or if none of the returned destinations are from the wallet, we can return the function right away.
  Otherwise, we are walking through all the wallet txs + outputs for no reason (`output_scripts` is empty).

ACKs for top commit:
  achow101:
    ACK baa3ddc
  theStack:
    re-ACK baa3ddc
  w0xlt:
    ACK bitcoin@baa3ddc

Tree-SHA512: 00e10365b179bf008da2f3ef8fbb3ee04a330426374020e3f2d0151b16991baba4ef2b944e4659452f3e4d6cb20f128d0918ddf0453933a25a4d9fd8414a1911
@bitcoin bitcoin locked and limited conversation to collaborators May 23, 2023
@furszy furszy deleted the 2022_RPC_getreceivedbylabel_return_early branch May 27, 2023 01:51
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.

7 participants