mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
txorphanage: index workset by originating peer
This commit is contained in:
parent
d415b7261c
commit
a4fe09973a
4 changed files with 11 additions and 9 deletions
|
@ -2903,7 +2903,7 @@ bool PeerManagerImpl::ProcessOrphanTx(Peer& peer)
|
||||||
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
|
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
|
||||||
LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", orphanHash.ToString());
|
LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", orphanHash.ToString());
|
||||||
RelayTransaction(orphanHash, porphanTx->GetWitnessHash());
|
RelayTransaction(orphanHash, porphanTx->GetWitnessHash());
|
||||||
m_orphanage.AddChildrenToWorkSet(*porphanTx, peer.m_id);
|
m_orphanage.AddChildrenToWorkSet(*porphanTx);
|
||||||
m_orphanage.EraseTx(orphanHash);
|
m_orphanage.EraseTx(orphanHash);
|
||||||
for (const CTransactionRef& removedTx : result.m_replaced_transactions.value()) {
|
for (const CTransactionRef& removedTx : result.m_replaced_transactions.value()) {
|
||||||
AddToCompactExtraTransactions(removedTx);
|
AddToCompactExtraTransactions(removedTx);
|
||||||
|
@ -4030,7 +4030,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
||||||
m_txrequest.ForgetTxHash(tx.GetHash());
|
m_txrequest.ForgetTxHash(tx.GetHash());
|
||||||
m_txrequest.ForgetTxHash(tx.GetWitnessHash());
|
m_txrequest.ForgetTxHash(tx.GetWitnessHash());
|
||||||
RelayTransaction(tx.GetHash(), tx.GetWitnessHash());
|
RelayTransaction(tx.GetHash(), tx.GetWitnessHash());
|
||||||
m_orphanage.AddChildrenToWorkSet(tx, peer->m_id);
|
m_orphanage.AddChildrenToWorkSet(tx);
|
||||||
|
|
||||||
pfrom.m_last_tx_time = GetTime<std::chrono::seconds>();
|
pfrom.m_last_tx_time = GetTime<std::chrono::seconds>();
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ FUZZ_TARGET_INIT(txorphan, initialize_orphanage)
|
||||||
CallOneOf(
|
CallOneOf(
|
||||||
fuzzed_data_provider,
|
fuzzed_data_provider,
|
||||||
[&] {
|
[&] {
|
||||||
orphanage.AddChildrenToWorkSet(*tx, peer_id);
|
orphanage.AddChildrenToWorkSet(*tx);
|
||||||
},
|
},
|
||||||
[&] {
|
[&] {
|
||||||
{
|
{
|
||||||
|
|
|
@ -145,17 +145,19 @@ void TxOrphanage::LimitOrphans(unsigned int max_orphans)
|
||||||
if (nEvicted > 0) LogPrint(BCLog::MEMPOOL, "orphanage overflow, removed %u tx\n", nEvicted);
|
if (nEvicted > 0) LogPrint(BCLog::MEMPOOL, "orphanage overflow, removed %u tx\n", nEvicted);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TxOrphanage::AddChildrenToWorkSet(const CTransaction& tx, NodeId peer)
|
void TxOrphanage::AddChildrenToWorkSet(const CTransaction& tx)
|
||||||
{
|
{
|
||||||
LOCK(m_mutex);
|
LOCK(m_mutex);
|
||||||
|
|
||||||
// Get this peer's work set, emplacing an empty set it didn't exist
|
|
||||||
std::set<uint256>& orphan_work_set = m_peer_work_set.try_emplace(peer).first->second;
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < tx.vout.size(); i++) {
|
for (unsigned int i = 0; i < tx.vout.size(); i++) {
|
||||||
const auto it_by_prev = m_outpoint_to_orphan_it.find(COutPoint(tx.GetHash(), i));
|
const auto it_by_prev = m_outpoint_to_orphan_it.find(COutPoint(tx.GetHash(), i));
|
||||||
if (it_by_prev != m_outpoint_to_orphan_it.end()) {
|
if (it_by_prev != m_outpoint_to_orphan_it.end()) {
|
||||||
for (const auto& elem : it_by_prev->second) {
|
for (const auto& elem : it_by_prev->second) {
|
||||||
|
// Get this source peer's work set, emplacing an empty set if it didn't exist
|
||||||
|
// (note: if this peer wasn't still connected, we would have removed the orphan tx already)
|
||||||
|
std::set<uint256>& orphan_work_set = m_peer_work_set.try_emplace(elem->second.fromPeer).first->second;
|
||||||
|
// Add this tx to the work set
|
||||||
orphan_work_set.insert(elem->first);
|
orphan_work_set.insert(elem->first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,8 +47,8 @@ public:
|
||||||
/** Limit the orphanage to the given maximum */
|
/** Limit the orphanage to the given maximum */
|
||||||
void LimitOrphans(unsigned int max_orphans) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
|
void LimitOrphans(unsigned int max_orphans) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
|
||||||
|
|
||||||
/** Add any orphans that list a particular tx as a parent into a peer's work set */
|
/** Add any orphans that list a particular tx as a parent into the from peer's work set */
|
||||||
void AddChildrenToWorkSet(const CTransaction& tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
|
void AddChildrenToWorkSet(const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);;
|
||||||
|
|
||||||
/** Return how many entries exist in the orphange */
|
/** Return how many entries exist in the orphange */
|
||||||
size_t Size() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
|
size_t Size() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
|
||||||
|
@ -72,7 +72,7 @@ protected:
|
||||||
* -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS */
|
* -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS */
|
||||||
std::map<uint256, OrphanTx> m_orphans GUARDED_BY(m_mutex);
|
std::map<uint256, OrphanTx> m_orphans GUARDED_BY(m_mutex);
|
||||||
|
|
||||||
/** Which peer provided a parent tx of orphans that need to be reconsidered */
|
/** Which peer provided the orphans that need to be reconsidered */
|
||||||
std::map<NodeId, std::set<uint256>> m_peer_work_set GUARDED_BY(m_mutex);
|
std::map<NodeId, std::set<uint256>> m_peer_work_set GUARDED_BY(m_mutex);
|
||||||
|
|
||||||
using OrphanMap = decltype(m_orphans);
|
using OrphanMap = decltype(m_orphans);
|
||||||
|
|
Loading…
Add table
Reference in a new issue