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
4 changes: 2 additions & 2 deletions src/activemasternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void CActiveMasternode::ManageStatus()

if(GetMasterNodeVin(vin, pubKeyCollateralAddress, keyCollateralAddress)) {

if(GetInputAge(vin) < GetMasternodeConfirmationsRequired()){
if(GetInputAge(vin) < Params().GetConsensus().nMasternodeMinimumConfirmations){
status = ACTIVE_MASTERNODE_INPUT_TOO_NEW;
notCapableReason = strprintf("%s - %d confirmations", GetStatus(), GetInputAge(vin));
LogPrintf("CActiveMasternode::ManageStatus() - %s\n", notCapableReason);
Expand Down Expand Up @@ -153,7 +153,7 @@ std::string CActiveMasternode::GetStatus() {
switch (status) {
case ACTIVE_MASTERNODE_INITIAL: return "Node just started, not yet activated";
case ACTIVE_MASTERNODE_SYNC_IN_PROCESS: return "Sync in progress. Must wait until sync is complete to start Masternode";
case ACTIVE_MASTERNODE_INPUT_TOO_NEW: return strprintf("Masternode input must have at least %d confirmations", GetMasternodeConfirmationsRequired());
case ACTIVE_MASTERNODE_INPUT_TOO_NEW: return strprintf("Masternode input must have at least %d confirmations", Params().GetConsensus().nMasternodeMinimumConfirmations);
case ACTIVE_MASTERNODE_NOT_CAPABLE: return "Not capable masternode: " + notCapableReason;
case ACTIVE_MASTERNODE_STARTED: return "Masternode successfully started";
default: return "unknown";
Expand Down
3 changes: 3 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class CMainParams : public CChainParams {
consensus.nBudgetPaymentsCycleBlocks = 16616; // ~(60*24*30)/2.6, actual number of blocks per month is 200700 / 12 = 16725
consensus.nBudgetPaymentsWindowBlocks = 100;
consensus.nBudgetProposalEstablishingTime = 60*60*24;
consensus.nMasternodeMinimumConfirmations = 15;
consensus.nMajorityEnforceBlockUpgrade = 750;
consensus.nMajorityRejectBlockOutdated = 950;
consensus.nMajorityWindow = 1000;
Expand Down Expand Up @@ -184,6 +185,7 @@ class CTestNetParams : public CChainParams {
consensus.nBudgetPaymentsCycleBlocks = 50;
consensus.nBudgetPaymentsWindowBlocks = 10;
consensus.nBudgetProposalEstablishingTime = 60*20;
consensus.nMasternodeMinimumConfirmations = 1;
consensus.nMajorityEnforceBlockUpgrade = 51;
consensus.nMajorityRejectBlockOutdated = 75;
consensus.nMajorityWindow = 100;
Expand Down Expand Up @@ -273,6 +275,7 @@ class CRegTestParams : public CChainParams {
consensus.nBudgetPaymentsCycleBlocks = 50;
consensus.nBudgetPaymentsWindowBlocks = 100;
consensus.nBudgetProposalEstablishingTime = 60*20;
consensus.nMasternodeMinimumConfirmations = 1;
consensus.nMajorityEnforceBlockUpgrade = 750;
consensus.nMajorityRejectBlockOutdated = 950;
consensus.nMajorityWindow = 1000;
Expand Down
1 change: 1 addition & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct Params {
int nBudgetPaymentsCycleBlocks;
int nBudgetPaymentsWindowBlocks;
int nBudgetProposalEstablishingTime; // in seconds
int nMasternodeMinimumConfirmations;
/** Used to check majorities for block version upgrade */
int nMajorityEnforceBlockUpgrade;
int nMajorityRejectBlockOutdated;
Expand Down
33 changes: 18 additions & 15 deletions src/flat-database.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,22 +201,25 @@ class CFlatDB
int64_t nStart = GetTimeMillis();

LogPrintf("Verifying %s format...\n", strFilename);
ReadResult readResult = Read(objToSave, true);

// there was an error and it was not an error on file opening => do not proceed
if (readResult == FileError)
LogPrintf("Missing file - %s, will try to recreate\n", strFilename);
else if (readResult != Ok)
{
LogPrintf("Error reading %s: ", strFilename);
if(readResult == IncorrectFormat)
LogPrintf("magic is ok but data has invalid format, will try to recreate\n");
else
{
LogPrintf("file format is unknown or invalid, please fix it manually\n");
return false;
}
}
// 12.1 -- pls fix -- causing corruption of the dat files ---

// ReadResult readResult = Read(objToSave, true);

// // there was an error and it was not an error on file opening => do not proceed
// if (readResult == FileError)
// LogPrintf("Missing file - %s, will try to recreate\n", strFilename);
// else if (readResult != Ok)
// {
// LogPrintf("Error reading %s: ", strFilename);
// if(readResult == IncorrectFormat)
// LogPrintf("magic is ok but data has invalid format, will try to recreate\n");
// else
// {
// LogPrintf("file format is unknown or invalid, please fix it manually\n");
// return false;
// }
// }

LogPrintf("Writting info to %s...\n", strFilename);
Write(objToSave);
Expand Down
107 changes: 34 additions & 73 deletions src/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,24 +513,25 @@ bool CGovernanceManager::AddOrUpdateVote(CBudgetVote& vote, std::string& strErro
{
LOCK(cs);

// uint256 hash = vote.vinMasternode.prevout.GetHash();
// uint256 hash2 = vote.nParentHash;
// store newest vote per action
arith_uint256 a = UintToArith256(vote.nParentHash) + vote.nVoteAction;
uint256 hash2 = ArithToUint256(a);

// if(mapVotes[hash2].count(hash))
// {
// if(mapVotes[hash2][hash].nTime > vote.nTime){
// strError = strprintf("new vote older than existing vote - %s", vote.GetHash().ToString());
// LogPrint("mngovernance", "CGovernanceObject::AddOrUpdateVote - %s\n", strError);
// return false;
// }
// if(vote.nTime - mapVotes[hash2][hash].nTime < BUDGET_VOTE_UPDATE_MIN){
// strError = strprintf("time between votes is too soon - %s - %lli", vote.GetHash().ToString(), vote.nTime - mapVotes[hash2][hash].nTime);
// LogPrint("mngovernance", "CGovernanceObject::AddOrUpdateVote - %s\n", strError);
// return false;
// }
// }
if(mapVotes.count(hash2))
{
if(mapVotes[hash2].nTime > vote.nTime){
strError = strprintf("new vote older than existing vote - %s", vote.GetHash().ToString());
LogPrint("mngovernance", "CGovernanceObject::AddOrUpdateVote - %s\n", strError);
return false;
}
if(vote.nTime - mapVotes[hash2].nTime < BUDGET_VOTE_UPDATE_MIN){
strError = strprintf("time between votes is too soon - %s - %lli", vote.GetHash().ToString(), vote.nTime - mapVotes[hash2].nTime);
LogPrint("mngovernance", "CGovernanceObject::AddOrUpdateVote - %s\n", strError);
return false;
}
}

// mapVotes[hash2][hash] = vote;
mapVotes[hash2] = vote;
return true;
}

Expand Down Expand Up @@ -614,26 +615,6 @@ bool CGovernanceObject::IsValid(const CBlockIndex* pindex, std::string& strError
return false;
}

// if(address == CScript()) {
// strError = "Invalid proposal Payment Address";
// return false;
// }

// 12.1 - add valid predicates
// this can be handled by configuration
// found = false
// if strName[:10] = "proposal="; found = true;
// if strName[:10] = "contract="; found = true;
// if strName[:10] = "project="; found = true;
// if strName[:10] = "employee="; found = true;
// if strName[:10] = "project-milestone="; found = true;
// if strName[:10] = "project-report="; found = true;

// if not found: return false

// automatically expire
// if(GetTime() > nExpirationTime) return false;

if(fCheckCollateral){
int nConf = 0;
if(!IsCollateralValid(nFeeTXHash, GetHash(), strError, nTime, nConf, GOVERNANCE_FEE_TX)){
Expand All @@ -660,29 +641,6 @@ bool CGovernanceObject::IsValid(const CBlockIndex* pindex, std::string& strError
return true;
}

bool CGovernanceObject::NetworkWillPay()
{
/**
* vote nVoteType 1 to 10
* --------------------------
*
*
* // note: if the vote is not passing and we're before the starttime, it's invalid
* // note: plain english version - if funding votes nocount > funding votes yescount and GetTime() < nStartTime: return false
* if votecount(VOTE_TYPE_FUNDING, "no") > votecount(VOTE_TYPE_FUNDING, "yes") && GetTime() < nStartTime: return false
*/

std::string strError = "";

// -- If GetAbsoluteYesCount is more than -10% of the network, flag as invalid
// if(GetAbsoluteYesCount() < -(mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/10)) {
// strError = "Voted Down";
// return false;
// }

return true;
}

void CGovernanceObject::CleanAndRemove(bool fSignatureCheck) {
// TODO: do smth here
}
Expand All @@ -695,17 +653,17 @@ void CGovernanceManager::CleanAndRemove(bool fSignatureCheck)
*
*/

std::map<uint256, CBudgetVote>::iterator it2 = mapVotes.begin();
while(it2 != mapVotes.end()){
if(!(*it2).second.IsValid(fSignatureCheck))
{
// 12.1 - log to specialized handle (govobj?)
LogPrintf("CGovernanceManager::CleanAndRemove - Proposal/Budget is known, activating and removing orphan vote\n");
mapVotes.erase(it2++);
} else {
++it2;
}
}
// std::map<uint256, CBudgetVote>::iterator it2 = mapVotes.begin();
// while(it2 != mapVotes.end()){
// if(!(*it2).second.IsValid(fSignatureCheck))
// {
// // 12.1 - log to specialized handle (govobj?)
// LogPrintf("CGovernanceManager::CleanAndRemove - Proposal/Budget is known, activating and removing orphan vote\n");
// mapVotes.erase(it2++);
// } else {
// ++it2;
// }
// }
}

/**
Expand Down Expand Up @@ -742,9 +700,10 @@ std::string CGovernanceManager::ToString() const
{
std::ostringstream info;

info << "Proposals: " << (int)mapObjects.size() <<
info << "Governance Objects: " << (int)mapObjects.size() <<
", Seen Budgets: " << (int)mapSeenMasternodeBudgetProposals.size() <<
", Seen Budget Votes: " << (int)mapSeenMasternodeBudgetVotes.size();
", Seen Budget Votes: " << (int)mapSeenMasternodeBudgetVotes.size() <<
", Vote Count: " << (int)mapVotes.size();

return info.str();
}
Expand All @@ -770,9 +729,11 @@ int CGovernanceManager::CountMatchingAbsoluteVotes(int nVoteActionIn, int nVoteO

std::map<uint256, CBudgetVote>::iterator it2 = mapVotes.begin();
while(it2 != mapVotes.end()){
if(!(*it2).second.IsValid(true) && (*it2).second.nVoteAction == nVoteActionIn)
//if(!(*it2).second.IsValid(true) && (*it2).second.nVoteAction == nVoteActionIn)
if((*it2).second.IsValid(true) && (*it2).second.nVoteAction == nVoteActionIn)
{
nCount += ((*it2).second.nVoteOutcome == nVoteOutcomeIn ? 1 : 0);
++it2;
} else {
++it2;
}
Expand Down
3 changes: 1 addition & 2 deletions src/governance.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ class CGovernanceManager

// todo - 12.1 - move to private for better encapsulation
std::map<uint256, int> mapSeenMasternodeBudgetProposals;
std::map<uint256, CBudgetVote> mapOrphanMasternodeBudgetVotes;
std::map<uint256, int> mapSeenMasternodeBudgetVotes;
std::map<uint256, CBudgetVote> mapOrphanMasternodeBudgetVotes;
std::map<uint256, CBudgetVote> mapVotes;

CGovernanceManager() {
Expand Down Expand Up @@ -248,7 +248,6 @@ class CGovernanceObject

bool HasMinimumRequiredSupport();
bool IsValid(const CBlockIndex* pindex, std::string& strError, bool fCheckCollateral=true);
bool NetworkWillPay();

std::string GetName() {return strName; }

Expand Down
4 changes: 4 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ void Interrupt(boost::thread_group& threadGroup)
/** Preparing steps before shutting down or restarting the wallet */
void PrepareShutdown()
{
LogPrintf("1 %s\n", governance.ToString());

fRequestShutdown = true; // Needed when we shutdown the wallet
fRestartRequested = true; // Needed when we restart the wallet
LogPrintf("%s: In progress...\n", __func__);
Expand All @@ -199,6 +201,8 @@ void PrepareShutdown()
if (!lockShutdown)
return;

LogPrintf("2 %s\n", governance.ToString());

/// Note: Shutdown() must be able to handle cases in which AppInit2() failed part of the way,
/// for example if the data directory was found to be locked.
/// Be sure that anything that writes files or flushes caches only does this if the respective
Expand Down
10 changes: 5 additions & 5 deletions src/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,16 +487,16 @@ bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDos)

LogPrint("masternode", "CMasternodeBroadcast::CheckInputsAndAdd - Accepted Masternode entry\n");

if(GetInputAge(vin) < GetMasternodeConfirmationsRequired()){
LogPrintf("CMasternodeBroadcast::CheckInputsAndAdd - Input must have at least %d confirmations\n", GetMasternodeConfirmationsRequired());
if(GetInputAge(vin) < Params().GetConsensus().nMasternodeMinimumConfirmations){
LogPrintf("CMasternodeBroadcast::CheckInputsAndAdd - Input must have at least %d confirmations\n", Params().GetConsensus().nMasternodeMinimumConfirmations);
// maybe we miss few blocks, let this mnb to be checked again later
mnodeman.mapSeenMasternodeBroadcast.erase(GetHash());
masternodeSync.mapSeenSyncMNB.erase(GetHash());
return false;
}

// verify that sig time is legit in past
// should be at least not earlier than block when 1000 DASH tx got GetMasternodeConfirmationsRequired()
// should be at least not earlier than block when 1000 DASH tx got nMasternodeMinimumConfirmations
uint256 hashBlock = uint256();
CTransaction tx2;
GetTransaction(vin.prevout.hash, tx2, Params().GetConsensus(), hashBlock, true);
Expand All @@ -506,11 +506,11 @@ bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDos)
if (mi != mapBlockIndex.end() && (*mi).second)
{
CBlockIndex* pMNIndex = (*mi).second; // block for 1000 DASH tx -> 1 confirmation
CBlockIndex* pConfIndex = chainActive[pMNIndex->nHeight + GetMasternodeConfirmationsRequired() - 1]; // block where tx got GetMasternodeConfirmationsRequired()
CBlockIndex* pConfIndex = chainActive[pMNIndex->nHeight + Params().GetConsensus().nMasternodeMinimumConfirmations - 1]; // block where tx got nMasternodeMinimumConfirmations
if(pConfIndex->GetBlockTime() > sigTime)
{
LogPrintf("CMasternodeBroadcast::CheckInputsAndAdd - Bad sigTime %d for Masternode %20s %105s (%i conf block is at %d)\n",
sigTime, addr.ToString(), vin.ToString(), GetMasternodeConfirmationsRequired(), pConfIndex->GetBlockTime());
sigTime, addr.ToString(), vin.ToString(), Params().GetConsensus().nMasternodeMinimumConfirmations, pConfIndex->GetBlockTime());
return false;
}
}
Expand Down
11 changes: 0 additions & 11 deletions src/masternode.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#include "main.h"
#include "timedata.h"

#define MASTERNODE_MIN_CONFIRMATIONS_TEST 1
#define MASTERNODE_MIN_CONFIRMATIONS_MAIN 15
#define MASTERNODE_MIN_MNP_SECONDS (10*60)
#define MASTERNODE_MIN_MNB_SECONDS (5*60)
#define MASTERNODE_PING_SECONDS (5*60)
Expand All @@ -31,15 +29,6 @@ extern map<int64_t, uint256> mapCacheBlockHashes;

bool GetBlockHash(uint256& hash, int nBlockHeight);

int GetMasternodeConfirmationsRequired()
{
if(Params().NetworkIDString() == CBaseChainParams::MAIN)
return MASTERNODE_MIN_CONFIRMATIONS_MAIN;
else
return MASTERNODE_MIN_CONFIRMATIONS_TEST;
}


//
// The Masternode Ping Class : Contains a different serialize method for sending pings from masternodes throughout the network
//
Expand Down
1 change: 0 additions & 1 deletion src/masternodeconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class CMasternodeConfig
void add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex);

std::vector<CMasternodeEntry>& getEntries() {
printf("%d\n", (int)entries.size());
return entries;
}

Expand Down