Skip to content

refactor: Use ChainType enum exhaustively#27611

Merged
fanquake merged 1 commit into
bitcoin:masterfrom
sedited:followUp27491
May 10, 2023
Merged

refactor: Use ChainType enum exhaustively#27611
fanquake merged 1 commit into
bitcoin:masterfrom
sedited:followUp27491

Conversation

@sedited

@sedited sedited commented May 10, 2023

Copy link
Copy Markdown
Contributor

This is a follow up of #27491, more concretely #27491 (comment), for not using default cases (as per the style guide), and #27491 (comment) and #27491 (comment) for avoiding dead code.

@DrahtBot

DrahtBot commented May 10, 2023

Copy link
Copy Markdown
Contributor

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 fanquake
Concept ACK hebasto

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

@maflcko

maflcko commented May 10, 2023

Copy link
Copy Markdown
Member

Can remove (follow-up) from the title. Also, the docstring of the changed methods in the header is still wrong

@sedited

sedited commented May 10, 2023

Copy link
Copy Markdown
Contributor Author

Re #27611 (comment)

Also, the docstring of the changed methods in the header is still wrong

Do you mean these sedited@0e7abdc ?

@sedited sedited changed the title refactor(follow-up): Use ChainType enum exhaustively refactor: Use ChainType enum exhaustively May 10, 2023
@maflcko

maflcko commented May 10, 2023

Copy link
Copy Markdown
Member

I mean the ones of the touched methods Create*Params(), which are documented to throw the wrong exception type. Now that you changed to assert, there is no exception at all.

@maflcko

maflcko commented May 10, 2023

Copy link
Copy Markdown
Member

Example:

diff --git a/src/chainparams.h b/src/chainparams.h
index 6a65f40f80..23b272cc41 100644
--- a/src/chainparams.h
+++ b/src/chainparams.h
@@ -26,7 +26,6 @@ class ArgsManager;
 /**
  * Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
  * @returns a CChainParams* of the chosen chain.
- * @throws a std::runtime_error if the chain is not supported.
  */
 std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const ChainType chain);
 
@@ -38,7 +37,6 @@ const CChainParams &Params();
 
 /**
  * Sets the params returned by Params() to those for the given chain name.
- * @throws std::runtime_error when the chain is not supported.
  */
 void SelectParams(const ChainType chain);
 

@sedited

sedited commented May 10, 2023

Copy link
Copy Markdown
Contributor Author

Updated d0767a9 -> ef39bdf (followUp27491_0 -> followUp27491_1, compare)

  • Addressed @MarcoFalke's comment, removing exception docstring.
  • Added scripted-diff commit s/chain\ name/chain\ type/.

@maflcko maflcko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm, found another nit, feel free to ignore

Comment thread src/chainparamsbase.h Outdated
Comment thread src/chainparams.h Outdated
Comment thread src/chainparams.h
This is a follow up of bitcoin#27491,
more concretely
bitcoin#27491 (comment),
for not using default cases (as per the style guide), and
bitcoin#27491 (comment) and
bitcoin#27491 (comment) for
avoiding dead code.

Also change chain name to chain type in docstrings
@sedited

sedited commented May 10, 2023

Copy link
Copy Markdown
Contributor Author

Updated ef39bdf -> e230887 (followUp27491_1 -> followUp27491_2, compare)

  • Addressed @MarcoFalke's comment, but kept the first line of the docstring intact.
  • Squashed scripted-diff commit

@maflcko maflcko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@fanquake fanquake left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK e230887 - deals with almost all follow up comments out of #27491.

@hebasto

hebasto commented May 10, 2023

Copy link
Copy Markdown
Member

Concept ACK.

@fanquake
fanquake merged commit 104eed1 into bitcoin:master May 10, 2023

@hebasto hebasto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Post-merge ACK e230887.

Comment thread src/bitcoin-cli.cpp
case ChainType::MAIN:
return "";
}
assert(false);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Our Developer Notes also suggest a comment // no default case, so the compiler can warn about missing cases.

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 10, 2023
e230887 refactor: Use ChainType enum exhaustively (TheCharlatan)

Pull request description:

  This is a follow up of bitcoin#27491, more concretely bitcoin#27491 (comment), for not using default cases (as per the style guide), and bitcoin#27491 (comment) and bitcoin#27491 (comment) for avoiding dead code.

ACKs for top commit:
  fanquake:
    ACK e230887 - deals with almost all follow up comments out of bitcoin#27491.

Tree-SHA512: 1794190b03b91d3ca349a4da08e9610dbb3432983eee7cb21ecc758d1d7d710560c97661de14cdf493c28c00ebe8977511b4696055c0940e7f815b622dbacd16
@bitcoin bitcoin locked and limited conversation to collaborators May 9, 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.

5 participants