Skip to content

Conversation

mjdietzx
Copy link
Contributor

@mjdietzx mjdietzx commented Sep 8, 2021

This is a follow-up on top of #22650. Based on review there, we thought it would be an improvement to merge ScriptPubKeyToUniv and ScriptToUniv into a single function, but this didn't seem to belong in that PR. There are a few other minor cleanups here as well focused on style and making some fuzz tests run faster

@mjdietzx mjdietzx changed the title refactor: merge ScriptPubKeyToUniv and ScriptToUniv into a single function refactor: cleanup/followup of Remove -deprecatedrpc=addresses flag Sep 14, 2021
@mjdietzx mjdietzx marked this pull request as draft September 14, 2021 20:26
@mjdietzx
Copy link
Contributor Author

Marking this as a draft for now. I will be moving some of the refactoring/cleanup that was originally included in #22650 to this PR. So once that is done and I've rebased this PR, I will reopen it

@mjdietzx
Copy link
Contributor Author

Now that #22650 is merged, I rebased and finished this. This PR follows up with some cleanup, and addresses all the comments in the first PR that were left for now.

Just so we have them at-hand, I took all the original comments from #22650's review, and am putting them here.

@jonatack: maybe I'm missing something but perhaps merge ScriptPubKeyToUniv and ScriptToUniv into a single function

Done b9ad1d9


@jonatack: Named args could be nice wherever this function is invoked

and

@MarcoFalke: If you decide to do it here, at least use the proper clang-tidy format, so that it can be checked by the clang compiler

Done e9f3f1b


@MarcoFalke: as a follow-up it could make sense to de-duplicate the common help text

Done fe71ac8


@MarcoFalke: I think you can drop one of these statements to make the fuzz test run ~twice as fast. An alternative (to test both code paths) would be to deserialize a bool from the fuzzing input and use uint256{bool_val}

and

@meshcollider: This should really be replaced with include_address=true/false checks on ScriptPubKeyToUniv(script, o4, fIncludeHex, include_address)

Done e749168

@mjdietzx mjdietzx marked this pull request as ready for review September 29, 2021 03:15
@mjdietzx mjdietzx force-pushed the refactor_ScriptToUniv branch from 08543bf to 1402f0d Compare September 29, 2021 15:21
@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 29, 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:

  • #23599 (Tidy up RPCTxSerializationFlags by MarcoFalke)
  • #23546 (scripted-diff: Use clang-tidy syntax for C++ named arguments (tests only) by MarcoFalke)
  • #23486 (rpc: Only allow specific types to be P2(W)SH wrapped in decodescript by MarcoFalke)
  • #23320 (rpc: Add RPC help for getblock verbosity level 3 by kiminuo)
  • #23319 (rpc: Return fee and prevout (utxos) to getrawtransaction by dougEfresh)

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
Copy link
Contributor Author

mjdietzx commented Oct 25, 2021

Rebased, fixed some merge conflicts from #22918

void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool include_hex, bool include_address = true);
void ScriptToUniv(const CScript& script, UniValue& out);
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, int serialize_flags = 0, const CTxUndo* txundo = nullptr, TxVerbosity verbosity = TxVerbosity::SHOW_DETAILS);
void ScriptToUniv(const CScript& script, UniValue& out, bool include_hex = true, bool include_address = false);
Copy link
Member

Choose a reason for hiding this comment

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

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

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 think this is a great suggestion. And at first glance it seems to be straightforward enough to include in this PR. I'll follow up shortly

Copy link
Contributor Author

@mjdietzx mjdietzx Nov 13, 2021

Choose a reason for hiding this comment

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

I am leaning towards not including this change in this PR. I do think it is a great opportunity to cleanup and improve the code quality, so I would like to follow up with another PR doing this. This pattern is also used all over the place, not just ScriptToUniv, but TxToUniv, entryToJSON, and probably more. Anyways I want to spend some more time on this and don't want to end up doing too much in this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you take a quick look at the last two commits in this draft PR #23507?

a) is this along the lines of what you are thinking?
b) do you think it is worthwhile for me to do this across the codebase in #23507, eg entryToJSON, TxToJSON, etc... can be improved in the same way

Feel free to answer those in the linked PR and not here

@mjdietzx mjdietzx force-pushed the refactor_ScriptToUniv branch from 9d8cd50 to d4675f4 Compare November 13, 2021 20:11
@mjdietzx
Copy link
Contributor Author

Addressed indentation nit and rebased to master

@@ -1274,7 +1274,7 @@ static RPCHelpMan gettxout()
{RPCResult::Type::STR, "asm", ""},
{RPCResult::Type::STR_HEX, "hex", ""},
{RPCResult::Type::STR, "type", "The type, eg pubkeyhash"},
{RPCResult::Type::STR, "address", /* optional */ true, "The Bitcoin address (only if a well-defined address exists)"},
{RPCResult::Type::STR, "address", /* optional */ true, DESTINATION_ADDRESS},
Copy link
Member

Choose a reason for hiding this comment

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

it might be better to de-duplicate the whole asm/hex/type/address blob. Though, maybe create a separate pull for doc cleanups vs code refactorings?

Copy link
Member

Choose a reason for hiding this comment

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

See for example e7507f3 or f8911de on how to do this.

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 think this is a good suggestion. I will do this as a followup as you suggest. So I will get rid of 63a657c when I rebase and have a doc cleanup followup with these suggestions

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 1, 2021

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

Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft".

@DrahtBot
Copy link
Contributor

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.

@maflcko
Copy link
Member

maflcko commented Mar 22, 2022

I guess it is hard to tell how much of this is still relevant without doing a rebase?

@fanquake
Copy link
Member

I've rebased some of the commits here in #24673. Haven't done 63a657c as we might be able to follow up differently there, and do some de-duplication, see #22924 (comment).

@mjdietzx
Copy link
Contributor Author

Thanks @fanquake - it seems like the best path forward is closing this PR in favor of #24673? If so I'll close this and test/review the new PR

@fanquake
Copy link
Member

Thanks @fanquake - it seems like the best path forward is closing this PR in favor of #24673? If so I'll close this and test/review the new PR

Sure, lets do that for now, and then potentially follow up with #23507 etc.

@mjdietzx mjdietzx closed this Mar 25, 2022
maflcko pushed a commit that referenced this pull request Mar 31, 2022
9563a64 refactor: add stdd:: includes to core_write (fanquake)
8b9efeb refactor: use named args when ScriptToUniv or TxToUniv are invoked (Michael Dietz)
22f25a6 refactor: prefer snake case, TxToUniv arg hashBlock renamed block_hash (Michael Dietz)
828a094 refactor: merge ScriptPubKeyToUniv & ScriptToUniv into one function (Michael Dietz)

Pull request description:

  I've cherry-picked some of the commits out of #22924, and made minor changes (like fixing named args).

ACKs for top commit:
  MarcoFalke:
    re-ACK 9563a64 🕓

Tree-SHA512: 4f0e5b45c14cbf68b9e389bbe1211c125d95cbd3da5205b1cff6a4c44f15b15039ba2a5b25cd7e2580d9169404f1b7ff620d8a7e01f6112e3cb153ecfaef8916
@bitcoin bitcoin locked and limited conversation to collaborators Mar 25, 2023
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.

5 participants