Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/coinjoin/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ bool CCoinJoinClientSession::SignFinalTransaction(const CTxMemPool& mempool, con

// push all of our signatures to the Masternode
WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::%s -- pushing signed inputs to the masternode, finalMutableTransaction=%s", __func__, finalMutableTransaction.ToString()); /* Continued */
CNetMsgMaker msgMaker(peer.GetSendVersion());
CNetMsgMaker msgMaker(peer.GetCommonVersion());
connman.PushMessage(&peer, msgMaker.Make(NetMsgType::DSSIGNFINALTX, signed_inputs));
SetState(POOL_STATE_SIGNING);
nTimeLastSuccessfulStep = GetTime();
Expand Down Expand Up @@ -1201,7 +1201,7 @@ bool CCoinJoinClientSession::ProcessPendingDsaRequest(CConnman& connman)
bool fDone = connman.ForNode(pendingDsaRequest.GetAddr(), [this, &connman](CNode* pnode) {
WalletCJLogPrint(m_wallet, "-- processing dsa queue for addr=%s\n", pnode->addr.ToString());
nTimeLastSuccessfulStep = GetTime();
CNetMsgMaker msgMaker(pnode->GetSendVersion());
CNetMsgMaker msgMaker(pnode->GetCommonVersion());
connman.PushMessage(pnode, msgMaker.Make(NetMsgType::DSACCEPT, pendingDsaRequest.GetDSA()));
return true;
});
Expand Down Expand Up @@ -1809,7 +1809,7 @@ void CCoinJoinClientSession::RelayIn(const CCoinJoinEntry& entry, CConnman& conn

connman.ForNode(mixingMasternode->pdmnState->addr, [&entry, &connman, this](CNode* pnode) {
WalletCJLogPrint(m_wallet, "CCoinJoinClientSession::RelayIn -- found master, relaying message to %s\n", pnode->addr.ToString());
CNetMsgMaker msgMaker(pnode->GetSendVersion());
CNetMsgMaker msgMaker(pnode->GetCommonVersion());
connman.PushMessage(pnode, msgMaker.Make(NetMsgType::DSVIN, entry));
return true;
});
Expand Down
2 changes: 1 addition & 1 deletion src/coinjoin/coinjoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bool CCoinJoinQueue::CheckSignature(const CBLSPublicKey& blsPubKey) const
bool CCoinJoinQueue::Relay(CConnman& connman)
{
connman.ForEachNode([&connman, this](CNode* pnode) {
CNetMsgMaker msgMaker(pnode->GetSendVersion());
CNetMsgMaker msgMaker(pnode->GetCommonVersion());
if (pnode->fSendDSQueue) {
connman.PushMessage(pnode, msgMaker.Make(NetMsgType::DSQUEUE, (*this)));
}
Expand Down
6 changes: 3 additions & 3 deletions src/coinjoin/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ void CCoinJoinServer::RelayFinalTransaction(const CTransaction& txFinal)
// final mixing tx with empty signatures should be relayed to mixing participants only
for (const auto& entry : vecEntries) {
bool fOk = connman.ForNode(entry.addr, [&txFinal, this](CNode* pnode) {
CNetMsgMaker msgMaker(pnode->GetSendVersion());
CNetMsgMaker msgMaker(pnode->GetCommonVersion());
connman.PushMessage(pnode, msgMaker.Make(NetMsgType::DSFINALTX, nSessionID.load(), txFinal));
return true;
});
Expand All @@ -809,7 +809,7 @@ void CCoinJoinServer::RelayFinalTransaction(const CTransaction& txFinal)
void CCoinJoinServer::PushStatus(CNode& peer, PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID) const
{
CCoinJoinStatusUpdate psssup(nSessionID, nState, 0, nStatusUpdate, nMessageID);
connman.PushMessage(&peer, CNetMsgMaker(peer.GetSendVersion()).Make(NetMsgType::DSSTATUSUPDATE, psssup));
connman.PushMessage(&peer, CNetMsgMaker(peer.GetCommonVersion()).Make(NetMsgType::DSSTATUSUPDATE, psssup));
}

void CCoinJoinServer::RelayStatus(PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID)
Expand Down Expand Up @@ -859,7 +859,7 @@ void CCoinJoinServer::RelayCompletedTransaction(PoolMessage nMessageID)
LOCK(cs_coinjoin);
for (const auto& entry : vecEntries) {
bool fOk = connman.ForNode(entry.addr, [&nMessageID, this](CNode* pnode) {
CNetMsgMaker msgMaker(pnode->GetSendVersion());
CNetMsgMaker msgMaker(pnode->GetCommonVersion());
connman.PushMessage(pnode, msgMaker.Make(NetMsgType::DSCOMPLETE, nSessionID.load(), nMessageID));
return true;
});
Expand Down
4 changes: 2 additions & 2 deletions src/evo/mnauth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void CMNAuth::PushMNAUTH(CNode& peer, CConnman& connman, const CBlockIndex* tip)

LogPrint(BCLog::NET_NETCONN, "CMNAuth::%s -- Sending MNAUTH, peer=%d\n", __func__, peer.GetId());

connman.PushMessage(&peer, CNetMsgMaker(peer.GetSendVersion()).Make(NetMsgType::MNAUTH, mnauth));
connman.PushMessage(&peer, CNetMsgMaker(peer.GetCommonVersion()).Make(NetMsgType::MNAUTH, mnauth));
}

PeerMsgRet CMNAuth::ProcessMessage(CNode& peer, CConnman& connman, std::string_view msg_type, CDataStream& vRecv)
Expand Down Expand Up @@ -180,7 +180,7 @@ PeerMsgRet CMNAuth::ProcessMessage(CNode& peer, CConnman& connman, std::string_v
// Otherwise, the peer would only announce/send messages resulting from QRECSIG,
// e.g. InstantSend locks or ChainLocks. SPV and regular full nodes should not send
// this message as they are usually only interested in the higher level messages.
const CNetMsgMaker msgMaker(peer.GetSendVersion());
const CNetMsgMaker msgMaker(peer.GetCommonVersion());
connman.PushMessage(&peer, msgMaker.Make(NetMsgType::QSENDRECSIGS, true));
peer.m_masternode_iqr_connection = true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/governance/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ void CGovernanceManager::SyncSingleObjVotes(CNode& peer, const uint256& nProp, c
++nVoteCount;
}

CNetMsgMaker msgMaker(peer.GetSendVersion());
CNetMsgMaker msgMaker(peer.GetCommonVersion());
connman.PushMessage(&peer, msgMaker.Make(NetMsgType::SYNCSTATUSCOUNT, MASTERNODE_SYNC_GOVOBJ_VOTE, nVoteCount));
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s -- sent %d votes to peer=%d\n", __func__, nVoteCount, peer.GetId());
}
Expand Down Expand Up @@ -948,7 +948,7 @@ PeerMsgRet CGovernanceManager::SyncObjects(CNode& peer, CConnman& connman) const
++nObjCount;
}

CNetMsgMaker msgMaker(peer.GetSendVersion());
CNetMsgMaker msgMaker(peer.GetCommonVersion());
connman.PushMessage(&peer, msgMaker.Make(NetMsgType::SYNCSTATUSCOUNT, MASTERNODE_SYNC_GOVOBJ, nObjCount));
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s -- sent %d objects to peer=%d\n", __func__, nObjCount, peer.GetId());
return {};
Expand Down Expand Up @@ -1173,7 +1173,7 @@ void CGovernanceManager::RequestGovernanceObject(CNode* pfrom, const uint256& nH

LogPrint(BCLog::GOBJECT, "CGovernanceManager::RequestGovernanceObject -- nHash %s peer=%d\n", nHash.ToString(), pfrom->GetId());

CNetMsgMaker msgMaker(pfrom->GetSendVersion());
CNetMsgMaker msgMaker(pfrom->GetCommonVersion());

CBloomFilter filter;

Expand Down
8 changes: 4 additions & 4 deletions src/llmq/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ bool CQuorumManager::RequestQuorumData(CNode* pfrom, Consensus::LLMQType llmqTyp
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- sending QGETDATA quorumHash[%s] llmqType[%d] proRegTx[%s]\n", __func__, key.quorumHash.ToString(),
ToUnderlying(key.llmqType), key.proRegTx.ToString());

CNetMsgMaker msgMaker(pfrom->GetSendVersion());
CNetMsgMaker msgMaker(pfrom->GetCommonVersion());
connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::QGETDATA, request));

return true;
Expand Down Expand Up @@ -682,8 +682,8 @@ PeerMsgRet CQuorumManager::ProcessMessage(CNode& pfrom, const std::string& msg_t
break;
}
request.SetError(nError);
CDataStream ssResponse(SER_NETWORK, pfrom.GetSendVersion(), request, body);
connman.PushMessage(&pfrom, CNetMsgMaker(pfrom.GetSendVersion()).Make(NetMsgType::QDATA, ssResponse));
CDataStream ssResponse(SER_NETWORK, pfrom.GetCommonVersion(), request, body);
connman.PushMessage(&pfrom, CNetMsgMaker(pfrom.GetCommonVersion()).Make(NetMsgType::QDATA, ssResponse));
return ret;
};

Expand Down Expand Up @@ -715,7 +715,7 @@ PeerMsgRet CQuorumManager::ProcessMessage(CNode& pfrom, const std::string& msg_t
return sendQDATA(CQuorumDataRequest::Errors::QUORUM_NOT_FOUND, request_limit_exceeded);
}

CDataStream ssResponseData(SER_NETWORK, pfrom.GetSendVersion());
CDataStream ssResponseData(SER_NETWORK, pfrom.GetCommonVersion());

// Check if request wants QUORUM_VERIFICATION_VECTOR data
if (request.GetDataMask() & CQuorumDataRequest::QUORUM_VERIFICATION_VECTOR) {
Expand Down
2 changes: 1 addition & 1 deletion src/llmq/signing_shares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ bool CSigSharesManager::SendMessages()
bool didSend = false;

for (auto& pnode : vNodesCopy) {
CNetMsgMaker msgMaker(pnode->GetSendVersion());
CNetMsgMaker msgMaker(pnode->GetCommonVersion());

if (const auto it1 = sigSessionAnnouncements.find(pnode->GetId()); it1 != sigSessionAnnouncements.end()) {
std::vector<CSigSesAnn> msgs;
Expand Down
4 changes: 2 additions & 2 deletions src/masternode/sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void CMasternodeSync::ProcessTick()

for (auto& pnode : vNodesCopy)
{
CNetMsgMaker msgMaker(pnode->GetSendVersion());
CNetMsgMaker msgMaker(pnode->GetCommonVersion());

// Don't try to sync any data from outbound non-relay "masternode" connections.
// Inbound connection this early is most likely a "masternode" connection
Expand Down Expand Up @@ -301,7 +301,7 @@ void CMasternodeSync::ProcessTick()

void CMasternodeSync::SendGovernanceSyncRequest(CNode* pnode) const
{
CNetMsgMaker msgMaker(pnode->GetSendVersion());
CNetMsgMaker msgMaker(pnode->GetCommonVersion());

CBloomFilter filter;

Expand Down
48 changes: 19 additions & 29 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,32 +753,6 @@ bool CNode::ReceiveMsgBytes(Span<const uint8_t> msg_bytes, bool& complete)
return true;
}

void CNode::SetSendVersion(int nVersionIn)
{
// Send version may only be changed in the version message, and
// only one version message is allowed per session. We can therefore
// treat this value as const and even atomic as long as it's only used
// once a version message has been successfully processed. Any attempt to
// set this twice is an error.
if (nSendVersion != 0) {
error("Send version already set for node: %i. Refusing to change from %i to %i", id, nSendVersion, nVersionIn);
} else {
nSendVersion = nVersionIn;
}
}

int CNode::GetSendVersion() const
{
// The send version should always be explicitly set to
// INIT_PROTO_VERSION rather than using this value until SetSendVersion
// has been called.
if (nSendVersion == 0) {
error("Requesting unset send version for node: %i. Using %i", id, INIT_PROTO_VERSION);
return INIT_PROTO_VERSION;
}
return nSendVersion;
}

int V1TransportDeserializer::readHeader(Span<const uint8_t> msg_bytes)
{
// copy data to temporary parsing buffer
Expand Down Expand Up @@ -2364,18 +2338,23 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)

ConnectionType conn_type = ConnectionType::OUTBOUND_FULL_RELAY;
int64_t nTime = GetTimeMicros();
bool anchor = false;
bool fFeeler = false;

// Determine what type of connection to open. Opening
// OUTBOUND_FULL_RELAY connections gets the highest priority until we
// BLOCK_RELAY connections to addresses from anchors.dat gets the highest
// priority. Then we open OUTBOUND_FULL_RELAY priority until we
// meet our full-relay capacity. Then we open BLOCK_RELAY connection
// until we hit our block-relay-only peer limit.
// GetTryNewOutboundPeer() gets set when a stale tip is detected, so we
// try opening an additional OUTBOUND_FULL_RELAY connection. If none of
// these conditions are met, check the nNextFeeler timer to decide if
// we should open a FEELER.

if (nOutboundFullRelay < m_max_outbound_full_relay) {
if (!m_anchors.empty() && (nOutboundBlockRelay < m_max_outbound_block_relay)) {
conn_type = ConnectionType::BLOCK_RELAY;
anchor = true;
} else if (nOutboundFullRelay < m_max_outbound_full_relay) {
// OUTBOUND_FULL_RELAY
} else if (nOutboundBlockRelay < m_max_outbound_block_relay) {
conn_type = ConnectionType::BLOCK_RELAY;
Expand All @@ -2398,6 +2377,17 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
int nTries = 0;
while (!interruptNet)
{
if (anchor && !m_anchors.empty()) {
const CAddress addr = m_anchors.back();
m_anchors.pop_back();
if (!addr.IsValid() || IsLocal(addr) || !IsReachable(addr) ||
!HasAllDesirableServiceFlags(addr.nServices) ||
setConnected.count(addr.GetGroup(addrman.m_asmap))) continue;
addrConnect = addr;
LogPrint(BCLog::NET, "Trying to make an anchor connection to %s\n", addrConnect.ToString());
break;
}

// If we didn't find an appropriate destination after trying 100 addresses fetched from addrman,
// stop this loop, and let the outer loop run again (which sleeps, adds seed nodes, recalculates
// already-connected network ranges, ...) before trying new addrman addresses.
Expand Down Expand Up @@ -3601,7 +3591,7 @@ void CConnman::SetMasternodeQuorumRelayMembers(Consensus::LLMQType llmqType, con
// Otherwise the peer would only announce/send messages resulting from QRECSIG,
// e.g. InstantSend locks or ChainLocks. SPV and regular full nodes should not send
// this message as they are usually only interested in the higher level messages.
const CNetMsgMaker msgMaker(pnode->GetSendVersion());
const CNetMsgMaker msgMaker(pnode->GetCommonVersion());
PushMessage(pnode, msgMaker.Make(NetMsgType::QSENDRECSIGS, true));
pnode->m_masternode_iqr_connection = true;
}
Expand Down
31 changes: 12 additions & 19 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ struct CSerializedNetMsg

/** Different types of connections to a peer. This enum encapsulates the
* information we have available at the time of opening or accepting the
* connection. Aside from INBOUND, all types are initiated by us. */
* connection. Aside from INBOUND, all types are initiated by us.
*
* If adding or removing types, please update CONNECTION_TYPE_DOC in
* src/rpc/net.cpp. */
enum class ConnectionType {
/**
* Inbound connections are those initiated by a peer. This is the only
Expand Down Expand Up @@ -182,7 +185,9 @@ enum class ConnectionType {
* attacks. By not relaying transactions or addresses, these connections
* are harder to detect by a third party, thus helping obfuscate the
* network topology. We automatically attempt to open
* MAX_BLOCK_RELAY_ONLY_CONNECTIONS using addresses from our AddrMan.
* MAX_BLOCK_RELAY_ONLY_ANCHORS using addresses from our anchors.dat. Then
* addresses from our AddrMan if MAX_BLOCK_RELAY_ONLY_CONNECTIONS
* isn't reached yet.
*/
BLOCK_RELAY,

Expand All @@ -195,15 +200,6 @@ enum class ConnectionType {
ADDR_FETCH,
};

const std::vector<std::string> CONNECTION_TYPE_DOC{
"outbound-full-relay (default automatic connections)",
"block-relay-only (does not relay transactions or addresses)",
"inbound (initiated by the peer)",
"manual (added via addnode RPC or -addnode/-connect configuration options)",
"addr-fetch (short-lived automatic connection for soliciting addresses)",
"feeler (short-lived automatic connection for testing addresses)"};


class NetEventsInterface;
class CConnman
{
Expand Down Expand Up @@ -1129,7 +1125,6 @@ class CNode
RecursiveMutex cs_sendProcessing;

uint64_t nRecvBytes GUARDED_BY(cs_vRecv){0};
std::atomic<int> nRecvVersion{INIT_PROTO_VERSION};

std::atomic<int64_t> nLastSend{0};
std::atomic<int64_t> nLastRecv{0};
Expand Down Expand Up @@ -1358,6 +1353,7 @@ class CNode
const NodeId id;
const uint64_t nLocalHostNonce;
const ConnectionType m_conn_type;
std::atomic<int> m_greatest_common_version{INIT_PROTO_VERSION};

//! Services offered to this peer.
//!
Expand All @@ -1376,7 +1372,6 @@ class CNode
//! service advertisements.
const ServiceFlags nLocalServices;

int nSendVersion {0};
std::list<CNetMessage> vRecvMsg; // Used only by SocketHandler thread

mutable RecursiveMutex cs_addrName;
Expand Down Expand Up @@ -1423,16 +1418,14 @@ class CNode
*/
bool ReceiveMsgBytes(Span<const uint8_t> msg_bytes, bool& complete);

void SetRecvVersion(int nVersionIn)
void SetCommonVersion(int greatest_common_version)
{
nRecvVersion = nVersionIn;
m_greatest_common_version = greatest_common_version;
}
int GetRecvVersion() const
int GetCommonVersion() const
{
return nRecvVersion;
return m_greatest_common_version;
}
void SetSendVersion(int nVersionIn);
int GetSendVersion() const;

CService GetAddrLocal() const;
//! May not be called more than once
Expand Down
Loading