Skip to content

Commit

Permalink
Fixed issues with propagation of governance objects (#1489)
Browse files Browse the repository at this point in the history
* process governance objects in CheckMasternodeOrphanObjects as usual

* code refactoring: SetRateChecksHelper class added

* fixed race condition issues with propagation of governance objects

* change GetCollateralConfirmations signature

* code refactoring

* reduced minimum number of collateral confirmations required for relaying proposals

* bug fixes and improvements
  • Loading branch information
the-schnibble authored and UdjinM6 committed Jul 5, 2017
1 parent d787fe4 commit 109c5fd
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 81 deletions.
32 changes: 19 additions & 13 deletions src/governance-object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,15 @@ void CGovernanceObject::UpdateLocalValidity()
bool CGovernanceObject::IsValidLocally(std::string& strError, bool fCheckCollateral)
{
bool fMissingMasternode = false;
bool fMissingConfirmations = false;

return IsValidLocally(strError, fMissingMasternode, fCheckCollateral);
return IsValidLocally(strError, fMissingMasternode, fMissingConfirmations, fCheckCollateral);
}

bool CGovernanceObject::IsValidLocally(std::string& strError, bool& fMissingMasternode, bool fCheckCollateral)
bool CGovernanceObject::IsValidLocally(std::string& strError, bool& fMissingMasternode, bool& fMissingConfirmations, bool fCheckCollateral)
{
fMissingMasternode = false;
fMissingConfirmations = false;

if(fUnparsable) {
strError = "Object data unparseable";
Expand Down Expand Up @@ -481,11 +483,8 @@ bool CGovernanceObject::IsValidLocally(std::string& strError, bool& fMissingMast
return true;
}

if(!IsCollateralValid(strError)) {
// strError set in IsCollateralValid
if(strError == "") strError = "Collateral is invalid";
if (!IsCollateralValid(strError, fMissingConfirmations))
return false;
}
}

/*
Expand Down Expand Up @@ -515,9 +514,10 @@ CAmount CGovernanceObject::GetMinCollateralFee()
}
}

bool CGovernanceObject::IsCollateralValid(std::string& strError)
bool CGovernanceObject::IsCollateralValid(std::string& strError, bool& fMissingConfirmations)
{
strError = "";
fMissingConfirmations = false;
CAmount nMinFee = GetMinCollateralFee();
uint256 nExpectedHash = GetHash();

Expand All @@ -543,7 +543,7 @@ bool CGovernanceObject::IsCollateralValid(std::string& strError)
CScript findScript;
findScript << OP_RETURN << ToByteVector(nExpectedHash);

DBG( cout << "IsCollateralValid txCollateral.vout.size() = " << txCollateral.vout.size() << endl; );
DBG( cout << "IsCollateralValid: txCollateral.vout.size() = " << txCollateral.vout.size() << endl; );

DBG( cout << "IsCollateralValid: findScript = " << ScriptToAsmStr( findScript, false ) << endl; );

Expand Down Expand Up @@ -591,14 +591,20 @@ bool CGovernanceObject::IsCollateralValid(std::string& strError)
}
}

if(nConfirmationsIn >= GOVERNANCE_FEE_CONFIRMATIONS) {
strError = "valid";
} else {
strError = strprintf("Collateral requires at least %d confirmations - %d confirmations", GOVERNANCE_FEE_CONFIRMATIONS, nConfirmationsIn);
LogPrintf ("CGovernanceObject::IsCollateralValid -- %s - %d confirmations\n", strError, nConfirmationsIn);
if(nConfirmationsIn < GOVERNANCE_FEE_CONFIRMATIONS) {
strError = strprintf("Collateral requires at least %d confirmations to be relayed throughout the network (it has only %d)", GOVERNANCE_FEE_CONFIRMATIONS, nConfirmationsIn);
if (nConfirmationsIn >= GOVERNANCE_MIN_RELAY_FEE_CONFIRMATIONS) {
fMissingConfirmations = true;
strError += ", pre-accepted -- waiting for required confirmations";
} else {
strError += ", rejected -- try again later";
}
LogPrintf ("CGovernanceObject::IsCollateralValid -- %s\n", strError);

return false;
}

strError = "valid";
return true;
}

Expand Down
5 changes: 3 additions & 2 deletions src/governance-object.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static const int GOVERNANCE_OBJECT_WATCHDOG = 3;
static const CAmount GOVERNANCE_PROPOSAL_FEE_TX = (5.0*COIN);

static const int64_t GOVERNANCE_FEE_CONFIRMATIONS = 6;
static const int64_t GOVERNANCE_MIN_RELAY_FEE_CONFIRMATIONS = 1;
static const int64_t GOVERNANCE_UPDATE_MIN = 60*60;
static const int64_t GOVERNANCE_DELETION_DELAY = 10*60;
static const int64_t GOVERNANCE_ORPHAN_EXPIRATION_TIME = 10*60;
Expand Down Expand Up @@ -263,10 +264,10 @@ class CGovernanceObject

bool IsValidLocally(std::string& strError, bool fCheckCollateral);

bool IsValidLocally(std::string& strError, bool& fMissingMasternode, bool fCheckCollateral);
bool IsValidLocally(std::string& strError, bool& fMissingMasternode, bool& fMissingConfirmations, bool fCheckCollateral);

/// Check the collateral transaction for the budget proposal/finalized budget
bool IsCollateralValid(std::string& strError);
bool IsCollateralValid(std::string& strError, bool &fMissingConfirmations);

void UpdateLocalValidity();

Expand Down
Loading

0 comments on commit 109c5fd

Please sign in to comment.