Skip to content

Commit

Permalink
Merge pull request #806 from evan82/v0.12.1.x-sync-process-2
Browse files Browse the repository at this point in the history
V0.12.1.x Sync Processing
  • Loading branch information
Evan Duffield committed May 25, 2016
2 parents 585544a + ff06e58 commit 7f52065
Show file tree
Hide file tree
Showing 15 changed files with 224 additions and 223 deletions.
2 changes: 1 addition & 1 deletion src/darksend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ CActiveMasternode activeMasternode;
udjinm6 - udjinm6@dash.org
*/

void CDarksendPool::ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream& vRecv)
void CDarksendPool::ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv)
{
if(fLiteMode) return; //disable all Darksend/Masternode related functionality
if(!masternodeSync.IsBlockchainSynced()) return;
Expand Down
2 changes: 1 addition & 1 deletion src/darksend.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ class CDarksendPool
* dssub | Darksend Subscribe To
* \param vRecv
*/
void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);

void InitCollateralAddress(){
SetCollateralAddress(Params().DarksendPoolDummyAddress());
Expand Down
26 changes: 13 additions & 13 deletions src/governance-vote.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ class CGovernanceVote;

#define VOTE_SIGNAL_NONE 0 // SIGNAL VARIOUS THINGS TO HAPPEN:
#define VOTE_SIGNAL_FUNDING 1 // -- fund this object for it's stated amount
#define VOTE_SIGNAL_VALID 2 // -- this object checks out to sentinel
#define VOTE_SIGNAL_VALID 2 // -- this object checks out in sentinel engine
#define VOTE_SIGNAL_DELETE 3 // -- this object should be deleted from memory entirely
#define VOTE_SIGNAL_CLEAR_REGISTERS 4 // -- this object's registers should be cleared (stored elsewhere, e.g. dashdrive)
#define VOTE_SIGNAL_ENDORSED 5 // -- officially endorsed by the network somehow (delegation)
#define VOTE_SIGNAL_RELEASE_BOUNTY1 6 // -- release the first bounty associated with this
#define VOTE_SIGNAL_RELEASE_BOUNTY2 7 // -- second
#define VOTE_SIGNAL_RELEASE_BOUNTY3 8 // -- third
#define VOTE_SIGNAL_NOOP1 9 // FOR FURTHER EXPANSION
#define VOTE_SIGNAL_NOOP2 10 //
#define VOTE_SIGNAL_NOOP3 11 //
#define VOTE_SIGNAL_NOOP4 12 //
#define VOTE_SIGNAL_NOOP5 13 //
#define VOTE_SIGNAL_NOOP6 14 //
#define VOTE_SIGNAL_NOOP7 15 //
#define VOTE_SIGNAL_ENDORSED 4 // -- officially endorsed by the network somehow (delegation)
#define VOTE_SIGNAL_NOOP1 5 // FOR FURTHER EXPANSION
#define VOTE_SIGNAL_NOOP2 6 //
#define VOTE_SIGNAL_NOOP3 7 //
#define VOTE_SIGNAL_NOOP4 8 //
#define VOTE_SIGNAL_NOOP5 9 //
#define VOTE_SIGNAL_NOOP6 10 //
#define VOTE_SIGNAL_NOOP7 11 //
#define VOTE_SIGNAL_NOOP8 12 //
#define VOTE_SIGNAL_NOOP9 13 //
#define VOTE_SIGNAL_NOOP10 14 //
#define VOTE_SIGNAL_NOOP11 15 //
#define VOTE_SIGNAL_CUSTOM_START 16 // SENTINEL CUSTOM ACTIONS
#define VOTE_SIGNAL_CUSTOM_END 35 // 16-35

Expand Down
47 changes: 27 additions & 20 deletions src/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,39 @@ void CGovernanceManager::CheckAndRemove()
{
LogPrintf("CGovernanceManager::CheckAndRemove \n");

// 12.1 -- disabled -- use "delete" voting mechanism

// DELETE OBJECTS WHICH MASTERNODE HAS FLAGGED DELETE=TRUE

std::map<uint256, CGovernanceObject>::iterator it = mapObjects.begin();
while(it != mapObjects.end())
{
CGovernanceObject* pObj = &((*it).second);

pObj->UpdateLocalValidity(pCurrentBlockIndex);
pObj->UpdateSentinelVariables(pCurrentBlockIndex);
++it;
}

// UPDATE CACHING MECHANISMS FOR GOVERNANCE OBJECTS

if(!pCurrentBlockIndex) return;

std::string strError = "";

std::map<uint256, CGovernanceObject>::iterator it2 = mapObjects.begin();
while(it2 != mapObjects.end())
{
CGovernanceObject* pbudgetProposal = &((*it2).second);
CGovernanceObject* pObj = &((*it2).second);

// UPDATE LOCAL VALIDITY AGAINST CRYPTO DATA
pObj->UpdateLocalValidity(pCurrentBlockIndex);

pbudgetProposal->UpdateLocalValidity(pCurrentBlockIndex);
// UPDATE SENTINEL SIGNALING VARIABLES
pObj->UpdateSentinelVariables(pCurrentBlockIndex);
++it2;
}
}

CGovernanceObject *CGovernanceManager::FindProposal(const std::string &strName)
CGovernanceObject *CGovernanceManager::FindGovernanceObject(const std::string &strName)
{
//find the prop with the highest yes count

Expand All @@ -164,7 +180,7 @@ CGovernanceObject *CGovernanceManager::FindProposal(const std::string &strName)
return pbudgetProposal;
}

CGovernanceObject *CGovernanceManager::FindProposal(uint256 nHash)
CGovernanceObject *CGovernanceManager::FindGovernanceObject(uint256 nHash)
{
LOCK(cs);

Expand Down Expand Up @@ -396,13 +412,6 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C

}

//todo - 12.1 - terrible name - maybe DoesObjectExist?
bool CGovernanceManager::PropExists(uint256 nHash)
{
if(mapObjects.count(nHash)) return true;
return false;
}

// description: incremental sync with our peers
// note: incremental syncing seems excessive, well just have clients ask for specific objects and their votes
// note: 12.1 - remove
Expand Down Expand Up @@ -458,10 +467,11 @@ void CGovernanceManager::Sync(CNode* pfrom, uint256 nProp)

int nInvCount = 0;

// sync gov objects
// SYNC GOVERNANCE OBJECTS WITH OTHER CLIENT

std::map<uint256, int>::iterator it1 = mapSeenGovernanceObjects.begin();
while(it1 != mapSeenGovernanceObjects.end()){
CGovernanceObject* pbudgetProposal = FindProposal((*it1).first);
CGovernanceObject* pbudgetProposal = FindGovernanceObject((*it1).first);
if(pbudgetProposal && pbudgetProposal->fCachedValid && ((nProp == uint256() || ((*it1).first == nProp)))){
// Push the inventory budget proposal message over to the other client
pfrom->PushInventory(CInv(MSG_BUDGET_PROPOSAL, (*it1).first));
Expand All @@ -470,7 +480,8 @@ void CGovernanceManager::Sync(CNode* pfrom, uint256 nProp)
++it1;
}

// sync votes
// SYNC OUR GOVERNANCE OBJECT VOTES WITH THEIR GOVERNANCE OBJECT VOTES

std::map<uint256, CGovernanceVote>::iterator it2 = mapVotes.begin();
while(it2 != mapVotes.end()){
pfrom->PushInventory(CInv(MSG_BUDGET_VOTE, (*it2).first));
Expand Down Expand Up @@ -549,11 +560,7 @@ CGovernanceObject::CGovernanceObject()
fCachedFunding = false;
fCachedValid = true;
fCachedDelete = false;
fCachedClearRegisters = false;
fCachedEndorsed = false;
fCachedReleaseBounty1 = false;
fCachedReleaseBounty2 = false;
fCachedReleaseBounty3 = false;

}

Expand Down
43 changes: 31 additions & 12 deletions src/governance.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base58.h"
#include "masternode.h"
#include "governance-vote.h"
#include "masternodeman.h"
#include <boost/lexical_cast.hpp>
#include "init.h"

Expand Down Expand Up @@ -97,8 +98,8 @@ class CGovernanceManager
void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
void NewBlock();

CGovernanceObject *FindProposal(const std::string &strName);
CGovernanceObject *FindProposal(uint256 nHash);
CGovernanceObject *FindGovernanceObject(const std::string &strName);
CGovernanceObject *FindGovernanceObject(uint256 nHash);

std::vector<CGovernanceObject*> GetAllProposals(int64_t nMoreThanTime);

Expand All @@ -108,7 +109,6 @@ class CGovernanceManager
bool AddGovernanceObject (CGovernanceObject& budgetProposal);
bool UpdateGovernanceObject(CGovernanceVote& vote, CNode* pfrom, std::string& strError);
bool AddOrUpdateVote(CGovernanceVote& vote, std::string& strError);
bool PropExists(uint256 nHash);
std::string GetRequiredPaymentsString(int nBlockHeight);
void CleanAndRemove(bool fSignatureCheck);
void CheckAndRemove();
Expand Down Expand Up @@ -172,18 +172,37 @@ class CGovernanceObject
bool fCachedFunding;
bool fCachedValid;
bool fCachedDelete;
bool fCachedClearRegisters;
bool fCachedEndorsed;
bool fCachedReleaseBounty1;
bool fCachedReleaseBounty2;
bool fCachedReleaseBounty3;

CGovernanceObject();
CGovernanceObject(uint256 nHashParentIn, int nRevisionIn, std::string strNameIn, int64_t nTime, uint256 nFeeTXHashIn);
CGovernanceObject(const CGovernanceObject& other);

// Update local validity : store the values in memory
void UpdateLocalValidity(const CBlockIndex *pCurrentBlockIndex) {fCachedLocalValidity = IsValid(pCurrentBlockIndex, strLocalValidityError);};
void UpdateSentinelVariables(const CBlockIndex *pCurrentBlockIndex)
{
/*
#define VOTE_SIGNAL_FUNDING 1 // -- fund this object for it's stated amount
#define VOTE_SIGNAL_VALID 2 // -- this object checks out to sentinel
#define VOTE_SIGNAL_DELETE 3 // -- this object should be deleted from memory entirely
#define VOTE_SIGNAL_ENDORSED 5 // -- officially endorsed by the network somehow (delegation)
*/

int nMnCount = mnodeman.CountEnabled();
int nAbsYesVoteReq = nMnCount / 10;

// set all flags to false
fCachedFunding = false;
fCachedValid = false;
fCachedDelete = false;
fCachedEndorsed = false;

if(GetAbsoluteYesCount(VOTE_SIGNAL_FUNDING) >= nAbsYesVoteReq) fCachedFunding = true;
if(GetAbsoluteYesCount(VOTE_SIGNAL_VALID) >= nAbsYesVoteReq) fCachedValid = true;
if(GetAbsoluteYesCount(VOTE_SIGNAL_DELETE) >= nAbsYesVoteReq) fCachedDelete = true;
if(GetAbsoluteYesCount(VOTE_SIGNAL_ENDORSED) >= nAbsYesVoteReq) fCachedEndorsed = true;
}

void swap(CGovernanceObject& first, CGovernanceObject& second) // nothrow
{
Expand All @@ -203,12 +222,7 @@ class CGovernanceObject
swap(first.fCachedFunding, second.fCachedFunding);
swap(first.fCachedValid, second.fCachedValid);
swap(first.fCachedDelete, second.fCachedDelete);
swap(first.fCachedClearRegisters, second.fCachedClearRegisters);
swap(first.fCachedEndorsed, second.fCachedEndorsed);
swap(first.fCachedReleaseBounty1, second.fCachedReleaseBounty1);
swap(first.fCachedReleaseBounty2, second.fCachedReleaseBounty2);
swap(first.fCachedReleaseBounty3, second.fCachedReleaseBounty3);

}

bool HasMinimumRequiredSupport();
Expand All @@ -225,6 +239,7 @@ class CGovernanceObject
void CleanAndRemove(bool fSignatureCheck);
void Relay();


uint256 GetHash(){

/*
Expand All @@ -236,7 +251,10 @@ class CGovernanceObject
*/

CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
ss << nHashParent;
ss << nRevision;
ss << strName;
ss << nTime;
ss << strData;
uint256 h1 = ss.GetHash();

Expand All @@ -256,6 +274,7 @@ class CGovernanceObject

bool SetData(std::string& strError, std::string strDataIn)
{
// (assumption) this is equal to pythons len(strData) > 512*4, I think
if(strDataIn.size() > 512*4)
{
strError = "Too big.";
Expand Down
6 changes: 4 additions & 2 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ void PrepareShutdown()
GenerateBitcoins(false, 0, Params());
StopNode();

// todo - 12.1 - magic strings as const
// STORE DATA CACHES INTO SERIALIZED DAT FILES

CFlatDB<CMasternodeMan> flatdb1("mncache.dat", "magicMasternodeCache");
flatdb1.Dump(mnodeman);
CFlatDB<CMasternodePayments> flatdb2("mnpayments.dat", "magicMasternodePaymentsCache");
Expand Down Expand Up @@ -1824,7 +1825,8 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)

// ********************************************************* Step 10: Load cache data

// todo - 12.1 - magic strings as const
// LOAD SERIALIZED DAT FILES INTO DATA CACHES FOR INTERNAL USE

uiInterface.InitMessage(_("Loading masternode cache..."));
CFlatDB<CMasternodeMan> flatdb1("mncache.dat", "magicMasternodeCache");
flatdb1.Load(mnodeman);
Expand Down
5 changes: 2 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,6 @@ CAmount GetBlockSubsidy(int nPrevBits, int nPrevHeight, const Consensus::Params&
// LogPrintf("height %u diff %4.2f reward %i \n", nPrevHeight, dDiff, nSubsidy);
nSubsidy *= COIN;

// updated - 12.1 - unified logic
// yearly decline of production by 7.1% per year, projected 21.3M coins max by year 2050.
for(int i = consensusParams.nSubsidyHalvingInterval; i <= nPrevHeight; i += consensusParams.nSubsidyHalvingInterval) nSubsidy -= nSubsidy/14;

Expand Down Expand Up @@ -5605,9 +5604,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
if (found)
{
//probably one the extensions
darkSendPool.ProcessMessageDarksend(pfrom, strCommand, vRecv);
darkSendPool.ProcessMessage(pfrom, strCommand, vRecv);
mnodeman.ProcessMessage(pfrom, strCommand, vRecv);
mnpayments.ProcessMessageMasternodePayments(pfrom, strCommand, vRecv);
mnpayments.ProcessMessage(pfrom, strCommand, vRecv);
ProcessMessageInstantX(pfrom, strCommand, vRecv);
ProcessSpork(pfrom, strCommand, vRecv);
masternodeSync.ProcessMessage(pfrom, strCommand, vRecv);
Expand Down
16 changes: 2 additions & 14 deletions src/masternode-budget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@
#include "main.h"
#include "init.h"

// todo 12.1 - remove the unused
#include "governance.h"
#include "masternode.h"
#include "darksend.h"
#include "governance.h"
#include "masternodeman.h"
#include "masternode-sync.h"
#include "util.h"
//#include "addrman.h"
//#include <boost/filesystem.hpp>
//#include <boost/lexical_cast.hpp>

CBudgetManager budget;
CCriticalSection cs_budget;

Expand Down Expand Up @@ -783,7 +771,7 @@ std::string CFinalizedBudget::GetProposals()
std::string ret = "";

BOOST_FOREACH(CTxBudgetPayment& budgetPayment, vecBudgetPayments){
CGovernanceObject* pbudgetProposal = governance.FindProposal(budgetPayment.nProposalHash);
CGovernanceObject* pbudgetProposal = governance.FindGovernanceObject(budgetPayment.nProposalHash);

std::string token = budgetPayment.nProposalHash.ToString();

Expand All @@ -807,7 +795,7 @@ std::string CFinalizedBudget::GetStatus()
continue;
}

CGovernanceObject* pbudgetProposal = governance.FindProposal(budgetPayment.nProposalHash);
CGovernanceObject* pbudgetProposal = governance.FindGovernanceObject(budgetPayment.nProposalHash);
if(!pbudgetProposal){
if(retBadHashes == ""){
retBadHashes = "Unknown proposal hash! Check this proposal before voting" + budgetPayment.nProposalHash.ToString();
Expand Down
Loading

0 comments on commit 7f52065

Please sign in to comment.