mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-12 13:42:10 +02:00
net: optimize compact block extra tx iteration
`vExtraTxnForCompact` was resized to its configured capacity on the first insertion.
Before the ring was filled, compact block reconstruction scanned default `{Wtxid::ZERO, nullptr}` entries created for unused slots.
Reserve the configured capacity and append entries until the cache is full, then keep the same ring-buffer overwrite behavior.
This preserves the configured maximum and replacement order while keeping reconstruction from scanning unused capacity.
This commit is contained in:
@@ -1907,11 +1907,13 @@ std::vector<CTransactionRef> PeerManagerImpl::AbortPrivateBroadcast(const uint25
|
||||
|
||||
void PeerManagerImpl::AddToCompactExtraTransactions(const CTransactionRef& tx)
|
||||
{
|
||||
if (m_opts.max_extra_txs <= 0)
|
||||
return;
|
||||
if (!vExtraTxnForCompact.size())
|
||||
vExtraTxnForCompact.resize(m_opts.max_extra_txs);
|
||||
vExtraTxnForCompact[vExtraTxnForCompactIt] = std::make_pair(tx->GetWitnessHash(), tx);
|
||||
if (m_opts.max_extra_txs == 0) return;
|
||||
if (vExtraTxnForCompact.size() < m_opts.max_extra_txs) {
|
||||
if (vExtraTxnForCompact.empty()) vExtraTxnForCompact.reserve(m_opts.max_extra_txs);
|
||||
vExtraTxnForCompact.emplace_back(tx->GetWitnessHash(), tx);
|
||||
} else {
|
||||
vExtraTxnForCompact[vExtraTxnForCompactIt] = std::make_pair(tx->GetWitnessHash(), tx);
|
||||
}
|
||||
vExtraTxnForCompactIt = (vExtraTxnForCompactIt + 1) % m_opts.max_extra_txs;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user