Masternode payment consensus via quorums
- Payees are chosen by their last payment, if no payment it's based on their hash - Fixed a few issues with counting quorum votes
This commit is contained in:
parent
d470eddc01
commit
bd4a7f2fad
10
src/main.cpp
10
src/main.cpp
@ -3234,11 +3234,13 @@ bool ProcessNewBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDis
|
||||
if (!fImporting && !fReindex && chainActive.Height() > Checkpoints::GetTotalBlocksEstimate()){
|
||||
CScript payee;
|
||||
CTxIn vin;
|
||||
if(masternodePayments.GetBlockPayee(chainActive.Tip()->nHeight, payee)){
|
||||
//UPDATE MASTERNODE LAST PAID TIME
|
||||
CMasternode* pmn = mnodeman.Find(vin);
|
||||
if(pmn != NULL) pmn->nLastPaid = GetAdjustedTime();
|
||||
|
||||
if(masternodePayments.GetBlockPayee(chainActive.Tip()->nHeight+1, payee)){
|
||||
//UPDATE MASTERNODE LAST PAID TIME
|
||||
CMasternode* pmn = mnodeman.Find(payee);
|
||||
if(pmn != NULL) {
|
||||
pmn->nLastPaid = GetAdjustedTime();
|
||||
}
|
||||
LogPrintf("%s : Update Masternode Last Paid Time - %d\n", __func__, chainActive.Tip()->nHeight);
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ bool CMasternodePaymentWinner::Sign(CKey& keyMasternode, CPubKey& pubKeyMasterno
|
||||
|
||||
bool CMasternodePayments::GetBlockPayee(int nBlockHeight, CScript& payee)
|
||||
{
|
||||
if(!mapMasternodeBlocks.count(nBlockHeight)){
|
||||
if(mapMasternodeBlocks.count(nBlockHeight)){
|
||||
return mapMasternodeBlocks[nBlockHeight].GetPayee(payee);
|
||||
}
|
||||
|
||||
@ -146,9 +146,11 @@ bool CMasternodePayments::IsScheduled(CMasternode& mn)
|
||||
CScript payee;
|
||||
for(int64_t h = pindexPrev->nHeight; h <= pindexPrev->nHeight+10; h++){
|
||||
if(mapMasternodeBlocks.count(h)){
|
||||
mapMasternodeBlocks[h].GetPayee(payee);
|
||||
if(payee != CScript() && mnpayee == payee) return true;
|
||||
if(mn.donationAddress != CScript() && mn.donationAddress == payee) return true;
|
||||
if(mapMasternodeBlocks[h].GetPayee(payee)){
|
||||
if(mnpayee == payee || mn.donationAddress == payee) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -169,7 +171,7 @@ bool CMasternodePayments::AddWinningMasternode(CMasternodePaymentWinner& winnerI
|
||||
mapMasternodePayeeVotes[winnerIn.GetHash()] = winnerIn;
|
||||
|
||||
if(!mapMasternodeBlocks.count(winnerIn.nBlockHeight)){
|
||||
CMasternodeBlockPayees blockPayees;
|
||||
CMasternodeBlockPayees blockPayees(winnerIn.nBlockHeight);
|
||||
mapMasternodeBlocks[winnerIn.nBlockHeight] = blockPayees;
|
||||
}
|
||||
|
||||
@ -236,9 +238,9 @@ std::string CMasternodeBlockPayees::GetRequiredPaymentsString()
|
||||
CBitcoinAddress address2(address1);
|
||||
|
||||
if(ret != "Unknown"){
|
||||
ret += ", " + address2.ToString() + ":" + boost::lexical_cast<std::string>(payee.nValue);
|
||||
ret += ", " + address2.ToString() + ":" + boost::lexical_cast<std::string>(payee.nValue) + ":" + boost::lexical_cast<std::string>(payee.nVotes);
|
||||
} else {
|
||||
ret = address2.ToString() + ":" + boost::lexical_cast<std::string>(payee.nValue);
|
||||
ret = address2.ToString() + ":" + boost::lexical_cast<std::string>(payee.nValue) + ":" + boost::lexical_cast<std::string>(payee.nVotes);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
return nVotes > -1;
|
||||
return (nVotes > -1);
|
||||
}
|
||||
|
||||
bool IsTransactionValid(const CTransaction& txNew);
|
||||
@ -126,6 +126,8 @@ public:
|
||||
uint256 GetHash(){
|
||||
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
|
||||
ss << payee;
|
||||
ss << nBlockHeight;
|
||||
ss << vinMasternode.prevout;
|
||||
|
||||
return ss.GetHash();
|
||||
}
|
||||
|
@ -85,9 +85,7 @@ CMasternode::CMasternode()
|
||||
nScanningErrorCount = 0;
|
||||
nLastScanningErrorBlockHeight = 0;
|
||||
nVotedTimes = 0;
|
||||
|
||||
//mark last paid as current for new entries
|
||||
nLastPaid = GetAdjustedTime();
|
||||
nLastPaid = 0;
|
||||
}
|
||||
|
||||
CMasternode::CMasternode(const CMasternode& other)
|
||||
@ -138,7 +136,7 @@ CMasternode::CMasternode(CService newAddr, CTxIn newVin, CPubKey newPubkey, std:
|
||||
donationPercentage = newDonationPercentage;
|
||||
nScanningErrorCount = 0;
|
||||
nLastScanningErrorBlockHeight = 0;
|
||||
nLastPaid = GetAdjustedTime();
|
||||
nLastPaid = 0;
|
||||
nVotedTimes = 0;
|
||||
}
|
||||
|
||||
@ -269,9 +267,7 @@ CMasternodeBroadcast::CMasternodeBroadcast()
|
||||
donationPercentage = 0;
|
||||
nScanningErrorCount = 0;
|
||||
nLastScanningErrorBlockHeight = 0;
|
||||
|
||||
//mark last paid as current for new entries
|
||||
nLastPaid = GetAdjustedTime();
|
||||
nLastPaid = 0;
|
||||
}
|
||||
|
||||
CMasternodeBroadcast::CMasternodeBroadcast(CService newAddr, CTxIn newVin, CPubKey newPubkey, CPubKey newPubkey2, int protocolVersionIn, CScript newDonationAddress, int newDonationPercentage)
|
||||
@ -295,7 +291,7 @@ CMasternodeBroadcast::CMasternodeBroadcast(CService newAddr, CTxIn newVin, CPubK
|
||||
donationPercentage = newDonationPercentage;
|
||||
nScanningErrorCount = 0;
|
||||
nLastScanningErrorBlockHeight = 0;
|
||||
nLastPaid = GetAdjustedTime();
|
||||
nLastPaid = 0;
|
||||
}
|
||||
|
||||
CMasternodeBroadcast::CMasternodeBroadcast(const CMasternode& other)
|
||||
|
@ -165,8 +165,16 @@ public:
|
||||
|
||||
int64_t SecondsSincePayment()
|
||||
{
|
||||
return (GetAdjustedTime() - nLastPaid);
|
||||
int64_t sec = (GetAdjustedTime() - nLastPaid);
|
||||
if(sec < 60*60*24*30) return sec; //if it's less than 30 days, give seconds
|
||||
|
||||
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
|
||||
ss << vin;
|
||||
ss << sigTime;
|
||||
uint256 hash = ss.GetHash();
|
||||
|
||||
memcpy(&sec, &hash, 64);
|
||||
return sec;
|
||||
}
|
||||
|
||||
void UpdateFromNewBroadcast(CMasternodeBroadcast& mnb);
|
||||
|
@ -326,6 +326,20 @@ void CMasternodeMan::DsegUpdate(CNode* pnode)
|
||||
mWeAskedForMasternodeList[pnode->addr] = askAgain;
|
||||
}
|
||||
|
||||
CMasternode *CMasternodeMan::Find(const CScript &payee)
|
||||
{
|
||||
LOCK(cs);
|
||||
CScript payee2;
|
||||
|
||||
BOOST_FOREACH(CMasternode& mn, vMasternodes)
|
||||
{
|
||||
payee2 = GetScriptForDestination(mn.pubkey.GetID());
|
||||
if(payee2 == payee)
|
||||
return &mn;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CMasternode *CMasternodeMan::Find(const CTxIn &vin)
|
||||
{
|
||||
LOCK(cs);
|
||||
@ -578,14 +592,7 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
|
||||
|
||||
// make sure it's still unspent
|
||||
// - this is checked later by .check() in many places and by ThreadCheckDarkSendPool()
|
||||
|
||||
//if it's a broadcast or we're synced
|
||||
if(fRequested || !IsSyncingMasternodeAssets()){
|
||||
mnb.nLastPaid = GetAdjustedTime();
|
||||
}
|
||||
|
||||
if(mnb.CheckInputsAndAdd(nDoS, fRequested)) {
|
||||
|
||||
// use this as a peer
|
||||
addrman.Add(CAddress(mnb.addr), pfrom->addr, 2*60*60);
|
||||
} else {
|
||||
|
@ -105,6 +105,7 @@ public:
|
||||
void DsegUpdate(CNode* pnode);
|
||||
|
||||
/// Find an entry
|
||||
CMasternode* Find(const CScript &payee);
|
||||
CMasternode* Find(const CTxIn& vin);
|
||||
CMasternode* Find(const CPubKey& pubKeyMasternode);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user