Skip to content

Commit

Permalink
wallet: assert to ensure accuracy of CMerkleTx::GetBlocksToMaturity
Browse files Browse the repository at this point in the history
According to my understanding, it should not be possible for coinbase
transactions to be conflicting, thus it should not be possible for
GetDepthInMainChain to return a negative result. If it did, this would
also result in innacurate results for GetBlocksToMaturity due to the
math therein. asserting ensures accuracy.
  • Loading branch information
Empact committed Jul 13, 2018
1 parent 2ea7eb6 commit 93de289
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4397,7 +4397,9 @@ int CMerkleTx::GetBlocksToMaturity() const
{
if (!IsCoinBase())
return 0;
return std::max(0, (COINBASE_MATURITY+1) - GetDepthInMainChain());
int chain_depth = GetDepthInMainChain();
assert(chain_depth >= 0); // coinbase tx should not be conflicted
return std::max(0, (COINBASE_MATURITY+1) - chain_depth);
}


Expand Down

0 comments on commit 93de289

Please sign in to comment.