mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
[refactor] change per-peer workset to info map within orphanage
No change for now, moving from map of NodeId->workset to NodeId->PeerOrphanInfo struct that holds the workset. In future commits, we will start tracking more things per-peer in the orphanage.
This commit is contained in:
parent
59cd0f0e09
commit
672c69c688
2 changed files with 25 additions and 20 deletions
|
@ -103,7 +103,7 @@ int TxOrphanage::EraseTx(const Wtxid& wtxid)
|
|||
|
||||
void TxOrphanage::EraseForPeer(NodeId peer)
|
||||
{
|
||||
m_peer_work_set.erase(peer);
|
||||
m_peer_orphanage_info.erase(peer);
|
||||
|
||||
int nErased = 0;
|
||||
std::map<Wtxid, OrphanTx>::iterator iter = m_orphans.begin();
|
||||
|
@ -174,7 +174,7 @@ void TxOrphanage::AddChildrenToWorkSet(const CTransaction& tx, FastRandomContext
|
|||
|
||||
// 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<Wtxid>& orphan_work_set = m_peer_work_set.try_emplace(announcer).first->second;
|
||||
std::set<Wtxid>& orphan_work_set = m_peer_orphanage_info.try_emplace(announcer).first->second.m_work_set;
|
||||
// Add this tx to the work set
|
||||
orphan_work_set.insert(elem->first);
|
||||
LogDebug(BCLog::TXPACKAGES, "added %s (wtxid=%s) to peer %d workset\n",
|
||||
|
@ -203,9 +203,10 @@ bool TxOrphanage::HaveTxFromPeer(const Wtxid& wtxid, NodeId peer) const
|
|||
|
||||
CTransactionRef TxOrphanage::GetTxToReconsider(NodeId peer)
|
||||
{
|
||||
auto work_set_it = m_peer_work_set.find(peer);
|
||||
if (work_set_it != m_peer_work_set.end()) {
|
||||
auto& work_set = work_set_it->second;
|
||||
auto peer_it = m_peer_orphanage_info.find(peer);
|
||||
if (peer_it == m_peer_orphanage_info.end()) return nullptr;
|
||||
|
||||
auto& work_set = peer_it->second.m_work_set;
|
||||
while (!work_set.empty()) {
|
||||
Wtxid wtxid = *work_set.begin();
|
||||
work_set.erase(work_set.begin());
|
||||
|
@ -215,19 +216,17 @@ CTransactionRef TxOrphanage::GetTxToReconsider(NodeId peer)
|
|||
return orphan_it->second.tx;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool TxOrphanage::HaveTxToReconsider(NodeId peer)
|
||||
{
|
||||
auto work_set_it = m_peer_work_set.find(peer);
|
||||
if (work_set_it != m_peer_work_set.end()) {
|
||||
auto& work_set = work_set_it->second;
|
||||
auto peer_it = m_peer_orphanage_info.find(peer);
|
||||
if (peer_it == m_peer_orphanage_info.end()) return false;
|
||||
|
||||
auto& work_set = peer_it->second.m_work_set;
|
||||
return !work_set.empty();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void TxOrphanage::EraseForBlock(const CBlock& block)
|
||||
{
|
||||
|
|
|
@ -109,8 +109,14 @@ protected:
|
|||
* -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS */
|
||||
std::map<Wtxid, OrphanTx> m_orphans;
|
||||
|
||||
/** Which peer provided the orphans that need to be reconsidered */
|
||||
std::map<NodeId, std::set<Wtxid>> m_peer_work_set;
|
||||
struct PeerOrphanInfo {
|
||||
/** List of transactions that should be reconsidered: added to in AddChildrenToWorkSet,
|
||||
* removed from one-by-one with each call to GetTxToReconsider. The wtxids may refer to
|
||||
* transactions that are no longer present in orphanage; these are lazily removed in
|
||||
* GetTxToReconsider. */
|
||||
std::set<Wtxid> m_work_set;
|
||||
};
|
||||
std::map<NodeId, PeerOrphanInfo> m_peer_orphanage_info;
|
||||
|
||||
using OrphanMap = decltype(m_orphans);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue