mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-06 13:47:56 +02:00
net_processing: store transactions for private broadcast in PeerManager
Extend `PeerManager` with a transaction storage and a new method `InitiateTxBroadcastPrivate()` which: * adds a transaction to that storage and * calls `CConnman::PrivateBroadcast::NumToOpenAdd()` to open dedicated privacy connections that will pick an entry from the transaction storage and broadcast it.
This commit is contained in:
@@ -44,6 +44,7 @@
|
||||
#include <policy/policy.h>
|
||||
#include <primitives/block.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <private_broadcast.h>
|
||||
#include <protocol.h>
|
||||
#include <random.h>
|
||||
#include <scheduler.h>
|
||||
@@ -196,6 +197,8 @@ static constexpr double MAX_ADDR_RATE_PER_SECOND{0.1};
|
||||
static constexpr size_t MAX_ADDR_PROCESSING_TOKEN_BUCKET{MAX_ADDR_TO_SEND};
|
||||
/** The compactblocks version we support. See BIP 152. */
|
||||
static constexpr uint64_t CMPCTBLOCKS_VERSION{2};
|
||||
/** For private broadcast, send a transaction to this many peers. */
|
||||
static constexpr size_t NUM_PRIVATE_BROADCAST_PER_TX{3};
|
||||
|
||||
// Internal stuff
|
||||
namespace {
|
||||
@@ -538,6 +541,7 @@ public:
|
||||
PeerManagerInfo GetInfo() const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
||||
void SendPings() override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
||||
void InitiateTxBroadcastToAll(const Txid& txid, const Wtxid& wtxid) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
||||
void InitiateTxBroadcastPrivate(const CTransactionRef& tx) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
||||
void SetBestBlock(int height, std::chrono::seconds time) override
|
||||
{
|
||||
m_best_height = height;
|
||||
@@ -1070,6 +1074,9 @@ private:
|
||||
void PushAddress(Peer& peer, const CAddress& addr) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex);
|
||||
|
||||
void LogBlockHeader(const CBlockIndex& index, const CNode& peer, bool via_compact_block);
|
||||
|
||||
/// The transactions to be broadcast privately.
|
||||
PrivateBroadcast m_tx_for_private_broadcast;
|
||||
};
|
||||
|
||||
const CNodeState* PeerManagerImpl::State(NodeId pnode) const
|
||||
@@ -2147,6 +2154,17 @@ void PeerManagerImpl::InitiateTxBroadcastToAll(const Txid& txid, const Wtxid& wt
|
||||
}
|
||||
}
|
||||
|
||||
void PeerManagerImpl::InitiateTxBroadcastPrivate(const CTransactionRef& tx)
|
||||
{
|
||||
const auto txstr{strprintf("txid=%s, wtxid=%s", tx->GetHash().ToString(), tx->GetWitnessHash().ToString())};
|
||||
if (m_tx_for_private_broadcast.Add(tx)) {
|
||||
LogDebug(BCLog::PRIVBROADCAST, "Requesting %d new connections due to %s", NUM_PRIVATE_BROADCAST_PER_TX, txstr);
|
||||
m_connman.m_private_broadcast.NumToOpenAdd(NUM_PRIVATE_BROADCAST_PER_TX);
|
||||
} else {
|
||||
LogDebug(BCLog::PRIVBROADCAST, "Ignoring unnecessary request to schedule an already scheduled transaction: %s", txstr);
|
||||
}
|
||||
}
|
||||
|
||||
void PeerManagerImpl::RelayAddress(NodeId originator,
|
||||
const CAddress& addr,
|
||||
bool fReachable)
|
||||
|
||||
Reference in New Issue
Block a user