Add CMerkleTx::IsImmatureCoinBase method#13631
Conversation
|
For reference: Lines 4435 to 4438 in 062738c |
src/wallet/wallet.h
Outdated
There was a problem hiding this comment.
Nits: Maybe move the comment to the function body, because it's an implementation detail of IsImmatureCoinbase; and update the comment by replacing "is" with "returns".
src/wallet/wallet.cpp
Outdated
There was a problem hiding this comment.
It seems safe to optimize this boolean expression and remove the IsCoinBase() condition in IsImmatureCoinBase, because GetBlocksToMaturity already calls IsCoinBase, which effectively makes this condition redundant.
I do however appreciate the defensiveness of having the redundantIsCoinBase() condition; it is not specified that GetBlocksToMaturity must return 0 if it is not a coinbase transaction.
Therefore, if we optimize the boolean expression in IsImmatureCoinBase and fully rely on the result of GetBlocksToMaturity, I would like to suggest to add a comment to the interface documentation of the CMerkleTx::GetBlocksToMaturity method that explicitly states the postcondition that GetBlocksToMaturity must return 0 if it is not a coinbase transaction.
src/wallet/wallet.h
Outdated
There was a problem hiding this comment.
If we are going to rely on the result of GetBlocksToMaturity, and not defensively call IsCoinBase(), a unit test would be nice to verify the expected behaviour.
|
Concept ACK |
|
Concept ACK. Makes the intention clear. Agree with @251labs points. |
d0fe31e to
1503a9a
Compare
|
Added docs, moved the implementations together. I also noticed that the result of |
1503a9a to
192075f
Compare
|
Moved the GetBlocksToMaturity assert out into #13657 |
86a1caf to
328d830
Compare
328d830 to
860e214
Compare
|
Nice, utACK 860e214 |
|
utACK 860e214. |
|
utACK 860e214f7ba899efae397205891181056adf3fc2 |
860e214 to
bb65387
Compare
|
Rebased for #12257 |
|
re-utACK bb653872be8d251c21ee32c2948100b7febbd477 |
|
re-utACK bb65387. |
All but one call to GetBlocksToMaturity is testing it relative to 0 for the purposes of determining whether the coinbase tx is immature. In such case, the value greater than 0 implies that the tx is coinbase, so there is no need to separately test that status. This names the concept for easy singular use.
bb65387 to
23f4343
Compare
|
Noticed the whitespace was off. Diff: diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index fc6f03a16..540a7b0fc 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -1926,8 +1926,7 @@ CAmount CWalletTx::GetCredit(const isminefilter& filter) const
CAmount CWalletTx::GetImmatureCredit(bool fUseCache) const
{
- if (IsImmatureCoinBase() && IsInMainChain())
- {
+ if (IsImmatureCoinBase() && IsInMainChain()) {
if (fUseCache && fImmatureCreditCached)
return nImmatureCreditCached;
nImmatureCreditCached = pwallet->GetCredit(*tx, ISMINE_SPENDABLE);
@@ -1985,8 +1984,7 @@ CAmount CWalletTx::GetAvailableCredit(bool fUseCache, const isminefilter& filter
CAmount CWalletTx::GetImmatureWatchOnlyCredit(const bool fUseCache) const
{
- if (IsImmatureCoinBase() && IsInMainChain())
- {
+ if (IsImmatureCoinBase() && IsInMainChain()) {
if (fUseCache && fImmatureWatchCreditCached)
return nImmatureWatchCreditCached;
nImmatureWatchCreditCached = pwallet->GetCredit(*tx, ISMINE_WATCH_ONLY);
@@ -4399,8 +4397,8 @@ int CMerkleTx::GetBlocksToMaturity() const
bool CMerkleTx::IsImmatureCoinBase() const
{
- // note GetBlocksToMaturity is 0 for non-coinbase tx
- return GetBlocksToMaturity() > 0;
+ // note GetBlocksToMaturity is 0 for non-coinbase tx
+ return GetBlocksToMaturity() > 0;
}
bool CWalletTx::AcceptToMemoryPool(const CAmount& nAbsurdFee, CValidationState& state) |
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. |
|
utACK 23f4343 |
23f4343 Add CMerkleTx::IsImmatureCoinBase method (Ben Woosley) Pull request description: All but one call to `GetBlocksToMaturity` is testing it relative to 0 for the purposes of determining whether the coinbase tx is immature. In such case, the value greater than 0 implies that the tx is coinbase, so there is no need to separately test that status. This names the concept for easy singular use. Tree-SHA512: 4470d07404a0707144f9827b9a94c5c4905f23ee6f9248edc5df599a59d28e21ea0201d8abe5d5d73b39cb05b60c861ea8e04767eef04433e2ee95dcfed653ee
23f4343 Add CMerkleTx::IsImmatureCoinBase method (Ben Woosley) Pull request description: All but one call to `GetBlocksToMaturity` is testing it relative to 0 for the purposes of determining whether the coinbase tx is immature. In such case, the value greater than 0 implies that the tx is coinbase, so there is no need to separately test that status. This names the concept for easy singular use. Tree-SHA512: 4470d07404a0707144f9827b9a94c5c4905f23ee6f9248edc5df599a59d28e21ea0201d8abe5d5d73b39cb05b60c861ea8e04767eef04433e2ee95dcfed653ee # Conflicts: # src/wallet/wallet.h
23f4343 Add CMerkleTx::IsImmatureCoinBase method (Ben Woosley) Pull request description: All but one call to `GetBlocksToMaturity` is testing it relative to 0 for the purposes of determining whether the coinbase tx is immature. In such case, the value greater than 0 implies that the tx is coinbase, so there is no need to separately test that status. This names the concept for easy singular use. Tree-SHA512: 4470d07404a0707144f9827b9a94c5c4905f23ee6f9248edc5df599a59d28e21ea0201d8abe5d5d73b39cb05b60c861ea8e04767eef04433e2ee95dcfed653ee # Conflicts: # src/wallet/wallet.h
All but one call to
GetBlocksToMaturityis testing it relative to 0for the purposes of determining whether the coinbase tx is immature.
In such case, the value greater than 0 implies that the tx is coinbase,
so there is no need to separately test that status.
This names the concept for easy singular use.