Return void instead of bool for functions that cannot fail#13774
Return void instead of bool for functions that cannot fail#13774maflcko merged 1 commit intobitcoin:masterfrom
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.
ACK, beside one comment and one nit.
src/validation.cpp
Outdated
There was a problem hiding this comment.
nit: Can keep the return g_ch... here, no?
src/interfaces/wallet.cpp
Outdated
There was a problem hiding this comment.
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.
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.
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.
So this is pending future use? If not I don't follow.
There was a problem hiding this comment.
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.
| @@ -4091,9 +4079,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(const std::string& name, | |||
|
|
|||
| // generate a new master key | |||
| CPubKey masterPubKey = walletInstance->GenerateNewSeed(); | |||
| @@ -4130,9 +4116,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(const std::string& name, | |||
| } else { | |||
| // generate a new seed | |||
| CPubKey seed = walletInstance->GenerateNewSeed(); | |||
|
@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
…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: