Skip to content

Conversation

@practicalswift
Copy link
Contributor

@practicalswift practicalswift commented Jul 26, 2018

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"

@maflcko
Copy link
Member

maflcko commented Jul 26, 2018

Hmm, could you do the same for all other functions that qualify (e.g. CTxMemPool::addUnchecked)? Would be nice if we could avoid a flood of pulls that do the same. See also #13412.

@practicalswift practicalswift changed the title wallet: SetMinVersion(...) cannot fail. Return void instead of bool. Return void instead of bool for functions that cannot fail Jul 27, 2018
@practicalswift
Copy link
Contributor Author

@MarcoFalke Done! :-)

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 27, 2018

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.

Copy link
Member

@maflcko maflcko left a 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.

Copy link
Member

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?

Copy link
Member

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

@maflcko
Copy link
Member

maflcko commented Jul 27, 2018

Also, could just squash into one commit?

@practicalswift practicalswift force-pushed the SetMinVersion-return-value branch 2 times, most recently from 519cb9e to d7f114a Compare July 27, 2018 11:17
* CBlockTreeDB::ReadReindexing(...)
* CChainState::ResetBlockFailureFlags(...)
* CTxMemPool::addUnchecked(...)
* CWallet::LoadDestData(...)
* CWallet::LoadKeyMetadata(...)
* CWallet::LoadScriptMetadata(...)
* CWallet::LoadToWallet(...)
* CWallet::SetHDChain(...)
* CWallet::SetHDSeed(...)
* RemoveLocal(...)
* SetMinVersion(...)
* StartHTTPServer(...)
* StartRPC(...)
* TorControlConnection::Disconnect(...)
@practicalswift practicalswift force-pushed the SetMinVersion-return-value branch from d7f114a to d78a8dc Compare July 27, 2018 11:19
@practicalswift
Copy link
Contributor Author

@MarcoFalke Thanks for reviewing! Feedback addressed. Please re-review :-)

@maflcko
Copy link
Member

maflcko commented Jul 27, 2018

utACK d78a8dc

@promag
Copy link
Contributor

promag commented Jul 27, 2018

utACK d78a8dc.


bool CBlockTreeDB::ReadReindexing(bool &fReindexing) {
void CBlockTreeDB::ReadReindexing(bool &fReindexing) {
fReindexing = Exists(DB_REINDEX_FLAG);
Copy link
Contributor

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);
Copy link
Contributor

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

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Member

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();
Copy link
Contributor

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();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: could inline

@maflcko
Copy link
Member

maflcko commented Jul 27, 2018

@Empact I agree with the feedback, but this should be addressed in a separate pull request, if deemed important enough.

@practicalswift
Copy link
Contributor Author

@Empact Does d78a8dc have your ACK? :-)

@Empact
Copy link
Contributor

Empact commented Jul 28, 2018

utACK d78a8dc

@maflcko maflcko merged commit d78a8dc into bitcoin:master Jul 29, 2018
maflcko pushed a commit that referenced this pull request Jul 29, 2018
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
jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 11, 2019
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
jonspock pushed a commit to jonspock/devault that referenced this pull request Dec 27, 2019
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
jonspock pushed a commit to devaultcrypto/devault that referenced this pull request Dec 29, 2019
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
kiminuo added a commit to kiminuo/bitcoin that referenced this pull request Apr 2, 2021
Copy link

@trongham trongham left a comment

Choose a reason for hiding this comment

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

Tr

@practicalswift practicalswift deleted the SetMinVersion-return-value branch April 10, 2021 19:35
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jul 1, 2021
…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
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jul 2, 2021
…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
gades pushed a commit to cosanta/cosanta-core that referenced this pull request May 4, 2022
…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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
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.

7 participants