Skip to content

Commit

Permalink
Refactor transaction logging in BlockAssembler
Browse files Browse the repository at this point in the history
- Updated logging categories from STAKEMODIF to SELECTCOINS for better clarity in transaction handling.
- Added checks for spent coins and maturity of previous outputs in the TestTransaction method, enhancing transaction validation.
- Improved logging for skipped transactions in both TestTransaction and TestPackageTransactions methods, providing more detailed insights into transaction processing decisions.

These changes aim to improve the debugging process and ensure more robust transaction validation within the mining workflow.
  • Loading branch information
andyoknen committed Jan 7, 2025
1 parent 235d6f8 commit fd9118c
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ bool BlockAssembler::TestTransaction(const CTransactionRef& tx, PocketBlockRef&
// Payload should be in operative table Transactions
if (!ptx)
{
LogPrint(BCLog::STAKEMODIF, "Warning: build block skip transaction %s with result 'NOT FOUND'\n",
LogPrint(BCLog::SELECTCOINS, "Warning: build block skip transaction %s with result 'NOT FOUND'\n",
tx->GetHash().GetHex());

return false;
Expand All @@ -248,7 +248,7 @@ bool BlockAssembler::TestTransaction(const CTransactionRef& tx, PocketBlockRef&
// Check consensus
if (auto[ok, result] = PocketConsensus::SocialConsensusHelper::Check(tx, ptx, ChainActive().Height() + 1); !ok)
{
LogPrint(BCLog::STAKEMODIF, "Warning: build block skip transaction %s with check result %d\n",
LogPrint(BCLog::SELECTCOINS, "Warning: build block skip transaction %s with check result %d\n",
tx->GetHash().GetHex(), (int) result);

return false;
Expand All @@ -257,11 +257,30 @@ bool BlockAssembler::TestTransaction(const CTransactionRef& tx, PocketBlockRef&
// Validate consensus
if (auto[ok, result] = PocketConsensus::SocialConsensusHelper::Validate(tx, ptx, pblockTemplate, ChainActive().Height() + 1); !ok)
{
LogPrint(BCLog::STAKEMODIF, "Warning: build block skip transaction %s with validate result %d\n",
LogPrint(BCLog::SELECTCOINS, "Warning: build block skip transaction %s with validate result %d\n",
tx->GetHash().GetHex(), (int) result);

return false;
}

CCoinsViewCache view(&::ChainstateActive().CoinsTip());
for (unsigned int i = 0; i < tx->vin.size(); ++i) {
const COutPoint &prevout = tx->vin[i].prevout;
const Coin& coin = view.AccessCoin(prevout);
if (coin.IsSpent())
{
LogPrint(BCLog::SELECTCOINS, "Warning: build block skip transaction: tx - %s, prev - %s is spent\n", tx->GetHash().GetHex(), prevout.hash.GetHex());
return false;
}

// If prev is pocketnet, check that it's matured
if (ChainActive().Height() + 1 - coin.nHeight < POCKETNET_MATURITY)
{
LogPrint(BCLog::SELECTCOINS, "Warning: build block skip transaction: tx - %s, prev - %s, %d - %d = %d < %d\n",
tx->GetHash().GetHex(), prevout.hash.GetHex(), ChainActive().Height() + 1, coin.nHeight, ChainActive().Height() + 1 - coin.nHeight, POCKETNET_MATURITY);
return false;
}
}

// All is good - save for descendants
pblockTemplate->push_back(ptx);
Expand Down Expand Up @@ -289,10 +308,12 @@ bool BlockAssembler::TestPackageTransactions(const CTxMemPool::setEntries& packa
{
if (!IsFinalTx(it->GetTx(), nHeight, nLockTimeCutoff))
{
LogPrint(BCLog::SELECTCOINS, "Warning: build block skip transaction: tx - %s, height - %d, locktime - %d\n", it->GetTx().GetHash().GetHex(), nHeight, nLockTimeCutoff);
return false;
}
if (!fIncludeWitness && it->GetTx().HasWitness())
{
LogPrint(BCLog::SELECTCOINS, "Warning: build block skip transaction: tx - %s, height - %d, HasWitness\n", it->GetTx().GetHash().GetHex(), nHeight);
return false;
}
}
Expand Down Expand Up @@ -473,7 +494,7 @@ void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpda

if (packageFees < minFee)
{
LogPrintf("tx - %s, fee - %s, minFee - %s\n", iter->GetTx().GetHash().GetHex(), packageFees, minFee);
LogPrint(BCLog::SELECTCOINS, "Warning: build block skip transaction %s, fee (%s) < minFee (%s)\n", iter->GetTx().GetHash().GetHex(), packageFees, minFee);

if (fUsingModified)
{
Expand Down

0 comments on commit fd9118c

Please sign in to comment.