mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-09 10:43:19 -05:00
net_processing: relay txs from m_most_recent_block
This commit is contained in:
parent
a36134fcc7
commit
fccecd75fe
1 changed files with 24 additions and 6 deletions
|
@ -851,6 +851,7 @@ private:
|
||||||
std::shared_ptr<const CBlock> m_most_recent_block GUARDED_BY(m_most_recent_block_mutex);
|
std::shared_ptr<const CBlock> m_most_recent_block GUARDED_BY(m_most_recent_block_mutex);
|
||||||
std::shared_ptr<const CBlockHeaderAndShortTxIDs> m_most_recent_compact_block GUARDED_BY(m_most_recent_block_mutex);
|
std::shared_ptr<const CBlockHeaderAndShortTxIDs> m_most_recent_compact_block GUARDED_BY(m_most_recent_block_mutex);
|
||||||
uint256 m_most_recent_block_hash GUARDED_BY(m_most_recent_block_mutex);
|
uint256 m_most_recent_block_hash GUARDED_BY(m_most_recent_block_mutex);
|
||||||
|
std::unique_ptr<const std::map<uint256, CTransactionRef>> m_most_recent_block_txs GUARDED_BY(m_most_recent_block_mutex);
|
||||||
|
|
||||||
// Data about the low-work headers synchronization, aggregated from all peers' HeadersSyncStates.
|
// Data about the low-work headers synchronization, aggregated from all peers' HeadersSyncStates.
|
||||||
/** Mutex guarding the other m_headers_presync_* variables. */
|
/** Mutex guarding the other m_headers_presync_* variables. */
|
||||||
|
@ -910,7 +911,7 @@ private:
|
||||||
|
|
||||||
/** Determine whether or not a peer can request a transaction, and return it (or nullptr if not found or not allowed). */
|
/** Determine whether or not a peer can request a transaction, and return it (or nullptr if not found or not allowed). */
|
||||||
CTransactionRef FindTxForGetData(const Peer::TxRelay& tx_relay, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now)
|
CTransactionRef FindTxForGetData(const Peer::TxRelay& tx_relay, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now)
|
||||||
EXCLUSIVE_LOCKS_REQUIRED(NetEventsInterface::g_msgproc_mutex);
|
EXCLUSIVE_LOCKS_REQUIRED(!m_most_recent_block_mutex, NetEventsInterface::g_msgproc_mutex);
|
||||||
|
|
||||||
void ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic<bool>& interruptMsgProc)
|
void ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic<bool>& interruptMsgProc)
|
||||||
EXCLUSIVE_LOCKS_REQUIRED(!m_most_recent_block_mutex, peer.m_getdata_requests_mutex, NetEventsInterface::g_msgproc_mutex)
|
EXCLUSIVE_LOCKS_REQUIRED(!m_most_recent_block_mutex, peer.m_getdata_requests_mutex, NetEventsInterface::g_msgproc_mutex)
|
||||||
|
@ -1927,10 +1928,17 @@ void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::sha
|
||||||
std::async(std::launch::deferred, [&] { return msgMaker.Make(NetMsgType::CMPCTBLOCK, *pcmpctblock); })};
|
std::async(std::launch::deferred, [&] { return msgMaker.Make(NetMsgType::CMPCTBLOCK, *pcmpctblock); })};
|
||||||
|
|
||||||
{
|
{
|
||||||
|
auto most_recent_block_txs = std::make_unique<std::map<uint256, CTransactionRef>>();
|
||||||
|
for (const auto& tx : pblock->vtx) {
|
||||||
|
most_recent_block_txs->emplace(tx->GetHash(), tx);
|
||||||
|
most_recent_block_txs->emplace(tx->GetWitnessHash(), tx);
|
||||||
|
}
|
||||||
|
|
||||||
LOCK(m_most_recent_block_mutex);
|
LOCK(m_most_recent_block_mutex);
|
||||||
m_most_recent_block_hash = hashBlock;
|
m_most_recent_block_hash = hashBlock;
|
||||||
m_most_recent_block = pblock;
|
m_most_recent_block = pblock;
|
||||||
m_most_recent_compact_block = pcmpctblock;
|
m_most_recent_compact_block = pcmpctblock;
|
||||||
|
m_most_recent_block_txs = std::move(most_recent_block_txs);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_connman.ForEachNode([this, pindex, &lazy_ser, &hashBlock](CNode* pnode) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
|
m_connman.ForEachNode([this, pindex, &lazy_ser, &hashBlock](CNode* pnode) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
|
||||||
|
@ -2301,11 +2309,21 @@ CTransactionRef PeerManagerImpl::FindTxForGetData(const Peer::TxRelay& tx_relay,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, the transaction must have been announced recently.
|
// Otherwise, the transaction might have been announced recently.
|
||||||
if (tx_relay.m_recently_announced_invs.contains(gtxid.GetHash())) {
|
bool recent = tx_relay.m_recently_announced_invs.contains(gtxid.GetHash());
|
||||||
// If it was, it can be relayed from either the mempool...
|
if (recent && txinfo.tx) return std::move(txinfo.tx);
|
||||||
if (txinfo.tx) return std::move(txinfo.tx);
|
|
||||||
// ... or the relay pool.
|
// Or it might be from the most recent block
|
||||||
|
{
|
||||||
|
LOCK(m_most_recent_block_mutex);
|
||||||
|
if (m_most_recent_block_txs != nullptr) {
|
||||||
|
auto it = m_most_recent_block_txs->find(gtxid.GetHash());
|
||||||
|
if (it != m_most_recent_block_txs->end()) return it->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or it might be recent and in the relay pool.
|
||||||
|
if (recent) {
|
||||||
auto mi = mapRelay.find(gtxid.GetHash());
|
auto mi = mapRelay.find(gtxid.GetHash());
|
||||||
if (mi != mapRelay.end()) return mi->second;
|
if (mi != mapRelay.end()) return mi->second;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue