Skip to content

Commit

Permalink
Merge pull request pocketnetteam#800 from pocketnetteam:fix/miner_spent
Browse files Browse the repository at this point in the history
Refactor transaction logging in BlockAssembler
  • Loading branch information
andyoknen authored Jan 7, 2025
2 parents 235d6f8 + fd9118c commit d06a58d
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 d06a58d

Please sign in to comment.