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:
|
||||
return mapSporks.count(inv.hash);
|
||||
|
||||
case MSG_MASTERNODE_WINNER:
|
||||
return mnpayments.mapMasternodePayeeVotes.count(inv.hash);
|
||||
case MSG_MASTERNODE_PAYMENT_VOTE:
|
||||
return mnpayments.mapMasternodePaymentVotes.count(inv.hash);
|
||||
|
||||
case MSG_MASTERNODE_WINNER_BLOCK:
|
||||
case MSG_MASTERNODE_PAYMENT_BLOCK:
|
||||
{
|
||||
BlockMap::iterator mi = mapBlockIndex.find(inv.hash);
|
||||
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(mnpayments.mapMasternodePayeeVotes.count(inv.hash)) {
|
||||
if (!pushed && inv.type == MSG_MASTERNODE_PAYMENT_VOTE) {
|
||||
if(mnpayments.mapMasternodePaymentVotes.count(inv.hash)) {
|
||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ss.reserve(1000);
|
||||
ss << mnpayments.mapMasternodePayeeVotes[inv.hash];
|
||||
pfrom->PushMessage(NetMsgType::MNWINNER, ss);
|
||||
ss << mnpayments.mapMasternodePaymentVotes[inv.hash];
|
||||
pfrom->PushMessage(NetMsgType::MASTERNODEPAYMENTVOTE, ss);
|
||||
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);
|
||||
LOCK(cs_mapMasternodeBlocks);
|
||||
if (mi != mapBlockIndex.end() && mnpayments.mapMasternodeBlocks.count(mi->second->nHeight)) {
|
||||
BOOST_FOREACH(CMasternodePayee& payee, mnpayments.mapMasternodeBlocks[mi->second->nHeight].vecPayees) {
|
||||
std::vector<uint256> vecVoteHashes = payee.GetVoteHashes();
|
||||
BOOST_FOREACH(uint256& hash, vecVoteHashes) {
|
||||
if(mnpayments.mapMasternodePayeeVotes.count(hash)) {
|
||||
if(mnpayments.mapMasternodePaymentVotes.count(hash)) {
|
||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ss.reserve(1000);
|
||||
ss << mnpayments.mapMasternodePayeeVotes[hash];
|
||||
pfrom->PushMessage(NetMsgType::MNWINNER, ss);
|
||||
ss << mnpayments.mapMasternodePaymentVotes[hash];
|
||||
pfrom->PushMessage(NetMsgType::MASTERNODEPAYMENTVOTE, ss);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ CMasternodePayments mnpayments;
|
||||
|
||||
CCriticalSection cs_vecPayees;
|
||||
CCriticalSection cs_mapMasternodeBlocks;
|
||||
CCriticalSection cs_mapMasternodePayeeVotes;
|
||||
CCriticalSection cs_mapMasternodePaymentVotes;
|
||||
|
||||
/**
|
||||
* IsBlockValueValid
|
||||
@ -211,14 +211,14 @@ std::string GetRequiredPaymentsString(int nBlockHeight)
|
||||
|
||||
void CMasternodePayments::Clear()
|
||||
{
|
||||
LOCK2(cs_mapMasternodeBlocks, cs_mapMasternodePayeeVotes);
|
||||
LOCK2(cs_mapMasternodeBlocks, cs_mapMasternodePaymentVotes);
|
||||
mapMasternodeBlocks.clear();
|
||||
mapMasternodePayeeVotes.clear();
|
||||
mapMasternodePaymentVotes.clear();
|
||||
}
|
||||
|
||||
bool CMasternodePayments::CanVote(COutPoint outMasternode, int nBlockHeight)
|
||||
{
|
||||
LOCK(cs_mapMasternodePayeeVotes);
|
||||
LOCK(cs_mapMasternodePaymentVotes);
|
||||
|
||||
if (mapMasternodesLastVote.count(outMasternode) && mapMasternodesLastVote[outMasternode] == nBlockHeight) {
|
||||
return false;
|
||||
@ -284,7 +284,7 @@ void CMasternodePayments::ProcessMessage(CNode* pfrom, std::string& strCommand,
|
||||
|
||||
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.
|
||||
// We could start processing this after masternode list is synced
|
||||
@ -295,74 +295,74 @@ void CMasternodePayments::ProcessMessage(CNode* pfrom, std::string& strCommand,
|
||||
vRecv >> nCountNeeded;
|
||||
|
||||
if(Params().NetworkIDString() == CBaseChainParams::MAIN){
|
||||
if(pfrom->HasFulfilledRequest(NetMsgType::MNWINNERSSYNC)) {
|
||||
LogPrintf("MNWINNERSSYNC -- peer already asked me for the list, peer=%d\n", pfrom->id);
|
||||
if(pfrom->HasFulfilledRequest(NetMsgType::MASTERNODEPAYMENTSYNC)) {
|
||||
LogPrintf("MASTERNODEPAYMENTSYNC -- peer already asked me for the list, peer=%d\n", pfrom->id);
|
||||
Misbehaving(pfrom->GetId(), 20);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
pfrom->FulfilledRequest(NetMsgType::MNWINNERSSYNC);
|
||||
pfrom->FulfilledRequest(NetMsgType::MASTERNODEPAYMENTSYNC);
|
||||
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;
|
||||
vRecv >> winner;
|
||||
CMasternodePaymentVote vote;
|
||||
vRecv >> vote;
|
||||
|
||||
if(pfrom->nVersion < GetMinMasternodePaymentsProto()) return;
|
||||
|
||||
if(!pCurrentBlockIndex) return;
|
||||
|
||||
if(mapMasternodePayeeVotes.count(winner.GetHash())) {
|
||||
LogPrint("mnpayments", "MNWINNER -- hash=%s, nHeight=%d seen\n", winner.GetHash().ToString(), pCurrentBlockIndex->nHeight);
|
||||
masternodeSync.AddedMasternodeWinner();
|
||||
if(mapMasternodePaymentVotes.count(vote.GetHash())) {
|
||||
LogPrint("mnpayments", "MASTERNODEPAYMENTVOTE -- hash=%s, nHeight=%d seen\n", vote.GetHash().ToString(), pCurrentBlockIndex->nHeight);
|
||||
masternodeSync.AddedPaymentVote();
|
||||
return;
|
||||
}
|
||||
|
||||
int nFirstBlock = pCurrentBlockIndex->nHeight - GetStorageLimit();
|
||||
if(winner.nBlockHeight < nFirstBlock || winner.nBlockHeight > pCurrentBlockIndex->nHeight+20) {
|
||||
LogPrint("mnpayments", "MNWINNER -- winner out of range: nFirstBlock=%d, nBlockHeight=%d, nHeight=%d\n", nFirstBlock, winner.nBlockHeight, pCurrentBlockIndex->nHeight);
|
||||
if(vote.nBlockHeight < nFirstBlock || vote.nBlockHeight > pCurrentBlockIndex->nHeight+20) {
|
||||
LogPrint("mnpayments", "MASTERNODEPAYMENTVOTE -- vote out of range: nFirstBlock=%d, nBlockHeight=%d, nHeight=%d\n", nFirstBlock, vote.nBlockHeight, pCurrentBlockIndex->nHeight);
|
||||
return;
|
||||
}
|
||||
|
||||
std::string strError = "";
|
||||
if(!winner.IsValid(pfrom, pCurrentBlockIndex->nHeight, strError)) {
|
||||
LogPrint("mnpayments", "MNWINNER -- invalid message, error: %s\n", strError);
|
||||
if(!vote.IsValid(pfrom, pCurrentBlockIndex->nHeight, strError)) {
|
||||
LogPrint("mnpayments", "MASTERNODEPAYMENTVOTE -- invalid message, error: %s\n", strError);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!CanVote(winner.vinMasternode.prevout, winner.nBlockHeight)) {
|
||||
LogPrintf("MNWINNER -- masternode already voted, masternode=%s\n", winner.vinMasternode.prevout.ToStringShort());
|
||||
if(!CanVote(vote.vinMasternode.prevout, vote.nBlockHeight)) {
|
||||
LogPrintf("MASTERNODEPAYMENTVOTE -- masternode already voted, masternode=%s\n", vote.vinMasternode.prevout.ToStringShort());
|
||||
return;
|
||||
}
|
||||
|
||||
if(!winner.CheckSignature()) {
|
||||
if(!vote.CheckSignature()) {
|
||||
// do not ban for old mnw, MN simply might be not active anymore
|
||||
if(masternodeSync.IsSynced() && winner.nBlockHeight > pCurrentBlockIndex->nHeight) {
|
||||
LogPrintf("MNWINNER -- invalid signature\n");
|
||||
if(masternodeSync.IsSynced() && vote.nBlockHeight > pCurrentBlockIndex->nHeight) {
|
||||
LogPrintf("MASTERNODEPAYMENTVOTE -- invalid signature\n");
|
||||
Misbehaving(pfrom->GetId(), 20);
|
||||
}
|
||||
// it could just be a non-synced masternode
|
||||
mnodeman.AskForMN(pfrom, winner.vinMasternode);
|
||||
mnodeman.AskForMN(pfrom, vote.vinMasternode);
|
||||
return;
|
||||
}
|
||||
|
||||
CTxDestination address1;
|
||||
ExtractDestination(winner.payee, address1);
|
||||
ExtractDestination(vote.payee, 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)){
|
||||
winner.Relay();
|
||||
masternodeSync.AddedMasternodeWinner();
|
||||
if(AddPaymentVote(vote)){
|
||||
vote.Relay();
|
||||
masternodeSync.AddedPaymentVote();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CMasternodePaymentWinner::Sign()
|
||||
bool CMasternodePaymentVote::Sign()
|
||||
{
|
||||
std::string strError;
|
||||
std::string strMessage = vinMasternode.prevout.ToStringShort() +
|
||||
@ -370,12 +370,12 @@ bool CMasternodePaymentWinner::Sign()
|
||||
ScriptToAsmStr(payee);
|
||||
|
||||
if(!darkSendSigner.SignMessage(strMessage, vchSig, activeMasternode.keyMasternode)) {
|
||||
LogPrintf("CMasternodePaymentWinner::Sign -- SignMessage() failed\n");
|
||||
LogPrintf("CMasternodePaymentVote::Sign -- SignMessage() failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -385,14 +385,14 @@ bool CMasternodePaymentWinner::Sign()
|
||||
bool CMasternodePayments::GetBlockPayee(int nBlockHeight, CScript& payee)
|
||||
{
|
||||
if(mapMasternodeBlocks.count(nBlockHeight)){
|
||||
return mapMasternodeBlocks[nBlockHeight].GetPayee(payee);
|
||||
return mapMasternodeBlocks[nBlockHeight].GetBestPayee(payee);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
LOCK(cs_mapMasternodeBlocks);
|
||||
@ -405,7 +405,7 @@ bool CMasternodePayments::IsScheduled(CMasternode& mn, int nNotBlockHeight)
|
||||
CScript payee;
|
||||
for(int64_t h = pCurrentBlockIndex->nHeight; h <= pCurrentBlockIndex->nHeight + 8; h++){
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -413,47 +413,47 @@ bool CMasternodePayments::IsScheduled(CMasternode& mn, int nNotBlockHeight)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CMasternodePayments::AddWinningMasternode(CMasternodePaymentWinner& winnerIn)
|
||||
bool CMasternodePayments::AddPaymentVote(const CMasternodePaymentVote& vote)
|
||||
{
|
||||
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)) {
|
||||
CMasternodeBlockPayees blockPayees(winnerIn.nBlockHeight);
|
||||
mapMasternodeBlocks[winnerIn.nBlockHeight] = blockPayees;
|
||||
if(!mapMasternodeBlocks.count(vote.nBlockHeight)) {
|
||||
CMasternodeBlockPayees blockPayees(vote.nBlockHeight);
|
||||
mapMasternodeBlocks[vote.nBlockHeight] = blockPayees;
|
||||
}
|
||||
|
||||
mapMasternodeBlocks[winnerIn.nBlockHeight].AddPayee(winnerIn);
|
||||
mapMasternodeBlocks[vote.nBlockHeight].AddPayee(vote);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CMasternodeBlockPayees::AddPayee(CMasternodePaymentWinner winner)
|
||||
void CMasternodeBlockPayees::AddPayee(const CMasternodePaymentVote& vote)
|
||||
{
|
||||
LOCK(cs_vecPayees);
|
||||
|
||||
BOOST_FOREACH(CMasternodePayee& payee, vecPayees) {
|
||||
if (payee.GetPayee() == winner.payee) {
|
||||
payee.AddVoteHash(winner.GetHash());
|
||||
if (payee.GetPayee() == vote.payee) {
|
||||
payee.AddVoteHash(vote.GetHash());
|
||||
return;
|
||||
}
|
||||
}
|
||||
CMasternodePayee payeeNew(winner.payee, winner.GetHash());
|
||||
CMasternodePayee payeeNew(vote.payee, vote.GetHash());
|
||||
vecPayees.push_back(payeeNew);
|
||||
}
|
||||
|
||||
bool CMasternodeBlockPayees::GetPayee(CScript& payeeRet)
|
||||
bool CMasternodeBlockPayees::GetBestPayee(CScript& payeeRet)
|
||||
{
|
||||
LOCK(cs_vecPayees);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -575,18 +575,18 @@ void CMasternodePayments::CheckAndRemove()
|
||||
{
|
||||
if(!pCurrentBlockIndex) return;
|
||||
|
||||
LOCK2(cs_mapMasternodePayeeVotes, cs_mapMasternodeBlocks);
|
||||
LOCK2(cs_mapMasternodePaymentVotes, cs_mapMasternodeBlocks);
|
||||
|
||||
int nLimit = GetStorageLimit();
|
||||
|
||||
std::map<uint256, CMasternodePaymentWinner>::iterator it = mapMasternodePayeeVotes.begin();
|
||||
while(it != mapMasternodePayeeVotes.end()) {
|
||||
CMasternodePaymentWinner winner = (*it).second;
|
||||
std::map<uint256, CMasternodePaymentVote>::iterator it = mapMasternodePaymentVotes.begin();
|
||||
while(it != mapMasternodePaymentVotes.end()) {
|
||||
CMasternodePaymentVote vote = (*it).second;
|
||||
|
||||
if(pCurrentBlockIndex->nHeight - winner.nBlockHeight > nLimit) {
|
||||
LogPrint("mnpayments", "CMasternodePayments::CheckAndRemove -- Removing old Masternode payment: nBlockHeight=%d\n", winner.nBlockHeight);
|
||||
mapMasternodePayeeVotes.erase(it++);
|
||||
mapMasternodeBlocks.erase(winner.nBlockHeight);
|
||||
if(pCurrentBlockIndex->nHeight - vote.nBlockHeight > nLimit) {
|
||||
LogPrint("mnpayments", "CMasternodePayments::CheckAndRemove -- Removing old Masternode payment: nBlockHeight=%d\n", vote.nBlockHeight);
|
||||
mapMasternodePaymentVotes.erase(it++);
|
||||
mapMasternodeBlocks.erase(vote.nBlockHeight);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
@ -594,7 +594,7 @@ void CMasternodePayments::CheckAndRemove()
|
||||
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);
|
||||
|
||||
@ -610,7 +610,7 @@ bool CMasternodePaymentWinner::IsValid(CNode* pnode, int nValidationHeight, std:
|
||||
|
||||
int nMinRequiredProtocol;
|
||||
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();
|
||||
} else {
|
||||
// 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
|
||||
if(nRank > MNPAYMENTS_SIGNATURES_TOTAL*2 && nBlockHeight > nValidationHeight) {
|
||||
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);
|
||||
}
|
||||
// Still invalid however
|
||||
@ -683,22 +683,22 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight)
|
||||
|
||||
CScript payee = GetScriptForDestination(pmn->pubKeyCollateralAddress.GetID());
|
||||
|
||||
CMasternodePaymentWinner newWinner(activeMasternode.vin, nBlockHeight, payee);
|
||||
CMasternodePaymentVote voteNew(activeMasternode.vin, nBlockHeight, payee);
|
||||
|
||||
CTxDestination address1;
|
||||
ExtractDestination(payee, 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
|
||||
|
||||
LogPrintf("CMasternodePayments::ProcessBlock -- Signing Winner\n");
|
||||
if (newWinner.Sign()) {
|
||||
LogPrintf("CMasternodePayments::ProcessBlock -- AddWinningMasternode()\n");
|
||||
LogPrintf("CMasternodePayments::ProcessBlock -- Signing vote\n");
|
||||
if (voteNew.Sign()) {
|
||||
LogPrintf("CMasternodePayments::ProcessBlock -- AddPaymentVote()\n");
|
||||
|
||||
if (AddWinningMasternode(newWinner)) {
|
||||
newWinner.Relay();
|
||||
if (AddPaymentVote(voteNew)) {
|
||||
voteNew.Relay();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -706,13 +706,13 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight)
|
||||
return false;
|
||||
}
|
||||
|
||||
void CMasternodePaymentWinner::Relay()
|
||||
void CMasternodePaymentVote::Relay()
|
||||
{
|
||||
CInv inv(MSG_MASTERNODE_WINNER, GetHash());
|
||||
CInv inv(MSG_MASTERNODE_PAYMENT_VOTE, GetHash());
|
||||
RelayInv(inv);
|
||||
}
|
||||
|
||||
bool CMasternodePaymentWinner::CheckSignature()
|
||||
bool CMasternodePaymentVote::CheckSignature()
|
||||
{
|
||||
|
||||
CMasternode* pmn = mnodeman.Find(vinMasternode);
|
||||
@ -725,13 +725,13 @@ bool CMasternodePaymentWinner::CheckSignature()
|
||||
|
||||
std::string 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;
|
||||
}
|
||||
|
||||
std::string CMasternodePaymentWinner::ToString() const
|
||||
std::string CMasternodePaymentVote::ToString() const
|
||||
{
|
||||
std::ostringstream info;
|
||||
|
||||
@ -755,7 +755,7 @@ void CMasternodePayments::Sync(CNode* pnode, int nCountNeeded)
|
||||
int nLimit = GetStorageLimit();
|
||||
if(nCountNeeded > nLimit) nCountNeeded = nLimit;
|
||||
} 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;
|
||||
}
|
||||
|
||||
@ -766,14 +766,14 @@ void CMasternodePayments::Sync(CNode* pnode, int nCountNeeded)
|
||||
BOOST_FOREACH(CMasternodePayee& payee, mapMasternodeBlocks[h].vecPayees) {
|
||||
std::vector<uint256> vecVoteHashes = payee.GetVoteHashes();
|
||||
BOOST_FOREACH(uint256& hash, vecVoteHashes) {
|
||||
pnode->PushInventory(CInv(MSG_MASTERNODE_WINNER, hash));
|
||||
pnode->PushInventory(CInv(MSG_MASTERNODE_PAYMENT_VOTE, hash));
|
||||
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);
|
||||
}
|
||||
|
||||
@ -820,7 +820,7 @@ void CMasternodePayments::RequestLowDataPaymentBlocks(CNode* pnode)
|
||||
// Low data block found, let's try to sync it
|
||||
uint256 hash;
|
||||
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
|
||||
if(vToFetch.size() == MAX_INV_SZ) {
|
||||
@ -842,7 +842,7 @@ std::string CMasternodePayments::ToString() const
|
||||
{
|
||||
std::ostringstream info;
|
||||
|
||||
info << "Votes: " << (int)mapMasternodePayeeVotes.size() <<
|
||||
info << "Votes: " << (int)mapMasternodePaymentVotes.size() <<
|
||||
", Blocks: " << (int)mapMasternodeBlocks.size();
|
||||
|
||||
return info.str();
|
||||
|
@ -13,14 +13,14 @@
|
||||
#include "utilstrencodings.h"
|
||||
|
||||
class CMasternodePayments;
|
||||
class CMasternodePaymentWinner;
|
||||
class CMasternodePaymentVote;
|
||||
class CMasternodeBlockPayees;
|
||||
|
||||
static const int MNPAYMENTS_SIGNATURES_REQUIRED = 6;
|
||||
static const int MNPAYMENTS_SIGNATURES_TOTAL = 10;
|
||||
|
||||
//! 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
|
||||
// V2 - Newest protocol version
|
||||
static const int MIN_MASTERNODE_PAYMENT_PROTO_VERSION_1 = 70103;
|
||||
@ -90,8 +90,8 @@ public:
|
||||
READWRITE(vecPayees);
|
||||
}
|
||||
|
||||
void AddPayee(CMasternodePaymentWinner winner);
|
||||
bool GetPayee(CScript& payeeRet);
|
||||
void AddPayee(const CMasternodePaymentVote& vote);
|
||||
bool GetBestPayee(CScript& payeeRet);
|
||||
bool HasPayeeWithVotes(CScript payeeIn, int nVotesReq);
|
||||
|
||||
bool IsTransactionValid(const CTransaction& txNew);
|
||||
@ -99,8 +99,8 @@ public:
|
||||
std::string GetRequiredPaymentsString();
|
||||
};
|
||||
|
||||
// for storing the winning payments
|
||||
class CMasternodePaymentWinner
|
||||
// vote for the winning payment
|
||||
class CMasternodePaymentVote
|
||||
{
|
||||
public:
|
||||
CTxIn vinMasternode;
|
||||
@ -109,16 +109,18 @@ public:
|
||||
CScript payee;
|
||||
std::vector<unsigned char> vchSig;
|
||||
|
||||
CMasternodePaymentWinner() :
|
||||
vinMasternode(CTxIn()),
|
||||
CMasternodePaymentVote() :
|
||||
vinMasternode(),
|
||||
nBlockHeight(0),
|
||||
payee(CScript())
|
||||
payee(),
|
||||
vchSig()
|
||||
{}
|
||||
|
||||
CMasternodePaymentWinner(CTxIn vinMasternode, int nBlockHeight, CScript payee) :
|
||||
CMasternodePaymentVote(CTxIn vinMasternode, int nBlockHeight, CScript payee) :
|
||||
vinMasternode(vinMasternode),
|
||||
nBlockHeight(nBlockHeight),
|
||||
payee(payee)
|
||||
payee(payee),
|
||||
vchSig()
|
||||
{}
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
@ -165,7 +167,7 @@ private:
|
||||
const CBlockIndex *pCurrentBlockIndex;
|
||||
|
||||
public:
|
||||
std::map<uint256, CMasternodePaymentWinner> mapMasternodePayeeVotes;
|
||||
std::map<uint256, CMasternodePaymentVote> mapMasternodePaymentVotes;
|
||||
std::map<int, CMasternodeBlockPayees> mapMasternodeBlocks;
|
||||
std::map<COutPoint, int> mapMasternodesLastVote;
|
||||
|
||||
@ -175,13 +177,13 @@ public:
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
READWRITE(mapMasternodePayeeVotes);
|
||||
READWRITE(mapMasternodePaymentVotes);
|
||||
READWRITE(mapMasternodeBlocks);
|
||||
}
|
||||
|
||||
void Clear();
|
||||
|
||||
bool AddWinningMasternode(CMasternodePaymentWinner& winner);
|
||||
bool AddPaymentVote(const CMasternodePaymentVote& vote);
|
||||
bool ProcessBlock(int nBlockHeight);
|
||||
|
||||
void Sync(CNode* node, int nCountNeeded);
|
||||
@ -201,7 +203,7 @@ public:
|
||||
std::string ToString() const;
|
||||
|
||||
int GetBlockCount() { return mapMasternodeBlocks.size(); }
|
||||
int GetVoteCount() { return mapMasternodePayeeVotes.size(); }
|
||||
int GetVoteCount() { return mapMasternodePaymentVotes.size(); }
|
||||
|
||||
bool IsEnoughData(int nMnCount);
|
||||
int GetStorageLimit();
|
||||
|
@ -51,7 +51,7 @@ void CMasternodeSync::Reset()
|
||||
nRequestedMasternodeAttempt = 0;
|
||||
nTimeAssetSyncStarted = GetTime();
|
||||
nTimeLastMasternodeList = GetTime();
|
||||
nTimeLastMasternodeWinner = GetTime();
|
||||
nTimeLastPaymentVote = GetTime();
|
||||
nTimeLastBudgetItem = GetTime();
|
||||
nTimeLastFailure = 0;
|
||||
nCountFailures = 0;
|
||||
@ -88,7 +88,7 @@ void CMasternodeSync::SwitchToNextAsset()
|
||||
nRequestedMasternodeAssets = MASTERNODE_SYNC_LIST;
|
||||
break;
|
||||
case(MASTERNODE_SYNC_LIST):
|
||||
nTimeLastMasternodeWinner = GetTime();
|
||||
nTimeLastPaymentVote = GetTime();
|
||||
nRequestedMasternodeAssets = MASTERNODE_SYNC_MNW;
|
||||
break;
|
||||
case(MASTERNODE_SYNC_MNW):
|
||||
@ -113,7 +113,7 @@ std::string CMasternodeSync::GetSyncStatus()
|
||||
case MASTERNODE_SYNC_INITIAL: return _("Synchronization pending...");
|
||||
case MASTERNODE_SYNC_SPORKS: return _("Synchronizing sporks...");
|
||||
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_FAILED: return _("Synchronization failed");
|
||||
case MASTERNODE_SYNC_FINISHED: return _("Synchronization finished");
|
||||
@ -144,7 +144,7 @@ void CMasternodeSync::ClearFulfilledRequest()
|
||||
BOOST_FOREACH(CNode* pnode, vNodes)
|
||||
{
|
||||
pnode->ClearFulfilledRequest("spork-sync");
|
||||
pnode->ClearFulfilledRequest("masternode-winner-sync");
|
||||
pnode->ClearFulfilledRequest("masternode-payment-sync");
|
||||
pnode->ClearFulfilledRequest("governance-sync");
|
||||
pnode->ClearFulfilledRequest("masternode-sync");
|
||||
}
|
||||
@ -209,7 +209,7 @@ void CMasternodeSync::ProcessTick()
|
||||
mnodeman.DsegUpdate(pnode);
|
||||
} else if(nRequestedMasternodeAttempt < 6) {
|
||||
int nMnCount = mnodeman.CountEnabled();
|
||||
pnode->PushMessage(NetMsgType::MNWINNERSSYNC, nMnCount); //sync payees
|
||||
pnode->PushMessage(NetMsgType::MASTERNODEPAYMENTSYNC, nMnCount); //sync payment votes
|
||||
uint256 n = uint256();
|
||||
pnode->PushMessage(NetMsgType::MNGOVERNANCESYNC, n); //sync masternode votes
|
||||
} 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
|
||||
}
|
||||
|
||||
// MNW : SYNC MASTERNODE WINNERS FROM OTHER CONNECTED CLIENTS
|
||||
// MNW : SYNC MASTERNODE PAYMENT VOTES FROM OTHER CONNECTED CLIENTS
|
||||
|
||||
if(nRequestedMasternodeAssets == MASTERNODE_SYNC_MNW) {
|
||||
// check for timeout first
|
||||
// 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.
|
||||
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);
|
||||
if (nRequestedMasternodeAttempt == 0) {
|
||||
LogPrintf("CMasternodeSync::Process -- WARNING: failed to sync %s\n", GetAssetName());
|
||||
@ -303,14 +303,14 @@ void CMasternodeSync::ProcessTick()
|
||||
}
|
||||
|
||||
// only request once from each peer
|
||||
if(pnode->HasFulfilledRequest("masternode-winner-sync")) continue;
|
||||
pnode->FulfilledRequest("masternode-winner-sync");
|
||||
if(pnode->HasFulfilledRequest("masternode-payment-sync")) continue;
|
||||
pnode->FulfilledRequest("masternode-payment-sync");
|
||||
|
||||
if(pnode->nVersion < mnpayments.GetMinMasternodePaymentsProto()) continue;
|
||||
nRequestedMasternodeAttempt++;
|
||||
|
||||
// ask node for all winners it has (new nodes will only return future winners)
|
||||
pnode->PushMessage(NetMsgType::MNWINNERSSYNC, mnpayments.GetStorageLimit());
|
||||
// ask node for all payment votes it has (new nodes will only return votes for future payments)
|
||||
pnode->PushMessage(NetMsgType::MASTERNODEPAYMENTSYNC, mnpayments.GetStorageLimit());
|
||||
// ask node for missing pieces only (old nodes will not be asked)
|
||||
mnpayments.RequestLowDataPaymentBlocks(pnode);
|
||||
|
||||
|
@ -42,7 +42,7 @@ private:
|
||||
|
||||
// Last time when we received some masternode asset ...
|
||||
int64_t nTimeLastMasternodeList;
|
||||
int64_t nTimeLastMasternodeWinner;
|
||||
int64_t nTimeLastPaymentVote;
|
||||
int64_t nTimeLastBudgetItem;
|
||||
// ... or failed
|
||||
int64_t nTimeLastFailure;
|
||||
@ -60,7 +60,7 @@ public:
|
||||
CMasternodeSync() { Reset(); }
|
||||
|
||||
void AddedMasternodeList() { nTimeLastMasternodeList = GetTime(); }
|
||||
void AddedMasternodeWinner() { nTimeLastMasternodeWinner = GetTime(); }
|
||||
void AddedPaymentVote() { nTimeLastPaymentVote = GetTime(); }
|
||||
void AddedBudgetItem(uint256 hash);
|
||||
|
||||
bool IsFailed() { return nRequestedMasternodeAssets == MASTERNODE_SYNC_FAILED; }
|
||||
|
@ -40,9 +40,9 @@ const char *TXLOCKREQUEST="ix";
|
||||
const char *TXLOCKVOTE="txlvote";
|
||||
const char *SPORK="spork";
|
||||
const char *GETSPORKS="getsporks";
|
||||
const char *MNWINNER="mnw";
|
||||
const char *MNWINNERBLOCK="mnwb";
|
||||
const char *MNWINNERSSYNC="mnget";
|
||||
const char *MASTERNODEPAYMENTVOTE="mnw";
|
||||
const char *MASTERNODEPAYMENTBLOCK="mnwb";
|
||||
const char *MASTERNODEPAYMENTSYNC="mnget";
|
||||
const char *MNSCANERROR="mn scan error"; // not implemented
|
||||
const char *MNBUDGETSYNC="mnvs"; // depreciated since 12.1
|
||||
const char *MNBUDGETVOTE="mvote"; // depreciated since 12.1
|
||||
@ -78,8 +78,8 @@ static const char* ppszTypeName[] =
|
||||
NetMsgType::TXLOCKREQUEST,
|
||||
NetMsgType::TXLOCKVOTE,
|
||||
NetMsgType::SPORK,
|
||||
NetMsgType::MNWINNER,
|
||||
NetMsgType::MNWINNERBLOCK, // reusing, was MNSCANERROR previousely, was NOT used in 12.0, we need this for inv
|
||||
NetMsgType::MASTERNODEPAYMENTVOTE,
|
||||
NetMsgType::MASTERNODEPAYMENTBLOCK, // reusing, was MNSCANERROR previousely, was NOT used in 12.0, we need this for inv
|
||||
NetMsgType::MNBUDGETVOTE, // depreciated since 12.1
|
||||
NetMsgType::MNBUDGETPROPOSAL, // depreciated since 12.1
|
||||
NetMsgType::MNBUDGETFINAL, // depreciated since 12.1
|
||||
@ -124,9 +124,9 @@ const static std::string allNetMessageTypes[] = {
|
||||
NetMsgType::TXLOCKVOTE,
|
||||
NetMsgType::SPORK,
|
||||
NetMsgType::GETSPORKS,
|
||||
NetMsgType::MNWINNER,
|
||||
// NetMsgType::MNWINNERBLOCK, // there is no message for this, only inventory
|
||||
NetMsgType::MNWINNERSSYNC,
|
||||
NetMsgType::MASTERNODEPAYMENTVOTE,
|
||||
// NetMsgType::MASTERNODEPAYMENTBLOCK, // there is no message for this, only inventory
|
||||
NetMsgType::MASTERNODEPAYMENTSYNC,
|
||||
NetMsgType::MNANNOUNCE,
|
||||
NetMsgType::MNPING,
|
||||
NetMsgType::DSACCEPT,
|
||||
|
@ -226,8 +226,8 @@ extern const char *TXLOCKREQUEST;
|
||||
extern const char *TXLOCKVOTE;
|
||||
extern const char *SPORK;
|
||||
extern const char *GETSPORKS;
|
||||
extern const char *MNWINNER;
|
||||
extern const char *MNWINNERSSYNC;
|
||||
extern const char *MASTERNODEPAYMENTVOTE;
|
||||
extern const char *MASTERNODEPAYMENTSYNC;
|
||||
extern const char *MNANNOUNCE;
|
||||
extern const char *MNPING;
|
||||
extern const char *DSACCEPT;
|
||||
@ -345,8 +345,8 @@ enum {
|
||||
MSG_TXLOCK_REQUEST,
|
||||
MSG_TXLOCK_VOTE,
|
||||
MSG_SPORK,
|
||||
MSG_MASTERNODE_WINNER,
|
||||
MSG_MASTERNODE_WINNER_BLOCK, // reusing, was MSG_MASTERNODE_SCANNING_ERROR previousely, was NOT used in 12.0
|
||||
MSG_MASTERNODE_PAYMENT_VOTE,
|
||||
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_PROPOSAL, // depreciated since 12.1
|
||||
MSG_BUDGET_FINALIZED, // depreciated since 12.1
|
||||
|
Loading…
Reference in New Issue
Block a user