Skip to content

Commit 1a3cbf1

Browse files
committed
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.
1 parent bc33509 commit 1a3cbf1

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/net_processing.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,11 +1907,13 @@ std::vector<CTransactionRef> PeerManagerImpl::AbortPrivateBroadcast(const uint25
19071907

19081908
void PeerManagerImpl::AddToCompactExtraTransactions(const CTransactionRef& tx)
19091909
{
1910-
if (m_opts.max_extra_txs <= 0)
1911-
return;
1912-
if (!vExtraTxnForCompact.size())
1913-
vExtraTxnForCompact.resize(m_opts.max_extra_txs);
1914-
vExtraTxnForCompact[vExtraTxnForCompactIt] = std::make_pair(tx->GetWitnessHash(), tx);
1910+
if (m_opts.max_extra_txs == 0) return;
1911+
if (vExtraTxnForCompact.size() < m_opts.max_extra_txs) {
1912+
if (vExtraTxnForCompact.empty()) vExtraTxnForCompact.reserve(m_opts.max_extra_txs);
1913+
vExtraTxnForCompact.emplace_back(tx->GetWitnessHash(), tx);
1914+
} else {
1915+
vExtraTxnForCompact[vExtraTxnForCompactIt] = std::make_pair(tx->GetWitnessHash(), tx);
1916+
}
19151917
vExtraTxnForCompactIt = (vExtraTxnForCompactIt + 1) % m_opts.max_extra_txs;
19161918
}
19171919

0 commit comments

Comments
 (0)