Skip to content

Conversation

devtimnbr
Copy link
Contributor

Remove the m_is_test_chain bool
Compiled and run tests locally

#28376

@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 31, 2023

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 MarcoFalke, ajtowns
Concept NACK luke-jr
Concept ACK theStack

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

Conflicts

No conflicts as of last run.

@fanquake fanquake linked an issue Aug 31, 2023 that may be closed by this pull request
@@ -103,7 +103,7 @@ class CChainParams
/** Default value for -checkmempool and -checkblockindex argument */
bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; }
/** If this chain is exclusively used for testing */
bool IsTestChain() const { return m_is_test_chain; }
bool IsTestChain() const { return m_chain_type != ChainType::MAIN; }
/** If this chain allows time to be mocked */
bool IsMockableChain() const { return m_is_mockable_chain; }
Copy link
Member

Choose a reason for hiding this comment

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

Looks like it would be cleaner to remove this method completely? This is only used to check that the chain type is regtest, which can be seen in the error strings. See:

$ git grep -A1 IsMockableChain  src/rpc/
src/rpc/mempool.cpp:            if (!Params().IsMockableChain()) {
src/rpc/mempool.cpp-                throw std::runtime_error("submitpackage is for regression testing (-regtest mode) only");
--
src/rpc/node.cpp:    if (!Params().IsMockableChain()) {
src/rpc/node.cpp-        throw std::runtime_error("setmocktime is for regression testing (-regtest mode) only");
--
src/rpc/node.cpp:    if (!Params().IsMockableChain()) {
src/rpc/node.cpp-        throw std::runtime_error("mockscheduler is for regression testing (-regtest mode) only");

The rpc code would be easier to read if the chain type check was inlined and this method be removed, I'd say. For example, submitpackage has nothing to do with whether the time can be mocked.

Copy link
Member

Choose a reason for hiding this comment

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

For clarity, my comment is on IsMockableChain, not on IsTestChain.

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 see. So keep IsTestChain and remove IsMockableChain method and replace all occurrences with inline checks like != ChainType::REGTEST?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think it makes sense to keep the IsTestChain alias, because it is just one line of code and it makes code that uses it easier to read.

However, the IsMockableChain helper is used only in contexts to check for regtest, so I think it makes code easier to read to use a regtest chain-type check directly.

Copy link
Contributor

Choose a reason for hiding this comment

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

"mockable time" isn't a concept with libbitcoinkernel, so I think it makes sense to move IsMockableChain out of the kernel module. IsTestChain otoh seems like an important enough concept to still have in the kernel and be something we can ask about any chain we might have.

@maflcko
Copy link
Member

maflcko commented Sep 1, 2023

lgtm ACK 27b4084

Looks good, with or without the other suggestion.

@devtimnbr
Copy link
Contributor Author

Thanks for the suggestion. I've removed the IsTestChain method and replaced all occurrences with inline checks of the ChainType.

@devtimnbr devtimnbr force-pushed the refactor_remove_m_is_test_chain branch from 48e7791 to 4a1cd56 Compare September 1, 2023 12:29
@theStack
Copy link
Contributor

theStack commented Sep 1, 2023

Concept ACK

Copy link
Contributor

@ajtowns ajtowns 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

@@ -862,7 +862,7 @@ static RPCHelpMan submitpackage()
},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
if (!Params().IsMockableChain()) {
if (Params().GetChainType() != ChainType::REGTEST) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This change makes sense independently; submitpackage has no relationship to mocktime.

src/rpc/node.cpp Outdated
@@ -42,7 +42,7 @@ static RPCHelpMan setmocktime()
RPCExamples{""},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
if (!Params().IsMockableChain()) {
if (Params().GetChainType() != ChainType::REGTEST) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not really convinced this makes sense though; having the IsMockable condition in one place (via an easily greppable name), rather than two places seems sensible. OTOH, could easily have that code just be in rpc/node.cpp rather than kernel/chainparams.h, eg

static bool IsMockable(const CChainParams& params)
{
    return params.GetChainType() == ChainType::REGTEST;
}

if (!IsMockable(Params())) { error...; }

May also make sense to add an error in init.cpp if -mocktime is specified with a different chain (in which case mocktime activates but you can't ever change it, so things will break pretty quickly), in which case perhaps putting IsMockable into src/chainparams.h (rather than kernel/chainparams.h) or similar would make sense.

May want to also replace Params() with EnsureAnyChainman(request.context).GetParams() to reduce global accesses?

Copy link
Member

Choose a reason for hiding this comment

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

If the function is kept, I'd prefer to keep it in the place it is now. Doesn't seem worth it to move a single function into another file (like src/chainparams.h). I guess this can be done in the future, if there is more than one function.

Keeping the location as-is should also make it a smaller diff and less controversial :)

@luke-jr
Copy link
Member

luke-jr commented Sep 5, 2023

Concept NACK.

@maflcko
Copy link
Member

maflcko commented Sep 6, 2023

As for the second commit, I think it can be reduced down to just #28379 (comment) and I think everyone agrees to keep IsMockableChain, because it is useful.

@maflcko
Copy link
Member

maflcko commented Sep 14, 2023

Please squash your last 3 commits according to https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#squashing-commits

You should end up with a total of 2 commits in the end.

@devtimnbr devtimnbr force-pushed the refactor_remove_m_is_test_chain branch from 770c7b3 to 78c2707 Compare September 15, 2023 14:34
@devtimnbr
Copy link
Contributor Author

Please squash your last 3 commits according to https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#squashing-commits

You should end up with a total of 2 commits in the end.

Thank you Marco. I wasn't quite sure if you wanted to keep the history due to the discussion.

@maflcko
Copy link
Member

maflcko commented Sep 15, 2023

re-ACK 78c2707

only change since previous review is adding one commit

@maflcko maflcko requested a review from ajtowns September 21, 2023 14:16
@ajtowns
Copy link
Contributor

ajtowns commented Sep 21, 2023

ACK 78c2707

@DrahtBot DrahtBot removed the request for review from ajtowns September 21, 2023 14:53
@fanquake fanquake merged commit f290914 into bitcoin:master Sep 21, 2023
Frank-GER pushed a commit to syscoin/syscoin that referenced this pull request Sep 25, 2023
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 26, 2023
@bitcoin bitcoin locked and limited conversation to collaborators Sep 20, 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.

Remove m_is_test_chain, use ChainType directly
7 participants