Skip to content

Commit

Permalink
Merge bitcoin#13657: wallet: assert to ensure accuracy of CMerkleTx::…
Browse files Browse the repository at this point in the history
…GetBlocksToMaturity

93de289 wallet: assert to ensure accuracy of CMerkleTx::GetBlocksToMaturity (Ben Woosley)

Pull request description:

  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.

Tree-SHA512: 8e71c26f09fe457cfb00c362ca27066f7f018ea2af1f395090fdc7fd9f5964b76f4317c23f7a4923776f00087558511da5c1c368095be39fb1bacc614a93c32f
  • Loading branch information
laanwj authored and PastaPastaPasta committed Dec 18, 2020
1 parent e6089da commit 4d0edcf
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 @@ -5607,7 +5607,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 4d0edcf

Please sign in to comment.