-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(mining): validate cumulative special transaction state per package #7570
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
base: develop
Are you sure you want to change the base?
Changes from all commits
4f666b9
109c8f2
90b8a3b
4886b9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| Bug Fixes | ||
| --------- | ||
|
|
||
| - Block template creation now checks credit pool limits across complete | ||
| transaction packages. Because Asset Unlock limits are cumulative, a package | ||
| may exceed the block's limit even though its transactions were accepted | ||
| individually. Such packages are now skipped so miners can continue building | ||
| a template instead of template creation failing. (#7570) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,16 +69,14 @@ BlockAssembler::Options::Options() | |
| } | ||
|
|
||
| BlockAssembler::BlockAssembler(Chainstate& chainstate, const NodeContext& node, const CTxMemPool* mempool, const Options& options) : | ||
| m_blockman(chainstate.m_blockman), | ||
| m_chain_helper(chainstate.ChainHelper()), | ||
| m_chainstate(chainstate), | ||
| m_evoDb(*Assert(node.evodb)), | ||
| m_chainlocks(*Assert(node.chainlocks)), | ||
| m_clhandler(*Assert(node.clhandler)), | ||
| chainparams(chainstate.m_chainman.GetParams()), | ||
| m_mempool(mempool), | ||
| m_quorum_block_processor(*Assert(Assert(node.llmq_ctx)->quorum_block_processor)), | ||
| m_qman(*Assert(Assert(node.llmq_ctx)->qman)) | ||
| m_quorum_block_processor(*Assert(Assert(node.llmq_ctx)->quorum_block_processor)) | ||
| { | ||
| blockMinFeeRate = options.blockMinFeeRate; | ||
| nBlockMaxSize = options.nBlockMaxSize; | ||
|
|
@@ -554,48 +552,6 @@ void BlockAssembler::addPackageTxs(const CTxMemPool& mempool, int& nPackagesSele | |
| } | ||
| } | ||
|
|
||
| if (creditPoolDiff != std::nullopt) { | ||
| // If one transaction is skipped due to limits, it is not a reason to interrupt | ||
| // whole process of adding transactions. | ||
| // `state` is local here because used only to log info about this specific tx | ||
| TxValidationState state; | ||
|
|
||
| if (iter->GetTx().IsSpecialTxVersion() && iter->GetTx().nType == TRANSACTION_ASSET_UNLOCK) { | ||
| // ASSET_UNLOCK transactions may expire after being added to mempool | ||
| // They should not be included to the block | ||
| if (!CheckAssetUnlockTx(m_blockman, m_qman, iter->GetTx(), pindexPrev, creditPoolDiff->pool.indexes, state)) { | ||
| if (fUsingModified) { | ||
| mapModifiedTx.get<ancestor_score>().erase(modit); | ||
| failedTx.insert(iter); | ||
| } | ||
| LogPrintf("%s: asset unlock tx %s is skipped due %s\n", | ||
| __func__, iter->GetTx().GetHash().ToString(), state.ToString()); | ||
| continue; | ||
| } | ||
| } | ||
| if (!creditPoolDiff->ProcessLockUnlockTransaction(iter->GetTx(), state)) { | ||
| if (fUsingModified) { | ||
| mapModifiedTx.get<ancestor_score>().erase(modit); | ||
| failedTx.insert(iter); | ||
| } | ||
| LogPrintf("%s: asset-locks tx %s skipped due %s\n", | ||
| __func__, iter->GetTx().GetHash().ToString(), state.ToString()); | ||
| continue; | ||
| } | ||
| } | ||
| if (std::optional<uint8_t> signal = extractEHFSignal(iter->GetTx()); signal != std::nullopt) { | ||
| if (signals.find(*signal) != signals.end()) { | ||
| if (fUsingModified) { | ||
| mapModifiedTx.get<ancestor_score>().erase(modit); | ||
| failedTx.insert(iter); | ||
| } | ||
| LogPrintf("%s: ehf signal tx %s skipped due to duplicate %d\n", | ||
| __func__, iter->GetTx().GetHash().ToString(), *signal); | ||
| continue; | ||
| } | ||
| signals.insert({*signal, 0}); | ||
| } | ||
|
|
||
| // We skip mapTx entries that are inBlock, and mapModifiedTx shouldn't | ||
| // contain anything that is inBlock. | ||
| assert(!inBlock.count(iter)); | ||
|
|
@@ -648,13 +604,48 @@ void BlockAssembler::addPackageTxs(const CTxMemPool& mempool, int& nPackagesSele | |
| continue; | ||
| } | ||
|
|
||
| // This transaction will make it in; reset the failed counter. | ||
| nConsecutiveFailed = 0; | ||
|
|
||
| // Package can be added. Sort the entries in a valid order. | ||
| std::vector<CTxMemPool::txiter> sortedEntries; | ||
| SortForBlock(ancestors, sortedEntries); | ||
|
|
||
| auto packageSignals = signals; | ||
| std::vector<CTransactionRef> creditPoolTransactions; | ||
| bool validPackage{true}; | ||
| for (const auto& entry : sortedEntries) { | ||
| const auto& tx = entry->GetTx(); | ||
| if (std::optional<uint8_t> signal = extractEHFSignal(tx); signal != std::nullopt) { | ||
| if (!packageSignals.emplace(*signal, 0).second) { | ||
| LogPrintf("%s: package tx %s skipped due to duplicate EHF signal %d\n", __func__, | ||
| tx.GetHash().ToString(), *signal); | ||
| validPackage = false; | ||
| break; | ||
| } | ||
| } | ||
| if (tx.IsSpecialTxVersion() && (tx.nType == TRANSACTION_ASSET_LOCK || tx.nType == TRANSACTION_ASSET_UNLOCK)) { | ||
| creditPoolTransactions.emplace_back(entry->GetSharedTx()); | ||
| } | ||
| } | ||
|
|
||
| if (validPackage && creditPoolDiff != std::nullopt && !creditPoolTransactions.empty()) { | ||
| TxValidationState state; | ||
| if (!creditPoolDiff->ProcessLockUnlockTransactions(creditPoolTransactions, state)) { | ||
| LogPrintf("%s: package tx %s skipped due to credit pool state: %s\n", __func__, | ||
| iter->GetTx().GetHash().ToString(), state.ToString()); | ||
| validPackage = false; | ||
| } | ||
| } | ||
| if (!validPackage) { | ||
| if (fUsingModified) { | ||
| mapModifiedTx.get<ancestor_score>().erase(modit); | ||
| failedTx.insert(iter); | ||
| } | ||
| continue; | ||
| } | ||
|
|
||
| // This transaction will make it in; reset the failed counter. | ||
| nConsecutiveFailed = 0; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new package-level EHF and credit-pool checks can reject a package after TestPackageTransactions(). Leaving the reset at its old location would clear the size/sigops failure streak even when one of those checks rejects the package and nothing is added. Moving it after validPackage preserves the intended invariant: the counter is reset only when the package will actually be added to the block.\n\n---\n🤖 Posted autonomously by Codex on behalf of pasta. |
||
| signals = std::move(packageSignals); | ||
|
|
||
| for (size_t i = 0; i < sortedEntries.size(); ++i) { | ||
| AddToBlock(sortedEntries[i]); | ||
| // Erase from the modified set, if present | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Suggestion: Avoid copying all accepted unlock indexes for every package
newIndexescontains the indexes from every Asset Unlock already accepted into the candidate block, so copying the entire set before each package causes O(n²) hash-node allocations across independent unlock packages. A 2 MB template can contain thousands of small Asset Unlock transactions because the withdrawal limit constrains their total amount rather than their count. Once the amount limit is exhausted, each additional unlock package still copies all previously accepted indexes before immediately failing. This work occurs insideCreateNewBlock()while bothcs_mainand the mempool lock are held. Record only the indexes inserted by this invocation and erase those during rollback; the amount fields can continue using scalar snapshots.source: ['codex']
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved in this update — Avoid copying all accepted unlock indexes for every package no longer present.
Auto-resolved by the review system based on the latest commit diff. If you believe this was closed in error, reopen the thread.