Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CreateNewBlock with invalid fluxnode txes #232

Merged
merged 1 commit into from
Dec 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const CScript& s
// This vector will be sorted into a priority queue:
vector<TxPriority> vecPriority;
vecPriority.reserve(mempool.mapTx.size());
vector<CTransaction> vecInvalidFluxnodeTransactions;
vecInvalidFluxnodeTransactions.reserve(mempool.mapTx.size());
for (CTxMemPool::indexed_transaction_set::iterator mi = mempool.mapTx.begin();
mi != mempool.mapTx.end(); ++mi)
{
Expand Down Expand Up @@ -226,8 +228,7 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const CScript& s
const CCoins* coins = view.AccessCoins(tx.collateralIn.hash);
if (!coins) {
LogPrintf("Remove fluxnode transaction because its collateral is not found. %s\n", tx.GetHash().GetHex());
std::list<CTransaction> removed;
mempool.remove(tx, removed, false);
vecInvalidFluxnodeTransactions.push_back(tx);
continue;
}

Expand All @@ -237,16 +238,14 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const CScript& s

if (data.IsNull()) {
LogPrintf("Remove fluxnode transaction because its confirm isn't ready. %s\n", tx.GetHash().GetHex());
std::list<CTransaction> removed;
mempool.remove(tx, removed, false);
vecInvalidFluxnodeTransactions.push_back(tx);
continue;
}

if (tx.nUpdateType == FluxnodeUpdateType::INITIAL_CONFIRM) {
if (nNeedLocation != FLUXNODE_TX_STARTED) {
LogPrintf("Remove fluxnode transaction because its not started %s\n", tx.GetHash().GetHex());
std::list<CTransaction> removed;
mempool.remove(tx, removed, false);
vecInvalidFluxnodeTransactions.push_back(tx);
continue;
}
}
Expand All @@ -256,8 +255,7 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const CScript& s
LOCK(g_fluxnodeCache.cs);
if (!g_fluxnodeCache.CheckConfirmationHeights(nHeight, tx.collateralIn, tx.ip)) {
LogPrintf("Remove fluxnode transaction if failed CheckConfirmationHeights %s\n", tx.GetHash().GetHex());
std::list<CTransaction> removed;
mempool.remove(tx, removed, false);
vecInvalidFluxnodeTransactions.push_back(tx);
continue;
}
}
Expand Down Expand Up @@ -295,6 +293,12 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const CScript& s
vecPriority.push_back(TxPriority(dPriority, feeRate, &(mi->GetTx())));
}

// Remove invalid fluxnode transactions
for (const auto& badtx: vecInvalidFluxnodeTransactions) {
std::list<CTransaction> listRemoved;
mempool.remove(badtx,listRemoved,false);
}

// Collect transactions into block
uint64_t nBlockSize = 1000;
uint64_t nBlockTx = 0;
Expand Down