Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mn sync #728

Closed
wants to merge 1 commit into from
Closed
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
53 changes: 15 additions & 38 deletions src/masternode-sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,18 @@ void CMasternodeSync::GetNextAsset()
case(MASTERNODE_SYNC_INITIAL):
case(MASTERNODE_SYNC_FAILED): // should never be used here actually, use Reset() instead
ClearFulfilledRequest();
//printf("MASTERNODE_SYNC_SPORKS\n");
RequestedMasternodeAssets = MASTERNODE_SYNC_SPORKS;
break;
case(MASTERNODE_SYNC_SPORKS):
//printf("MASTERNODE_SYNC_LIST\n");
lastMasternodeList = GetTime();
RequestedMasternodeAssets = MASTERNODE_SYNC_LIST;
break;
case(MASTERNODE_SYNC_LIST):
//printf("MASTERNODE_SYNC_MNW\n");
lastMasternodeWinner = GetTime();
RequestedMasternodeAssets = MASTERNODE_SYNC_MNW;
break;
case(MASTERNODE_SYNC_MNW):
//printf("MASTERNODE_SYNC_BUDGET\n");
lastBudgetItem = GetTime();
RequestedMasternodeAssets = MASTERNODE_SYNC_BUDGET;
break;
case(MASTERNODE_SYNC_BUDGET):
Expand Down Expand Up @@ -231,7 +230,7 @@ void CMasternodeSync::Process()
/*
Resync if we lose all masternodes from sleep/wake or failure to sync originally
*/
if(mnodeman.CountEnabled() == 0) {
if(nMnCount == 0) {
Reset();
} else
return;
Expand All @@ -257,14 +256,9 @@ void CMasternodeSync::Process()
if(Params().NetworkIDString() != CBaseChainParams::REGTEST &&
!IsBlockchainSynced() && RequestedMasternodeAssets > MASTERNODE_SYNC_SPORKS) return;


//printf("CMasternodeSync::Process() TICK2 - %d %d \n", tick, RequestedMasternodeAssets);

TRY_LOCK(cs_vNodes, lockRecv);
if(!lockRecv) return;

//printf("CMasternodeSync::Process() TICK3 - %d %d \n", tick, RequestedMasternodeAssets);

BOOST_FOREACH(CNode* pnode, vNodes)
{
/*
Expand Down Expand Up @@ -292,33 +286,27 @@ void CMasternodeSync::Process()
*/

// ALWAYS ASK FOR SPORKS AS WE SYNC (we skip this mode now)
if(!pnode->HasFulfilledRequest("getspork"))
{
if(!pnode->HasFulfilledRequest("getspork"))
{
pnode->FulfilledRequest("getspork");
pnode->PushMessage(NetMsgType::GETSPORKS); //get current network sporks
}
pnode->FulfilledRequest("getspork");
pnode->PushMessage(NetMsgType::GETSPORKS); //get current network sporks
}

//we always ask for sporks, so just skip this
if(RequestedMasternodeAssets == MASTERNODE_SYNC_SPORKS){
GetNextAsset();
return;
}
//we always ask for sporks, so just skip this
if(RequestedMasternodeAssets == MASTERNODE_SYNC_SPORKS){
GetNextAsset();
return;
}

if (pnode->nVersion >= mnpayments.GetMinMasternodePaymentsProto()) {

// MODE : MASTERNODE_SYNC_LIST
if(RequestedMasternodeAssets == MASTERNODE_SYNC_LIST) {
//printf("MASTERNODE_SYNC_LIST Timeout at %d\n", lastMasternodeList < GetTime() - MASTERNODE_SYNC_TIMEOUT);

// shall we move onto the next asset?

//printf("Masternode count %d est %d\n", nMnCount, mnodeman.GetEstimatedMasternodes(pCurrentBlockIndex->nHeight));
if(nMnCount > mnodeman.GetEstimatedMasternodes(pCurrentBlockIndex->nHeight)*0.9)
{
GetNextAsset();
//printf("synced masternode list successfully\n");
return;
}

Expand All @@ -343,7 +331,6 @@ void CMasternodeSync::Process()

// MODE : MASTERNODE_SYNC_MNW
if(RequestedMasternodeAssets == MASTERNODE_SYNC_MNW) {
//printf("MASTERNODE_SYNC_MNW Timeout at %d\n", lastMasternodeWinner < GetTime() - MASTERNODE_SYNC_TIMEOUT);

// Shall we move onto the next asset?
// --
Expand All @@ -353,16 +340,13 @@ void CMasternodeSync::Process()
return;
}

//printf("MASTERNODE_SYNC_MNW BlockCount %d, mnCount %d\n", mnpayments.GetBlockCount(), nMnCount);

// target blocks count
if(mnpayments.GetBlockCount() > nMnCount)
// we store nMnCount*1.25 payments blocks so nMnCount*1.2 should be enough most of the time
if(mnpayments.GetBlockCount() > nMnCount*1.2)
{
//printf("MASTERNODE_SYNC_MNW VoteCount %d, mnCount*6 %d\n", mnpayments.GetVoteCount(), nMnCount*6);
// target votes, max ten per item. 6 average should be fine
if(mnpayments.GetVoteCount() > nMnCount*6)
if(mnpayments.GetVoteCount() > nMnCount*1.2*6)
{
//printf("Successfully synced mnw blocks and votes %d %d\n", mnpayments.GetBlockCount(), mnpayments.GetVoteCount());
GetNextAsset();
return;
}
Expand All @@ -383,20 +367,13 @@ void CMasternodeSync::Process()

// MODE : MASTERNODE_SYNC_BUDGET
if(RequestedMasternodeAssets == MASTERNODE_SYNC_BUDGET){
//printf("MASTERNODE_SYNC_BUDGET Timeout at %d\n", lastBudgetItem < GetTime() - MASTERNODE_SYNC_TIMEOUT);

// shall we move onto the next asset
if(countBudgetItemProp > 0 && countBudgetItemFin)
{
//printf("MASTERNODE_SYNC_BUDGET countBudgetItemProp %d - %d\n", (sumBudgetItemProp / countBudgetItemProp), budget.CountProposalInventoryItems());
//printf("MASTERNODE_SYNC_BUDGET countBudgetItemFin %d - %d\n", (sumBudgetItemFin / countBudgetItemFin), budget.CountFinalizedInventoryItems());

if(budget.CountProposalInventoryItems() >= (sumBudgetItemProp / countBudgetItemProp)*0.9)
{
//printf("HAVE BUDGETS\n");
if(budget.CountFinalizedInventoryItems() >= (sumBudgetItemFin / countBudgetItemFin)*0.9)
{
//printf("HAVE FINAL BUDGETS\n");
GetNextAsset();
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/masternode-sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#define MASTERNODE_SYNC_FAILED 998
#define MASTERNODE_SYNC_FINISHED 999

#define MASTERNODE_SYNC_TIMEOUT 120
#define MASTERNODE_SYNC_TIMEOUT 30 // our blocks are 2.5 minutes so 30 seconds should be fine

class CMasternodeSync;
extern CMasternodeSync masternodeSync;
Expand Down