Skip to content

Conversation

mjdietzx
Copy link
Contributor

@mjdietzx mjdietzx commented Nov 13, 2021

Now functions return a UniValue instead of mutating a parameter that's passed by reference.

After this PR, any time a UniValue is passed by reference, it should be const. This is the case everywhere in the codebase now (please double check me on this) except for SoftForkDescPushBack (which I didn't want to touch), and the RPC request handling logic.

Motivation for this PR was based on a suggestion in #22924 review:

I wonder why we don't return the UniValue (or optional in case it can fail) instead of having it as second parameter. It would seem better API design to me.

I figured it's simple enough, why not do this across the entire codebase. Hopefully I didn't get carried away

@lsilva01
Copy link
Contributor

Concept ACK.

@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 14, 2021

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #26039 (rpc: Run type check against RPCArgs (1/2) by MarcoFalke)
  • #23319 (rpc: Return fee and prevout (utxos) to getrawtransaction by dougEfresh)
  • #21283 (Implement BIP 370 PSBTv2 by achow101)
  • #17783 (util: Fix -norpcwhitelist, -norpcallowip, and similar corner case behavior by ryanofsky)

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.

@mjdietzx mjdietzx force-pushed the ret_UniValue_instead_of_pass_by_ref branch 3 times, most recently from a01a216 to 140767e Compare November 14, 2021 04:28
@mjdietzx mjdietzx changed the title Refactor: Improve API design of ScriptToUniv, TxToUniv Refactor: Improve API design of ScriptToUniv, TxToUniv etc to return the UniValue instead of mutating the parameter/reference Nov 14, 2021
@mjdietzx mjdietzx changed the title Refactor: Improve API design of ScriptToUniv, TxToUniv etc to return the UniValue instead of mutating the parameter/reference Refactor: Improve API design of ScriptToUniv, TxToUniv etc to return the UniValue instead of mutating a parameter/reference Nov 14, 2021
@mjdietzx mjdietzx force-pushed the ret_UniValue_instead_of_pass_by_ref branch 2 times, most recently from 5081cf9 to 82826eb Compare November 14, 2021 20:26
@mjdietzx mjdietzx marked this pull request as ready for review November 15, 2021 14:59
@mjdietzx mjdietzx force-pushed the ret_UniValue_instead_of_pass_by_ref branch from 82826eb to 092ad6a Compare November 15, 2021 18:01
@mjdietzx
Copy link
Contributor Author

mjdietzx commented Aug 5, 2022

Does anyone want this PR enough to review it if I rebase? If so I will do a careful rebase/review. If not I'm ok with closing this

@fanquake
Copy link
Member

fanquake commented Oct 3, 2022

Does anyone want this PR enough to review it if I rebase? If so I will do a careful rebase/review. If not I'm ok with closing this

I think this change is worthwhile. If you're happy to do a rebase I'll review it. If not, I'll pick this up.

@mjdietzx mjdietzx force-pushed the ret_UniValue_instead_of_pass_by_ref branch from 20b68de to df41d46 Compare October 3, 2022 22:30
@mjdietzx
Copy link
Contributor Author

mjdietzx commented Oct 3, 2022

Thanks @fanquake, rebased.

I am also going to do a thorough re-review since I did this a while ago. Also I dropped fcffbde for now, I need to take some time to go through @MarcoFalke's #25464 before I rebase this commit.

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 8, 2022

🐙 This pull request conflicts with the target branch and needs rebase.

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 8, 2023

There hasn't been much activity lately and the patch still needs rebase. What is the status here?

  • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
  • Is it no longer relevant? ➡️ Please close.
  • Did the author lose interest or time to work on this? ➡️ Please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.

@achow101 achow101 closed this Apr 25, 2023
TxToUniv(tx, /*block_hash=*/uint256::ZERO, /*entry=*/u);
TxToUniv(tx, /*block_hash=*/uint256::ONE, /*entry=*/u);
(void)TxToUniv(tx, /*block_hash=*/uint256::ZERO);
(void)TxToUniv(tx, /*block_hash=*/uint256::ONE);
Copy link
Member

Choose a reason for hiding this comment

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

I think this is a bugfix for the fuzz test, which eats too much memory (especially under msan)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh man I'm curious how you ended up back in this PR!? Is that just from your memory?

Anyways lmk if you want me to do anything. I'd be happy to rebase this, open a PR with just this commit, etc.. whatever you suggest. Also feel free to just cherry-pick that commit or whatever is most efficient for you as well incase you are just commenting this for documentation purposes

Copy link
Member

Choose a reason for hiding this comment

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

Maybe just split out the TxToUniv change in a new pull?

@bitcoin bitcoin locked and limited conversation to collaborators Jun 6, 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