|
10 | 10 | #include <blockencodings.h>
|
11 | 11 | #include <blockfilter.h>
|
12 | 12 | #include <chainparams.h>
|
13 |
| -#include <common/args.h> |
14 | 13 | #include <consensus/amount.h>
|
15 | 14 | #include <consensus/validation.h>
|
16 | 15 | #include <deploymentstatus.h>
|
@@ -487,7 +486,7 @@ class PeerManagerImpl final : public PeerManager
|
487 | 486 | public:
|
488 | 487 | PeerManagerImpl(CConnman& connman, AddrMan& addrman,
|
489 | 488 | BanMan* banman, ChainstateManager& chainman,
|
490 |
| - CTxMemPool& pool, bool ignore_incoming_txs); |
| 489 | + CTxMemPool& pool, Options opts); |
491 | 490 |
|
492 | 491 | /** Overridden from CValidationInterface. */
|
493 | 492 | void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected) override
|
@@ -515,7 +514,7 @@ class PeerManagerImpl final : public PeerManager
|
515 | 514 | std::optional<std::string> FetchBlock(NodeId peer_id, const CBlockIndex& block_index) override
|
516 | 515 | EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
517 | 516 | bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
518 |
| - bool IgnoresIncomingTxs() override { return m_ignore_incoming_txs; } |
| 517 | + bool IgnoresIncomingTxs() override { return m_opts.ignore_incoming_txs; } |
519 | 518 | void SendPings() override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
520 | 519 | void RelayTransaction(const uint256& txid, const uint256& wtxid) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
521 | 520 | void SetBestHeight(int height) override { m_best_height = height; };
|
@@ -718,8 +717,7 @@ class PeerManagerImpl final : public PeerManager
|
718 | 717 | /** Next time to check for stale tip */
|
719 | 718 | std::chrono::seconds m_stale_tip_check_time GUARDED_BY(cs_main){0s};
|
720 | 719 |
|
721 |
| - /** Whether this node is running in -blocksonly mode */ |
722 |
| - const bool m_ignore_incoming_txs; |
| 720 | + const Options m_opts; |
723 | 721 |
|
724 | 722 | bool RejectIncomingTxs(const CNode& peer) const;
|
725 | 723 |
|
@@ -1212,7 +1210,7 @@ void PeerManagerImpl::MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid)
|
1212 | 1210 | // When in -blocksonly mode, never request high-bandwidth mode from peers. Our
|
1213 | 1211 | // mempool will not contain the transactions necessary to reconstruct the
|
1214 | 1212 | // compact block.
|
1215 |
| - if (m_ignore_incoming_txs) return; |
| 1213 | + if (m_opts.ignore_incoming_txs) return; |
1216 | 1214 |
|
1217 | 1215 | CNodeState* nodestate = State(nodeid);
|
1218 | 1216 | if (!nodestate || !nodestate->m_provides_cmpctblocks) {
|
@@ -1650,13 +1648,12 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) c
|
1650 | 1648 |
|
1651 | 1649 | void PeerManagerImpl::AddToCompactExtraTransactions(const CTransactionRef& tx)
|
1652 | 1650 | {
|
1653 |
| - size_t max_extra_txn = gArgs.GetIntArg("-blockreconstructionextratxn", DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN); |
1654 |
| - if (max_extra_txn <= 0) |
| 1651 | + if (m_opts.max_extra_txs <= 0) |
1655 | 1652 | return;
|
1656 | 1653 | if (!vExtraTxnForCompact.size())
|
1657 |
| - vExtraTxnForCompact.resize(max_extra_txn); |
| 1654 | + vExtraTxnForCompact.resize(m_opts.max_extra_txs); |
1658 | 1655 | vExtraTxnForCompact[vExtraTxnForCompactIt] = std::make_pair(tx->GetWitnessHash(), tx);
|
1659 |
| - vExtraTxnForCompactIt = (vExtraTxnForCompactIt + 1) % max_extra_txn; |
| 1656 | + vExtraTxnForCompactIt = (vExtraTxnForCompactIt + 1) % m_opts.max_extra_txs; |
1660 | 1657 | }
|
1661 | 1658 |
|
1662 | 1659 | void PeerManagerImpl::Misbehaving(Peer& peer, int howmuch, const std::string& message)
|
@@ -1809,25 +1806,25 @@ std::optional<std::string> PeerManagerImpl::FetchBlock(NodeId peer_id, const CBl
|
1809 | 1806 |
|
1810 | 1807 | std::unique_ptr<PeerManager> PeerManager::make(CConnman& connman, AddrMan& addrman,
|
1811 | 1808 | BanMan* banman, ChainstateManager& chainman,
|
1812 |
| - CTxMemPool& pool, bool ignore_incoming_txs) |
| 1809 | + CTxMemPool& pool, Options opts) |
1813 | 1810 | {
|
1814 |
| - return std::make_unique<PeerManagerImpl>(connman, addrman, banman, chainman, pool, ignore_incoming_txs); |
| 1811 | + return std::make_unique<PeerManagerImpl>(connman, addrman, banman, chainman, pool, opts); |
1815 | 1812 | }
|
1816 | 1813 |
|
1817 | 1814 | PeerManagerImpl::PeerManagerImpl(CConnman& connman, AddrMan& addrman,
|
1818 | 1815 | BanMan* banman, ChainstateManager& chainman,
|
1819 |
| - CTxMemPool& pool, bool ignore_incoming_txs) |
| 1816 | + CTxMemPool& pool, Options opts) |
1820 | 1817 | : m_chainparams(chainman.GetParams()),
|
1821 | 1818 | m_connman(connman),
|
1822 | 1819 | m_addrman(addrman),
|
1823 | 1820 | m_banman(banman),
|
1824 | 1821 | m_chainman(chainman),
|
1825 | 1822 | m_mempool(pool),
|
1826 |
| - m_ignore_incoming_txs(ignore_incoming_txs) |
| 1823 | + m_opts{opts} |
1827 | 1824 | {
|
1828 | 1825 | // While Erlay support is incomplete, it must be enabled explicitly via -txreconciliation.
|
1829 | 1826 | // This argument can go away after Erlay support is complete.
|
1830 |
| - if (gArgs.GetBoolArg("-txreconciliation", DEFAULT_TXRECONCILIATION_ENABLE)) { |
| 1827 | + if (opts.reconcile_txs) { |
1831 | 1828 | m_txreconciliation = std::make_unique<TxReconciliationTracker>(TXRECONCILIATION_VERSION);
|
1832 | 1829 | }
|
1833 | 1830 | }
|
@@ -2729,7 +2726,7 @@ void PeerManagerImpl::HeadersDirectFetchBlocks(CNode& pfrom, const Peer& peer, c
|
2729 | 2726 | last_header.nHeight);
|
2730 | 2727 | }
|
2731 | 2728 | if (vGetData.size() > 0) {
|
2732 |
| - if (!m_ignore_incoming_txs && |
| 2729 | + if (!m_opts.ignore_incoming_txs && |
2733 | 2730 | nodestate->m_provides_cmpctblocks &&
|
2734 | 2731 | vGetData.size() == 1 &&
|
2735 | 2732 | mapBlocksInFlight.size() == 1 &&
|
@@ -3434,7 +3431,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
3434 | 3431 | // - we are not in -blocksonly mode.
|
3435 | 3432 | const auto* tx_relay = peer->GetTxRelay();
|
3436 | 3433 | if (tx_relay && WITH_LOCK(tx_relay->m_bloom_filter_mutex, return tx_relay->m_relay_txs) &&
|
3437 |
| - !pfrom.IsAddrFetchConn() && !m_ignore_incoming_txs) { |
| 3434 | + !pfrom.IsAddrFetchConn() && !m_opts.ignore_incoming_txs) { |
3438 | 3435 | const uint64_t recon_salt = m_txreconciliation->PreRegisterPeer(pfrom.GetId());
|
3439 | 3436 | m_connman.PushMessage(&pfrom, msg_maker.Make(NetMsgType::SENDTXRCNCL,
|
3440 | 3437 | TXRECONCILIATION_VERSION, recon_salt));
|
@@ -4239,8 +4236,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
4239 | 4236 | m_txrequest.ForgetTxHash(tx.GetWitnessHash());
|
4240 | 4237 |
|
4241 | 4238 | // DoS prevention: do not allow m_orphanage to grow unbounded (see CVE-2012-3789)
|
4242 |
| - unsigned int nMaxOrphanTx = (unsigned int)std::max((int64_t)0, gArgs.GetIntArg("-maxorphantx", DEFAULT_MAX_ORPHAN_TRANSACTIONS)); |
4243 |
| - m_orphanage.LimitOrphans(nMaxOrphanTx); |
| 4239 | + m_orphanage.LimitOrphans(m_opts.max_orphan_txs); |
4244 | 4240 | } else {
|
4245 | 4241 | LogPrint(BCLog::MEMPOOL, "not keeping orphan with rejected parents %s\n",tx.GetHash().ToString());
|
4246 | 4242 | // We will continue to reject this tx since it has rejected
|
@@ -5008,7 +5004,7 @@ bool PeerManagerImpl::ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt
|
5008 | 5004 | msg.m_recv.data()
|
5009 | 5005 | );
|
5010 | 5006 |
|
5011 |
| - if (gArgs.GetBoolArg("-capturemessages", false)) { |
| 5007 | + if (m_opts.capture_messages) { |
5012 | 5008 | CaptureMessage(pfrom->addr, msg.m_type, MakeUCharSpan(msg.m_recv), /*is_incoming=*/true);
|
5013 | 5009 | }
|
5014 | 5010 |
|
@@ -5358,7 +5354,7 @@ void PeerManagerImpl::MaybeSendSendHeaders(CNode& node, Peer& peer)
|
5358 | 5354 |
|
5359 | 5355 | void PeerManagerImpl::MaybeSendFeefilter(CNode& pto, Peer& peer, std::chrono::microseconds current_time)
|
5360 | 5356 | {
|
5361 |
| - if (m_ignore_incoming_txs) return; |
| 5357 | + if (m_opts.ignore_incoming_txs) return; |
5362 | 5358 | if (pto.GetCommonVersion() < FEEFILTER_VERSION) return;
|
5363 | 5359 | // peers with the forcerelay permission should not filter txs to us
|
5364 | 5360 | if (pto.HasPermission(NetPermissionFlags::ForceRelay)) return;
|
@@ -5426,7 +5422,7 @@ bool PeerManagerImpl::RejectIncomingTxs(const CNode& peer) const
|
5426 | 5422 | if (peer.IsBlockOnlyConn()) return true;
|
5427 | 5423 | if (peer.IsFeelerConn()) return true;
|
5428 | 5424 | // In -blocksonly mode, peers need the 'relay' permission to send txs to us
|
5429 |
| - if (m_ignore_incoming_txs && !peer.HasPermission(NetPermissionFlags::Relay)) return true; |
| 5425 | + if (m_opts.ignore_incoming_txs && !peer.HasPermission(NetPermissionFlags::Relay)) return true; |
5430 | 5426 | return false;
|
5431 | 5427 | }
|
5432 | 5428 |
|
|
0 commit comments