Skip to content

Commit

Permalink
net: move Relay{Inv, InvFiltered, Transaction} out of CConnman
Browse files Browse the repository at this point in the history
  • Loading branch information
kwvg committed Apr 23, 2024
1 parent d54ba44 commit 0323c6c
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/coinjoin/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ void CCoinJoinServer::CommitFinalTransaction()
LogPrint(BCLog::COINJOIN, "CCoinJoinServer::CommitFinalTransaction -- TRANSMITTING DSTX\n");

CInv inv(MSG_DSTX, hashTx);
connman.RelayInv(inv);
RelayInv(connman, inv);

// Tell the clients it was successful
RelayCompletedTransaction(MSG_SUCCESS);
Expand Down Expand Up @@ -459,7 +459,7 @@ void CCoinJoinServer::ConsumeCollateral(const CTransactionRef& txref) const
if (!ATMPIfSaneFee(m_chainstate, mempool, txref, false /* bypass_limits */)) {
LogPrint(BCLog::COINJOIN, "%s -- AcceptToMemoryPool failed\n", __func__);
} else {
connman.RelayTransaction(*txref, static_cast<bool>(m_dstxman.GetDSTX(txref->GetHash())));
RelayTransaction(connman, *txref, static_cast<bool>(m_dstxman.GetDSTX(txref->GetHash())));
LogPrint(BCLog::COINJOIN, "%s -- Collateral was consumed\n", __func__);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/governance/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ void CGovernanceObject::Relay(CConnman& connman, const CMasternodeSync& mn_sync)
}

CInv inv(MSG_GOVERNANCE_OBJECT, GetHash());
connman.RelayInv(inv, minProtoVersion);
RelayInv(connman, inv, minProtoVersion);
}

void CGovernanceObject::UpdateSentinelVariables(const CDeterministicMNList& tip_mn_list)
Expand Down
2 changes: 1 addition & 1 deletion src/governance/vote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void CGovernanceVote::Relay(CConnman& connman, const CMasternodeSync& mn_sync, c
}

CInv inv(MSG_GOVERNANCE_OBJECT_VOTE, GetHash());
connman.RelayInv(inv);
RelayInv(connman, inv);
}

