diff --git a/divi/src/MasternodeBroadcastFactory.cpp b/divi/src/MasternodeBroadcastFactory.cpp index fac4d3730..7207e8863 100644 --- a/divi/src/MasternodeBroadcastFactory.cpp +++ b/divi/src/MasternodeBroadcastFactory.cpp @@ -17,7 +17,10 @@ extern CChain chainActive; extern bool fReindex; extern bool fImporting; -bool CMasternodeBroadcastFactory::checkBlockchainSync(std::string& strErrorRet, bool fOffline) +namespace +{ + +bool checkBlockchainSync(std::string& strErrorRet, bool fOffline) { if (!fOffline && !IsBlockchainSynced()) { strErrorRet = "Sync in progress. Must wait until sync is complete to start Masternode"; @@ -26,7 +29,7 @@ bool CMasternodeBroadcastFactory::checkBlockchainSync(std::string& strErrorRet, } return true; } -bool CMasternodeBroadcastFactory::setMasternodeKeys( +bool setMasternodeKeys( const std::string& strKeyMasternode, std::pair& masternodeKeyPair, std::string& strErrorRet) @@ -38,7 +41,7 @@ bool CMasternodeBroadcastFactory::setMasternodeKeys( } return true; } -bool CMasternodeBroadcastFactory::setMasternodeCollateralKeys( +bool setMasternodeCollateralKeys( const std::string& txHash, const std::string& outputIndex, const std::string& service, @@ -63,7 +66,7 @@ bool CMasternodeBroadcastFactory::setMasternodeCollateralKeys( return true; } -bool CMasternodeBroadcastFactory::checkMasternodeCollateral( +bool checkMasternodeCollateral( const CTxIn& txin, const std::string& txHash, const std::string& outputIndex, @@ -95,7 +98,7 @@ bool CMasternodeBroadcastFactory::checkMasternodeCollateral( return true; } -bool CMasternodeBroadcastFactory::createArgumentsFromConfig( +bool createArgumentsFromConfig( const CMasternodeConfig::CMasternodeEntry configEntry, std::string& strErrorRet, bool fOffline, @@ -121,6 +124,8 @@ bool CMasternodeBroadcastFactory::createArgumentsFromConfig( return true; } +} // anonymous namespace + bool CMasternodeBroadcastFactory::Create( const CMasternodeConfig::CMasternodeEntry configEntry, CPubKey pubkeyCollateralAddress, @@ -278,10 +283,10 @@ CMasternodePing createDelayedMasternodePing(const CMasternodeBroadcast& mnb) } // anonymous namespace void CMasternodeBroadcastFactory::createWithoutSignatures( - CTxIn txin, - CService service, - CPubKey pubKeyCollateralAddressNew, - CPubKey pubKeyMasternodeNew, + const CTxIn& txin, + const CService& service, + const CPubKey& pubKeyCollateralAddressNew, + const CPubKey& pubKeyMasternodeNew, const MasternodeTier nMasternodeTier, bool deferRelay, CMasternodeBroadcast& mnbRet) @@ -299,12 +304,12 @@ void CMasternodeBroadcastFactory::createWithoutSignatures( } bool CMasternodeBroadcastFactory::Create( - CTxIn txin, - CService service, - CKey keyCollateralAddressNew, - CPubKey pubKeyCollateralAddressNew, - CKey keyMasternodeNew, - CPubKey pubKeyMasternodeNew, + const CTxIn& txin, + const CService& service, + const CKey& keyCollateralAddressNew, + const CPubKey& pubKeyCollateralAddressNew, + const CKey& keyMasternodeNew, + const CPubKey& pubKeyMasternodeNew, const MasternodeTier nMasternodeTier, std::string& strErrorRet, CMasternodeBroadcast& mnbRet, diff --git a/divi/src/MasternodeBroadcastFactory.h b/divi/src/MasternodeBroadcastFactory.h index e7edd478a..2f576f060 100644 --- a/divi/src/MasternodeBroadcastFactory.h +++ b/divi/src/MasternodeBroadcastFactory.h @@ -37,10 +37,10 @@ class CMasternodeBroadcastFactory std::string& strErrorRet); private: static void createWithoutSignatures( - CTxIn txin, - CService service, - CPubKey pubKeyCollateralAddressNew, - CPubKey pubKeyMasternodeNew, + const CTxIn& txin, + const CService& service, + const CPubKey& pubKeyCollateralAddressNew, + const CPubKey& pubKeyMasternodeNew, MasternodeTier nMasternodeTier, bool deferRelay, CMasternodeBroadcast& mnbRet); @@ -57,45 +57,15 @@ class CMasternodeBroadcastFactory CMasternodeBroadcast& mnb, std::string& strErrorRet); - static bool Create(CTxIn vin, - CService service, - CKey keyCollateralAddressNew, - CPubKey pubKeyCollateralAddressNew, - CKey keyMasternodeNew, - CPubKey pubKeyMasternodeNew, - MasternodeTier nMasternodeTier, - std::string& strErrorRet, - CMasternodeBroadcast& mnbRet, - bool deferRelay); - static bool checkBlockchainSync( - std::string& strErrorRet, bool fOffline); - static bool setMasternodeKeys( - const std::string& strKeyMasternode, - std::pair& masternodeKeyPair, - std::string& strErrorRet); - static bool setMasternodeCollateralKeys( - const std::string& txHash, - const std::string& outputIndex, - const std::string& service, - bool collateralPrivKeyIsRemote, - CTxIn& txin, - std::pair& masternodeCollateralKeyPair, - std::string& error); - static bool checkMasternodeCollateral( - const CTxIn& txin, - const std::string& txHash, - const std::string& outputIndex, - const std::string& service, - MasternodeTier& nMasternodeTier, - std::string& strErrorRet); - static bool createArgumentsFromConfig( - const CMasternodeConfig::CMasternodeEntry configEntry, - std::string& strErrorRet, - bool fOffline, - bool collateralPrivKeyIsRemote, - CTxIn& txin, - std::pair& masternodeKeyPair, - std::pair& masternodeCollateralKeyPair, - MasternodeTier& nMasternodeTier); + static bool Create(const CTxIn& vin, + const CService& service, + const CKey& keyCollateralAddressNew, + const CPubKey& pubKeyCollateralAddressNew, + const CKey& keyMasternodeNew, + const CPubKey& pubKeyMasternodeNew, + MasternodeTier nMasternodeTier, + std::string& strErrorRet, + CMasternodeBroadcast& mnbRet, + bool deferRelay); }; -#endif //MASTERNODE_BROADCAST_FACTORY_H \ No newline at end of file +#endif //MASTERNODE_BROADCAST_FACTORY_H diff --git a/divi/src/main.cpp b/divi/src/main.cpp index a66520311..717071c42 100755 --- a/divi/src/main.cpp +++ b/divi/src/main.cpp @@ -1202,7 +1202,10 @@ void Misbehaving(NodeId pnode, int howmuch) LogPrintf("Misbehaving: %s (%d -> %d)\n", state->name, state->nMisbehavior - howmuch, state->nMisbehavior); } -void static InvalidChainFound(CBlockIndex* pindexNew) +namespace +{ + +void InvalidChainFound(CBlockIndex* pindexNew) { if (!pindexBestInvalid || pindexNew->nChainWork > pindexBestInvalid->nChainWork) pindexBestInvalid = pindexNew; @@ -1217,7 +1220,7 @@ void static InvalidChainFound(CBlockIndex* pindexNew) CheckForkWarningConditions(); } -void static InvalidBlockFound(CBlockIndex* pindex, const CValidationState& state) +void InvalidBlockFound(CBlockIndex* pindex, const CValidationState& state) { int nDoS = 0; if (state.IsInvalid(nDoS)) { @@ -1237,7 +1240,7 @@ void static InvalidBlockFound(CBlockIndex* pindex, const CValidationState& state } } -void static FlushBlockFile(bool fFinalize = false) +void FlushBlockFile(bool fFinalize = false) { LOCK(cs_LastBlockFile); @@ -1260,9 +1263,35 @@ void static FlushBlockFile(bool fFinalize = false) } } -bool FindUndoPos(CValidationState& state, int nFile, CDiskBlockPos& pos, unsigned int nAddSize); +bool FindUndoPos(CValidationState& state, int nFile, CDiskBlockPos& pos, unsigned int nAddSize) +{ + pos.nFile = nFile; + + LOCK(cs_LastBlockFile); + + unsigned int nNewSize; + pos.nPos = vinfoBlockFile[nFile].nUndoSize; + nNewSize = vinfoBlockFile[nFile].nUndoSize += nAddSize; + setDirtyFileInfo.insert(nFile); + + unsigned int nOldChunks = (pos.nPos + UNDOFILE_CHUNK_SIZE - 1) / UNDOFILE_CHUNK_SIZE; + unsigned int nNewChunks = (nNewSize + UNDOFILE_CHUNK_SIZE - 1) / UNDOFILE_CHUNK_SIZE; + if (nNewChunks > nOldChunks) { + if (CheckDiskSpace(nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos)) { + FILE* file = OpenUndoFile(pos); + if (file) { + LogPrintf("Pre-allocating up to position 0x%x in rev%05u.dat\n", nNewChunks * UNDOFILE_CHUNK_SIZE, pos.nFile); + AllocateFileRange(file, pos.nPos, nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos); + fclose(file); + } + } else + return state.Error("out of disk space"); + } + + return true; +} -static int64_t nTimeTotal = 0; +int64_t nTimeTotal = 0; void VerifyBestBlockIsAtPreviousBlock(const CBlockIndex* pindex, CCoinsViewCache& view) { @@ -1391,6 +1420,8 @@ bool UpdateDBIndicesForNewBlock( return true; } +} // anonymous namespace + bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck, bool fAlreadyChecked) { AssertLockHeld(cs_main); @@ -2140,34 +2171,6 @@ bool FindBlockPos(CValidationState& state, CDiskBlockPos& pos, unsigned int nAdd return true; } -bool FindUndoPos(CValidationState& state, int nFile, CDiskBlockPos& pos, unsigned int nAddSize) -{ - pos.nFile = nFile; - - LOCK(cs_LastBlockFile); - - unsigned int nNewSize; - pos.nPos = vinfoBlockFile[nFile].nUndoSize; - nNewSize = vinfoBlockFile[nFile].nUndoSize += nAddSize; - setDirtyFileInfo.insert(nFile); - - unsigned int nOldChunks = (pos.nPos + UNDOFILE_CHUNK_SIZE - 1) / UNDOFILE_CHUNK_SIZE; - unsigned int nNewChunks = (nNewSize + UNDOFILE_CHUNK_SIZE - 1) / UNDOFILE_CHUNK_SIZE; - if (nNewChunks > nOldChunks) { - if (CheckDiskSpace(nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos)) { - FILE* file = OpenUndoFile(pos); - if (file) { - LogPrintf("Pre-allocating up to position 0x%x in rev%05u.dat\n", nNewChunks * UNDOFILE_CHUNK_SIZE, pos.nFile); - AllocateFileRange(file, pos.nPos, nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos); - fclose(file); - } - } else - return state.Error("out of disk space"); - } - - return true; -} - bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckMerkleRoot) { // These are checks that are independent of context. diff --git a/divi/src/masternode-sync.h b/divi/src/masternode-sync.h index 1ce4a3b33..c15d852e1 100644 --- a/divi/src/masternode-sync.h +++ b/divi/src/masternode-sync.h @@ -85,7 +85,7 @@ class CMasternodeSync bool MasternodeWinnersListIsSync(CNode* pnode, const int64_t now); void Process(bool networkIsRegtest); bool IsSynced() const; - bool IsMasternodeListSynced() { return RequestedMasternodeAssets > MASTERNODE_SYNC_LIST; } + bool IsMasternodeListSynced() const { return RequestedMasternodeAssets > MASTERNODE_SYNC_LIST; } void AskForMN(CNode* pnode, const CTxIn& vin) const; }; diff --git a/divi/src/masternode.cpp b/divi/src/masternode.cpp index d2391d2c2..cf457f42b 100644 --- a/divi/src/masternode.cpp +++ b/divi/src/masternode.cpp @@ -258,7 +258,10 @@ bool CMasternode::IsValidNetAddr() const (IsReachable(addr) && addr.IsRoutable()); } -CMasternodeBroadcast::CMasternodeBroadcast(CService newAddr, CTxIn newVin, CPubKey pubKeyCollateralAddressNew, CPubKey pubKeyMasternodeNew, const MasternodeTier nMasternodeTier, int protocolVersionIn) +CMasternodeBroadcast::CMasternodeBroadcast( + const CService& newAddr, const CTxIn& newVin, + const CPubKey& pubKeyCollateralAddressNew, const CPubKey& pubKeyMasternodeNew, + const MasternodeTier nMasternodeTier, const int protocolVersionIn) { vin = newVin; addr = newAddr; diff --git a/divi/src/masternode.h b/divi/src/masternode.h index f987234c1..b561097fc 100644 --- a/divi/src/masternode.h +++ b/divi/src/masternode.h @@ -146,15 +146,19 @@ class CMasternode class CMasternodeBroadcast : public CMasternode { -public: - CMasternodeBroadcast() = default; +private: CMasternodeBroadcast( - CService newAddr, - CTxIn newVin, - CPubKey pubKeyCollateralAddress, - CPubKey pubKeyMasternode, + const CService& newAddr, + const CTxIn& newVin, + const CPubKey& pubKeyCollateralAddress, + const CPubKey& pubKeyMasternode, MasternodeTier nMasternodeTier, int protocolVersionIn); + + friend class CMasternodeBroadcastFactory; + +public: + CMasternodeBroadcast() = default; CMasternodeBroadcast(const CMasternode& mn); void Relay() const; diff --git a/divi/src/masternodeconfig.cpp b/divi/src/masternodeconfig.cpp index 91b9debb9..c48f8304d 100644 --- a/divi/src/masternodeconfig.cpp +++ b/divi/src/masternodeconfig.cpp @@ -23,10 +23,11 @@ boost::filesystem::path GetMasternodeConfigFile() if (!pathConfigFile.is_complete()) pathConfigFile = GetDataDir() / pathConfigFile; return pathConfigFile; } -void CMasternodeConfig::add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex) + +void CMasternodeConfig::add(const std::string& alias, const std::string& ip, const std::string& privKey, + const std::string& txHash, const std::string& outputIndex) { - CMasternodeEntry cme(alias, ip, privKey, txHash, outputIndex); - entries.push_back(cme); + entries.emplace_back(alias, ip, privKey, txHash, outputIndex); } bool CMasternodeConfig::read(std::string& strErr) @@ -94,15 +95,16 @@ CMasternodeConfig::CMasternodeConfig() { entries = std::vector(); } + const std::vector& CMasternodeConfig::getEntries() const { return entries; } -int CMasternodeConfig::getCount() +int CMasternodeConfig::getCount() const { int c = -1; - BOOST_FOREACH (CMasternodeEntry e, entries) { + for (const auto& e : entries) { if (e.getAlias() != "") c++; } return c; diff --git a/divi/src/masternodeconfig.h b/divi/src/masternodeconfig.h index d5ac185d9..2d34edb4a 100644 --- a/divi/src/masternodeconfig.h +++ b/divi/src/masternodeconfig.h @@ -25,7 +25,9 @@ class CMasternodeConfig std::string outputIndex; public: - CMasternodeEntry(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex) + CMasternodeEntry(const std::string& alias, const std::string& ip, + const std::string& privKey, + const std::string& txHash, const std::string& outputIndex) { this->alias = alias; this->ip = ip; @@ -91,9 +93,10 @@ class CMasternodeConfig void clear(); bool read(std::string& strErr); - void add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex); + void add(const std::string& alias, const std::string& ip, const std::string& privKey, + const std::string& txHash, const std::string& outputIndex); const std::vector& getEntries() const; - int getCount(); + int getCount() const; private: std::vector entries;