mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-14 12:43:40 +02:00
Merge c97270d722 into merged_master (Bitcoin PR bitcoin/bitcoin#27499)
This commit is contained in:
commit
aacc36f977
9 changed files with 87 additions and 37 deletions
|
|
@ -10,7 +10,6 @@
|
|||
#include <blockencodings.h>
|
||||
#include <blockfilter.h>
|
||||
#include <chainparams.h>
|
||||
#include <common/args.h>
|
||||
#include <consensus/amount.h>
|
||||
#include <consensus/validation.h>
|
||||
#include <deploymentstatus.h>
|
||||
|
|
@ -487,7 +486,7 @@ class PeerManagerImpl final : public PeerManager
|
|||
public:
|
||||
PeerManagerImpl(CConnman& connman, AddrMan& addrman,
|
||||
BanMan* banman, ChainstateManager& chainman,
|
||||
CTxMemPool& pool, bool ignore_incoming_txs);
|
||||
CTxMemPool& pool, Options opts);
|
||||
|
||||
/** Overridden from CValidationInterface. */
|
||||
void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected) override
|
||||
|
|
@ -515,7 +514,7 @@ public:
|
|||
std::optional<std::string> FetchBlock(NodeId peer_id, const CBlockIndex& block_index) override
|
||||
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
||||
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
||||
bool IgnoresIncomingTxs() override { return m_ignore_incoming_txs; }
|
||||
bool IgnoresIncomingTxs() override { return m_opts.ignore_incoming_txs; }
|
||||
void SendPings() override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
||||
void RelayTransaction(const uint256& txid, const uint256& wtxid) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
||||
void SetBestHeight(int height) override { m_best_height = height; };
|
||||
|
|
@ -718,8 +717,7 @@ private:
|
|||
/** Next time to check for stale tip */
|
||||
std::chrono::seconds m_stale_tip_check_time GUARDED_BY(cs_main){0s};
|
||||
|
||||
/** Whether this node is running in -blocksonly mode */
|
||||
const bool m_ignore_incoming_txs;
|
||||
const Options m_opts;
|
||||
|
||||
bool RejectIncomingTxs(const CNode& peer) const;
|
||||
|
||||
|
|
@ -1212,7 +1210,7 @@ void PeerManagerImpl::MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid)
|
|||
// When in -blocksonly mode, never request high-bandwidth mode from peers. Our
|
||||
// mempool will not contain the transactions necessary to reconstruct the
|
||||
// compact block.
|
||||
if (m_ignore_incoming_txs) return;
|
||||
if (m_opts.ignore_incoming_txs) return;
|
||||
|
||||
CNodeState* nodestate = State(nodeid);
|
||||
if (!nodestate || !nodestate->m_provides_cmpctblocks) {
|
||||
|
|
@ -1654,13 +1652,12 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) c
|
|||
|
||||
void PeerManagerImpl::AddToCompactExtraTransactions(const CTransactionRef& tx)
|
||||
{
|
||||
size_t max_extra_txn = gArgs.GetIntArg("-blockreconstructionextratxn", DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN);
|
||||
if (max_extra_txn <= 0)
|
||||
if (m_opts.max_extra_txs <= 0)
|
||||
return;
|
||||
if (!vExtraTxnForCompact.size())
|
||||
vExtraTxnForCompact.resize(max_extra_txn);
|
||||
vExtraTxnForCompact.resize(m_opts.max_extra_txs);
|
||||
vExtraTxnForCompact[vExtraTxnForCompactIt] = std::make_pair(tx->GetWitnessHash(), tx);
|
||||
vExtraTxnForCompactIt = (vExtraTxnForCompactIt + 1) % max_extra_txn;
|
||||
vExtraTxnForCompactIt = (vExtraTxnForCompactIt + 1) % m_opts.max_extra_txs;
|
||||
}
|
||||
|
||||
void PeerManagerImpl::Misbehaving(Peer& peer, int howmuch, const std::string& message)
|
||||
|
|
@ -1813,25 +1810,25 @@ std::optional<std::string> PeerManagerImpl::FetchBlock(NodeId peer_id, const CBl
|
|||
|
||||
std::unique_ptr<PeerManager> PeerManager::make(CConnman& connman, AddrMan& addrman,
|
||||
BanMan* banman, ChainstateManager& chainman,
|
||||
CTxMemPool& pool, bool ignore_incoming_txs)
|
||||
CTxMemPool& pool, Options opts)
|
||||
{
|
||||
return std::make_unique<PeerManagerImpl>(connman, addrman, banman, chainman, pool, ignore_incoming_txs);
|
||||
return std::make_unique<PeerManagerImpl>(connman, addrman, banman, chainman, pool, opts);
|
||||
}
|
||||
|
||||
PeerManagerImpl::PeerManagerImpl(CConnman& connman, AddrMan& addrman,
|
||||
BanMan* banman, ChainstateManager& chainman,
|
||||
CTxMemPool& pool, bool ignore_incoming_txs)
|
||||
CTxMemPool& pool, Options opts)
|
||||
: m_chainparams(chainman.GetParams()),
|
||||
m_connman(connman),
|
||||
m_addrman(addrman),
|
||||
m_banman(banman),
|
||||
m_chainman(chainman),
|
||||
m_mempool(pool),
|
||||
m_ignore_incoming_txs(ignore_incoming_txs)
|
||||
m_opts{opts}
|
||||
{
|
||||
// While Erlay support is incomplete, it must be enabled explicitly via -txreconciliation.
|
||||
// This argument can go away after Erlay support is complete.
|
||||
if (gArgs.GetBoolArg("-txreconciliation", DEFAULT_TXRECONCILIATION_ENABLE)) {
|
||||
if (opts.reconcile_txs) {
|
||||
m_txreconciliation = std::make_unique<TxReconciliationTracker>(TXRECONCILIATION_VERSION);
|
||||
}
|
||||
}
|
||||
|
|
@ -2733,7 +2730,7 @@ void PeerManagerImpl::HeadersDirectFetchBlocks(CNode& pfrom, const Peer& peer, c
|
|||
last_header.nHeight);
|
||||
}
|
||||
if (vGetData.size() > 0) {
|
||||
if (!m_ignore_incoming_txs &&
|
||||
if (!m_opts.ignore_incoming_txs &&
|
||||
nodestate->m_provides_cmpctblocks &&
|
||||
vGetData.size() == 1 &&
|
||||
mapBlocksInFlight.size() == 1 &&
|
||||
|
|
@ -3486,7 +3483,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
// - we are not in -blocksonly mode.
|
||||
const auto* tx_relay = peer->GetTxRelay();
|
||||
if (tx_relay && WITH_LOCK(tx_relay->m_bloom_filter_mutex, return tx_relay->m_relay_txs) &&
|
||||
!pfrom.IsAddrFetchConn() && !m_ignore_incoming_txs) {
|
||||
!pfrom.IsAddrFetchConn() && !m_opts.ignore_incoming_txs) {
|
||||
const uint64_t recon_salt = m_txreconciliation->PreRegisterPeer(pfrom.GetId());
|
||||
m_connman.PushMessage(&pfrom, msg_maker.Make(NetMsgType::SENDTXRCNCL,
|
||||
TXRECONCILIATION_VERSION, recon_salt));
|
||||
|
|
@ -4299,8 +4296,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
m_txrequest.ForgetTxHash(tx.GetWitnessHash());
|
||||
|
||||
// DoS prevention: do not allow m_orphanage to grow unbounded (see CVE-2012-3789)
|
||||
unsigned int nMaxOrphanTx = (unsigned int)std::max((int64_t)0, gArgs.GetIntArg("-maxorphantx", DEFAULT_MAX_ORPHAN_TRANSACTIONS));
|
||||
m_orphanage.LimitOrphans(nMaxOrphanTx);
|
||||
m_orphanage.LimitOrphans(m_opts.max_orphan_txs);
|
||||
} else {
|
||||
LogPrint(BCLog::MEMPOOL, "not keeping orphan with rejected parents %s\n",tx.GetHash().ToString());
|
||||
// We will continue to reject this tx since it has rejected
|
||||
|
|
@ -5075,7 +5071,7 @@ bool PeerManagerImpl::ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt
|
|||
msg.m_recv.data()
|
||||
);
|
||||
|
||||
if (gArgs.GetBoolArg("-capturemessages", false)) {
|
||||
if (m_opts.capture_messages) {
|
||||
CaptureMessage(pfrom->addr, msg.m_type, MakeUCharSpan(msg.m_recv), /*is_incoming=*/true);
|
||||
}
|
||||
|
||||
|
|
@ -5425,7 +5421,7 @@ void PeerManagerImpl::MaybeSendSendHeaders(CNode& node, Peer& peer)
|
|||
|
||||
void PeerManagerImpl::MaybeSendFeefilter(CNode& pto, Peer& peer, std::chrono::microseconds current_time)
|
||||
{
|
||||
if (m_ignore_incoming_txs) return;
|
||||
if (m_opts.ignore_incoming_txs) return;
|
||||
if (pto.GetCommonVersion() < FEEFILTER_VERSION) return;
|
||||
// peers with the forcerelay permission should not filter txs to us
|
||||
if (pto.HasPermission(NetPermissionFlags::ForceRelay)) return;
|
||||
|
|
@ -5493,7 +5489,7 @@ bool PeerManagerImpl::RejectIncomingTxs(const CNode& peer) const
|
|||
if (peer.IsBlockOnlyConn()) return true;
|
||||
if (peer.IsFeelerConn()) return true;
|
||||
// In -blocksonly mode, peers need the 'relay' permission to send txs to us
|
||||
if (m_ignore_incoming_txs && !peer.HasPermission(NetPermissionFlags::Relay)) return true;
|
||||
if (m_opts.ignore_incoming_txs && !peer.HasPermission(NetPermissionFlags::Relay)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue