mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
[refactor] move ValidationInterface functions to TxDownloadManager
This is move-only.
This commit is contained in:
parent
f6c860efb1
commit
af918349de
4 changed files with 67 additions and 26 deletions
|
@ -2036,8 +2036,7 @@ void PeerManagerImpl::ActiveTipChange(const CBlockIndex& new_tip, bool is_ibd)
|
|||
// If the chain tip has changed, previously rejected transactions might now be valid, e.g. due
|
||||
// to a timelock. Reset the rejection filters to give those transactions another chance if we
|
||||
// see them again.
|
||||
RecentRejectsFilter().reset();
|
||||
RecentRejectsReconsiderableFilter().reset();
|
||||
m_txdownloadman.ActiveTipChange();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2072,33 +2071,13 @@ void PeerManagerImpl::BlockConnected(
|
|||
return;
|
||||
}
|
||||
LOCK(m_tx_download_mutex);
|
||||
auto& m_orphanage = m_txdownloadman.GetOrphanageRef();
|
||||
auto& m_txrequest = m_txdownloadman.GetTxRequestRef();
|
||||
|
||||
m_orphanage.EraseForBlock(*pblock);
|
||||
|
||||
for (const auto& ptx : pblock->vtx) {
|
||||
RecentConfirmedTransactionsFilter().insert(ptx->GetHash().ToUint256());
|
||||
if (ptx->HasWitness()) {
|
||||
RecentConfirmedTransactionsFilter().insert(ptx->GetWitnessHash().ToUint256());
|
||||
}
|
||||
m_txrequest.ForgetTxHash(ptx->GetHash());
|
||||
m_txrequest.ForgetTxHash(ptx->GetWitnessHash());
|
||||
}
|
||||
m_txdownloadman.BlockConnected(pblock);
|
||||
}
|
||||
|
||||
void PeerManagerImpl::BlockDisconnected(const std::shared_ptr<const CBlock> &block, const CBlockIndex* pindex)
|
||||
{
|
||||
// To avoid relay problems with transactions that were previously
|
||||
// confirmed, clear our filter of recently confirmed transactions whenever
|
||||
// there's a reorg.
|
||||
// This means that in a 1-block reorg (where 1 block is disconnected and
|
||||
// then another block reconnected), our filter will drop to having only one
|
||||
// block's worth of transactions in it, but that should be fine, since
|
||||
// presumably the most common case of relaying a confirmed transaction
|
||||
// should be just after a new block containing it is found.
|
||||
LOCK(m_tx_download_mutex);
|
||||
RecentConfirmedTransactionsFilter().reset();
|
||||
m_txdownloadman.BlockDisconnected();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,10 +8,10 @@
|
|||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
class CBlock;
|
||||
class CRollingBloomFilter;
|
||||
class TxOrphanage;
|
||||
class TxRequestTracker;
|
||||
class CRollingBloomFilter;
|
||||
|
||||
namespace node {
|
||||
class TxDownloadManagerImpl;
|
||||
|
||||
|
@ -48,6 +48,11 @@ public:
|
|||
CRollingBloomFilter& RecentRejectsFilter();
|
||||
CRollingBloomFilter& RecentRejectsReconsiderableFilter();
|
||||
CRollingBloomFilter& RecentConfirmedTransactionsFilter();
|
||||
|
||||
// Responses to chain events. TxDownloadManager is not an actual client of ValidationInterface, these are called through PeerManager.
|
||||
void ActiveTipChange();
|
||||
void BlockConnected(const std::shared_ptr<const CBlock>& pblock);
|
||||
void BlockDisconnected();
|
||||
};
|
||||
} // namespace node
|
||||
#endif // BITCOIN_NODE_TXDOWNLOADMAN_H
|
||||
|
|
|
@ -5,7 +5,13 @@
|
|||
#include <node/txdownloadman_impl.h>
|
||||
#include <node/txdownloadman.h>
|
||||
|
||||
#include <chain.h>
|
||||
#include <consensus/validation.h>
|
||||
#include <validation.h>
|
||||
#include <validationinterface.h>
|
||||
|
||||
namespace node {
|
||||
// TxDownloadManager wrappers
|
||||
TxDownloadManager::TxDownloadManager() :
|
||||
m_impl{std::make_unique<TxDownloadManagerImpl>()}
|
||||
{}
|
||||
|
@ -31,4 +37,50 @@ CRollingBloomFilter& TxDownloadManager::RecentConfirmedTransactionsFilter()
|
|||
{
|
||||
return m_impl->RecentConfirmedTransactionsFilter();
|
||||
}
|
||||
void TxDownloadManager::ActiveTipChange()
|
||||
{
|
||||
m_impl->ActiveTipChange();
|
||||
}
|
||||
void TxDownloadManager::BlockConnected(const std::shared_ptr<const CBlock>& pblock)
|
||||
{
|
||||
m_impl->BlockConnected(pblock);
|
||||
}
|
||||
void TxDownloadManager::BlockDisconnected()
|
||||
{
|
||||
m_impl->BlockDisconnected();
|
||||
}
|
||||
|
||||
// TxDownloadManagerImpl
|
||||
void TxDownloadManagerImpl::ActiveTipChange()
|
||||
{
|
||||
RecentRejectsFilter().reset();
|
||||
RecentRejectsReconsiderableFilter().reset();
|
||||
}
|
||||
|
||||
void TxDownloadManagerImpl::BlockConnected(const std::shared_ptr<const CBlock>& pblock)
|
||||
{
|
||||
m_orphanage.EraseForBlock(*pblock);
|
||||
|
||||
for (const auto& ptx : pblock->vtx) {
|
||||
RecentConfirmedTransactionsFilter().insert(ptx->GetHash().ToUint256());
|
||||
if (ptx->HasWitness()) {
|
||||
RecentConfirmedTransactionsFilter().insert(ptx->GetWitnessHash().ToUint256());
|
||||
}
|
||||
m_txrequest.ForgetTxHash(ptx->GetHash());
|
||||
m_txrequest.ForgetTxHash(ptx->GetWitnessHash());
|
||||
}
|
||||
}
|
||||
|
||||
void TxDownloadManagerImpl::BlockDisconnected()
|
||||
{
|
||||
// To avoid relay problems with transactions that were previously
|
||||
// confirmed, clear our filter of recently confirmed transactions whenever
|
||||
// there's a reorg.
|
||||
// This means that in a 1-block reorg (where 1 block is disconnected and
|
||||
// then another block reconnected), our filter will drop to having only one
|
||||
// block's worth of transactions in it, but that should be fine, since
|
||||
// presumably the most common case of relaying a confirmed transaction
|
||||
// should be just after a new block containing it is found.
|
||||
RecentConfirmedTransactionsFilter().reset();
|
||||
}
|
||||
} // namespace node
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <node/txdownloadman.h>
|
||||
|
||||
#include <common/bloom.h>
|
||||
#include <kernel/chain.h>
|
||||
#include <net.h>
|
||||
#include <txorphanage.h>
|
||||
#include <txrequest.h>
|
||||
|
@ -122,6 +123,10 @@ public:
|
|||
}
|
||||
|
||||
TxDownloadManagerImpl() = default;
|
||||
|
||||
void ActiveTipChange();
|
||||
void BlockConnected(const std::shared_ptr<const CBlock>& pblock);
|
||||
void BlockDisconnected();
|
||||
};
|
||||
} // namespace node
|
||||
#endif // BITCOIN_NODE_TXDOWNLOADMAN_IMPL_H
|
||||
|
|
Loading…
Add table
Reference in a new issue