refactor: change Process* functions from accepting a ptr to a reference (#5062)

also drops an almost always unneeded string
converts some std::strings to std::string_view
also drops an unneeded param
This commit is contained in:
PastaPastaPasta 2022-10-28 14:50:54 -05:00 committed by GitHub
parent e04b31cb9a
commit aaa5c7967d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 189 additions and 194 deletions

View File

@ -32,7 +32,7 @@ std::map<const std::string, std::shared_ptr<CCoinJoinClientManager>> coinJoinCli
std::unique_ptr<CCoinJoinClientQueueManager> coinJoinClientQueueManager;
void CCoinJoinClientQueueManager::ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv, bool enable_bip61)
void CCoinJoinClientQueueManager::ProcessMessage(const CNode& peer, std::string_view msg_type, CDataStream& vRecv)
{
if (fMasternodeMode) return;
if (!CCoinJoinClientOptions::IsEnabled()) return;
@ -44,11 +44,11 @@ void CCoinJoinClientQueueManager::ProcessMessage(CNode* pfrom, const std::string
}
if (msg_type == NetMsgType::DSQUEUE) {
CCoinJoinClientQueueManager::ProcessDSQueue(pfrom, msg_type, vRecv, enable_bip61);
CCoinJoinClientQueueManager::ProcessDSQueue(peer, vRecv);
}
}
void CCoinJoinClientQueueManager::ProcessDSQueue(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, bool enable_bip61)
void CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, CDataStream& vRecv)
{
CCoinJoinQueue dsq;
vRecv >> dsq;
@ -64,7 +64,7 @@ void CCoinJoinClientQueueManager::ProcessDSQueue(CNode* pfrom, const std::string
}
if (q.fReady == dsq.fReady && q.masternodeOutpoint == dsq.masternodeOutpoint) {
// no way the same mn can send another dsq with the same readiness this soon
LogPrint(BCLog::COINJOIN, "DSQUEUE -- Peer %s is sending WAY too many dsq messages for a masternode with collateral %s\n", pfrom->GetLogString(), dsq.masternodeOutpoint.ToStringShort());
LogPrint(BCLog::COINJOIN, "DSQUEUE -- Peer %s is sending WAY too many dsq messages for a masternode with collateral %s\n", peer.GetLogString(), dsq.masternodeOutpoint.ToStringShort());
return;
}
}
@ -80,7 +80,7 @@ void CCoinJoinClientQueueManager::ProcessDSQueue(CNode* pfrom, const std::string
if (!dsq.CheckSignature(dmn->pdmnState->pubKeyOperator.Get())) {
LOCK(cs_main);
Misbehaving(pfrom->GetId(), 10);
Misbehaving(peer.GetId(), 10);
return;
}
@ -113,7 +113,7 @@ void CCoinJoinClientQueueManager::ProcessDSQueue(CNode* pfrom, const std::string
}
}
void CCoinJoinClientManager::ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv, CConnman& connman, bool enable_bip61)
void CCoinJoinClientManager::ProcessMessage(CNode& peer, std::string_view msg_type, CDataStream& vRecv, CConnman& connman, bool enable_bip61)
{
if (fMasternodeMode) return;
if (!CCoinJoinClientOptions::IsEnabled()) return;
@ -132,12 +132,12 @@ void CCoinJoinClientManager::ProcessMessage(CNode* pfrom, const std::string& msg
AssertLockNotHeld(cs_deqsessions);
LOCK(cs_deqsessions);
for (auto& session : deqSessions) {
session.ProcessMessage(pfrom, msg_type, vRecv, connman, enable_bip61);
session.ProcessMessage(peer, msg_type, vRecv, connman, enable_bip61);
}
}
}
void CCoinJoinClientSession::ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv, CConnman& connman, bool enable_bip61)
void CCoinJoinClientSession::ProcessMessage(CNode& peer, std::string_view msg_type, CDataStream& vRecv, CConnman& connman, bool enable_bip61)
{
if (fMasternodeMode) return;
if (!CCoinJoinClientOptions::IsEnabled()) return;
@ -145,7 +145,7 @@ void CCoinJoinClientSession::ProcessMessage(CNode* pfrom, const std::string& msg
if (msg_type == NetMsgType::DSSTATUSUPDATE) {
if (!mixingMasternode) return;
if (mixingMasternode->pdmnState->addr != pfrom->addr) {
if (mixingMasternode->pdmnState->addr != peer.addr) {
return;
}
@ -156,7 +156,7 @@ void CCoinJoinClientSession::ProcessMessage(CNode* pfrom, const std::string& msg
} else if (msg_type == NetMsgType::DSFINALTX) {
if (!mixingMasternode) return;
if (mixingMasternode->pdmnState->addr != pfrom->addr) {
if (mixingMasternode->pdmnState->addr != peer.addr) {
return;
}
@ -172,12 +172,12 @@ void CCoinJoinClientSession::ProcessMessage(CNode* pfrom, const std::string& msg
LogPrint(BCLog::COINJOIN, "DSFINALTX -- txNew %s", txNew.ToString()); /* Continued */
// check to see if input is spent already? (and probably not confirmed)
SignFinalTransaction(txNew, pfrom, connman);
SignFinalTransaction(txNew, peer, connman);
} else if (msg_type == NetMsgType::DSCOMPLETE) {
if (!mixingMasternode) return;
if (mixingMasternode->pdmnState->addr != pfrom->addr) {
LogPrint(BCLog::COINJOIN, "DSCOMPLETE -- message doesn't match current Masternode: infoMixingMasternode=%s addr=%s\n", mixingMasternode->pdmnState->addr.ToString(), pfrom->addr.ToString());
if (mixingMasternode->pdmnState->addr != peer.addr) {
LogPrint(BCLog::COINJOIN, "DSCOMPLETE -- message doesn't match current Masternode: infoMixingMasternode=%s addr=%s\n", mixingMasternode->pdmnState->addr.ToString(), peer.addr.ToString());
return;
}
@ -518,11 +518,11 @@ void CCoinJoinClientSession::ProcessPoolStateUpdate(CCoinJoinStatusUpdate psssup
// check it to make sure it's what we want, then sign it if we agree.
// If we refuse to sign, it's possible we'll be charged collateral
//
bool CCoinJoinClientSession::SignFinalTransaction(const CTransaction& finalTransactionNew, CNode* pnode, CConnman& connman)
bool CCoinJoinClientSession::SignFinalTransaction(const CTransaction& finalTransactionNew, CNode& peer, CConnman& connman)
{
if (!CCoinJoinClientOptions::IsEnabled()) return false;
if (fMasternodeMode || pnode == nullptr) return false;
if (fMasternodeMode) return false;
if (!mixingMasternode) return false;
LOCK(mixingWallet.cs_wallet);
@ -624,8 +624,8 @@ bool CCoinJoinClientSession::SignFinalTransaction(const CTransaction& finalTrans
// push all of our signatures to the Masternode
LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::%s -- pushing sigs to the masternode, finalMutableTransaction=%s", __func__, finalMutableTransaction.ToString()); /* Continued */
CNetMsgMaker msgMaker(pnode->GetSendVersion());
connman.PushMessage(pnode, msgMaker.Make(NetMsgType::DSSIGNFINALTX, sigs));
CNetMsgMaker msgMaker(peer.GetSendVersion());
connman.PushMessage(&peer, msgMaker.Make(NetMsgType::DSSIGNFINALTX, sigs));
SetState(POOL_STATE_SIGNING);
nTimeLastSuccessfulStep = GetTime();

View File

@ -111,7 +111,7 @@ private:
void CompletedTransaction(PoolMessage nMessageID);
/// As a client, check and sign the final transaction
bool SignFinalTransaction(const CTransaction& finalTransactionNew, CNode* pnode, CConnman& connman) LOCKS_EXCLUDED(cs_coinjoin);
bool SignFinalTransaction(const CTransaction& finalTransactionNew, CNode& peer, CConnman& connman) LOCKS_EXCLUDED(cs_coinjoin);
void RelayIn(const CCoinJoinEntry& entry, CConnman& connman) const;
@ -123,7 +123,7 @@ public:
{
}
void ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv, CConnman& connman, bool enable_bip61);
void ProcessMessage(CNode& peer, std::string_view msg_type, CDataStream& vRecv, CConnman& connman, bool enable_bip61);
void UnlockCoins();
@ -157,8 +157,8 @@ public:
explicit CCoinJoinClientQueueManager(CConnman& _connman) :
connman(_connman) {};
void ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv, bool enable_bip61) LOCKS_EXCLUDED(cs_vecqueue);
void ProcessDSQueue(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv, bool enable_bip61);
void ProcessMessage(const CNode& peer, std::string_view msg_type, CDataStream& vRecv) LOCKS_EXCLUDED(cs_vecqueue);
void ProcessDSQueue(const CNode& peer, CDataStream& vRecv);
void DoMaintenance();
};
@ -201,7 +201,7 @@ public:
explicit CCoinJoinClientManager(CWallet& wallet) :
mixingWallet(wallet) {}
void ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv, CConnman& connman, bool enable_bip61) LOCKS_EXCLUDED(cs_deqsessions);
void ProcessMessage(CNode& peer, std::string_view msg_type, CDataStream& vRecv, CConnman& connman, bool enable_bip61) LOCKS_EXCLUDED(cs_deqsessions);
bool StartMixing();
void StopMixing();

View File

@ -26,31 +26,28 @@
std::unique_ptr<CCoinJoinServer> coinJoinServer;
constexpr static CAmount DEFAULT_MAX_RAW_TX_FEE{COIN / 10};
void CCoinJoinServer::ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv, bool enable_bip61)
void CCoinJoinServer::ProcessMessage(CNode& peer, std::string_view msg_type, CDataStream& vRecv)
{
if (!fMasternodeMode) return;
if (!masternodeSync->IsBlockchainSynced()) return;
if (msg_type == NetMsgType::DSACCEPT) {
ProcessDSACCEPT(pfrom, msg_type, vRecv, enable_bip61);
return;
ProcessDSACCEPT(peer, vRecv);
} else if (msg_type == NetMsgType::DSQUEUE) {
ProcessDSQUEUE(pfrom, msg_type, vRecv, enable_bip61);
return;
ProcessDSQUEUE(peer, vRecv);
} else if (msg_type == NetMsgType::DSVIN) {
ProcessDSVIN(pfrom, msg_type, vRecv, enable_bip61);
return;
ProcessDSVIN(peer, vRecv);
} else if (msg_type == NetMsgType::DSSIGNFINALTX) {
ProcessDSSIGNFINALTX(pfrom, msg_type, vRecv, enable_bip61);
ProcessDSSIGNFINALTX(vRecv);
}
}
void CCoinJoinServer::ProcessDSACCEPT(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv, bool enable_bip61)
void CCoinJoinServer::ProcessDSACCEPT(CNode& peer, CDataStream& vRecv)
{
if (IsSessionReady()) {
// too many users in this session already, reject new ones
LogPrint(BCLog::COINJOIN, "DSACCEPT -- queue is already full!\n");
PushStatus(pfrom, STATUS_REJECTED, ERR_QUEUE_FULL);
PushStatus(peer, STATUS_REJECTED, ERR_QUEUE_FULL);
return;
}
@ -62,7 +59,7 @@ void CCoinJoinServer::ProcessDSACCEPT(CNode* pfrom, const std::string& msg_type,
auto mnList = deterministicMNManager->GetListAtChainTip();
auto dmn = WITH_LOCK(activeMasternodeInfoCs, return mnList.GetValidMNByCollateral(activeMasternodeInfo.outpoint));
if (!dmn) {
PushStatus(pfrom, STATUS_REJECTED, ERR_MN_LIST);
PushStatus(peer, STATUS_REJECTED, ERR_MN_LIST);
return;
}
@ -77,7 +74,7 @@ void CCoinJoinServer::ProcessDSACCEPT(CNode* pfrom, const std::string& msg_type,
[&mnOutpoint](const auto& q){return q.masternodeOutpoint == mnOutpoint;})) {
// refuse to create another queue this often
LogPrint(BCLog::COINJOIN, "DSACCEPT -- last dsq is still in queue, refuse to mix\n");
PushStatus(pfrom, STATUS_REJECTED, ERR_RECENT);
PushStatus(peer, STATUS_REJECTED, ERR_RECENT);
return;
}
}
@ -86,11 +83,11 @@ void CCoinJoinServer::ProcessDSACCEPT(CNode* pfrom, const std::string& msg_type,
int64_t nDsqThreshold = mmetaman.GetDsqThreshold(dmn->proTxHash, mnList.GetValidMNsCount());
if (nLastDsq != 0 && nDsqThreshold > mmetaman.GetDsqCount()) {
if (fLogIPs) {
LogPrint(BCLog::COINJOIN, "DSACCEPT -- last dsq too recent, must wait: peer=%d, addr=%s\n", pfrom->GetId(), pfrom->addr.ToString());
LogPrint(BCLog::COINJOIN, "DSACCEPT -- last dsq too recent, must wait: peer=%d, addr=%s\n", peer.GetId(), peer.addr.ToString());
} else {
LogPrint(BCLog::COINJOIN, "DSACCEPT -- last dsq too recent, must wait: peer=%d\n", pfrom->GetId());
LogPrint(BCLog::COINJOIN, "DSACCEPT -- last dsq too recent, must wait: peer=%d\n", peer.GetId());
}
PushStatus(pfrom, STATUS_REJECTED, ERR_RECENT);
PushStatus(peer, STATUS_REJECTED, ERR_RECENT);
return;
}
}
@ -101,16 +98,16 @@ void CCoinJoinServer::ProcessDSACCEPT(CNode* pfrom, const std::string& msg_type,
: AddUserToExistingSession(dsa, nMessageID);
if (fResult) {
LogPrint(BCLog::COINJOIN, "DSACCEPT -- is compatible, please submit!\n");
PushStatus(pfrom, STATUS_ACCEPTED, nMessageID);
PushStatus(peer, STATUS_ACCEPTED, nMessageID);
return;
} else {
LogPrint(BCLog::COINJOIN, "DSACCEPT -- not compatible with existing transactions!\n");
PushStatus(pfrom, STATUS_REJECTED, nMessageID);
PushStatus(peer, STATUS_REJECTED, nMessageID);
return;
}
}
void CCoinJoinServer::ProcessDSQUEUE(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv, bool enable_bip61)
void CCoinJoinServer::ProcessDSQUEUE(const CNode& peer, CDataStream& vRecv)
{
CCoinJoinQueue dsq;
vRecv >> dsq;
@ -126,7 +123,7 @@ void CCoinJoinServer::ProcessDSQUEUE(CNode* pfrom, const std::string& msg_type,
}
if (q.fReady == dsq.fReady && q.masternodeOutpoint == dsq.masternodeOutpoint) {
// no way the same mn can send another dsq with the same readiness this soon
LogPrint(BCLog::COINJOIN, "DSQUEUE -- Peer %s is sending WAY too many dsq messages for a masternode with collateral %s\n", pfrom->GetLogString(), dsq.masternodeOutpoint.ToStringShort());
LogPrint(BCLog::COINJOIN, "DSQUEUE -- Peer %s is sending WAY too many dsq messages for a masternode with collateral %s\n", peer.GetLogString(), dsq.masternodeOutpoint.ToStringShort());
return;
}
}
@ -142,7 +139,7 @@ void CCoinJoinServer::ProcessDSQUEUE(CNode* pfrom, const std::string& msg_type,
if (!dsq.CheckSignature(dmn->pdmnState->pubKeyOperator.Get())) {
LOCK(cs_main);
Misbehaving(pfrom->GetId(), 10);
Misbehaving(peer.GetId(), 10);
return;
}
@ -166,12 +163,12 @@ void CCoinJoinServer::ProcessDSQUEUE(CNode* pfrom, const std::string& msg_type,
}
}
void CCoinJoinServer::ProcessDSVIN(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv, bool enable_bip61)
void CCoinJoinServer::ProcessDSVIN(CNode& peer, CDataStream& vRecv)
{
//do we have enough users in the current session?
if (!IsSessionReady()) {
LogPrint(BCLog::COINJOIN, "DSVIN -- session not complete!\n");
PushStatus(pfrom, STATUS_REJECTED, ERR_SESSION);
PushStatus(peer, STATUS_REJECTED, ERR_SESSION);
return;
}
@ -182,18 +179,18 @@ void CCoinJoinServer::ProcessDSVIN(CNode* pfrom, const std::string& msg_type, CD
PoolMessage nMessageID = MSG_NOERR;
entry.addr = pfrom->addr;
entry.addr = peer.addr;
if (AddEntry(entry, nMessageID)) {
PushStatus(pfrom, STATUS_ACCEPTED, nMessageID);
PushStatus(peer, STATUS_ACCEPTED, nMessageID);
CheckPool();
LOCK(cs_coinjoin);
RelayStatus(STATUS_ACCEPTED);
} else {
PushStatus(pfrom, STATUS_REJECTED, nMessageID);
PushStatus(peer, STATUS_REJECTED, nMessageID);
}
}
void CCoinJoinServer::ProcessDSSIGNFINALTX(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv, bool enable_bip61)
void CCoinJoinServer::ProcessDSSIGNFINALTX(CDataStream& vRecv)
{
std::vector<CTxIn> vecTxIn;
vRecv >> vecTxIn;
@ -783,11 +780,10 @@ void CCoinJoinServer::RelayFinalTransaction(const CTransaction& txFinal)
}
}
void CCoinJoinServer::PushStatus(CNode* pnode, PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID) const
void CCoinJoinServer::PushStatus(CNode& peer, PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID) const
{
if (!pnode) return;
CCoinJoinStatusUpdate psssup(nSessionID, nState, 0, nStatusUpdate, nMessageID);
connman.PushMessage(pnode, CNetMsgMaker(pnode->GetSendVersion()).Make(NetMsgType::DSSTATUSUPDATE, psssup));
connman.PushMessage(&peer, CNetMsgMaker(peer.GetSendVersion()).Make(NetMsgType::DSSTATUSUPDATE, psssup));
}
void CCoinJoinServer::RelayStatus(PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID)
@ -798,7 +794,7 @@ void CCoinJoinServer::RelayStatus(PoolStatusUpdate nStatusUpdate, PoolMessage nM
for (const auto& entry : vecEntries) {
// make sure everyone is still connected
bool fOk = connman.ForNode(entry.addr, [&nStatusUpdate, &nMessageID, this](CNode* pnode) {
PushStatus(pnode, nStatusUpdate, nMessageID);
PushStatus(*pnode, nStatusUpdate, nMessageID);
return true;
});
if (!fOk) {
@ -815,7 +811,7 @@ void CCoinJoinServer::RelayStatus(PoolStatusUpdate nStatusUpdate, PoolMessage nM
// notify everyone else that this session should be terminated
for (const auto& entry : vecEntries) {
connman.ForNode(entry.addr, [this](CNode* pnode) {
PushStatus(pnode, STATUS_REJECTED, MSG_NOERR);
PushStatus(*pnode, STATUS_REJECTED, MSG_NOERR);
return true;
});
}

View File

@ -62,14 +62,14 @@ private:
/// Relay mixing Messages
void RelayFinalTransaction(const CTransaction& txFinal) EXCLUSIVE_LOCKS_REQUIRED(cs_coinjoin);
void PushStatus(CNode* pnode, PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID) const;
void PushStatus(CNode& peer, PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID) const;
void RelayStatus(PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID = MSG_NOERR) EXCLUSIVE_LOCKS_REQUIRED(cs_coinjoin);
void RelayCompletedTransaction(PoolMessage nMessageID) LOCKS_EXCLUDED(cs_coinjoin);
void ProcessDSACCEPT(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv, bool enable_bip61) LOCKS_EXCLUDED(cs_vecqueue);
void ProcessDSQUEUE(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv, bool enable_bip61) LOCKS_EXCLUDED(cs_vecqueue);
void ProcessDSVIN(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv, bool enable_bip61) LOCKS_EXCLUDED(cs_coinjoin);
void ProcessDSSIGNFINALTX(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv, bool enable_bip61) LOCKS_EXCLUDED(cs_coinjoin);
void ProcessDSACCEPT(CNode& peer, CDataStream& vRecv) LOCKS_EXCLUDED(cs_vecqueue);
void ProcessDSQUEUE(const CNode& peer, CDataStream& vRecv) LOCKS_EXCLUDED(cs_vecqueue);
void ProcessDSVIN(CNode& peer, CDataStream& vRecv) LOCKS_EXCLUDED(cs_coinjoin);
void ProcessDSSIGNFINALTX(CDataStream& vRecv) LOCKS_EXCLUDED(cs_coinjoin);
void SetNull() EXCLUSIVE_LOCKS_REQUIRED(cs_coinjoin);
@ -79,7 +79,7 @@ public:
fUnitTest(false),
connman(_connman) {};
void ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv, bool enable_bip61);
void ProcessMessage(CNode& pfrom, std::string_view msg_type, CDataStream& vRecv);
bool HasTimedOut() const;
void CheckTimeout();

View File

@ -16,7 +16,7 @@
#include <unordered_set>
void CMNAuth::PushMNAUTH(CNode* pnode, CConnman& connman)
void CMNAuth::PushMNAUTH(CNode& peer, CConnman& connman)
{
LOCK(activeMasternodeInfoCs);
if (!fMasternodeMode || activeMasternodeInfo.proTxHash.IsNull()) {
@ -24,7 +24,7 @@ void CMNAuth::PushMNAUTH(CNode* pnode, CConnman& connman)
}
uint256 signHash;
const auto receivedMNAuthChallenge = pnode->GetReceivedMNAuthChallenge();
const auto receivedMNAuthChallenge = peer.GetReceivedMNAuthChallenge();
if (receivedMNAuthChallenge.IsNull()) {
return;
}
@ -38,22 +38,22 @@ void CMNAuth::PushMNAUTH(CNode* pnode, CConnman& connman)
if (Params().NetworkIDString() != CBaseChainParams::MAIN && gArgs.IsArgSet("-pushversion")) {
nOurNodeVersion = gArgs.GetArg("-pushversion", PROTOCOL_VERSION);
}
if (pnode->nVersion < MNAUTH_NODE_VER_VERSION || nOurNodeVersion < MNAUTH_NODE_VER_VERSION) {
signHash = ::SerializeHash(std::make_tuple(*activeMasternodeInfo.blsPubKeyOperator, receivedMNAuthChallenge, pnode->fInbound));
if (peer.nVersion < MNAUTH_NODE_VER_VERSION || nOurNodeVersion < MNAUTH_NODE_VER_VERSION) {
signHash = ::SerializeHash(std::make_tuple(*activeMasternodeInfo.blsPubKeyOperator, receivedMNAuthChallenge, peer.fInbound));
} else {
signHash = ::SerializeHash(std::make_tuple(*activeMasternodeInfo.blsPubKeyOperator, receivedMNAuthChallenge, pnode->fInbound, nOurNodeVersion));
signHash = ::SerializeHash(std::make_tuple(*activeMasternodeInfo.blsPubKeyOperator, receivedMNAuthChallenge, peer.fInbound, nOurNodeVersion));
}
CMNAuth mnauth;
mnauth.proRegTxHash = activeMasternodeInfo.proTxHash;
mnauth.sig = activeMasternodeInfo.blsKeyOperator->Sign(signHash);
LogPrint(BCLog::NET_NETCONN, "CMNAuth::%s -- Sending MNAUTH, peer=%d\n", __func__, pnode->GetId());
LogPrint(BCLog::NET_NETCONN, "CMNAuth::%s -- Sending MNAUTH, peer=%d\n", __func__, peer.GetId());
connman.PushMessage(pnode, CNetMsgMaker(pnode->GetSendVersion()).Make(NetMsgType::MNAUTH, mnauth));
connman.PushMessage(&peer, CNetMsgMaker(peer.GetSendVersion()).Make(NetMsgType::MNAUTH, mnauth));
}
void CMNAuth::ProcessMessage(CNode* pnode, const std::string& msg_type, CDataStream& vRecv, CConnman& connman)
void CMNAuth::ProcessMessage(CNode& peer, std::string_view msg_type, CDataStream& vRecv, CConnman& connman)
{
if (msg_type != NetMsgType::MNAUTH || !masternodeSync->IsBlockchainSynced()) {
// we can't verify MNAUTH messages when we don't have the latest MN list
@ -64,28 +64,28 @@ void CMNAuth::ProcessMessage(CNode* pnode, const std::string& msg_type, CDataStr
vRecv >> mnauth;
// only one MNAUTH allowed
if (!pnode->GetVerifiedProRegTxHash().IsNull()) {
if (!peer.GetVerifiedProRegTxHash().IsNull()) {
LOCK(cs_main);
Misbehaving(pnode->GetId(), 100, "duplicate mnauth");
Misbehaving(peer.GetId(), 100, "duplicate mnauth");
return;
}
if ((~pnode->nServices) & (NODE_NETWORK | NODE_BLOOM)) {
if ((~peer.nServices) & (NODE_NETWORK | NODE_BLOOM)) {
// either NODE_NETWORK or NODE_BLOOM bit is missing in node's services
LOCK(cs_main);
Misbehaving(pnode->GetId(), 100, "mnauth from a node with invalid services");
Misbehaving(peer.GetId(), 100, "mnauth from a node with invalid services");
return;
}
if (mnauth.proRegTxHash.IsNull()) {
LOCK(cs_main);
Misbehaving(pnode->GetId(), 100, "empty mnauth proRegTxHash");
Misbehaving(peer.GetId(), 100, "empty mnauth proRegTxHash");
return;
}
if (!mnauth.sig.IsValid()) {
LOCK(cs_main);
Misbehaving(pnode->GetId(), 100, "invalid mnauth signature");
Misbehaving(peer.GetId(), 100, "invalid mnauth signature");
return;
}
@ -96,7 +96,7 @@ void CMNAuth::ProcessMessage(CNode* pnode, const std::string& msg_type, CDataStr
// in case node was unlucky and not up to date, just let it be connected as a regular node, which gives it
// a chance to get up-to-date and thus realize that it's not a MN anymore. We still give it a
// low DoS score.
Misbehaving(pnode->GetId(), 10, "missing mnauth masternode");
Misbehaving(peer.GetId(), 10, "missing mnauth masternode");
return;
}
@ -106,33 +106,33 @@ void CMNAuth::ProcessMessage(CNode* pnode, const std::string& msg_type, CDataStr
nOurNodeVersion = gArgs.GetArg("-pushversion", PROTOCOL_VERSION);
}
// See comment in PushMNAUTH (fInbound is negated here as we're on the other side of the connection)
if (pnode->nVersion < MNAUTH_NODE_VER_VERSION || nOurNodeVersion < MNAUTH_NODE_VER_VERSION) {
signHash = ::SerializeHash(std::make_tuple(dmn->pdmnState->pubKeyOperator, pnode->GetSentMNAuthChallenge(), !pnode->fInbound));
if (peer.nVersion < MNAUTH_NODE_VER_VERSION || nOurNodeVersion < MNAUTH_NODE_VER_VERSION) {
signHash = ::SerializeHash(std::make_tuple(dmn->pdmnState->pubKeyOperator, peer.GetSentMNAuthChallenge(), !peer.fInbound));
} else {
signHash = ::SerializeHash(std::make_tuple(dmn->pdmnState->pubKeyOperator, pnode->GetSentMNAuthChallenge(), !pnode->fInbound, pnode->nVersion.load()));
signHash = ::SerializeHash(std::make_tuple(dmn->pdmnState->pubKeyOperator, peer.GetSentMNAuthChallenge(), !peer.fInbound, peer.nVersion.load()));
}
LogPrint(BCLog::NET_NETCONN, "CMNAuth::%s -- constructed signHash for nVersion %d, peer=%d\n", __func__, pnode->nVersion, pnode->GetId());
LogPrint(BCLog::NET_NETCONN, "CMNAuth::%s -- constructed signHash for nVersion %d, peer=%d\n", __func__, peer.nVersion, peer.GetId());
if (!mnauth.sig.VerifyInsecure(dmn->pdmnState->pubKeyOperator.Get(), signHash)) {
LOCK(cs_main);
// Same as above, MN seems to not know its fate yet, so give it a chance to update. If this is a
// malicious node (DoSing us), it'll get banned soon.
Misbehaving(pnode->GetId(), 10, "mnauth signature verification failed");
Misbehaving(peer.GetId(), 10, "mnauth signature verification failed");
return;
}
if (!pnode->fInbound) {
if (!peer.fInbound) {
mmetaman.GetMetaInfo(mnauth.proRegTxHash)->SetLastOutboundSuccess(GetAdjustedTime());
if (pnode->m_masternode_probe_connection) {
if (peer.m_masternode_probe_connection) {
LogPrint(BCLog::NET_NETCONN, "CMNAuth::ProcessMessage -- Masternode probe successful for %s, disconnecting. peer=%d\n",
mnauth.proRegTxHash.ToString(), pnode->GetId());
pnode->fDisconnect = true;
mnauth.proRegTxHash.ToString(), peer.GetId());
peer.fDisconnect = true;
return;
}
}
connman.ForEachNode([&](CNode* pnode2) {
if (pnode->fDisconnect) {
if (peer.fDisconnect) {
// we've already disconnected the new peer
return;
}
@ -141,50 +141,50 @@ void CMNAuth::ProcessMessage(CNode* pnode, const std::string& msg_type, CDataStr
if (fMasternodeMode) {
const auto deterministicOutbound = WITH_LOCK(activeMasternodeInfoCs, return llmq::utils::DeterministicOutboundConnection(activeMasternodeInfo.proTxHash, mnauth.proRegTxHash));
LogPrint(BCLog::NET_NETCONN, "CMNAuth::ProcessMessage -- Masternode %s has already verified as peer %d, deterministicOutbound=%s. peer=%d\n",
mnauth.proRegTxHash.ToString(), pnode2->GetId(), deterministicOutbound.ToString(), pnode->GetId());
mnauth.proRegTxHash.ToString(), pnode2->GetId(), deterministicOutbound.ToString(), peer.GetId());
if (WITH_LOCK(activeMasternodeInfoCs, return deterministicOutbound == activeMasternodeInfo.proTxHash)) {
if (pnode2->fInbound) {
LogPrint(BCLog::NET_NETCONN, "CMNAuth::ProcessMessage -- dropping old inbound, peer=%d\n", pnode2->GetId());
pnode2->fDisconnect = true;
} else if (pnode->fInbound) {
LogPrint(BCLog::NET_NETCONN, "CMNAuth::ProcessMessage -- dropping new inbound, peer=%d\n", pnode->GetId());
pnode->fDisconnect = true;
} else if (peer.fInbound) {
LogPrint(BCLog::NET_NETCONN, "CMNAuth::ProcessMessage -- dropping new inbound, peer=%d\n", peer.GetId());
peer.fDisconnect = true;
}
} else {
if (!pnode2->fInbound) {
LogPrint(BCLog::NET_NETCONN, "CMNAuth::ProcessMessage -- dropping old outbound, peer=%d\n", pnode2->GetId());
pnode2->fDisconnect = true;
} else if (!pnode->fInbound) {
LogPrint(BCLog::NET_NETCONN, "CMNAuth::ProcessMessage -- dropping new outbound, peer=%d\n", pnode->GetId());
pnode->fDisconnect = true;
} else if (!peer.fInbound) {
LogPrint(BCLog::NET_NETCONN, "CMNAuth::ProcessMessage -- dropping new outbound, peer=%d\n", peer.GetId());
peer.fDisconnect = true;
}
}
} else {
LogPrint(BCLog::NET_NETCONN, "CMNAuth::ProcessMessage -- Masternode %s has already verified as peer %d, dropping new connection. peer=%d\n",
mnauth.proRegTxHash.ToString(), pnode2->GetId(), pnode->GetId());
pnode->fDisconnect = true;
mnauth.proRegTxHash.ToString(), pnode2->GetId(), peer.GetId());
peer.fDisconnect = true;
}
}
});
if (pnode->fDisconnect) {
if (peer.fDisconnect) {
return;
}
pnode->SetVerifiedProRegTxHash(mnauth.proRegTxHash);
pnode->SetVerifiedPubKeyHash(dmn->pdmnState->pubKeyOperator.GetHash());
peer.SetVerifiedProRegTxHash(mnauth.proRegTxHash);
peer.SetVerifiedPubKeyHash(dmn->pdmnState->pubKeyOperator.GetHash());
if (!pnode->m_masternode_iqr_connection && connman.IsMasternodeQuorumRelayMember(pnode->GetVerifiedProRegTxHash())) {
if (!peer.m_masternode_iqr_connection && connman.IsMasternodeQuorumRelayMember(peer.GetVerifiedProRegTxHash())) {
// Tell our peer that we're interested in plain LLMQ recovered signatures.
// 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());
connman.PushMessage(pnode, msgMaker.Make(NetMsgType::QSENDRECSIGS, true));
pnode->m_masternode_iqr_connection = true;
const CNetMsgMaker msgMaker(peer.GetSendVersion());
connman.PushMessage(&peer, msgMaker.Make(NetMsgType::QSENDRECSIGS, true));
peer.m_masternode_iqr_connection = true;
}
LogPrint(BCLog::NET_NETCONN, "CMNAuth::%s -- Valid MNAUTH for %s, peer=%d\n", __func__, mnauth.proRegTxHash.ToString(), pnode->GetId());
LogPrint(BCLog::NET_NETCONN, "CMNAuth::%s -- Valid MNAUTH for %s, peer=%d\n", __func__, mnauth.proRegTxHash.ToString(), peer.GetId());
}
void CMNAuth::NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff, CConnman& connman)

View File

@ -44,8 +44,8 @@ public:
READWRITE(obj.proRegTxHash, obj.sig);
}
static void PushMNAUTH(CNode* pnode, CConnman& connman);
static void ProcessMessage(CNode* pnode, const std::string& msg_type, CDataStream& vRecv, CConnman& connman);
static void PushMNAUTH(CNode& peer, CConnman& connman);
static void ProcessMessage(CNode& peer, std::string_view msg_type, CDataStream& vRecv, CConnman& connman);
static void NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff, CConnman& connman);
};

View File

@ -87,7 +87,7 @@ bool CGovernanceManager::SerializeVoteForHash(const uint256& nHash, CDataStream&
return cmapVoteToObject.Get(nHash, pGovobj) && pGovobj->GetVoteFile().SerializeVoteToStream(nHash, ss);
}
void CGovernanceManager::ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv, CConnman& connman, bool enable_bip61)
void CGovernanceManager::ProcessMessage(CNode& peer, std::string_view msg_type, CDataStream& vRecv, CConnman& connman)
{
if (fDisableGovernance) return;
if (masternodeSync == nullptr || !masternodeSync->IsBlockchainSynced()) return;
@ -108,11 +108,11 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, const std::string& msg_typ
filter.UpdateEmptyFull();
if (nProp == uint256()) {
SyncObjects(pfrom, connman);
SyncObjects(peer, connman);
} else {
SyncSingleObjVotes(pfrom, nProp, filter, connman);
SyncSingleObjVotes(peer, nProp, filter, connman);
}
LogPrint(BCLog::GOBJECT, "MNGOVERNANCESYNC -- syncing governance objects to our peer %s\n", pfrom->GetLogString());
LogPrint(BCLog::GOBJECT, "MNGOVERNANCESYNC -- syncing governance objects to our peer %s\n", peer.GetLogString());
}
// A NEW GOVERNANCE OBJECT HAS ARRIVED
@ -126,7 +126,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, const std::string& msg_typ
{
LOCK(cs_main);
EraseObjectRequest(pfrom->GetId(), CInv(MSG_GOVERNANCE_OBJECT, nHash));
EraseObjectRequest(peer.GetId(), CInv(MSG_GOVERNANCE_OBJECT, nHash));
}
if (!masternodeSync->IsBlockchainSynced()) {
@ -176,13 +176,13 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, const std::string& msg_typ
} else {
LogPrint(BCLog::GOBJECT, "MNGOVERNANCEOBJECT -- Governance object is invalid - %s\n", strError);
// apply node's ban score
Misbehaving(pfrom->GetId(), 20);
Misbehaving(peer.GetId(), 20);
}
return;
}
AddGovernanceObject(govobj, connman, pfrom);
AddGovernanceObject(govobj, connman, &peer);
}
// A NEW GOVERNANCE OBJECT VOTE HAS ARRIVED
@ -194,7 +194,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, const std::string& msg_typ
{
LOCK(cs_main);
EraseObjectRequest(pfrom->GetId(), CInv(MSG_GOVERNANCE_OBJECT_VOTE, nHash));
EraseObjectRequest(peer.GetId(), CInv(MSG_GOVERNANCE_OBJECT_VOTE, nHash));
}
// Ignore such messages until masternode list is synced
@ -209,12 +209,12 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, const std::string& msg_typ
if (!AcceptVoteMessage(nHash)) {
LogPrint(BCLog::GOBJECT, "MNGOVERNANCEOBJECTVOTE -- Received unrequested vote object: %s, hash: %s, peer = %d\n",
vote.ToString(), strHash, pfrom->GetId());
vote.ToString(), strHash, peer.GetId());
return;
}
CGovernanceException exception;
if (ProcessVote(pfrom, vote, exception, connman)) {
if (ProcessVote(&peer, vote, exception, connman)) {
LogPrint(BCLog::GOBJECT, "MNGOVERNANCEOBJECTVOTE -- %s new\n", strHash);
masternodeSync->BumpAssetLastTime("MNGOVERNANCEOBJECTVOTE");
vote.Relay(connman);
@ -222,7 +222,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, const std::string& msg_typ
LogPrint(BCLog::GOBJECT, "MNGOVERNANCEOBJECTVOTE -- Rejected vote, error = %s\n", exception.what());
if ((exception.GetNodePenalty() != 0) && masternodeSync->IsSynced()) {
LOCK(cs_main);
Misbehaving(pfrom->GetId(), exception.GetNodePenalty());
Misbehaving(peer.GetId(), exception.GetNodePenalty());
}
return;
}
@ -570,7 +570,7 @@ bool CGovernanceManager::ConfirmInventoryRequest(const CInv& inv)
return true;
}
void CGovernanceManager::SyncSingleObjVotes(CNode* pnode, const uint256& nProp, const CBloomFilter& filter, CConnman& connman)
void CGovernanceManager::SyncSingleObjVotes(CNode& peer, const uint256& nProp, const CBloomFilter& filter, CConnman& connman)
{
// do not provide any data until our node is synced
if (!masternodeSync->IsSynced()) return;
@ -579,24 +579,24 @@ void CGovernanceManager::SyncSingleObjVotes(CNode* pnode, const uint256& nProp,
// SYNC GOVERNANCE OBJECTS WITH OTHER CLIENT
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s -- syncing single object to peer=%d, nProp = %s\n", __func__, pnode->GetId(), nProp.ToString());
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s -- syncing single object to peer=%d, nProp = %s\n", __func__, peer.GetId(), nProp.ToString());
LOCK(cs);
// single valid object and its valid votes
auto it = mapObjects.find(nProp);
if (it == mapObjects.end()) {
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s -- no matching object for hash %s, peer=%d\n", __func__, nProp.ToString(), pnode->GetId());
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s -- no matching object for hash %s, peer=%d\n", __func__, nProp.ToString(), peer.GetId());
return;
}
const CGovernanceObject& govobj = it->second;
std::string strHash = it->first.ToString();
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s -- attempting to sync govobj: %s, peer=%d\n", __func__, strHash, pnode->GetId());
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s -- attempting to sync govobj: %s, peer=%d\n", __func__, strHash, peer.GetId());
if (govobj.IsSetCachedDelete() || govobj.IsSetExpired()) {
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s -- not syncing deleted/expired govobj: %s, peer=%d\n", __func__,
strHash, pnode->GetId());
strHash, peer.GetId());
return;
}
@ -610,34 +610,34 @@ void CGovernanceManager::SyncSingleObjVotes(CNode* pnode, const uint256& nProp,
if (filter.contains(nVoteHash) || !vote.IsValid(onlyVotingKeyAllowed)) {
continue;
}
pnode->PushInventory(CInv(MSG_GOVERNANCE_OBJECT_VOTE, nVoteHash));
peer.PushInventory(CInv(MSG_GOVERNANCE_OBJECT_VOTE, nVoteHash));
++nVoteCount;
}
CNetMsgMaker msgMaker(pnode->GetSendVersion());
connman.PushMessage(pnode, msgMaker.Make(NetMsgType::SYNCSTATUSCOUNT, MASTERNODE_SYNC_GOVOBJ_VOTE, nVoteCount));
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s -- sent %d votes to peer=%d\n", __func__, nVoteCount, pnode->GetId());
CNetMsgMaker msgMaker(peer.GetSendVersion());
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());
}
void CGovernanceManager::SyncObjects(CNode* pnode, CConnman& connman) const
void CGovernanceManager::SyncObjects(CNode& peer, CConnman& connman) const
{
// do not provide any data until our node is synced
if (!masternodeSync->IsSynced()) return;
if (netfulfilledman.HasFulfilledRequest(pnode->addr, NetMsgType::MNGOVERNANCESYNC)) {
if (netfulfilledman.HasFulfilledRequest(peer.addr, NetMsgType::MNGOVERNANCESYNC)) {
// Asking for the whole list multiple times in a short period of time is no good
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s -- peer already asked me for the list\n", __func__);
LOCK(cs_main);
Misbehaving(pnode->GetId(), 20);
Misbehaving(peer.GetId(), 20);
return;
}
netfulfilledman.AddFulfilledRequest(pnode->addr, NetMsgType::MNGOVERNANCESYNC);
netfulfilledman.AddFulfilledRequest(peer.addr, NetMsgType::MNGOVERNANCESYNC);
int nObjCount = 0;
// SYNC GOVERNANCE OBJECTS WITH OTHER CLIENT
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s -- syncing all objects to peer=%d\n", __func__, pnode->GetId());
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s -- syncing all objects to peer=%d\n", __func__, peer.GetId());
bool fAllowScript = WITH_LOCK(cs_main, return VersionBitsTipState(Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0024) == ThresholdState::ACTIVE);
@ -649,15 +649,15 @@ void CGovernanceManager::SyncObjects(CNode* pnode, CConnman& connman) const
const CGovernanceObject& govobj = objPair.second;
std::string strHash = nHash.ToString();
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s -- attempting to sync govobj: %s, peer=%d\n", __func__, strHash, pnode->GetId());
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s -- attempting to sync govobj: %s, peer=%d\n", __func__, strHash, peer.GetId());
if (govobj.IsSetCachedDelete() || govobj.IsSetExpired()) {
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s -- not syncing deleted/expired govobj: %s, peer=%d\n", __func__,
strHash, pnode->GetId());
strHash, peer.GetId());
continue;
}
if (fAllowScript && pnode->nVersion < GOVSCRIPT_PROTO_VERSION && govobj.GetObjectType() == GOVERNANCE_OBJECT_PROPOSAL) {
if (fAllowScript && peer.nVersion < GOVSCRIPT_PROTO_VERSION && govobj.GetObjectType() == GOVERNANCE_OBJECT_PROPOSAL) {
// We know this proposal is valid locally, otherwise we would not store it.
// But we don't want to relay it to pre-GOVSCRIPT_PROTO_VERSION peers if payment_address is p2sh
// because they won't accept it anyway and will simply ban us eventually.
@ -665,20 +665,20 @@ void CGovernanceManager::SyncObjects(CNode* pnode, CConnman& connman) const
if (!validator.Validate(false /* ignore expiration */)) {
// The only way we could get here is when proposal is valid but payment_address is actually p2sh.
LogPrintf("CGovernanceManager::%s -- not syncing p2sh govobj to older node: %s, peer=%d\n", __func__,
strHash, pnode->GetId());
strHash, peer.GetId());
continue;
}
}
// Push the inventory budget proposal message over to the other client
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s -- syncing govobj: %s, peer=%d\n", __func__, strHash, pnode->GetId());
pnode->PushInventory(CInv(MSG_GOVERNANCE_OBJECT, nHash));
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s -- syncing govobj: %s, peer=%d\n", __func__, strHash, peer.GetId());
peer.PushInventory(CInv(MSG_GOVERNANCE_OBJECT, nHash));
++nObjCount;
}
CNetMsgMaker msgMaker(pnode->GetSendVersion());
connman.PushMessage(pnode, msgMaker.Make(NetMsgType::SYNCSTATUSCOUNT, MASTERNODE_SYNC_GOVOBJ, nObjCount));
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s -- sent %d objects to peer=%d\n", __func__, nObjCount, pnode->GetId());
CNetMsgMaker msgMaker(peer.GetSendVersion());
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());
}
void CGovernanceManager::MasternodeRateUpdate(const CGovernanceObject& govobj)
@ -925,10 +925,10 @@ void CGovernanceManager::RequestGovernanceObject(CNode* pfrom, const uint256& nH
connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::MNGOVERNANCESYNC, nHash, filter));
}
int CGovernanceManager::RequestGovernanceObjectVotes(CNode* pnode, CConnman& connman)
int CGovernanceManager::RequestGovernanceObjectVotes(CNode& peer, CConnman& connman)
{
std::vector<CNode*> vNodesCopy;
vNodesCopy.push_back(pnode);
vNodesCopy.push_back(&peer);
return RequestGovernanceObjectVotes(vNodesCopy, connman);
}

View File

@ -230,10 +230,10 @@ public:
*/
bool ConfirmInventoryRequest(const CInv& inv);
void SyncSingleObjVotes(CNode* pnode, const uint256& nProp, const CBloomFilter& filter, CConnman& connman);
void SyncObjects(CNode* pnode, CConnman& connman) const;
void SyncSingleObjVotes(CNode& peer, const uint256& nProp, const CBloomFilter& filter, CConnman& connman);
void SyncObjects(CNode& peer, CConnman& connman) const;
void ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv, CConnman& connman, bool enable_bip61);
void ProcessMessage(CNode& peer, std::string_view msg_type, CDataStream& vRecv, CConnman& connman);
void DoMaintenance(CConnman& connman);
@ -346,7 +346,7 @@ public:
void InitOnLoad();
int RequestGovernanceObjectVotes(CNode* pnode, CConnman& connman);
int RequestGovernanceObjectVotes(CNode& peer, CConnman& connman);
int RequestGovernanceObjectVotes(const std::vector<CNode*>& vNodesCopy, CConnman& connman);
private:

View File

@ -41,7 +41,7 @@ CQuorumBlockProcessor::CQuorumBlockProcessor(CEvoDB &_evoDb, CConnman& _connman)
utils::InitQuorumsCache(mapHasMinedCommitmentCache);
}
void CQuorumBlockProcessor::ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv)
void CQuorumBlockProcessor::ProcessMessage(const CNode& peer, std::string_view msg_type, CDataStream& vRecv)
{
if (msg_type != NetMsgType::QFCOMMITMENT) {
return;
@ -50,18 +50,18 @@ void CQuorumBlockProcessor::ProcessMessage(CNode* pfrom, const std::string& msg_
CFinalCommitment qc;
vRecv >> qc;
WITH_LOCK(cs_main, EraseObjectRequest(pfrom->GetId(), CInv(MSG_QUORUM_FINAL_COMMITMENT, ::SerializeHash(qc))));
WITH_LOCK(cs_main, EraseObjectRequest(peer.GetId(), CInv(MSG_QUORUM_FINAL_COMMITMENT, ::SerializeHash(qc))));
if (qc.IsNull()) {
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- null commitment from peer=%d\n", __func__, pfrom->GetId());
WITH_LOCK(cs_main, Misbehaving(pfrom->GetId(), 100));
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- null commitment from peer=%d\n", __func__, peer.GetId());
WITH_LOCK(cs_main, Misbehaving(peer.GetId(), 100));
return;
}
if (!Params().HasLLMQ(qc.llmqType)) {
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- invalid commitment type %d from peer=%d\n", __func__,
uint8_t(qc.llmqType), pfrom->GetId());
WITH_LOCK(cs_main, Misbehaving(pfrom->GetId(), 100));
uint8_t(qc.llmqType), peer.GetId());
WITH_LOCK(cs_main, Misbehaving(peer.GetId(), 100));
return;
}
auto type = qc.llmqType;
@ -73,22 +73,22 @@ void CQuorumBlockProcessor::ProcessMessage(CNode* pfrom, const std::string& msg_
pQuorumBaseBlockIndex = LookupBlockIndex(qc.quorumHash);
if (pQuorumBaseBlockIndex == nullptr) {
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- unknown block %s in commitment, peer=%d\n", __func__,
qc.quorumHash.ToString(), pfrom->GetId());
qc.quorumHash.ToString(), peer.GetId());
// can't really punish the node here, as we might simply be the one that is on the wrong chain or not
// fully synced
return;
}
if (::ChainActive().Tip()->GetAncestor(pQuorumBaseBlockIndex->nHeight) != pQuorumBaseBlockIndex) {
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- block %s not in active chain, peer=%d\n", __func__,
qc.quorumHash.ToString(), pfrom->GetId());
qc.quorumHash.ToString(), peer.GetId());
// same, can't punish
return;
}
int quorumHeight = pQuorumBaseBlockIndex->nHeight - (pQuorumBaseBlockIndex->nHeight % GetLLMQParams(type).dkgInterval) + int(qc.quorumIndex);
if (quorumHeight != pQuorumBaseBlockIndex->nHeight) {
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- block %s is not the first block in the DKG interval, peer=%d\n", __func__,
qc.quorumHash.ToString(), pfrom->GetId());
Misbehaving(pfrom->GetId(), 100);
qc.quorumHash.ToString(), peer.GetId());
Misbehaving(peer.GetId(), 100);
return;
}
}
@ -110,13 +110,13 @@ void CQuorumBlockProcessor::ProcessMessage(CNode* pfrom, const std::string& msg_
if (!qc.Verify(pQuorumBaseBlockIndex, true)) {
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- commitment for quorum %s:%d is not valid quorumIndex[%d] nversion[%d], peer=%d\n",
__func__, qc.quorumHash.ToString(),
uint8_t(qc.llmqType), qc.quorumIndex, qc.nVersion, pfrom->GetId());
WITH_LOCK(cs_main, Misbehaving(pfrom->GetId(), 100));
uint8_t(qc.llmqType), qc.quorumIndex, qc.nVersion, peer.GetId());
WITH_LOCK(cs_main, Misbehaving(peer.GetId(), 100));
return;
}
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- received commitment for quorum %s:%d, validMembers=%d, signers=%d, peer=%d\n", __func__,
qc.quorumHash.ToString(), uint8_t(qc.llmqType), qc.CountValidMembers(), qc.CountSigners(), pfrom->GetId());
qc.quorumHash.ToString(), uint8_t(qc.llmqType), qc.CountValidMembers(), qc.CountSigners(), peer.GetId());
AddMineableCommitment(qc);
}

View File

@ -47,7 +47,7 @@ public:
bool UpgradeDB();
void ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv);
void ProcessMessage(const CNode& peer, std::string_view msg_type, CDataStream& vRecv);
bool ProcessBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& state, bool fJustCheck, bool fBLSChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
bool UndoBlock(const CBlock& block, const CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);

View File

@ -96,19 +96,19 @@ std::string CMasternodeSync::GetSyncStatus() const
}
}
void CMasternodeSync::ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv) const
void CMasternodeSync::ProcessMessage(const CNode& peer, std::string_view msg_type, CDataStream& vRecv) const
{
if (msg_type == NetMsgType::SYNCSTATUSCOUNT) { //Sync status count
//Sync status count
if (msg_type != NetMsgType::SYNCSTATUSCOUNT) return;
//do not care about stats if sync process finished
if (IsSynced()) return;
//do not care about stats if sync process finished
if (IsSynced()) return;
int nItemID;
int nCount;
vRecv >> nItemID >> nCount;
int nItemID;
int nCount;
vRecv >> nItemID >> nCount;
LogPrint(BCLog::MNSYNC, "SYNCSTATUSCOUNT -- got inventory count: nItemID=%d nCount=%d peer=%d\n", nItemID, nCount, pfrom->GetId());
}
LogPrint(BCLog::MNSYNC, "SYNCSTATUSCOUNT -- got inventory count: nItemID=%d nCount=%d peer=%d\n", nItemID, nCount, peer.GetId());
}
void CMasternodeSync::ProcessTick()
@ -262,7 +262,7 @@ void CMasternodeSync::ProcessTick()
if(!netfulfilledman.HasFulfilledRequest(pnode->addr, "governance-sync")) {
continue; // to early for this node
}
int nObjsLeftToAsk = governance->RequestGovernanceObjectVotes(pnode, connman);
int nObjsLeftToAsk = governance->RequestGovernanceObjectVotes(*pnode, connman);
// check for data
if(nObjsLeftToAsk == 0) {
static int64_t nTimeNoObjectsLeft = 0;

View File

@ -68,7 +68,7 @@ public:
void Reset(bool fForce = false, bool fNotifyReset = true);
void SwitchToNextAsset();
void ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv) const;
void ProcessMessage(const CNode& peer, std::string_view msg_type, CDataStream& vRecv) const;
void ProcessTick();
void AcceptedBlockHeader(const CBlockIndex *pindexNew);

View File

@ -2837,7 +2837,7 @@ bool ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRec
}
if (!pfrom->m_masternode_probe_connection) {
CMNAuth::PushMNAUTH(pfrom, *connman);
CMNAuth::PushMNAUTH(*pfrom, *connman);
}
// Tell our peer we prefer to receive headers rather than inv's
@ -4156,17 +4156,17 @@ bool ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRec
{
//probably one the extensions
#ifdef ENABLE_WALLET
coinJoinClientQueueManager->ProcessMessage(pfrom, msg_type, vRecv, enable_bip61);
coinJoinClientQueueManager->ProcessMessage(*pfrom, msg_type, vRecv);
for (auto& pair : coinJoinClientManagers) {
pair.second->ProcessMessage(pfrom, msg_type, vRecv, *connman, enable_bip61);
pair.second->ProcessMessage(*pfrom, msg_type, vRecv, *connman, enable_bip61);
}
#endif // ENABLE_WALLET
coinJoinServer->ProcessMessage(pfrom, msg_type, vRecv, enable_bip61);
sporkManager->ProcessSporkMessages(pfrom, msg_type, vRecv, *connman);
masternodeSync->ProcessMessage(pfrom, msg_type, vRecv);
governance->ProcessMessage(pfrom, msg_type, vRecv, *connman, enable_bip61);
CMNAuth::ProcessMessage(pfrom, msg_type, vRecv, *connman);
quorum_block_processor.ProcessMessage(pfrom, msg_type, vRecv);
coinJoinServer->ProcessMessage(*pfrom, msg_type, vRecv);
sporkManager->ProcessSporkMessages(*pfrom, msg_type, vRecv, *connman);
masternodeSync->ProcessMessage(*pfrom, msg_type, vRecv);
governance->ProcessMessage(*pfrom, msg_type, vRecv, *connman);
CMNAuth::ProcessMessage(*pfrom, msg_type, vRecv, *connman);
quorum_block_processor.ProcessMessage(*pfrom, msg_type, vRecv);
qdkgsman.ProcessMessage(pfrom, qman, msg_type, vRecv);
qman.ProcessMessage(pfrom, msg_type, vRecv);
shareman.ProcessMessage(pfrom, msg_type, vRecv, *sporkManager);

View File

@ -104,16 +104,17 @@ void CSporkManager::CheckAndRemove()
}
}
void CSporkManager::ProcessSporkMessages(CNode* pfrom, std::string_view msg_type, CDataStream& vRecv, CConnman& connman)
void CSporkManager::ProcessSporkMessages(CNode& peer, std::string_view msg_type, CDataStream& vRecv, CConnman& connman)
{
ProcessSpork(pfrom, msg_type, vRecv, connman);
ProcessGetSporks(pfrom, msg_type, connman);
if (msg_type == NetMsgType::SPORK) {
ProcessSpork(peer, vRecv, connman);
} else if (msg_type == NetMsgType::GETSPORKS) {
ProcessGetSporks(peer, connman);
}
}
void CSporkManager::ProcessSpork(const CNode* pfrom, std::string_view msg_type, CDataStream& vRecv, CConnman& connman)
void CSporkManager::ProcessSpork(const CNode& peer, CDataStream& vRecv, CConnman& connman)
{
if (msg_type != NetMsgType::SPORK) return;
CSporkMessage spork;
vRecv >> spork;
@ -122,15 +123,15 @@ void CSporkManager::ProcessSpork(const CNode* pfrom, std::string_view msg_type,
std::string strLogMsg;
{
LOCK(cs_main);
EraseObjectRequest(pfrom->GetId(), CInv(MSG_SPORK, hash));
EraseObjectRequest(peer.GetId(), CInv(MSG_SPORK, hash));
if (!::ChainActive().Tip()) return;
strLogMsg = strprintf("SPORK -- hash: %s id: %d value: %10d bestHeight: %d peer=%d", hash.ToString(), spork.nSporkID, spork.nValue, ::ChainActive().Height(), pfrom->GetId());
strLogMsg = strprintf("SPORK -- hash: %s id: %d value: %10d bestHeight: %d peer=%d", hash.ToString(), spork.nSporkID, spork.nValue, ::ChainActive().Height(), peer.GetId());
}
if (spork.nTimeSigned > GetAdjustedTime() + 2 * 60 * 60) {
LOCK(cs_main);
LogPrint(BCLog::SPORK, "CSporkManager::ProcessSpork -- ERROR: too far into the future\n");
Misbehaving(pfrom->GetId(), 100);
Misbehaving(peer.GetId(), 100);
return;
}
@ -139,7 +140,7 @@ void CSporkManager::ProcessSpork(const CNode* pfrom, std::string_view msg_type,
if (opt_keyIDSigner == std::nullopt || WITH_LOCK(cs, return !setSporkPubKeyIDs.count(*opt_keyIDSigner))) {
LOCK(cs_main);
LogPrint(BCLog::SPORK, "CSporkManager::ProcessSpork -- ERROR: invalid signature\n");
Misbehaving(pfrom->GetId(), 100);
Misbehaving(peer.GetId(), 100);
return;
}
@ -175,14 +176,12 @@ void CSporkManager::ProcessSpork(const CNode* pfrom, std::string_view msg_type,
spork.Relay(connman);
}
void CSporkManager::ProcessGetSporks(CNode* pfrom, std::string_view msg_type, CConnman& connman)
void CSporkManager::ProcessGetSporks(CNode& peer, CConnman& connman)
{
if (msg_type != NetMsgType::GETSPORKS) return;
LOCK(cs); // make sure to not lock this together with cs_main
for (const auto& pair : mapSporksActive) {
for (const auto& signerSporkPair : pair.second) {
connman.PushMessage(pfrom, CNetMsgMaker(pfrom->GetSendVersion()).Make(NetMsgType::SPORK, signerSporkPair.second));
connman.PushMessage(&peer, CNetMsgMaker(peer.GetSendVersion()).Make(NetMsgType::SPORK, signerSporkPair.second));
}
}
}

View File

@ -232,7 +232,7 @@ public:
/**
* ProcessSporkMessages is used to call ProcessSpork and ProcessGetSporks. See below
*/
void ProcessSporkMessages(CNode* pfrom, std::string_view msg_type, CDataStream& vRecv, CConnman& connman);
void ProcessSporkMessages(CNode& peer, std::string_view msg_type, CDataStream& vRecv, CConnman& connman);
/**
* ProcessSpork is used to handle the 'spork' p2p message.
@ -240,7 +240,7 @@ public:
* For 'spork', it validates the spork and adds it to the internal spork storage and
* performs any necessary processing.
*/
void ProcessSpork(const CNode* pfrom, std::string_view msg_type, CDataStream& vRecv, CConnman& connman) LOCKS_EXCLUDED(cs);
void ProcessSpork(const CNode& peer, CDataStream& vRecv, CConnman& connman) LOCKS_EXCLUDED(cs);
/**
@ -248,7 +248,7 @@ public:
*
* For 'getsporks', it sends active sporks to the requesting peer.
*/
void ProcessGetSporks(CNode* pfrom, std::string_view msg_type, CConnman& connman) LOCKS_EXCLUDED(cs);
void ProcessGetSporks(CNode& peer, CConnman& connman) LOCKS_EXCLUDED(cs);
/**
* UpdateSpork is used by the spork RPC command to set a new spork value, sign