void CGovernanceVote::UpdateHash() const
Expand Down
2 changes: 1 addition & 1 deletion src/llmq/blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ void CQuorumBlockProcessor::AddMineableCommitment(const CFinalCommitment& fqc)
// We only relay the new commitment if it's new or better then the old one
if (relay) {
CInv inv(MSG_QUORUM_FINAL_COMMITMENT, commitmentHash);
connman.RelayInv(inv);
RelayInv(connman, inv);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/llmq/chainlocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ PeerMsgRet CChainLocksHandler::ProcessNewChainLock(const NodeId from, const llmq

// Note: do not hold cs while calling RelayInv
AssertLockNotHeld(cs);
connman.RelayInv(clsigInv);
RelayInv(connman, clsigInv);

if (pindex == nullptr) {
// we don't know the block/header for this CLSIG yet, so bail out for now
Expand Down
2 changes: 1 addition & 1 deletion src/llmq/ehf_signals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void CEHFSignalsHandler::HandleNewRecoveredSig(const CRecoveredSig& recoveredSig
LOCK(cs_main);
const MempoolAcceptResult result = AcceptToMemoryPool(chainstate, mempool, tx_to_sent, /* bypass_limits */ false);
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
connman.RelayTransaction(*tx_to_sent, /*is_dstx=*/ false);
RelayTransaction(connman, *tx_to_sent, /*is_dstx=*/ false);
} else {
LogPrintf("CEHFSignalsHandler::HandleNewRecoveredSig -- AcceptToMemoryPool failed: %s\n", result.m_state.ToString());
}
Expand Down
4 changes: 2 additions & 2 deletions src/llmq/instantsend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,11 +1051,11 @@ void CInstantSendManager::ProcessInstantSendLock(NodeId from, const uint256& has

CInv inv(MSG_ISDLOCK, hash);
if (tx != nullptr) {
connman.RelayInvFiltered(inv, *tx, ISDLOCK_PROTO_VERSION);
RelayInvFiltered(connman, inv, *tx, ISDLOCK_PROTO_VERSION);
} else {
// we don't have the TX yet, so we only filter based on txid. Later when that TX arrives, we will re-announce
// with the TX taken into account.
connman.RelayInvFiltered(inv, islock->txid, ISDLOCK_PROTO_VERSION);
RelayInvFiltered(connman, inv, islock->txid, ISDLOCK_PROTO_VERSION);
}

ResolveBlockConflicts(hash, *islock);
Expand Down
26 changes: 13 additions & 13 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3926,24 +3926,17 @@ bool CConnman::DisconnectNode(NodeId id)
return false;
}

void CConnman::RelayTransaction(const CTransaction& tx, const bool is_dstx)
{
uint256 hash = tx.GetHash();
CInv inv(is_dstx ? MSG_DSTX : MSG_TX, hash);
RelayInv(inv);
}

void CConnman::RelayInv(CInv &inv, const int minProtoVersion) {
ForEachNode([&](CNode* pnode) {
void RelayInv(CConnman& connman, CInv &inv, const int minProtoVersion) {
connman.ForEachNode([&](CNode* pnode) {
if (pnode->nVersion < minProtoVersion || !pnode->CanRelay())
return;
pnode->PushInventory(inv);
});
}

void CConnman::RelayInvFiltered(CInv &inv, const CTransaction& relatedTx, const int minProtoVersion)
void RelayInvFiltered(CConnman& connman, CInv &inv, const CTransaction& relatedTx, const int minProtoVersion)
{
ForEachNode([&](CNode* pnode) {
connman.ForEachNode([&](CNode* pnode) {
if (pnode->nVersion < minProtoVersion || !pnode->CanRelay() || pnode->IsBlockOnlyConn()) {
return;
}
Expand All @@ -3960,9 +3953,9 @@ void CConnman::RelayInvFiltered(CInv &inv, const CTransaction& relatedTx, const
});
}

void CConnman::RelayInvFiltered(CInv &inv, const uint256& relatedTxHash, const int minProtoVersion)
void RelayInvFiltered(CConnman& connman, CInv &inv, const uint256& relatedTxHash, const int minProtoVersion)
{
ForEachNode([&](CNode* pnode) {
connman.ForEachNode([&](CNode* pnode) {
if (pnode->nVersion < minProtoVersion || !pnode->CanRelay() || pnode->IsBlockOnlyConn()) {
return;
}
Expand All @@ -3979,6 +3972,13 @@ void CConnman::RelayInvFiltered(CInv &inv, const uint256& relatedTxHash, const i
});
}

void RelayTransaction(CConnman& connman, const CTransaction& tx, const bool is_dstx)
{
uint256 hash = tx.GetHash();
CInv inv(is_dstx ? MSG_DSTX : MSG_TX, hash);
RelayInv(connman, inv);
}

void CConnman::RecordBytesRecv(uint64_t bytes)
{
LOCK(cs_totalBytesRecv);
Expand Down
17 changes: 11 additions & 6 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -1116,12 +1116,6 @@ friend class CNode;
std::vector<CNode*> CopyNodeVector(std::function<bool(const CNode* pnode)> cond = AllNodes);
void ReleaseNodeVector(const std::vector<CNode*>& vecNodes);

void RelayTransaction(const CTransaction& tx, const bool is_dstx);
void RelayInv(CInv &inv, const int minProtoVersion = MIN_PEER_PROTO_VERSION);
void RelayInvFiltered(CInv &inv, const CTransaction &relatedTx, const int minProtoVersion = MIN_PEER_PROTO_VERSION);
// This overload will not update node filters, so use it only for the cases when other messages will update related transaction data in filters
void RelayInvFiltered(CInv &inv, const uint256 &relatedTxHash, const int minProtoVersion = MIN_PEER_PROTO_VERSION);

// Addrman functions
/**
* Return all or many randomly selected addresses, optionally by network.
Expand Down Expand Up @@ -1530,6 +1524,17 @@ friend class CNode;
friend struct ConnmanTestMsg;
};

void RelayInv(CConnman& connman, CInv &inv, const int minProtoVersion = MIN_PEER_PROTO_VERSION);
void RelayInvFiltered(CConnman& connman, CInv &inv, const CTransaction &relatedTx,
const int minProtoVersion = MIN_PEER_PROTO_VERSION);
/**
* This overload will not update node filters, so use it only for the cases
* when other messages will update related transaction data in filters
*/
void RelayInvFiltered(CConnman& connman, CInv &inv, const uint256 &relatedTxHash,
const int minProtoVersion = MIN_PEER_PROTO_VERSION);
void RelayTransaction(CConnman& connman, const CTransaction& tx, const bool is_dstx);

/** Return a timestamp in the future (in microseconds) for exponentially distributed events. */
std::chrono::microseconds PoissonNextSend(std::chrono::microseconds now, std::chrono::seconds average_interval);

Expand Down
2 changes: 1 addition & 1 deletion src/spork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,5 +454,5 @@ std::optional<CKeyID> CSporkMessage::GetSignerKeyID() const
void CSporkMessage::Relay(CConnman& connman) const
{
CInv inv(MSG_SPORK, GetHash());
connman.RelayInv(inv);
RelayInv(connman, inv);
}

0 comments on commit 0323c6c

Please sign in to comment.