-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Refactor: Remove m_is_test_chain #28379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor: Remove m_is_test_chain #28379
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsNo conflicts as of last run. |
@@ -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; } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
lgtm ACK 27b4084 Looks good, with or without the other suggestion. |
Thanks for the suggestion. I've removed the IsTestChain method and replaced all occurrences with inline checks of the ChainType. |
48e7791
to
4a1cd56
Compare
Concept ACK |
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :)
As for the second commit, I think it can be reduced down to just #28379 (comment) and I think everyone agrees to keep |
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. |
770c7b3
to
78c2707
Compare
Thank you Marco. I wasn't quite sure if you wanted to keep the history due to the discussion. |
re-ACK 78c2707 only change since previous review is adding one commit |
ACK 78c2707 |
Remove the m_is_test_chain bool
Compiled and run tests locally
#28376