Mostly winner -> payment vote (#1033)
Followup for the recent winner_block PR (#1028) and name confusion discovered during code review. "Mostly" because also: - CMasternodeBlockPayees::GetPayee -> CMasternodeBlockPayees::GetBestPayee which describes what this function is actually doing a bit better imo; - fixing constructor CMasternodePaymentVote empty constructor
This commit is contained in:
parent
2245d25497
commit
ec239ffa36
22
src/main.cpp
22
src/main.cpp
@ -4936,10 +4936,10 @@ bool static AlreadyHave(const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
|||||||
case MSG_SPORK:
|
case MSG_SPORK:
|
||||||
return mapSporks.count(inv.hash);
|
return mapSporks.count(inv.hash);
|
||||||
|
|
||||||
case MSG_MASTERNODE_WINNER:
|
case MSG_MASTERNODE_PAYMENT_VOTE:
|
||||||
return mnpayments.mapMasternodePayeeVotes.count(inv.hash);
|
return mnpayments.mapMasternodePaymentVotes.count(inv.hash);
|
||||||
|
|
||||||
case MSG_MASTERNODE_WINNER_BLOCK:
|
case MSG_MASTERNODE_PAYMENT_BLOCK:
|
||||||
{
|
{
|
||||||
BlockMap::iterator mi = mapBlockIndex.find(inv.hash);
|
BlockMap::iterator mi = mapBlockIndex.find(inv.hash);
|
||||||
return mi != mapBlockIndex.end() && mnpayments.mapMasternodeBlocks.find(mi->second->nHeight) != mnpayments.mapMasternodeBlocks.end();
|
return mi != mapBlockIndex.end() && mnpayments.mapMasternodeBlocks.find(mi->second->nHeight) != mnpayments.mapMasternodeBlocks.end();
|
||||||
@ -5112,28 +5112,28 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pushed && inv.type == MSG_MASTERNODE_WINNER) {
|
if (!pushed && inv.type == MSG_MASTERNODE_PAYMENT_VOTE) {
|
||||||
if(mnpayments.mapMasternodePayeeVotes.count(inv.hash)) {
|
if(mnpayments.mapMasternodePaymentVotes.count(inv.hash)) {
|
||||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||||
ss.reserve(1000);
|
ss.reserve(1000);
|
||||||
ss << mnpayments.mapMasternodePayeeVotes[inv.hash];
|
ss << mnpayments.mapMasternodePaymentVotes[inv.hash];
|
||||||
pfrom->PushMessage(NetMsgType::MNWINNER, ss);
|
pfrom->PushMessage(NetMsgType::MASTERNODEPAYMENTVOTE, ss);
|
||||||
pushed = true;
|
pushed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pushed && inv.type == MSG_MASTERNODE_WINNER_BLOCK) {
|
if (!pushed && inv.type == MSG_MASTERNODE_PAYMENT_BLOCK) {
|
||||||
BlockMap::iterator mi = mapBlockIndex.find(inv.hash);
|
BlockMap::iterator mi = mapBlockIndex.find(inv.hash);
|
||||||
LOCK(cs_mapMasternodeBlocks);
|
LOCK(cs_mapMasternodeBlocks);
|
||||||
if (mi != mapBlockIndex.end() && mnpayments.mapMasternodeBlocks.count(mi->second->nHeight)) {
|
if (mi != mapBlockIndex.end() && mnpayments.mapMasternodeBlocks.count(mi->second->nHeight)) {
|
||||||
BOOST_FOREACH(CMasternodePayee& payee, mnpayments.mapMasternodeBlocks[mi->second->nHeight].vecPayees) {
|
BOOST_FOREACH(CMasternodePayee& payee, mnpayments.mapMasternodeBlocks[mi->second->nHeight].vecPayees) {
|
||||||
std::vector<uint256> vecVoteHashes = payee.GetVoteHashes();
|
std::vector<uint256> vecVoteHashes = payee.GetVoteHashes();
|
||||||
BOOST_FOREACH(uint256& hash, vecVoteHashes) {
|
BOOST_FOREACH(uint256& hash, vecVoteHashes) {
|
||||||
if(mnpayments.mapMasternodePayeeVotes.count(hash)) {
|
if(mnpayments.mapMasternodePaymentVotes.count(hash)) {
|
||||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||||
ss.reserve(1000);
|
ss.reserve(1000);
|
||||||
ss << mnpayments.mapMasternodePayeeVotes[hash];
|
ss << mnpayments.mapMasternodePaymentVotes[hash];
|
||||||
pfrom->PushMessage(NetMsgType::MNWINNER, ss);
|
pfrom->PushMessage(NetMsgType::MASTERNODEPAYMENTVOTE, ss);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ CMasternodePayments mnpayments;
|
|||||||
|
|
||||||
CCriticalSection cs_vecPayees;
|
CCriticalSection cs_vecPayees;
|
||||||
CCriticalSection cs_mapMasternodeBlocks;
|
CCriticalSection cs_mapMasternodeBlocks;
|
||||||
CCriticalSection cs_mapMasternodePayeeVotes;
|
CCriticalSection cs_mapMasternodePaymentVotes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IsBlockValueValid
|
* IsBlockValueValid
|
||||||
@ -211,14 +211,14 @@ std::string GetRequiredPaymentsString(int nBlockHeight)
|
|||||||
|
|
||||||
void CMasternodePayments::Clear()
|
void CMasternodePayments::Clear()
|
||||||
{
|
{
|
||||||
LOCK2(cs_mapMasternodeBlocks, cs_mapMasternodePayeeVotes);
|
LOCK2(cs_mapMasternodeBlocks, cs_mapMasternodePaymentVotes);
|
||||||
mapMasternodeBlocks.clear();
|
mapMasternodeBlocks.clear();
|
||||||
mapMasternodePayeeVotes.clear();
|
mapMasternodePaymentVotes.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CMasternodePayments::CanVote(COutPoint outMasternode, int nBlockHeight)
|
bool CMasternodePayments::CanVote(COutPoint outMasternode, int nBlockHeight)
|
||||||
{
|
{
|
||||||
LOCK(cs_mapMasternodePayeeVotes);
|
LOCK(cs_mapMasternodePaymentVotes);
|
||||||
|
|
||||||
if (mapMasternodesLastVote.count(outMasternode) && mapMasternodesLastVote[outMasternode] == nBlockHeight) {
|
if (mapMasternodesLastVote.count(outMasternode) && mapMasternodesLastVote[outMasternode] == nBlockHeight) {
|
||||||
return false;
|
return false;
|
||||||
@ -284,7 +284,7 @@ void CMasternodePayments::ProcessMessage(CNode* pfrom, std::string& strCommand,
|
|||||||
|
|
||||||
if(fLiteMode) return; // disable all Dash specific functionality
|
if(fLiteMode) return; // disable all Dash specific functionality
|
||||||
|
|
||||||
if (strCommand == NetMsgType::MNWINNERSSYNC) { //Masternode Payments Request Sync
|
if (strCommand == NetMsgType::MASTERNODEPAYMENTSYNC) { //Masternode Payments Request Sync
|
||||||
|
|
||||||
// Ignore such requests until we are fully synced.
|
// Ignore such requests until we are fully synced.
|
||||||
// We could start processing this after masternode list is synced
|
// We could start processing this after masternode list is synced
|
||||||
@ -295,74 +295,74 @@ void CMasternodePayments::ProcessMessage(CNode* pfrom, std::string& strCommand,
|
|||||||
vRecv >> nCountNeeded;
|
vRecv >> nCountNeeded;
|
||||||
|
|
||||||
if(Params().NetworkIDString() == CBaseChainParams::MAIN){
|
if(Params().NetworkIDString() == CBaseChainParams::MAIN){
|
||||||
if(pfrom->HasFulfilledRequest(NetMsgType::MNWINNERSSYNC)) {
|
if(pfrom->HasFulfilledRequest(NetMsgType::MASTERNODEPAYMENTSYNC)) {
|
||||||
LogPrintf("MNWINNERSSYNC -- peer already asked me for the list, peer=%d\n", pfrom->id);
|
LogPrintf("MASTERNODEPAYMENTSYNC -- peer already asked me for the list, peer=%d\n", pfrom->id);
|
||||||
Misbehaving(pfrom->GetId(), 20);
|
Misbehaving(pfrom->GetId(), 20);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pfrom->FulfilledRequest(NetMsgType::MNWINNERSSYNC);
|
pfrom->FulfilledRequest(NetMsgType::MASTERNODEPAYMENTSYNC);
|
||||||
Sync(pfrom, nCountNeeded);
|
Sync(pfrom, nCountNeeded);
|
||||||
LogPrintf("MNWINNERSSYNC -- Sent Masternode winners to peer %d\n", pfrom->id);
|
LogPrintf("MASTERNODEPAYMENTSYNC -- Sent Masternode payment votes to peer %d\n", pfrom->id);
|
||||||
|
|
||||||
} else if (strCommand == NetMsgType::MNWINNER) { //Masternode Payments Declare Winner
|
} else if (strCommand == NetMsgType::MASTERNODEPAYMENTVOTE) { // Masternode Payments Vote for the Winner
|
||||||
|
|
||||||
CMasternodePaymentWinner winner;
|
CMasternodePaymentVote vote;
|
||||||
vRecv >> winner;
|
vRecv >> vote;
|
||||||
|
|
||||||
if(pfrom->nVersion < GetMinMasternodePaymentsProto()) return;
|
if(pfrom->nVersion < GetMinMasternodePaymentsProto()) return;
|
||||||
|
|
||||||
if(!pCurrentBlockIndex) return;
|
if(!pCurrentBlockIndex) return;
|
||||||
|
|
||||||
if(mapMasternodePayeeVotes.count(winner.GetHash())) {
|
if(mapMasternodePaymentVotes.count(vote.GetHash())) {
|
||||||
LogPrint("mnpayments", "MNWINNER -- hash=%s, nHeight=%d seen\n", winner.GetHash().ToString(), pCurrentBlockIndex->nHeight);
|
LogPrint("mnpayments", "MASTERNODEPAYMENTVOTE -- hash=%s, nHeight=%d seen\n", vote.GetHash().ToString(), pCurrentBlockIndex->nHeight);
|
||||||
masternodeSync.AddedMasternodeWinner();
|
masternodeSync.AddedPaymentVote();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nFirstBlock = pCurrentBlockIndex->nHeight - GetStorageLimit();
|
int nFirstBlock = pCurrentBlockIndex->nHeight - GetStorageLimit();
|
||||||
if(winner.nBlockHeight < nFirstBlock || winner.nBlockHeight > pCurrentBlockIndex->nHeight+20) {
|
if(vote.nBlockHeight < nFirstBlock || vote.nBlockHeight > pCurrentBlockIndex->nHeight+20) {
|
||||||
LogPrint("mnpayments", "MNWINNER -- winner out of range: nFirstBlock=%d, nBlockHeight=%d, nHeight=%d\n", nFirstBlock, winner.nBlockHeight, pCurrentBlockIndex->nHeight);
|
LogPrint("mnpayments", "MASTERNODEPAYMENTVOTE -- vote out of range: nFirstBlock=%d, nBlockHeight=%d, nHeight=%d\n", nFirstBlock, vote.nBlockHeight, pCurrentBlockIndex->nHeight);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string strError = "";
|
std::string strError = "";
|
||||||
if(!winner.IsValid(pfrom, pCurrentBlockIndex->nHeight, strError)) {
|
if(!vote.IsValid(pfrom, pCurrentBlockIndex->nHeight, strError)) {
|
||||||
LogPrint("mnpayments", "MNWINNER -- invalid message, error: %s\n", strError);
|
LogPrint("mnpayments", "MASTERNODEPAYMENTVOTE -- invalid message, error: %s\n", strError);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!CanVote(winner.vinMasternode.prevout, winner.nBlockHeight)) {
|
if(!CanVote(vote.vinMasternode.prevout, vote.nBlockHeight)) {
|
||||||
LogPrintf("MNWINNER -- masternode already voted, masternode=%s\n", winner.vinMasternode.prevout.ToStringShort());
|
LogPrintf("MASTERNODEPAYMENTVOTE -- masternode already voted, masternode=%s\n", vote.vinMasternode.prevout.ToStringShort());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!winner.CheckSignature()) {
|
if(!vote.CheckSignature()) {
|
||||||
// do not ban for old mnw, MN simply might be not active anymore
|
// do not ban for old mnw, MN simply might be not active anymore
|
||||||
if(masternodeSync.IsSynced() && winner.nBlockHeight > pCurrentBlockIndex->nHeight) {
|
if(masternodeSync.IsSynced() && vote.nBlockHeight > pCurrentBlockIndex->nHeight) {
|
||||||
LogPrintf("MNWINNER -- invalid signature\n");
|
LogPrintf("MASTERNODEPAYMENTVOTE -- invalid signature\n");
|
||||||
Misbehaving(pfrom->GetId(), 20);
|
Misbehaving(pfrom->GetId(), 20);
|
||||||
}
|
}
|
||||||
// it could just be a non-synced masternode
|
// it could just be a non-synced masternode
|
||||||
mnodeman.AskForMN(pfrom, winner.vinMasternode);
|
mnodeman.AskForMN(pfrom, vote.vinMasternode);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CTxDestination address1;
|
CTxDestination address1;
|
||||||
ExtractDestination(winner.payee, address1);
|
ExtractDestination(vote.payee, address1);
|
||||||
CBitcoinAddress address2(address1);
|
CBitcoinAddress address2(address1);
|
||||||
|
|
||||||
LogPrint("mnpayments", "MNWINNER -- winning vote: address=%s, nBlockHeight=%d, nHeight=%d, prevout=%s\n", address2.ToString(), winner.nBlockHeight, pCurrentBlockIndex->nHeight, winner.vinMasternode.prevout.ToStringShort());
|
LogPrint("mnpayments", "MASTERNODEPAYMENTVOTE -- vote: address=%s, nBlockHeight=%d, nHeight=%d, prevout=%s\n", address2.ToString(), vote.nBlockHeight, pCurrentBlockIndex->nHeight, vote.vinMasternode.prevout.ToStringShort());
|
||||||
|
|
||||||
if(AddWinningMasternode(winner)){
|
if(AddPaymentVote(vote)){
|
||||||
winner.Relay();
|
vote.Relay();
|
||||||
masternodeSync.AddedMasternodeWinner();
|
masternodeSync.AddedPaymentVote();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CMasternodePaymentWinner::Sign()
|
bool CMasternodePaymentVote::Sign()
|
||||||
{
|
{
|
||||||
std::string strError;
|
std::string strError;
|
||||||
std::string strMessage = vinMasternode.prevout.ToStringShort() +
|
std::string strMessage = vinMasternode.prevout.ToStringShort() +
|
||||||
@ -370,12 +370,12 @@ bool CMasternodePaymentWinner::Sign()
|
|||||||
ScriptToAsmStr(payee);
|
ScriptToAsmStr(payee);
|
||||||
|
|
||||||
if(!darkSendSigner.SignMessage(strMessage, vchSig, activeMasternode.keyMasternode)) {
|
if(!darkSendSigner.SignMessage(strMessage, vchSig, activeMasternode.keyMasternode)) {
|
||||||
LogPrintf("CMasternodePaymentWinner::Sign -- SignMessage() failed\n");
|
LogPrintf("CMasternodePaymentVote::Sign -- SignMessage() failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!darkSendSigner.VerifyMessage(activeMasternode.pubKeyMasternode, vchSig, strMessage, strError)) {
|
if(!darkSendSigner.VerifyMessage(activeMasternode.pubKeyMasternode, vchSig, strMessage, strError)) {
|
||||||
LogPrintf("CMasternodePaymentWinner::Sign -- VerifyMessage() failed, error: %s\n", strError);
|
LogPrintf("CMasternodePaymentVote::Sign -- VerifyMessage() failed, error: %s\n", strError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,14 +385,14 @@ bool CMasternodePaymentWinner::Sign()
|
|||||||
bool CMasternodePayments::GetBlockPayee(int nBlockHeight, CScript& payee)
|
bool CMasternodePayments::GetBlockPayee(int nBlockHeight, CScript& payee)
|
||||||
{
|
{
|
||||||
if(mapMasternodeBlocks.count(nBlockHeight)){
|
if(mapMasternodeBlocks.count(nBlockHeight)){
|
||||||
return mapMasternodeBlocks[nBlockHeight].GetPayee(payee);
|
return mapMasternodeBlocks[nBlockHeight].GetBestPayee(payee);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is this masternode scheduled to get paid soon?
|
// Is this masternode scheduled to get paid soon?
|
||||||
// -- Only look ahead up to 8 blocks to allow for propagation of the latest 2 winners
|
// -- Only look ahead up to 8 blocks to allow for propagation of the latest 2 blocks of votes
|
||||||
bool CMasternodePayments::IsScheduled(CMasternode& mn, int nNotBlockHeight)
|
bool CMasternodePayments::IsScheduled(CMasternode& mn, int nNotBlockHeight)
|
||||||
{
|
{
|
||||||
LOCK(cs_mapMasternodeBlocks);
|
LOCK(cs_mapMasternodeBlocks);
|
||||||
@ -405,7 +405,7 @@ bool CMasternodePayments::IsScheduled(CMasternode& mn, int nNotBlockHeight)
|
|||||||
CScript payee;
|
CScript payee;
|
||||||
for(int64_t h = pCurrentBlockIndex->nHeight; h <= pCurrentBlockIndex->nHeight + 8; h++){
|
for(int64_t h = pCurrentBlockIndex->nHeight; h <= pCurrentBlockIndex->nHeight + 8; h++){
|
||||||
if(h == nNotBlockHeight) continue;
|
if(h == nNotBlockHeight) continue;
|
||||||
if(mapMasternodeBlocks.count(h) && mapMasternodeBlocks[h].GetPayee(payee) && mnpayee == payee) {
|
if(mapMasternodeBlocks.count(h) && mapMasternodeBlocks[h].GetBestPayee(payee) && mnpayee == payee) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -413,47 +413,47 @@ bool CMasternodePayments::IsScheduled(CMasternode& mn, int nNotBlockHeight)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CMasternodePayments::AddWinningMasternode(CMasternodePaymentWinner& winnerIn)
|
bool CMasternodePayments::AddPaymentVote(const CMasternodePaymentVote& vote)
|
||||||
{
|
{
|
||||||
uint256 blockHash = uint256();
|
uint256 blockHash = uint256();
|
||||||
if(!GetBlockHash(blockHash, winnerIn.nBlockHeight - 101)) return false;
|
if(!GetBlockHash(blockHash, vote.nBlockHeight - 101)) return false;
|
||||||
|
|
||||||
LOCK2(cs_mapMasternodePayeeVotes, cs_mapMasternodeBlocks);
|
LOCK2(cs_mapMasternodePaymentVotes, cs_mapMasternodeBlocks);
|
||||||
|
|
||||||
if(mapMasternodePayeeVotes.count(winnerIn.GetHash())) return false;
|
if(mapMasternodePaymentVotes.count(vote.GetHash())) return false;
|
||||||
|
|
||||||
mapMasternodePayeeVotes[winnerIn.GetHash()] = winnerIn;
|
mapMasternodePaymentVotes[vote.GetHash()] = vote;
|
||||||
|
|
||||||
if(!mapMasternodeBlocks.count(winnerIn.nBlockHeight)) {
|
if(!mapMasternodeBlocks.count(vote.nBlockHeight)) {
|
||||||
CMasternodeBlockPayees blockPayees(winnerIn.nBlockHeight);
|
CMasternodeBlockPayees blockPayees(vote.nBlockHeight);
|
||||||
mapMasternodeBlocks[winnerIn.nBlockHeight] = blockPayees;
|
mapMasternodeBlocks[vote.nBlockHeight] = blockPayees;
|
||||||
}
|
}
|
||||||
|
|
||||||
mapMasternodeBlocks[winnerIn.nBlockHeight].AddPayee(winnerIn);
|
mapMasternodeBlocks[vote.nBlockHeight].AddPayee(vote);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMasternodeBlockPayees::AddPayee(CMasternodePaymentWinner winner)
|
void CMasternodeBlockPayees::AddPayee(const CMasternodePaymentVote& vote)
|
||||||
{
|
{
|
||||||
LOCK(cs_vecPayees);
|
LOCK(cs_vecPayees);
|
||||||
|
|
||||||
BOOST_FOREACH(CMasternodePayee& payee, vecPayees) {
|
BOOST_FOREACH(CMasternodePayee& payee, vecPayees) {
|
||||||
if (payee.GetPayee() == winner.payee) {
|
if (payee.GetPayee() == vote.payee) {
|
||||||
payee.AddVoteHash(winner.GetHash());
|
payee.AddVoteHash(vote.GetHash());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CMasternodePayee payeeNew(winner.payee, winner.GetHash());
|
CMasternodePayee payeeNew(vote.payee, vote.GetHash());
|
||||||
vecPayees.push_back(payeeNew);
|
vecPayees.push_back(payeeNew);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CMasternodeBlockPayees::GetPayee(CScript& payeeRet)
|
bool CMasternodeBlockPayees::GetBestPayee(CScript& payeeRet)
|
||||||
{
|
{
|
||||||
LOCK(cs_vecPayees);
|
LOCK(cs_vecPayees);
|
||||||
|
|
||||||
if(!vecPayees.size()) {
|
if(!vecPayees.size()) {
|
||||||
LogPrint("mnpayments", "CMasternodeBlockPayees::GetPayee -- ERROR: couldn't find any payee\n");
|
LogPrint("mnpayments", "CMasternodeBlockPayees::GetBestPayee -- ERROR: couldn't find any payee\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -575,18 +575,18 @@ void CMasternodePayments::CheckAndRemove()
|
|||||||
{
|
{
|
||||||
if(!pCurrentBlockIndex) return;
|
if(!pCurrentBlockIndex) return;
|
||||||
|
|
||||||
LOCK2(cs_mapMasternodePayeeVotes, cs_mapMasternodeBlocks);
|
LOCK2(cs_mapMasternodePaymentVotes, cs_mapMasternodeBlocks);
|
||||||
|
|
||||||
int nLimit = GetStorageLimit();
|
int nLimit = GetStorageLimit();
|
||||||
|
|
||||||
std::map<uint256, CMasternodePaymentWinner>::iterator it = mapMasternodePayeeVotes.begin();
|
std::map<uint256, CMasternodePaymentVote>::iterator it = mapMasternodePaymentVotes.begin();
|
||||||
while(it != mapMasternodePayeeVotes.end()) {
|
while(it != mapMasternodePaymentVotes.end()) {
|
||||||
CMasternodePaymentWinner winner = (*it).second;
|
CMasternodePaymentVote vote = (*it).second;
|
||||||
|
|
||||||
if(pCurrentBlockIndex->nHeight - winner.nBlockHeight > nLimit) {
|
if(pCurrentBlockIndex->nHeight - vote.nBlockHeight > nLimit) {
|
||||||
LogPrint("mnpayments", "CMasternodePayments::CheckAndRemove -- Removing old Masternode payment: nBlockHeight=%d\n", winner.nBlockHeight);
|
LogPrint("mnpayments", "CMasternodePayments::CheckAndRemove -- Removing old Masternode payment: nBlockHeight=%d\n", vote.nBlockHeight);
|
||||||
mapMasternodePayeeVotes.erase(it++);
|
mapMasternodePaymentVotes.erase(it++);
|
||||||
mapMasternodeBlocks.erase(winner.nBlockHeight);
|
mapMasternodeBlocks.erase(vote.nBlockHeight);
|
||||||
} else {
|
} else {
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
@ -594,7 +594,7 @@ void CMasternodePayments::CheckAndRemove()
|
|||||||
LogPrintf("CMasternodePayments::CheckAndRemove -- %s\n", ToString());
|
LogPrintf("CMasternodePayments::CheckAndRemove -- %s\n", ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CMasternodePaymentWinner::IsValid(CNode* pnode, int nValidationHeight, std::string& strError)
|
bool CMasternodePaymentVote::IsValid(CNode* pnode, int nValidationHeight, std::string& strError)
|
||||||
{
|
{
|
||||||
CMasternode* pmn = mnodeman.Find(vinMasternode);
|
CMasternode* pmn = mnodeman.Find(vinMasternode);
|
||||||
|
|
||||||
@ -610,7 +610,7 @@ bool CMasternodePaymentWinner::IsValid(CNode* pnode, int nValidationHeight, std:
|
|||||||
|
|
||||||
int nMinRequiredProtocol;
|
int nMinRequiredProtocol;
|
||||||
if(nBlockHeight > nValidationHeight) {
|
if(nBlockHeight > nValidationHeight) {
|
||||||
// new winners must comply SPORK_10_MASTERNODE_PAY_UPDATED_NODES rules
|
// new votes must comply SPORK_10_MASTERNODE_PAY_UPDATED_NODES rules
|
||||||
nMinRequiredProtocol = mnpayments.GetMinMasternodePaymentsProto();
|
nMinRequiredProtocol = mnpayments.GetMinMasternodePaymentsProto();
|
||||||
} else {
|
} else {
|
||||||
// allow non-updated masternodes for old blocks
|
// allow non-updated masternodes for old blocks
|
||||||
@ -631,7 +631,7 @@ bool CMasternodePaymentWinner::IsValid(CNode* pnode, int nValidationHeight, std:
|
|||||||
// Only ban for new mnw which is out of bounds, for old mnw MN list itself might be way too much off
|
// Only ban for new mnw which is out of bounds, for old mnw MN list itself might be way too much off
|
||||||
if(nRank > MNPAYMENTS_SIGNATURES_TOTAL*2 && nBlockHeight > nValidationHeight) {
|
if(nRank > MNPAYMENTS_SIGNATURES_TOTAL*2 && nBlockHeight > nValidationHeight) {
|
||||||
strError = strprintf("Masternode is not in the top %d (%d)", MNPAYMENTS_SIGNATURES_TOTAL*2, nRank);
|
strError = strprintf("Masternode is not in the top %d (%d)", MNPAYMENTS_SIGNATURES_TOTAL*2, nRank);
|
||||||
LogPrintf("CMasternodePaymentWinner::IsValid -- Error: %s\n", strError);
|
LogPrintf("CMasternodePaymentVote::IsValid -- Error: %s\n", strError);
|
||||||
Misbehaving(pnode->GetId(), 20);
|
Misbehaving(pnode->GetId(), 20);
|
||||||
}
|
}
|
||||||
// Still invalid however
|
// Still invalid however
|
||||||
@ -683,22 +683,22 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight)
|
|||||||
|
|
||||||
CScript payee = GetScriptForDestination(pmn->pubKeyCollateralAddress.GetID());
|
CScript payee = GetScriptForDestination(pmn->pubKeyCollateralAddress.GetID());
|
||||||
|
|
||||||
CMasternodePaymentWinner newWinner(activeMasternode.vin, nBlockHeight, payee);
|
CMasternodePaymentVote voteNew(activeMasternode.vin, nBlockHeight, payee);
|
||||||
|
|
||||||
CTxDestination address1;
|
CTxDestination address1;
|
||||||
ExtractDestination(payee, address1);
|
ExtractDestination(payee, address1);
|
||||||
CBitcoinAddress address2(address1);
|
CBitcoinAddress address2(address1);
|
||||||
|
|
||||||
LogPrintf("CMasternodePayments::ProcessBlock -- Winner: payee=%s, nBlockHeight=%d\n", address2.ToString(), nBlockHeight);
|
LogPrintf("CMasternodePayments::ProcessBlock -- vote: payee=%s, nBlockHeight=%d\n", address2.ToString(), nBlockHeight);
|
||||||
|
|
||||||
// SIGN MESSAGE TO NETWORK WITH OUR MASTERNODE KEYS
|
// SIGN MESSAGE TO NETWORK WITH OUR MASTERNODE KEYS
|
||||||
|
|
||||||
LogPrintf("CMasternodePayments::ProcessBlock -- Signing Winner\n");
|
LogPrintf("CMasternodePayments::ProcessBlock -- Signing vote\n");
|
||||||
if (newWinner.Sign()) {
|
if (voteNew.Sign()) {
|
||||||
LogPrintf("CMasternodePayments::ProcessBlock -- AddWinningMasternode()\n");
|
LogPrintf("CMasternodePayments::ProcessBlock -- AddPaymentVote()\n");
|
||||||
|
|
||||||
if (AddWinningMasternode(newWinner)) {
|
if (AddPaymentVote(voteNew)) {
|
||||||
newWinner.Relay();
|
voteNew.Relay();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -706,13 +706,13 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMasternodePaymentWinner::Relay()
|
void CMasternodePaymentVote::Relay()
|
||||||
{
|
{
|
||||||
CInv inv(MSG_MASTERNODE_WINNER, GetHash());
|
CInv inv(MSG_MASTERNODE_PAYMENT_VOTE, GetHash());
|
||||||
RelayInv(inv);
|
RelayInv(inv);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CMasternodePaymentWinner::CheckSignature()
|
bool CMasternodePaymentVote::CheckSignature()
|
||||||
{
|
{
|
||||||
|
|
||||||
CMasternode* pmn = mnodeman.Find(vinMasternode);
|
CMasternode* pmn = mnodeman.Find(vinMasternode);
|
||||||
@ -725,13 +725,13 @@ bool CMasternodePaymentWinner::CheckSignature()
|
|||||||
|
|
||||||
std::string strError = "";
|
std::string strError = "";
|
||||||
if (!darkSendSigner.VerifyMessage(pmn->pubKeyMasternode, vchSig, strMessage, strError)) {
|
if (!darkSendSigner.VerifyMessage(pmn->pubKeyMasternode, vchSig, strMessage, strError)) {
|
||||||
return error("CMasternodePaymentWinner::CheckSignature -- Got bad Masternode payment signature, masternode=%s, error: %s", vinMasternode.prevout.ToStringShort().c_str(), strError);
|
return error("CMasternodePaymentVote::CheckSignature -- Got bad Masternode payment signature, masternode=%s, error: %s", vinMasternode.prevout.ToStringShort().c_str(), strError);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CMasternodePaymentWinner::ToString() const
|
std::string CMasternodePaymentVote::ToString() const
|
||||||
{
|
{
|
||||||
std::ostringstream info;
|
std::ostringstream info;
|
||||||
|
|
||||||
@ -755,7 +755,7 @@ void CMasternodePayments::Sync(CNode* pnode, int nCountNeeded)
|
|||||||
int nLimit = GetStorageLimit();
|
int nLimit = GetStorageLimit();
|
||||||
if(nCountNeeded > nLimit) nCountNeeded = nLimit;
|
if(nCountNeeded > nLimit) nCountNeeded = nLimit;
|
||||||
} else {
|
} else {
|
||||||
// New nodes request missing payment blocks themselves, push only future winners to them
|
// New nodes request missing payment blocks themselves, push only votes for future blocks to them
|
||||||
nCountNeeded = 0;
|
nCountNeeded = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -766,14 +766,14 @@ void CMasternodePayments::Sync(CNode* pnode, int nCountNeeded)
|
|||||||
BOOST_FOREACH(CMasternodePayee& payee, mapMasternodeBlocks[h].vecPayees) {
|
BOOST_FOREACH(CMasternodePayee& payee, mapMasternodeBlocks[h].vecPayees) {
|
||||||
std::vector<uint256> vecVoteHashes = payee.GetVoteHashes();
|
std::vector<uint256> vecVoteHashes = payee.GetVoteHashes();
|
||||||
BOOST_FOREACH(uint256& hash, vecVoteHashes) {
|
BOOST_FOREACH(uint256& hash, vecVoteHashes) {
|
||||||
pnode->PushInventory(CInv(MSG_MASTERNODE_WINNER, hash));
|
pnode->PushInventory(CInv(MSG_MASTERNODE_PAYMENT_VOTE, hash));
|
||||||
nInvCount++;
|
nInvCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LogPrintf("CMasternodePayments::Sync -- Sent %d winners to peer %d\n", nInvCount, pnode->id);
|
LogPrintf("CMasternodePayments::Sync -- Sent %d votes to peer %d\n", nInvCount, pnode->id);
|
||||||
pnode->PushMessage(NetMsgType::SYNCSTATUSCOUNT, MASTERNODE_SYNC_MNW, nInvCount);
|
pnode->PushMessage(NetMsgType::SYNCSTATUSCOUNT, MASTERNODE_SYNC_MNW, nInvCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -820,7 +820,7 @@ void CMasternodePayments::RequestLowDataPaymentBlocks(CNode* pnode)
|
|||||||
// Low data block found, let's try to sync it
|
// Low data block found, let's try to sync it
|
||||||
uint256 hash;
|
uint256 hash;
|
||||||
if(GetBlockHash(hash, it->first)) {
|
if(GetBlockHash(hash, it->first)) {
|
||||||
vToFetch.push_back(CInv(MSG_MASTERNODE_WINNER_BLOCK, hash));
|
vToFetch.push_back(CInv(MSG_MASTERNODE_PAYMENT_BLOCK, hash));
|
||||||
}
|
}
|
||||||
// We should not violate GETDATA rules
|
// We should not violate GETDATA rules
|
||||||
if(vToFetch.size() == MAX_INV_SZ) {
|
if(vToFetch.size() == MAX_INV_SZ) {
|
||||||
@ -842,7 +842,7 @@ std::string CMasternodePayments::ToString() const
|
|||||||
{
|
{
|
||||||
std::ostringstream info;
|
std::ostringstream info;
|
||||||
|
|
||||||
info << "Votes: " << (int)mapMasternodePayeeVotes.size() <<
|
info << "Votes: " << (int)mapMasternodePaymentVotes.size() <<
|
||||||
", Blocks: " << (int)mapMasternodeBlocks.size();
|
", Blocks: " << (int)mapMasternodeBlocks.size();
|
||||||
|
|
||||||
return info.str();
|
return info.str();
|
||||||
|
@ -13,14 +13,14 @@
|
|||||||
#include "utilstrencodings.h"
|
#include "utilstrencodings.h"
|
||||||
|
|
||||||
class CMasternodePayments;
|
class CMasternodePayments;
|
||||||
class CMasternodePaymentWinner;
|
class CMasternodePaymentVote;
|
||||||
class CMasternodeBlockPayees;
|
class CMasternodeBlockPayees;
|
||||||
|
|
||||||
static const int MNPAYMENTS_SIGNATURES_REQUIRED = 6;
|
static const int MNPAYMENTS_SIGNATURES_REQUIRED = 6;
|
||||||
static const int MNPAYMENTS_SIGNATURES_TOTAL = 10;
|
static const int MNPAYMENTS_SIGNATURES_TOTAL = 10;
|
||||||
|
|
||||||
//! minimum peer version that can receive and send masternode payment messages,
|
//! minimum peer version that can receive and send masternode payment messages,
|
||||||
// vote for masternode winner and be elected as a winner
|
// vote for masternode and be elected as a payment winner
|
||||||
// V1 - Last protocol version before update
|
// V1 - Last protocol version before update
|
||||||
// V2 - Newest protocol version
|
// V2 - Newest protocol version
|
||||||
static const int MIN_MASTERNODE_PAYMENT_PROTO_VERSION_1 = 70103;
|
static const int MIN_MASTERNODE_PAYMENT_PROTO_VERSION_1 = 70103;
|
||||||
@ -90,8 +90,8 @@ public:
|
|||||||
READWRITE(vecPayees);
|
READWRITE(vecPayees);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddPayee(CMasternodePaymentWinner winner);
|
void AddPayee(const CMasternodePaymentVote& vote);
|
||||||
bool GetPayee(CScript& payeeRet);
|
bool GetBestPayee(CScript& payeeRet);
|
||||||
bool HasPayeeWithVotes(CScript payeeIn, int nVotesReq);
|
bool HasPayeeWithVotes(CScript payeeIn, int nVotesReq);
|
||||||
|
|
||||||
bool IsTransactionValid(const CTransaction& txNew);
|
bool IsTransactionValid(const CTransaction& txNew);
|
||||||
@ -99,8 +99,8 @@ public:
|
|||||||
std::string GetRequiredPaymentsString();
|
std::string GetRequiredPaymentsString();
|
||||||
};
|
};
|
||||||
|
|
||||||
// for storing the winning payments
|
// vote for the winning payment
|
||||||
class CMasternodePaymentWinner
|
class CMasternodePaymentVote
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CTxIn vinMasternode;
|
CTxIn vinMasternode;
|
||||||
@ -109,16 +109,18 @@ public:
|
|||||||
CScript payee;
|
CScript payee;
|
||||||
std::vector<unsigned char> vchSig;
|
std::vector<unsigned char> vchSig;
|
||||||
|
|
||||||
CMasternodePaymentWinner() :
|
CMasternodePaymentVote() :
|
||||||
vinMasternode(CTxIn()),
|
vinMasternode(),
|
||||||
nBlockHeight(0),
|
nBlockHeight(0),
|
||||||
payee(CScript())
|
payee(),
|
||||||
|
vchSig()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
CMasternodePaymentWinner(CTxIn vinMasternode, int nBlockHeight, CScript payee) :
|
CMasternodePaymentVote(CTxIn vinMasternode, int nBlockHeight, CScript payee) :
|
||||||
vinMasternode(vinMasternode),
|
vinMasternode(vinMasternode),
|
||||||
nBlockHeight(nBlockHeight),
|
nBlockHeight(nBlockHeight),
|
||||||
payee(payee)
|
payee(payee),
|
||||||
|
vchSig()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
ADD_SERIALIZE_METHODS;
|
ADD_SERIALIZE_METHODS;
|
||||||
@ -165,7 +167,7 @@ private:
|
|||||||
const CBlockIndex *pCurrentBlockIndex;
|
const CBlockIndex *pCurrentBlockIndex;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::map<uint256, CMasternodePaymentWinner> mapMasternodePayeeVotes;
|
std::map<uint256, CMasternodePaymentVote> mapMasternodePaymentVotes;
|
||||||
std::map<int, CMasternodeBlockPayees> mapMasternodeBlocks;
|
std::map<int, CMasternodeBlockPayees> mapMasternodeBlocks;
|
||||||
std::map<COutPoint, int> mapMasternodesLastVote;
|
std::map<COutPoint, int> mapMasternodesLastVote;
|
||||||
|
|
||||||
@ -175,13 +177,13 @@ public:
|
|||||||
|
|
||||||
template <typename Stream, typename Operation>
|
template <typename Stream, typename Operation>
|
||||||
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||||
READWRITE(mapMasternodePayeeVotes);
|
READWRITE(mapMasternodePaymentVotes);
|
||||||
READWRITE(mapMasternodeBlocks);
|
READWRITE(mapMasternodeBlocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
bool AddWinningMasternode(CMasternodePaymentWinner& winner);
|
bool AddPaymentVote(const CMasternodePaymentVote& vote);
|
||||||
bool ProcessBlock(int nBlockHeight);
|
bool ProcessBlock(int nBlockHeight);
|
||||||
|
|
||||||
void Sync(CNode* node, int nCountNeeded);
|
void Sync(CNode* node, int nCountNeeded);
|
||||||
@ -201,7 +203,7 @@ public:
|
|||||||
std::string ToString() const;
|
std::string ToString() const;
|
||||||
|
|
||||||
int GetBlockCount() { return mapMasternodeBlocks.size(); }
|
int GetBlockCount() { return mapMasternodeBlocks.size(); }
|
||||||
int GetVoteCount() { return mapMasternodePayeeVotes.size(); }
|
int GetVoteCount() { return mapMasternodePaymentVotes.size(); }
|
||||||
|
|
||||||
bool IsEnoughData(int nMnCount);
|
bool IsEnoughData(int nMnCount);
|
||||||
int GetStorageLimit();
|
int GetStorageLimit();
|
||||||
|
@ -51,7 +51,7 @@ void CMasternodeSync::Reset()
|
|||||||
nRequestedMasternodeAttempt = 0;
|
nRequestedMasternodeAttempt = 0;
|
||||||
nTimeAssetSyncStarted = GetTime();
|
nTimeAssetSyncStarted = GetTime();
|
||||||
nTimeLastMasternodeList = GetTime();
|
nTimeLastMasternodeList = GetTime();
|
||||||
nTimeLastMasternodeWinner = GetTime();
|
nTimeLastPaymentVote = GetTime();
|
||||||
nTimeLastBudgetItem = GetTime();
|
nTimeLastBudgetItem = GetTime();
|
||||||
nTimeLastFailure = 0;
|
nTimeLastFailure = 0;
|
||||||
nCountFailures = 0;
|
nCountFailures = 0;
|
||||||
@ -88,7 +88,7 @@ void CMasternodeSync::SwitchToNextAsset()
|
|||||||
nRequestedMasternodeAssets = MASTERNODE_SYNC_LIST;
|
nRequestedMasternodeAssets = MASTERNODE_SYNC_LIST;
|
||||||
break;
|
break;
|
||||||
case(MASTERNODE_SYNC_LIST):
|
case(MASTERNODE_SYNC_LIST):
|
||||||
nTimeLastMasternodeWinner = GetTime();
|
nTimeLastPaymentVote = GetTime();
|
||||||
nRequestedMasternodeAssets = MASTERNODE_SYNC_MNW;
|
nRequestedMasternodeAssets = MASTERNODE_SYNC_MNW;
|
||||||
break;
|
break;
|
||||||
case(MASTERNODE_SYNC_MNW):
|
case(MASTERNODE_SYNC_MNW):
|
||||||
@ -113,7 +113,7 @@ std::string CMasternodeSync::GetSyncStatus()
|
|||||||
case MASTERNODE_SYNC_INITIAL: return _("Synchronization pending...");
|
case MASTERNODE_SYNC_INITIAL: return _("Synchronization pending...");
|
||||||
case MASTERNODE_SYNC_SPORKS: return _("Synchronizing sporks...");
|
case MASTERNODE_SYNC_SPORKS: return _("Synchronizing sporks...");
|
||||||
case MASTERNODE_SYNC_LIST: return _("Synchronizing masternodes...");
|
case MASTERNODE_SYNC_LIST: return _("Synchronizing masternodes...");
|
||||||
case MASTERNODE_SYNC_MNW: return _("Synchronizing masternode winners...");
|
case MASTERNODE_SYNC_MNW: return _("Synchronizing masternode payments...");
|
||||||
case MASTERNODE_SYNC_GOVERNANCE: return _("Synchronizing governance objects...");
|
case MASTERNODE_SYNC_GOVERNANCE: return _("Synchronizing governance objects...");
|
||||||
case MASTERNODE_SYNC_FAILED: return _("Synchronization failed");
|
case MASTERNODE_SYNC_FAILED: return _("Synchronization failed");
|
||||||
case MASTERNODE_SYNC_FINISHED: return _("Synchronization finished");
|
case MASTERNODE_SYNC_FINISHED: return _("Synchronization finished");
|
||||||
@ -144,7 +144,7 @@ void CMasternodeSync::ClearFulfilledRequest()
|
|||||||
BOOST_FOREACH(CNode* pnode, vNodes)
|
BOOST_FOREACH(CNode* pnode, vNodes)
|
||||||
{
|
{
|
||||||
pnode->ClearFulfilledRequest("spork-sync");
|
pnode->ClearFulfilledRequest("spork-sync");
|
||||||
pnode->ClearFulfilledRequest("masternode-winner-sync");
|
pnode->ClearFulfilledRequest("masternode-payment-sync");
|
||||||
pnode->ClearFulfilledRequest("governance-sync");
|
pnode->ClearFulfilledRequest("governance-sync");
|
||||||
pnode->ClearFulfilledRequest("masternode-sync");
|
pnode->ClearFulfilledRequest("masternode-sync");
|
||||||
}
|
}
|
||||||
@ -209,7 +209,7 @@ void CMasternodeSync::ProcessTick()
|
|||||||
mnodeman.DsegUpdate(pnode);
|
mnodeman.DsegUpdate(pnode);
|
||||||
} else if(nRequestedMasternodeAttempt < 6) {
|
} else if(nRequestedMasternodeAttempt < 6) {
|
||||||
int nMnCount = mnodeman.CountEnabled();
|
int nMnCount = mnodeman.CountEnabled();
|
||||||
pnode->PushMessage(NetMsgType::MNWINNERSSYNC, nMnCount); //sync payees
|
pnode->PushMessage(NetMsgType::MASTERNODEPAYMENTSYNC, nMnCount); //sync payment votes
|
||||||
uint256 n = uint256();
|
uint256 n = uint256();
|
||||||
pnode->PushMessage(NetMsgType::MNGOVERNANCESYNC, n); //sync masternode votes
|
pnode->PushMessage(NetMsgType::MNGOVERNANCESYNC, n); //sync masternode votes
|
||||||
} else {
|
} else {
|
||||||
@ -275,13 +275,13 @@ void CMasternodeSync::ProcessTick()
|
|||||||
return; //this will cause each peer to get one request each six seconds for the various assets we need
|
return; //this will cause each peer to get one request each six seconds for the various assets we need
|
||||||
}
|
}
|
||||||
|
|
||||||
// MNW : SYNC MASTERNODE WINNERS FROM OTHER CONNECTED CLIENTS
|
// MNW : SYNC MASTERNODE PAYMENT VOTES FROM OTHER CONNECTED CLIENTS
|
||||||
|
|
||||||
if(nRequestedMasternodeAssets == MASTERNODE_SYNC_MNW) {
|
if(nRequestedMasternodeAssets == MASTERNODE_SYNC_MNW) {
|
||||||
// check for timeout first
|
// check for timeout first
|
||||||
// This might take a lot longer than MASTERNODE_SYNC_TIMEOUT_SECONDS minutes due to new blocks,
|
// This might take a lot longer than MASTERNODE_SYNC_TIMEOUT_SECONDS minutes due to new blocks,
|
||||||
// but that should be OK and it should timeout eventually.
|
// but that should be OK and it should timeout eventually.
|
||||||
if(nTimeLastMasternodeWinner < GetTime() - MASTERNODE_SYNC_TIMEOUT_SECONDS) {
|
if(nTimeLastPaymentVote < GetTime() - MASTERNODE_SYNC_TIMEOUT_SECONDS) {
|
||||||
LogPrintf("CMasternodeSync::Process -- nTick %d nRequestedMasternodeAssets %d -- timeout\n", nTick, nRequestedMasternodeAssets);
|
LogPrintf("CMasternodeSync::Process -- nTick %d nRequestedMasternodeAssets %d -- timeout\n", nTick, nRequestedMasternodeAssets);
|
||||||
if (nRequestedMasternodeAttempt == 0) {
|
if (nRequestedMasternodeAttempt == 0) {
|
||||||
LogPrintf("CMasternodeSync::Process -- WARNING: failed to sync %s\n", GetAssetName());
|
LogPrintf("CMasternodeSync::Process -- WARNING: failed to sync %s\n", GetAssetName());
|
||||||
@ -303,14 +303,14 @@ void CMasternodeSync::ProcessTick()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// only request once from each peer
|
// only request once from each peer
|
||||||
if(pnode->HasFulfilledRequest("masternode-winner-sync")) continue;
|
if(pnode->HasFulfilledRequest("masternode-payment-sync")) continue;
|
||||||
pnode->FulfilledRequest("masternode-winner-sync");
|
pnode->FulfilledRequest("masternode-payment-sync");
|
||||||
|
|
||||||
if(pnode->nVersion < mnpayments.GetMinMasternodePaymentsProto()) continue;
|
if(pnode->nVersion < mnpayments.GetMinMasternodePaymentsProto()) continue;
|
||||||
nRequestedMasternodeAttempt++;
|
nRequestedMasternodeAttempt++;
|
||||||
|
|
||||||
// ask node for all winners it has (new nodes will only return future winners)
|
// ask node for all payment votes it has (new nodes will only return votes for future payments)
|
||||||
pnode->PushMessage(NetMsgType::MNWINNERSSYNC, mnpayments.GetStorageLimit());
|
pnode->PushMessage(NetMsgType::MASTERNODEPAYMENTSYNC, mnpayments.GetStorageLimit());
|
||||||
// ask node for missing pieces only (old nodes will not be asked)
|
// ask node for missing pieces only (old nodes will not be asked)
|
||||||
mnpayments.RequestLowDataPaymentBlocks(pnode);
|
mnpayments.RequestLowDataPaymentBlocks(pnode);
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ private:
|
|||||||
|
|
||||||
// Last time when we received some masternode asset ...
|
// Last time when we received some masternode asset ...
|
||||||
int64_t nTimeLastMasternodeList;
|
int64_t nTimeLastMasternodeList;
|
||||||
int64_t nTimeLastMasternodeWinner;
|
int64_t nTimeLastPaymentVote;
|
||||||
int64_t nTimeLastBudgetItem;
|
int64_t nTimeLastBudgetItem;
|
||||||
// ... or failed
|
// ... or failed
|
||||||
int64_t nTimeLastFailure;
|
int64_t nTimeLastFailure;
|
||||||
@ -60,7 +60,7 @@ public:
|
|||||||
CMasternodeSync() { Reset(); }
|
CMasternodeSync() { Reset(); }
|
||||||
|
|
||||||
void AddedMasternodeList() { nTimeLastMasternodeList = GetTime(); }
|
void AddedMasternodeList() { nTimeLastMasternodeList = GetTime(); }
|
||||||
void AddedMasternodeWinner() { nTimeLastMasternodeWinner = GetTime(); }
|
void AddedPaymentVote() { nTimeLastPaymentVote = GetTime(); }
|
||||||
void AddedBudgetItem(uint256 hash);
|
void AddedBudgetItem(uint256 hash);
|
||||||
|
|
||||||
bool IsFailed() { return nRequestedMasternodeAssets == MASTERNODE_SYNC_FAILED; }
|
bool IsFailed() { return nRequestedMasternodeAssets == MASTERNODE_SYNC_FAILED; }
|
||||||
|
@ -40,9 +40,9 @@ const char *TXLOCKREQUEST="ix";
|
|||||||
const char *TXLOCKVOTE="txlvote";
|
const char *TXLOCKVOTE="txlvote";
|
||||||
const char *SPORK="spork";
|
const char *SPORK="spork";
|
||||||
const char *GETSPORKS="getsporks";
|
const char *GETSPORKS="getsporks";
|
||||||
const char *MNWINNER="mnw";
|
const char *MASTERNODEPAYMENTVOTE="mnw";
|
||||||
const char *MNWINNERBLOCK="mnwb";
|
const char *MASTERNODEPAYMENTBLOCK="mnwb";
|
||||||
const char *MNWINNERSSYNC="mnget";
|
const char *MASTERNODEPAYMENTSYNC="mnget";
|
||||||
const char *MNSCANERROR="mn scan error"; // not implemented
|
const char *MNSCANERROR="mn scan error"; // not implemented
|
||||||
const char *MNBUDGETSYNC="mnvs"; // depreciated since 12.1
|
const char *MNBUDGETSYNC="mnvs"; // depreciated since 12.1
|
||||||
const char *MNBUDGETVOTE="mvote"; // depreciated since 12.1
|
const char *MNBUDGETVOTE="mvote"; // depreciated since 12.1
|
||||||
@ -78,8 +78,8 @@ static const char* ppszTypeName[] =
|
|||||||
NetMsgType::TXLOCKREQUEST,
|
NetMsgType::TXLOCKREQUEST,
|
||||||
NetMsgType::TXLOCKVOTE,
|
NetMsgType::TXLOCKVOTE,
|
||||||
NetMsgType::SPORK,
|
NetMsgType::SPORK,
|
||||||
NetMsgType::MNWINNER,
|
NetMsgType::MASTERNODEPAYMENTVOTE,
|
||||||
NetMsgType::MNWINNERBLOCK, // reusing, was MNSCANERROR previousely, was NOT used in 12.0, we need this for inv
|
NetMsgType::MASTERNODEPAYMENTBLOCK, // reusing, was MNSCANERROR previousely, was NOT used in 12.0, we need this for inv
|
||||||
NetMsgType::MNBUDGETVOTE, // depreciated since 12.1
|
NetMsgType::MNBUDGETVOTE, // depreciated since 12.1
|
||||||
NetMsgType::MNBUDGETPROPOSAL, // depreciated since 12.1
|
NetMsgType::MNBUDGETPROPOSAL, // depreciated since 12.1
|
||||||
NetMsgType::MNBUDGETFINAL, // depreciated since 12.1
|
NetMsgType::MNBUDGETFINAL, // depreciated since 12.1
|
||||||
@ -124,9 +124,9 @@ const static std::string allNetMessageTypes[] = {
|
|||||||
NetMsgType::TXLOCKVOTE,
|
NetMsgType::TXLOCKVOTE,
|
||||||
NetMsgType::SPORK,
|
NetMsgType::SPORK,
|
||||||
NetMsgType::GETSPORKS,
|
NetMsgType::GETSPORKS,
|
||||||
NetMsgType::MNWINNER,
|
NetMsgType::MASTERNODEPAYMENTVOTE,
|
||||||
// NetMsgType::MNWINNERBLOCK, // there is no message for this, only inventory
|
// NetMsgType::MASTERNODEPAYMENTBLOCK, // there is no message for this, only inventory
|
||||||
NetMsgType::MNWINNERSSYNC,
|
NetMsgType::MASTERNODEPAYMENTSYNC,
|
||||||
NetMsgType::MNANNOUNCE,
|
NetMsgType::MNANNOUNCE,
|
||||||
NetMsgType::MNPING,
|
NetMsgType::MNPING,
|
||||||
NetMsgType::DSACCEPT,
|
NetMsgType::DSACCEPT,
|
||||||
|
@ -226,8 +226,8 @@ extern const char *TXLOCKREQUEST;
|
|||||||
extern const char *TXLOCKVOTE;
|
extern const char *TXLOCKVOTE;
|
||||||
extern const char *SPORK;
|
extern const char *SPORK;
|
||||||
extern const char *GETSPORKS;
|
extern const char *GETSPORKS;
|
||||||
extern const char *MNWINNER;
|
extern const char *MASTERNODEPAYMENTVOTE;
|
||||||
extern const char *MNWINNERSSYNC;
|
extern const char *MASTERNODEPAYMENTSYNC;
|
||||||
extern const char *MNANNOUNCE;
|
extern const char *MNANNOUNCE;
|
||||||
extern const char *MNPING;
|
extern const char *MNPING;
|
||||||
extern const char *DSACCEPT;
|
extern const char *DSACCEPT;
|
||||||
@ -345,8 +345,8 @@ enum {
|
|||||||
MSG_TXLOCK_REQUEST,
|
MSG_TXLOCK_REQUEST,
|
||||||
MSG_TXLOCK_VOTE,
|
MSG_TXLOCK_VOTE,
|
||||||
MSG_SPORK,
|
MSG_SPORK,
|
||||||
MSG_MASTERNODE_WINNER,
|
MSG_MASTERNODE_PAYMENT_VOTE,
|
||||||
MSG_MASTERNODE_WINNER_BLOCK, // reusing, was MSG_MASTERNODE_SCANNING_ERROR previousely, was NOT used in 12.0
|
MSG_MASTERNODE_PAYMENT_BLOCK, // reusing, was MSG_MASTERNODE_SCANNING_ERROR previousely, was NOT used in 12.0
|
||||||
MSG_BUDGET_VOTE, // depreciated since 12.1
|
MSG_BUDGET_VOTE, // depreciated since 12.1
|
||||||
MSG_BUDGET_PROPOSAL, // depreciated since 12.1
|
MSG_BUDGET_PROPOSAL, // depreciated since 12.1
|
||||||
MSG_BUDGET_FINALIZED, // depreciated since 12.1
|
MSG_BUDGET_FINALIZED, // depreciated since 12.1
|
||||||
|
Loading…
Reference in New Issue
Block a user