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)
|
void TxOrphanage::EraseForPeer(NodeId peer)
|
||||||
{
|
{
|
||||||
m_peer_work_set.erase(peer);
|
m_peer_orphanage_info.erase(peer);
|
||||||
|
|
||||||
int nErased = 0;
|
int nErased = 0;
|
||||||
std::map<Wtxid, OrphanTx>::iterator iter = m_orphans.begin();
|
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
|
// 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)
|
// (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
|
// Add this tx to the work set
|
||||||
orphan_work_set.insert(elem->first);
|
orphan_work_set.insert(elem->first);
|
||||||
LogDebug(BCLog::TXPACKAGES, "added %s (wtxid=%s) to peer %d workset\n",
|
LogDebug(BCLog::TXPACKAGES, "added %s (wtxid=%s) to peer %d workset\n",
|
||||||
|
@ -203,17 +203,17 @@ bool TxOrphanage::HaveTxFromPeer(const Wtxid& wtxid, NodeId peer) const
|
||||||
|
|
||||||
CTransactionRef TxOrphanage::GetTxToReconsider(NodeId peer)
|
CTransactionRef TxOrphanage::GetTxToReconsider(NodeId peer)
|
||||||
{
|
{
|
||||||
auto work_set_it = m_peer_work_set.find(peer);
|
auto peer_it = m_peer_orphanage_info.find(peer);
|
||||||
if (work_set_it != m_peer_work_set.end()) {
|
if (peer_it == m_peer_orphanage_info.end()) return nullptr;
|
||||||
auto& work_set = work_set_it->second;
|
|
||||||
while (!work_set.empty()) {
|
|
||||||
Wtxid wtxid = *work_set.begin();
|
|
||||||
work_set.erase(work_set.begin());
|
|
||||||
|
|
||||||
const auto orphan_it = m_orphans.find(wtxid);
|
auto& work_set = peer_it->second.m_work_set;
|
||||||
if (orphan_it != m_orphans.end()) {
|
while (!work_set.empty()) {
|
||||||
return orphan_it->second.tx;
|
Wtxid wtxid = *work_set.begin();
|
||||||
}
|
work_set.erase(work_set.begin());
|
||||||
|
|
||||||
|
const auto orphan_it = m_orphans.find(wtxid);
|
||||||
|
if (orphan_it != m_orphans.end()) {
|
||||||
|
return orphan_it->second.tx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -221,12 +221,11 @@ CTransactionRef TxOrphanage::GetTxToReconsider(NodeId peer)
|
||||||
|
|
||||||
bool TxOrphanage::HaveTxToReconsider(NodeId peer)
|
bool TxOrphanage::HaveTxToReconsider(NodeId peer)
|
||||||
{
|
{
|
||||||
auto work_set_it = m_peer_work_set.find(peer);
|
auto peer_it = m_peer_orphanage_info.find(peer);
|
||||||
if (work_set_it != m_peer_work_set.end()) {
|
if (peer_it == m_peer_orphanage_info.end()) return false;
|
||||||
auto& work_set = work_set_it->second;
|
|
||||||
return !work_set.empty();
|
auto& work_set = peer_it->second.m_work_set;
|
||||||
}
|
return !work_set.empty();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TxOrphanage::EraseForBlock(const CBlock& block)
|
void TxOrphanage::EraseForBlock(const CBlock& block)
|
||||||
|
|
|
@ -109,8 +109,14 @@ protected:
|
||||||
* -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS */
|
* -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS */
|
||||||
std::map<Wtxid, OrphanTx> m_orphans;
|
std::map<Wtxid, OrphanTx> m_orphans;
|
||||||
|
|
||||||
/** Which peer provided the orphans that need to be reconsidered */
|
struct PeerOrphanInfo {
|
||||||
std::map<NodeId, std::set<Wtxid>> m_peer_work_set;
|
/** 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);
|
using OrphanMap = decltype(m_orphans);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue