-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Return void instead of bool for functions that cannot fail #13774
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
Return void instead of bool for functions that cannot fail #13774
Conversation
|
Hmm, could you do the same for all other functions that qualify (e.g. |
|
@MarcoFalke Done! :-) |
Note to reviewers: This pull request conflicts with the following ones:
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. |
maflcko
left a comment
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.
ACK, beside one comment and one nit.
src/validation.cpp
Outdated
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.
nit: Can keep the return g_ch... here, no?
src/interfaces/wallet.cpp
Outdated
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.
CommitTransaction only temporarily returns true in all cases. This is about to change soonTM. Better leave this as is for now, since we pass in a state, which would be confusing if the return type was void
|
Also, could just squash into one commit? |
519cb9e to
d7f114a
Compare
* CBlockTreeDB::ReadReindexing(...) * CChainState::ResetBlockFailureFlags(...) * CTxMemPool::addUnchecked(...) * CWallet::LoadDestData(...) * CWallet::LoadKeyMetadata(...) * CWallet::LoadScriptMetadata(...) * CWallet::LoadToWallet(...) * CWallet::SetHDChain(...) * CWallet::SetHDSeed(...) * RemoveLocal(...) * SetMinVersion(...) * StartHTTPServer(...) * StartRPC(...) * TorControlConnection::Disconnect(...)
d7f114a to
d78a8dc
Compare
|
@MarcoFalke Thanks for reviewing! Feedback addressed. Please re-review :-) |
|
utACK d78a8dc |
|
utACK d78a8dc. |
|
|
||
| bool CBlockTreeDB::ReadReindexing(bool &fReindexing) { | ||
| void CBlockTreeDB::ReadReindexing(bool &fReindexing) { | ||
| fReindexing = Exists(DB_REINDEX_FLAG); |
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.
How about return this instead?
| bool ResetBlockFailureFlags(CBlockIndex *pindex) { | ||
|
|
||
| void ResetBlockFailureFlags(CBlockIndex *pindex) { | ||
| return g_chainstate.ResetBlockFailureFlags(pindex); |
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.
return in a void context
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.
We want to assert that the return code type is the same for both functions, so this looks correct as is.
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.
So this is pending future use? If not I don't follow.
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.
Imagine that Chainstate::ResetBlockFailureFlags returns bool in the future. This prevents the code from compiling, whereas removing the return would happily compile and hide a potential bug, no?
Also, changing it to something else in the future keeps the future diff smaller while keeping the return.
| walletInstance->SetMinVersion(FEATURE_HD); | ||
|
|
||
| // generate a new master key | ||
| CPubKey masterPubKey = walletInstance->GenerateNewSeed(); |
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.
nit: could inline
| walletInstance->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS); | ||
| } else { | ||
| // generate a new seed | ||
| CPubKey seed = walletInstance->GenerateNewSeed(); |
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.
nit: could inline
|
@Empact I agree with the feedback, but this should be addressed in a separate pull request, if deemed important enough. |
|
utACK d78a8dc |
d78a8dc Return void instead of bool for functions that cannot fail (practicalswift) Pull request description: Return `void` instead of `bool` for functions that cannot fail: * `CBlockTreeDB::ReadReindexing(...)` * `CChainState::ResetBlockFailureFlags(...)` * `CTxMemPool::addUnchecked(...)` * `CWallet::CommitTransaction(...)` * `CWallet::LoadDestData(...)` * `CWallet::LoadKeyMetadata(...)` * `CWallet::LoadScriptMetadata(...)` * `CWallet::LoadToWallet(...)` * `CWallet::SetHDChain(...)` * `CWallet::SetHDSeed(...)` * `PendingWalletTx::commit(...)` * `RemoveLocal(...)` * `SetMinVersion(...)` * `StartHTTPServer(...)` * `StartRPC(...)` * `TorControlConnection::Disconnect(...)` Some of the functions can fail by throwing. Found by manually inspecting the following candidate functions: ``` $ git grep -E '(^((static|virtual|inline|friend)[^a-z])*[^a-z]*bool [^=]*\(|return true|return false)' -- "*.cpp" "*.h" ``` Tree-SHA512: c0014e045362dbcd1a0cc8f69844e7b8cbae4f538e7632028daeca3a797ac11d8d3d86ebc480bedcb8626df3e96779d592747d52a12556fc49921b114fa0ccc6
Summary: Return `void` instead of `bool` for functions that cannot fail: * `CBlockTreeDB::ReadReindexing(...)` * `CChainState::ResetBlockFailureFlags(...)` * `CTxMemPool::addUnchecked(...)` * `CWallet::CommitTransaction(...)` * `CWallet::LoadDestData(...)` * `CWallet::LoadKeyMetadata(...)` * `CWallet::LoadScriptMetadata(...)` * `CWallet::LoadToWallet(...)` * `CWallet::SetHDChain(...)` * `CWallet::SetHDSeed(...)` * `PendingWalletTx::commit(...)` * `RemoveLocal(...)` * `SetMinVersion(...)` * `StartHTTPServer(...)` * `StartRPC(...)` * `TorControlConnection::Disconnect(...)` Backport of Bitcoin Core PR13774 bitcoin/bitcoin#13774 Test Plan: ``` make check-all ``` Reviewers: Fabien, #bitcoin_abc, deadalnix, jasonbcox Reviewed By: #bitcoin_abc, deadalnix, jasonbcox Subscribers: jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D4179
Summary: Return `void` instead of `bool` for functions that cannot fail: * `CBlockTreeDB::ReadReindexing(...)` * `CChainState::ResetBlockFailureFlags(...)` * `CTxMemPool::addUnchecked(...)` * `CWallet::CommitTransaction(...)` * `CWallet::LoadDestData(...)` * `CWallet::LoadKeyMetadata(...)` * `CWallet::LoadScriptMetadata(...)` * `CWallet::LoadToWallet(...)` * `CWallet::SetHDChain(...)` * `CWallet::SetHDSeed(...)` * `PendingWalletTx::commit(...)` * `RemoveLocal(...)` * `SetMinVersion(...)` * `StartHTTPServer(...)` * `StartRPC(...)` * `TorControlConnection::Disconnect(...)` Backport of Bitcoin Core PR13774 bitcoin/bitcoin#13774 Test Plan: ``` make check-all ``` Reviewers: Fabien, #bitcoin_abc, deadalnix, jasonbcox Reviewed By: #bitcoin_abc, deadalnix, jasonbcox Subscribers: jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D4179
Summary: Return `void` instead of `bool` for functions that cannot fail: * `CBlockTreeDB::ReadReindexing(...)` * `CChainState::ResetBlockFailureFlags(...)` * `CTxMemPool::addUnchecked(...)` * `CWallet::CommitTransaction(...)` * `CWallet::LoadDestData(...)` * `CWallet::LoadKeyMetadata(...)` * `CWallet::LoadScriptMetadata(...)` * `CWallet::LoadToWallet(...)` * `CWallet::SetHDChain(...)` * `CWallet::SetHDSeed(...)` * `PendingWalletTx::commit(...)` * `RemoveLocal(...)` * `SetMinVersion(...)` * `StartHTTPServer(...)` * `StartRPC(...)` * `TorControlConnection::Disconnect(...)` Backport of Bitcoin Core PR13774 bitcoin/bitcoin#13774 Test Plan: ``` make check-all ``` Reviewers: Fabien, #bitcoin_abc, deadalnix, jasonbcox Reviewed By: #bitcoin_abc, deadalnix, jasonbcox Subscribers: jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D4179
trongham
left a comment
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.
Tr
…annot fail d78a8dc Return void instead of bool for functions that cannot fail (practicalswift) Pull request description: Return `void` instead of `bool` for functions that cannot fail: * `CBlockTreeDB::ReadReindexing(...)` * `CChainState::ResetBlockFailureFlags(...)` * `CTxMemPool::addUnchecked(...)` * `CWallet::CommitTransaction(...)` * `CWallet::LoadDestData(...)` * `CWallet::LoadKeyMetadata(...)` * `CWallet::LoadScriptMetadata(...)` * `CWallet::LoadToWallet(...)` * `CWallet::SetHDChain(...)` * `CWallet::SetHDSeed(...)` * `PendingWalletTx::commit(...)` * `RemoveLocal(...)` * `SetMinVersion(...)` * `StartHTTPServer(...)` * `StartRPC(...)` * `TorControlConnection::Disconnect(...)` Some of the functions can fail by throwing. Found by manually inspecting the following candidate functions: ``` $ git grep -E '(^((static|virtual|inline|friend)[^a-z])*[^a-z]*bool [^=]*\(|return true|return false)' -- "*.cpp" "*.h" ``` Tree-SHA512: c0014e045362dbcd1a0cc8f69844e7b8cbae4f538e7632028daeca3a797ac11d8d3d86ebc480bedcb8626df3e96779d592747d52a12556fc49921b114fa0ccc6
…annot fail d78a8dc Return void instead of bool for functions that cannot fail (practicalswift) Pull request description: Return `void` instead of `bool` for functions that cannot fail: * `CBlockTreeDB::ReadReindexing(...)` * `CChainState::ResetBlockFailureFlags(...)` * `CTxMemPool::addUnchecked(...)` * `CWallet::CommitTransaction(...)` * `CWallet::LoadDestData(...)` * `CWallet::LoadKeyMetadata(...)` * `CWallet::LoadScriptMetadata(...)` * `CWallet::LoadToWallet(...)` * `CWallet::SetHDChain(...)` * `CWallet::SetHDSeed(...)` * `PendingWalletTx::commit(...)` * `RemoveLocal(...)` * `SetMinVersion(...)` * `StartHTTPServer(...)` * `StartRPC(...)` * `TorControlConnection::Disconnect(...)` Some of the functions can fail by throwing. Found by manually inspecting the following candidate functions: ``` $ git grep -E '(^((static|virtual|inline|friend)[^a-z])*[^a-z]*bool [^=]*\(|return true|return false)' -- "*.cpp" "*.h" ``` Tree-SHA512: c0014e045362dbcd1a0cc8f69844e7b8cbae4f538e7632028daeca3a797ac11d8d3d86ebc480bedcb8626df3e96779d592747d52a12556fc49921b114fa0ccc6
…annot fail d78a8dc Return void instead of bool for functions that cannot fail (practicalswift) Pull request description: Return `void` instead of `bool` for functions that cannot fail: * `CBlockTreeDB::ReadReindexing(...)` * `CChainState::ResetBlockFailureFlags(...)` * `CTxMemPool::addUnchecked(...)` * `CWallet::CommitTransaction(...)` * `CWallet::LoadDestData(...)` * `CWallet::LoadKeyMetadata(...)` * `CWallet::LoadScriptMetadata(...)` * `CWallet::LoadToWallet(...)` * `CWallet::SetHDChain(...)` * `CWallet::SetHDSeed(...)` * `PendingWalletTx::commit(...)` * `RemoveLocal(...)` * `SetMinVersion(...)` * `StartHTTPServer(...)` * `StartRPC(...)` * `TorControlConnection::Disconnect(...)` Some of the functions can fail by throwing. Found by manually inspecting the following candidate functions: ``` $ git grep -E '(^((static|virtual|inline|friend)[^a-z])*[^a-z]*bool [^=]*\(|return true|return false)' -- "*.cpp" "*.h" ``` Tree-SHA512: c0014e045362dbcd1a0cc8f69844e7b8cbae4f538e7632028daeca3a797ac11d8d3d86ebc480bedcb8626df3e96779d592747d52a12556fc49921b114fa0ccc6
Return
voidinstead ofboolfor functions that cannot fail:CBlockTreeDB::ReadReindexing(...)CChainState::ResetBlockFailureFlags(...)CTxMemPool::addUnchecked(...)CWallet::CommitTransaction(...)CWallet::LoadDestData(...)CWallet::LoadKeyMetadata(...)CWallet::LoadScriptMetadata(...)CWallet::LoadToWallet(...)CWallet::SetHDChain(...)CWallet::SetHDSeed(...)PendingWalletTx::commit(...)RemoveLocal(...)SetMinVersion(...)StartHTTPServer(...)StartRPC(...)TorControlConnection::Disconnect(...)Some of the functions can fail by throwing.
Found by manually inspecting the following candidate functions: