Skip to content

Commit

Permalink
Merge pull request #3305 from PastaPastaPasta/backport-11363
Browse files Browse the repository at this point in the history
Backport P2P refactor
  • Loading branch information
UdjinM6 authored Jan 31, 2020
2 parents 015a2a2 + 5cc46c3 commit 3bcf23f
Show file tree
Hide file tree
Showing 26 changed files with 367 additions and 406 deletions.
8 changes: 4 additions & 4 deletions src/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ int CAddrMan::Check_()
std::set<int> setTried;
std::map<int, int> mapNew;

if (vRandom.size() != nTried + nNew)
if (vRandom.size() != (size_t)(nTried + nNew))
return -7;

for (std::map<int, CAddrInfo>::iterator it = mapInfo.begin(); it != mapInfo.end(); it++) {
Expand All @@ -425,17 +425,17 @@ int CAddrMan::Check_()
}
if (mapAddr[info] != n)
return -5;
if (info.nRandomPos < 0 || info.nRandomPos >= vRandom.size() || vRandom[info.nRandomPos] != n)
if (info.nRandomPos < 0 || (size_t)info.nRandomPos >= vRandom.size() || vRandom[info.nRandomPos] != n)
return -14;
if (info.nLastTry < 0)
return -6;
if (info.nLastSuccess < 0)
return -8;
}

if (setTried.size() != nTried)
if (setTried.size() != (size_t)nTried)
return -9;
if (mapNew.size() != nNew)
if (mapNew.size() != (size_t)nNew)
return -10;

for (int n = 0; n < ADDRMAN_TRIED_BUCKET_COUNT; n++) {
Expand Down
11 changes: 8 additions & 3 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,13 @@ class CMainParams : public CChainParams {
assert(consensus.hashGenesisBlock == uint256S("0x00000ffd590b1485b3caadc19b22e6379c733355108f107a430458cdf3407ab6"));
assert(genesis.hashMerkleRoot == uint256S("0xe0028eb9648db56b1ac77cf090b99048a8007e2bb64b68f092c03c7f56a662c7"));

vSeeds.emplace_back("dnsseed.dash.org", true);
vSeeds.emplace_back("dnsseed.dashdot.io", true);
// Note that of those which support the service bits prefix, most only support a subset of
// possible options.
// This is fine at runtime as we'll fall back to using them as a oneshot if they dont support the
// service bits we want, but we should get them updated to support all service bits wanted by any
// release ASAP to avoid it where possible.
vSeeds.emplace_back("dnsseed.dash.org");
vSeeds.emplace_back("dnsseed.dashdot.io");

// Dash addresses start with 'X'
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,76);
Expand Down Expand Up @@ -510,7 +515,7 @@ class CTestNetParams : public CChainParams {

vSeeds.clear();
// nodes with support for servicebits filtering should be at the top
vSeeds.emplace_back("testnet-seed.dashdot.io", true);
vSeeds.emplace_back("testnet-seed.dashdot.io"); // Just a static list of stable node(s), only supports x9

// Testnet Dash addresses start with 'y'
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,140);
Expand Down
11 changes: 3 additions & 8 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
#include <memory>
#include <vector>

struct CDNSSeedData {
std::string host;
bool supportsServiceBitsFiltering;
CDNSSeedData(const std::string &strHost, bool supportsServiceBitsFilteringIn) : host(strHost), supportsServiceBitsFiltering(supportsServiceBitsFilteringIn) {}
};

struct SeedSpec6 {
uint8_t addr[16];
uint16_t port;
Expand Down Expand Up @@ -78,7 +72,8 @@ class CChainParams
bool AllowMultiplePorts() const { return fAllowMultiplePorts; }
/** Return the BIP70 network string (main, test or regtest) */
std::string NetworkIDString() const { return strNetworkID; }
const std::vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; }
/** Return the list of hostnames to look up for DNS seeds */
const std::vector<std::string>& DNSSeeds() const { return vSeeds; }
const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
int ExtCoinType() const { return nExtCoinType; }
const std::vector<SeedSpec6>& FixedSeeds() const { return vFixedSeeds; }
Expand All @@ -103,7 +98,7 @@ class CChainParams
CMessageHeader::MessageStartChars pchMessageStart;
int nDefaultPort;
uint64_t nPruneAfterHeight;
std::vector<CDNSSeedData> vSeeds;
std::vector<std::string> vSeeds;
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
int nExtCoinType;
std::string strNetworkID;
Expand Down
6 changes: 6 additions & 0 deletions src/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ typedef unsigned int SOCKET;
size_t strnlen( const char *start, size_t max_len);
#endif // HAVE_DECL_STRNLEN

#ifndef WIN32
typedef void* sockopt_arg_type;
#else
typedef char* sockopt_arg_type;
#endif

bool static inline IsSelectableSocket(const SOCKET& s) {
#ifdef WIN32
return true;
Expand Down
5 changes: 1 addition & 4 deletions src/dashd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,9 @@

void WaitForShutdown(boost::thread_group* threadGroup)
{
bool fShutdown = ShutdownRequested();
// Tell the main threads to shutdown.
while (!fShutdown)
while (!ShutdownRequested())
{
MilliSleep(200);
fShutdown = ShutdownRequested();
}
if (threadGroup)
{
Expand Down
14 changes: 10 additions & 4 deletions src/evo/mnauth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,19 @@ void CMNAuth::ProcessMessage(CNode* pnode, const std::string& strCommand, CDataS
}
if (fAlreadyHaveMNAUTH) {
LOCK(cs_main);
Misbehaving(pnode->GetId(), 100);
Misbehaving(pnode->GetId(), 100, "duplicate mnauth");
return;
}

if (mnauth.proRegTxHash.IsNull()) {
LOCK(cs_main);
Misbehaving(pnode->GetId(), 100, "empty mnauth proRegTxHash");
return;
}

if (mnauth.proRegTxHash.IsNull() || !mnauth.sig.IsValid()) {
LOCK(cs_main);
Misbehaving(pnode->GetId(), 100);
Misbehaving(pnode->GetId(), 100, "invalid mnauth signature");
return;
}

Expand All @@ -80,7 +86,7 @@ void CMNAuth::ProcessMessage(CNode* pnode, const std::string& strCommand, CDataS
// in case he was unlucky and not up to date, just let him be connected as a regular node, which gives him
// a chance to get up-to-date and thus realize by himself that he's not a MN anymore. We still give him a
// low DoS score.
Misbehaving(pnode->GetId(), 10);
Misbehaving(pnode->GetId(), 10, "missing mnauth masternode");
return;
}

Expand All @@ -95,7 +101,7 @@ void CMNAuth::ProcessMessage(CNode* pnode, const std::string& strCommand, CDataS
LOCK(cs_main);
// Same as above, MN seems to not know about his fate yet, so give him a chance to update. If this is a
// malicious actor (DoSing us), we'll ban him soon.
Misbehaving(pnode->GetId(), 10);
Misbehaving(pnode->GetId(), 10, "mnauth signature verification failed");
return;
}

Expand Down
24 changes: 12 additions & 12 deletions src/governance/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, const std::string& strComm
LogPrint(BCLog::GOBJECT, "MNGOVERNANCEOBJECT -- Received object: %s\n", strHash);

if (!AcceptObjectMessage(nHash)) {
LogPrintf("MNGOVERNANCEOBJECT -- Received unrequested object: %s\n", strHash);
LogPrint(BCLog::GOBJECT, "MNGOVERNANCEOBJECT -- Received unrequested object: %s\n", strHash);
return;
}

Expand All @@ -168,7 +168,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, const std::string& strComm

bool fRateCheckBypassed = false;
if (!MasternodeRateCheck(govobj, true, false, fRateCheckBypassed)) {
LogPrintf("MNGOVERNANCEOBJECT -- masternode rate check failed - %s - (current block height %d) \n", strHash, nCachedBlockHeight);
LogPrint(BCLog::GOBJECT, "MNGOVERNANCEOBJECT -- masternode rate check failed - %s - (current block height %d) \n", strHash, nCachedBlockHeight);
return;
}

Expand All @@ -180,7 +180,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, const std::string& strComm

if (fRateCheckBypassed && fIsValid) {
if (!MasternodeRateCheck(govobj, true)) {
LogPrintf("MNGOVERNANCEOBJECT -- masternode rate check failed (after signature verification) - %s - (current block height %d)\n", strHash, nCachedBlockHeight);
LogPrint(BCLog::GOBJECT, "MNGOVERNANCEOBJECT -- masternode rate check failed (after signature verification) - %s - (current block height %d)\n", strHash, nCachedBlockHeight);
return;
}
}
Expand All @@ -190,7 +190,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, const std::string& strComm
AddPostponedObject(govobj);
LogPrintf("MNGOVERNANCEOBJECT -- Not enough fee confirmations for: %s, strError = %s\n", strHash, strError);
} else {
LogPrintf("MNGOVERNANCEOBJECT -- Governance object is invalid - %s\n", strError);
LogPrint(BCLog::GOBJECT, "MNGOVERNANCEOBJECT -- Governance object is invalid - %s\n", strError);
// apply node's ban score
Misbehaving(pfrom->GetId(), 20);
}
Expand Down Expand Up @@ -292,7 +292,7 @@ void CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj, CConnman
// MAKE SURE THIS OBJECT IS OK

if (!govobj.IsValidLocally(strError, true)) {
LogPrintf("CGovernanceManager::AddGovernanceObject -- invalid governance object - %s - (nCachedBlockHeight %d) \n", strError, nCachedBlockHeight);
LogPrint(BCLog::GOBJECT, "CGovernanceManager::AddGovernanceObject -- invalid governance object - %s - (nCachedBlockHeight %d) \n", strError, nCachedBlockHeight);
return;
}

Expand All @@ -303,7 +303,7 @@ void CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj, CConnman
auto objpair = mapObjects.emplace(nHash, govobj);

if (!objpair.second) {
LogPrintf("CGovernanceManager::AddGovernanceObject -- already have governance object %s\n", nHash.ToString());
LogPrint(BCLog::GOBJECT, "CGovernanceManager::AddGovernanceObject -- already have governance object %s\n", nHash.ToString());
return;
}

Expand Down Expand Up @@ -747,13 +747,13 @@ bool CGovernanceManager::MasternodeRateCheck(const CGovernanceObject& govobj, bo
std::string strHash = govobj.GetHash().ToString();

if (nTimestamp < nNow - 2 * nSuperblockCycleSeconds) {
LogPrintf("CGovernanceManager::MasternodeRateCheck -- object %s rejected due to too old timestamp, masternode = %s, timestamp = %d, current time = %d\n",
LogPrint(BCLog::GOBJECT, "CGovernanceManager::MasternodeRateCheck -- object %s rejected due to too old timestamp, masternode = %s, timestamp = %d, current time = %d\n",
strHash, masternodeOutpoint.ToStringShort(), nTimestamp, nNow);
return false;
}

if (nTimestamp > nNow + MAX_TIME_FUTURE_DEVIATION) {
LogPrintf("CGovernanceManager::MasternodeRateCheck -- object %s rejected due to too new (future) timestamp, masternode = %s, timestamp = %d, current time = %d\n",
LogPrint(BCLog::GOBJECT, "CGovernanceManager::MasternodeRateCheck -- object %s rejected due to too new (future) timestamp, masternode = %s, timestamp = %d, current time = %d\n",
strHash, masternodeOutpoint.ToStringShort(), nTimestamp, nNow);
return false;
}
Expand All @@ -779,7 +779,7 @@ bool CGovernanceManager::MasternodeRateCheck(const CGovernanceObject& govobj, bo
return true;
}

LogPrintf("CGovernanceManager::MasternodeRateCheck -- Rate too high: object hash = %s, masternode = %s, object timestamp = %d, rate = %f, max rate = %f\n",
LogPrint(BCLog::GOBJECT, "CGovernanceManager::MasternodeRateCheck -- Rate too high: object hash = %s, masternode = %s, object timestamp = %d, rate = %f, max rate = %f\n",
strHash, masternodeOutpoint.ToStringShort(), nTimestamp, dRate, dMaxRate);

if (fUpdateFailStatus) {
Expand All @@ -806,7 +806,7 @@ bool CGovernanceManager::ProcessVote(CNode* pfrom, const CGovernanceVote& vote,
ostr << "CGovernanceManager::ProcessVote -- Old invalid vote "
<< ", MN outpoint = " << vote.GetMasternodeOutpoint().ToStringShort()
<< ", governance object hash = " << nHashGovobj.ToString();
LogPrintf("%s\n", ostr.str());
LogPrint(BCLog::GOBJECT, "%s\n", ostr.str());
exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_PERMANENT_ERROR, 20);
LEAVE_CRITICAL_SECTION(cs);
return false;
Expand All @@ -821,7 +821,7 @@ bool CGovernanceManager::ProcessVote(CNode* pfrom, const CGovernanceVote& vote,
if (cmmapOrphanVotes.Insert(nHashGovobj, vote_time_pair_t(vote, GetAdjustedTime() + GOVERNANCE_ORPHAN_EXPIRATION_TIME))) {
LEAVE_CRITICAL_SECTION(cs);
RequestGovernanceObject(pfrom, nHashGovobj, connman);
LogPrintf("%s\n", ostr.str());
LogPrint(BCLog::GOBJECT, "%s\n", ostr.str());
return false;
}

Expand Down Expand Up @@ -862,7 +862,7 @@ void CGovernanceManager::CheckPostponedObjects(CConnman& connman)
if (govobj.IsValidLocally(strError, false)) {
AddGovernanceObject(govobj, connman);
} else {
LogPrintf("CGovernanceManager::CheckPostponedObjects -- %s invalid\n", nHash.ToString());
LogPrint(BCLog::GOBJECT, "CGovernanceManager::CheckPostponedObjects -- %s invalid\n", nHash.ToString());
}

} else if (fMissingConfirmations) {
Expand Down
12 changes: 6 additions & 6 deletions src/llmq/quorums_blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ void CQuorumBlockProcessor::ProcessMessage(CNode* pfrom, const std::string& strC

if (qc.IsNull()) {
LOCK(cs_main);
LogPrintf("CQuorumBlockProcessor::%s -- null commitment from peer=%d\n", __func__, pfrom->GetId());
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- null commitment from peer=%d\n", __func__, pfrom->GetId());
Misbehaving(pfrom->GetId(), 100);
return;
}

if (!Params().GetConsensus().llmqs.count((Consensus::LLMQType)qc.llmqType)) {
LOCK(cs_main);
LogPrintf("llmq""CQuorumBlockProcessor::%s -- invalid commitment type %d from peer=%d\n", __func__,
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- invalid commitment type %d from peer=%d\n", __func__,
qc.llmqType, pfrom->GetId());
Misbehaving(pfrom->GetId(), 100);
return;
Expand All @@ -61,22 +61,22 @@ void CQuorumBlockProcessor::ProcessMessage(CNode* pfrom, const std::string& strC
{
LOCK(cs_main);
if (!mapBlockIndex.count(qc.quorumHash)) {
LogPrintf("CQuorumBlockProcessor::%s -- unknown block %s in commitment, peer=%d\n", __func__,
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- unknown block %s in commitment, peer=%d\n", __func__,
qc.quorumHash.ToString(), pfrom->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;
}
pquorumIndex = mapBlockIndex[qc.quorumHash];
if (chainActive.Tip()->GetAncestor(pquorumIndex->nHeight) != pquorumIndex) {
LogPrintf("CQuorumBlockProcessor::%s -- block %s not in active chain, peer=%d\n", __func__,
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- block %s not in active chain, peer=%d\n", __func__,
qc.quorumHash.ToString(), pfrom->GetId());
// same, can't punish
return;
}
int quorumHeight = pquorumIndex->nHeight - (pquorumIndex->nHeight % params.dkgInterval);
if (quorumHeight != pquorumIndex->nHeight) {
LogPrintf("CQuorumBlockProcessor::%s -- block %s is not the first block in the DKG interval, peer=%d\n", __func__,
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);
return;
Expand All @@ -103,7 +103,7 @@ void CQuorumBlockProcessor::ProcessMessage(CNode* pfrom, const std::string& strC

if (!qc.Verify(members, true)) {
LOCK(cs_main);
LogPrintf("CQuorumBlockProcessor::%s -- commitment for quorum %s:%d is not valid, peer=%d\n", __func__,
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- commitment for quorum %s:%d is not valid, peer=%d\n", __func__,
qc.quorumHash.ToString(), qc.llmqType, pfrom->GetId());
Misbehaving(pfrom->GetId(), 100);
return;
Expand Down
2 changes: 1 addition & 1 deletion src/llmq/quorums_chainlocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void CChainLocksHandler::ProcessNewChainLock(NodeId from, const llmq::CChainLock
uint256 requestId = ::SerializeHash(std::make_pair(CLSIG_REQUESTID_PREFIX, clsig.nHeight));
uint256 msgHash = clsig.blockHash;
if (!quorumSigningManager->VerifyRecoveredSig(Params().GetConsensus().llmqTypeChainLocks, clsig.nHeight, requestId, msgHash, clsig.sig)) {
LogPrintf("CChainLocksHandler::%s -- invalid CLSIG (%s), peer=%d\n", __func__, clsig.ToString(), from);
LogPrint(BCLog::CHAINLOCKS, "CChainLocksHandler::%s -- invalid CLSIG (%s), peer=%d\n", __func__, clsig.ToString(), from);
if (from != -1) {
LOCK(cs_main);
Misbehaving(from, 10);
Expand Down
12 changes: 6 additions & 6 deletions src/llmq/quorums_dkgsessionhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void CDKGPendingMessages::PushPendingMessage(NodeId from, CDataStream& vRecv)

if (messagesPerNode[from] >= maxMessagesPerNode) {
// TODO ban?
LogPrintf("CDKGPendingMessages::%s -- too many messages, peer=%d\n", __func__, from);
LogPrint(BCLog::LLMQ_DKG, "CDKGPendingMessages::%s -- too many messages, peer=%d\n", __func__, from);
return;
}
messagesPerNode[from]++;
Expand Down Expand Up @@ -403,7 +403,7 @@ bool ProcessPendingMessageBatch(CDKGSession& session, CDKGPendingMessages& pendi

for (const auto& p : msgs) {
if (!p.second) {
LogPrintf("%s -- failed to deserialize message, peer=%d\n", __func__, p.first);
LogPrint(BCLog::LLMQ_DKG, "%s -- failed to deserialize message, peer=%d\n", __func__, p.first);
{
LOCK(cs_main);
Misbehaving(p.first, 100);
Expand All @@ -421,13 +421,13 @@ bool ProcessPendingMessageBatch(CDKGSession& session, CDKGPendingMessages& pendi
bool ban = false;
if (!session.PreVerifyMessage(hash, msg, ban)) {
if (ban) {
LogPrintf("%s -- banning node due to failed preverification, peer=%d\n", __func__, p.first);
LogPrint(BCLog::LLMQ_DKG, "%s -- banning node due to failed preverification, peer=%d\n", __func__, p.first);
{
LOCK(cs_main);
Misbehaving(p.first, 100);
}
}
LogPrintf("%s -- skipping message due to failed preverification, peer=%d\n", __func__, p.first);
LogPrint(BCLog::LLMQ_DKG, "%s -- skipping message due to failed preverification, peer=%d\n", __func__, p.first);
continue;
}
hashes.emplace_back(hash);
Expand All @@ -441,7 +441,7 @@ bool ProcessPendingMessageBatch(CDKGSession& session, CDKGPendingMessages& pendi
if (!badNodes.empty()) {
LOCK(cs_main);
for (auto nodeId : badNodes) {
LogPrintf("%s -- failed to verify signature, peer=%d\n", __func__, nodeId);
LogPrint(BCLog::LLMQ_DKG, "%s -- failed to verify signature, peer=%d\n", __func__, nodeId);
Misbehaving(nodeId, 100);
}
}
Expand All @@ -455,7 +455,7 @@ bool ProcessPendingMessageBatch(CDKGSession& session, CDKGPendingMessages& pendi
bool ban = false;
session.ReceiveMessage(hashes[i], msg, ban);
if (ban) {
LogPrintf("%s -- banning node after ReceiveMessage failed, peer=%d\n", __func__, nodeId);
LogPrint(BCLog::LLMQ_DKG, "%s -- banning node after ReceiveMessage failed, peer=%d\n", __func__, nodeId);
LOCK(cs_main);
Misbehaving(nodeId, 100);
badNodes.emplace(nodeId);
Expand Down
2 changes: 1 addition & 1 deletion src/llmq/quorums_instantsend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ std::unordered_set<uint256> CInstantSendManager::ProcessPendingInstantSendLocks(
auto& islock = p.second.second;

if (batchVerifier.badMessages.count(hash)) {
LogPrintf("CInstantSendManager::%s -- txid=%s, islock=%s: invalid sig in islock, peer=%d\n", __func__,
LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, islock=%s: invalid sig in islock, peer=%d\n", __func__,
islock.txid.ToString(), hash.ToString(), nodeId);
badISLocks.emplace(hash);
continue;
Expand Down
Loading

0 comments on commit 3bcf23f

Please sign in to comment.