V0.12.1.x govobj submission (#846)

* Remove nTime from IsCollateralValid and document function
This commit is contained in:
Evan Duffield 2016-05-31 13:00:01 -07:00 committed by Holger Schinzel
parent dad85d9c12
commit d0ad4ad0e4
2 changed files with 21 additions and 12 deletions

View File

@ -28,11 +28,15 @@ std::vector<CGovernanceObject> vecImmatureGovernanceObjects;
int nSubmittedFinalBudget; int nSubmittedFinalBudget;
bool IsCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::string& strError, int64_t nTime, int& nConf, CAmount minFee) bool IsCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::string& strError, int& nConf, CAmount minFee)
{ {
CTransaction txCollateral; CTransaction txCollateral;
uint256 nBlockHash; uint256 nBlockHash;
int64_t nTime;
// RETRIEVE TRANSACTION IN QUESTION
if(!GetTransaction(nTxCollateralHash, txCollateral, Params().GetConsensus(), nBlockHash, true)){ if(!GetTransaction(nTxCollateralHash, txCollateral, Params().GetConsensus(), nBlockHash, true)){
strError = strprintf("Can't find collateral tx %s", txCollateral.ToString()); strError = strprintf("Can't find collateral tx %s", txCollateral.ToString());
LogPrintf ("CGovernanceObject::IsCollateralValid - %s\n", strError); LogPrintf ("CGovernanceObject::IsCollateralValid - %s\n", strError);
@ -45,6 +49,8 @@ bool IsCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::st
return false; return false;
} }
// LOOK FOR SPECIALIZED GOVERNANCE SCRIPT (PROOF OF BURN)
CScript findScript; CScript findScript;
findScript << OP_RETURN << ToByteVector(nExpectedHash); findScript << OP_RETURN << ToByteVector(nExpectedHash);
@ -64,30 +70,33 @@ bool IsCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::st
return false; return false;
} }
// GET CONFIRMATIONS FOR TRANSACTION
LOCK(cs_main); LOCK(cs_main);
int conf = GetIXConfirmations(nTxCollateralHash); int nConfirmationsIn = GetIXConfirmations(nTxCollateralHash);
if (nBlockHash != uint256()) { if (nBlockHash != uint256()) {
BlockMap::iterator mi = mapBlockIndex.find(nBlockHash); BlockMap::iterator mi = mapBlockIndex.find(nBlockHash);
if (mi != mapBlockIndex.end() && (*mi).second) { if (mi != mapBlockIndex.end() && (*mi).second) {
CBlockIndex* pindex = (*mi).second; CBlockIndex* pindex = (*mi).second;
if (chainActive.Contains(pindex)) { if (chainActive.Contains(pindex)) {
conf += chainActive.Height() - pindex->nHeight + 1; nConfirmationsIn += chainActive.Height() - pindex->nHeight + 1;
nTime = pindex->nTime; nTime = pindex->nTime;
} }
} }
} }
nConf = conf; nConf = nConfirmationsIn;
//if we're syncing we won't have instantX information, so accept 1 confirmation //if we're syncing we won't have instantX information, so accept 1 confirmation
if(conf >= GOVERNANCE_FEE_CONFIRMATIONS){ if(nConfirmationsIn >= GOVERNANCE_FEE_CONFIRMATIONS){
strError = "valid"; strError = "valid";
return true;
} else { } else {
strError = strprintf("Collateral requires at least %d confirmations - %d confirmations", GOVERNANCE_FEE_CONFIRMATIONS, conf); strError = strprintf("Collateral requires at least %d confirmations - %d confirmations", GOVERNANCE_FEE_CONFIRMATIONS, nConfirmationsIn);
LogPrintf ("CGovernanceObject::IsCollateralValid - %s - %d confirmations\n", strError, conf); LogPrintf ("CGovernanceObject::IsCollateralValid - %s - %d confirmations\n", strError, nConfirmationsIn);
return false; return false;
} }
return true;
} }
void CGovernanceManager::CheckOrphanVotes() void CGovernanceManager::CheckOrphanVotes()
@ -290,7 +299,7 @@ void CGovernanceManager::NewBlock()
{ {
std::string strError = ""; std::string strError = "";
int nConf = 0; int nConf = 0;
if(!IsCollateralValid((*it4).nFeeTXHash, (*it4).GetHash(), strError, (*it4).nTime, nConf, GOVERNANCE_FEE_TX)){ if(!IsCollateralValid((*it4).nFeeTXHash, (*it4).GetHash(), strError, nConf, GOVERNANCE_FEE_TX)){
++it4; ++it4;
continue; continue;
} }
@ -351,7 +360,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
std::string strError = ""; std::string strError = "";
int nConf = 0; int nConf = 0;
if(!IsCollateralValid(govobj.nFeeTXHash, govobj.GetHash(), strError, govobj.nTime, nConf, GOVERNANCE_FEE_TX)){ if(!IsCollateralValid(govobj.nFeeTXHash, govobj.GetHash(), strError, nConf, GOVERNANCE_FEE_TX)){
LogPrintf("Proposal FeeTX is not valid - %s - %s\n", govobj.nFeeTXHash.ToString(), strError); LogPrintf("Proposal FeeTX is not valid - %s - %s\n", govobj.nFeeTXHash.ToString(), strError);
//todo 12.1 //todo 12.1
//if(nConf >= 1) vecImmatureGovernanceObjects.push_back(govobj); //if(nConf >= 1) vecImmatureGovernanceObjects.push_back(govobj);
@ -620,7 +629,7 @@ bool CGovernanceObject::IsValid(const CBlockIndex* pindex, std::string& strError
if(fCheckCollateral){ if(fCheckCollateral){
int nConf = 0; int nConf = 0;
if(!IsCollateralValid(nFeeTXHash, GetHash(), strError, nTime, nConf, GOVERNANCE_FEE_TX)){ if(!IsCollateralValid(nFeeTXHash, GetHash(), strError, nConf, GOVERNANCE_FEE_TX)){
// strError set in IsCollateralValid // strError set in IsCollateralValid
return false; return false;
} }

View File

@ -42,7 +42,7 @@ extern CGovernanceManager governance;
#define SEEN_OBJECT_ERROR_IMMATURE 2 #define SEEN_OBJECT_ERROR_IMMATURE 2
//Check the collateral transaction for the budget proposal/finalized budget //Check the collateral transaction for the budget proposal/finalized budget
extern bool IsCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::string& strError, int64_t nTime, int& nConf, CAmount minFee); extern bool IsCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::string& strError, int& nConf, CAmount minFee);
// //