DigiByte-Core/digibyte

Coinbase Maturity

ycagel opened this issue · 1 comments

ycagel commented
          Awesome you found this @barrystyle ! Thanks for the contribution. It looks like there might be a couple of other places where `COINBASE_MATURITY_2` needs added properly to fix the issue as @beggsdl mentioned above. 

txmempool.cpp needs an additional COINBASE_MATURITY_2 entry:

digibyte/src/txmempool.cpp

Lines 535 to 538 in 1c2c656

unsigned int nMemPoolHeight = active_chainstate.m_chain.Tip()->nHeight + 1;
if (coin.IsSpent() || (coin.IsCoinBase() && ((signed long)nMemPoolHeight) - coin.nHeight < COINBASE_MATURITY)) {
txToRemove.insert(it);
break;

Here is txmempool.cpp COINBASE_MATURITY_2 in 7.17.3:

digibyte/src/txmempool.cpp

Lines 522 to 529 in 258afac

if (coin.IsSpent() || (coin.IsCoinBase() && ((signed long)nMemPoolHeight) - coin.nHeight < COINBASE_MATURITY)) {
txToRemove.insert(it);
break;
}
} else {
if (coin.IsSpent() || (coin.IsCoinBase() && ((signed long)nMemPoolHeight) - coin.nHeight < COINBASE_MATURITY_2)) {
txToRemove.insert(it);
break;

Also in src/wallet/wallet.cpp looks like we need change to COINBASE_MATURITY_2 as well:

digibyte/src/wallet/wallet.cpp

Lines 2904 to 2911 in 1c2c656

int CWalletTx::GetBlocksToMaturity() const
{
if (!IsCoinBase())
return 0;
int chain_depth = GetDepthInMainChain();
assert(chain_depth >= 0); // coinbase tx should not be conflicted
return std::max(0, (COINBASE_MATURITY+1) - chain_depth);
}

Here is what 7.17.3 shows:

digibyte/src/wallet/wallet.cpp

Lines 4419 to 4426 in 258afac

int CMerkleTx::GetBlocksToMaturity() const
{
if (!IsCoinBase())
return 0;
int chain_depth = GetDepthInMainChain();
assert(chain_depth >= 0); // coinbase tx should not be conflicted
return std::max(0, (COINBASE_MATURITY_2+1) - chain_depth);
}

V7.17.3 mentions COINBASE_MATURITY_2 in these locations:
Screenshot 2024-01-08 at 12 09 48 PM

current 8.22 including this PR onlys shows COINBASE_MATURITY_2 in 3 places outside of tests:
Screenshot 2024-01-08 at 12 10 57 PM

I can add additions on to this PR @barrystyle or you can modify yours. Just let me know.

Originally posted by @JaredTate in #157 (comment)

This should be resolved with #160