Spork changes / improvements

- New Command "Spork Active" : Show which sporks report as active
- Cleaned up the spork code and fixed some bugs with defaults
This commit is contained in:
Evan Duffield 2015-06-25 08:17:53 -07:00
parent 94493bee63
commit e3963ea71c
3 changed files with 33 additions and 20 deletions

View File

@ -82,7 +82,7 @@ void FillBlockPayee(CMutableTransaction& txNew, int64_t nFees)
{
CBlockIndex* pindexPrev = chainActive.Tip();
if(!pindexPrev) return;
if(budget.IsBudgetPaymentBlock(pindexPrev->nHeight+1)){
budget.FillBlockPayee(txNew, nFees);
} else {
@ -106,7 +106,7 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe
bool hasPayment = true;
CScript payee;
//spork
if(!masternodePayments.GetBlockPayee(pindexPrev->nHeight+1, payee)){
//no masternode detected
@ -121,7 +121,7 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe
CAmount blockValue = GetBlockValue(pindexPrev->nBits, pindexPrev->nHeight, nFees);
CAmount masternodePayment = GetMasternodePayment(pindexPrev->nHeight+1, blockValue);
txNew.vout[0].nValue = blockValue;
if(hasPayment){
@ -168,7 +168,7 @@ void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st
if(mapMasternodePayeeVotes.count(winner.GetHash())){
if(fDebug) LogPrintf("mnw - Already seen - %s bestHeight %d\n", winner.GetHash().ToString().c_str(), chainActive.Tip()->nHeight);
return;
return;
}
if(winner.nBlockHeight < chainActive.Tip()->nHeight - 10 || winner.nBlockHeight > chainActive.Tip()->nHeight+20){
@ -205,9 +205,9 @@ bool CMasternodePaymentWinner::Sign(CKey& keyMasternode, CPubKey& pubKeyMasterno
std::string strMasterNodeSignMessage;
std::string strMessage = vinMasternode.prevout.ToStringShort() +
boost::lexical_cast<std::string>(nBlockHeight) +
boost::lexical_cast<std::string>(nBlockHeight) +
payee.ToString();
if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchSig, keyMasternode)) {
LogPrintf("CMasternodePing::Sign() - Error: %s\n", errorMessage.c_str());
return false;
@ -263,7 +263,7 @@ bool CMasternodePayments::AddWinningMasternode(CMasternodePaymentWinner& winnerI
LogPrintf("CMasternodePayments::AddWinningMasternode - checkhash\n");
if(mapMasternodePayeeVotes.count(winnerIn.GetHash())){
return false;
return false;
}
mapMasternodePayeeVotes[winnerIn.GetHash()] = winnerIn;
@ -292,18 +292,20 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew)
BOOST_FOREACH(CMasternodePayee& payee, vecPayments)
if(payee.nVotes >= nMaxSignatures && payee.nVotes >= MNPAYMENTS_SIGNATURES_REQUIRED)
nMaxSignatures = payee.nVotes;
// if we don't have at least 6 signatures on a payee, approve whichever is the longest chain
if(nMaxSignatures < MNPAYMENTS_SIGNATURES_REQUIRED) return true;
BOOST_FOREACH(CMasternodePayee& payee, vecPayments)
{
bool found = false;
BOOST_FOREACH(CTxOut out, txNew.vout)
if(payee.scriptPubKey == out.scriptPubKey && payee.nValue == out.nValue)
BOOST_FOREACH(CTxOut out, txNew.vout){
if(payee.scriptPubKey == out.scriptPubKey && payee.nValue == out.nValue){
found = true;
}
}
if(payee.nVotes >= MNPAYMENTS_SIGNATURES_REQUIRED){
if(payee.nVotes >= MNPAYMENTS_SIGNATURES_REQUIRED){
if(found) return true;
CTxDestination address1;
@ -372,7 +374,7 @@ void CMasternodePayments::CleanPaymentList()
std::map<uint256, CMasternodePaymentWinner>::iterator it = mapMasternodePayeeVotes.begin();
while(it != mapMasternodePayeeVotes.end()) {
CMasternodePaymentWinner winner = (*it).second;
if(chainActive.Tip()->nHeight - winner.nBlockHeight > nLimit){
if(fDebug) LogPrintf("CMasternodePayments::CleanPaymentList - Removing old Masternode payment - block %d\n", winner.nBlockHeight);
mapMasternodePayeeVotes.erase(it++);
@ -438,7 +440,7 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight)
}
if(nBlockHeight <= nLastBlockHeight) return false;
CBlockIndex* pindexPrev = chainActive.Tip();
if(pindexPrev == NULL) return false;
CAmount blockValue = GetBlockValue(pindexPrev->nBits, pindexPrev->nHeight, 0);
@ -467,7 +469,7 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight)
CScript payee = GetScriptForDestination(pmn->pubkey.GetID());
newWinner.AddPayee(payee, masternodePayment);
CTxDestination address1;
ExtractDestination(payee, address1);
CBitcoinAddress address2(address1);
@ -525,7 +527,7 @@ bool CMasternodePaymentWinner::SignatureValid()
if(pmn != NULL)
{
std::string strMessage = vinMasternode.prevout.ToStringShort() +
boost::lexical_cast<std::string>(nBlockHeight) +
boost::lexical_cast<std::string>(nBlockHeight) +
payee.ToString();

View File

@ -165,7 +165,18 @@ Value spork(const Array& params, bool fHelp)
Object ret;
while(it != mapSporksActive.end()) {
ret.push_back(Pair(sporkManager.GetSporkNameByID(it->second.nSporkID), it->second.nValue));
if(sporkManager.GetSporkNameByID(it->second.nSporkID) != "Unknown")
ret.push_back(Pair(sporkManager.GetSporkNameByID(it->second.nSporkID), it->second.nValue));
it++;
}
return ret;
} else if(params.size() == 1 && params[0].get_str() == "active"){
std::map<int, CSporkMessage>::iterator it = mapSporksActive.begin();
Object ret;
while(it != mapSporksActive.end()) {
if(sporkManager.GetSporkNameByID(it->second.nSporkID) != "Unknown")
ret.push_back(Pair(sporkManager.GetSporkNameByID(it->second.nSporkID), IsSporkActive(it->second.nSporkID)));
it++;
}
return ret;
@ -189,7 +200,7 @@ Value spork(const Array& params, bool fHelp)
throw runtime_error(
"spork <name> [<value>]\n"
"<name> is the corresponding spork name, or 'show' to show all current spork settings"
"<name> is the corresponding spork name, or 'show' to show all current spork settings, active to show which sporks are active"
"<value> is a epoch datetime to enable or disable spork"
+ HelpRequiringPassphrase());
}

View File

@ -84,9 +84,9 @@ bool IsSporkActive(int nSporkID)
if(nSporkID == SPORK_2_INSTANTX) r = SPORK_2_INSTANTX_DEFAULT;
if(nSporkID == SPORK_3_INSTANTX_BLOCK_FILTERING) r = SPORK_3_INSTANTX_BLOCK_FILTERING_DEFAULT;
if(nSporkID == SPORK_5_MAX_VALUE) r = SPORK_5_MAX_VALUE_DEFAULT;
if(nSporkID == SPORK_7_MASTERNODE_SCANNING) r = SPORK_7_MASTERNODE_SCANNING;
if(nSporkID == SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT) r = SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT;
if(nSporkID == SPORK_9_MASTERNODE_BUDGET_ENFORCEMENT) r = SPORK_9_MASTERNODE_BUDGET_ENFORCEMENT;
if(nSporkID == SPORK_7_MASTERNODE_SCANNING) r = SPORK_7_MASTERNODE_SCANNING_DEFAULT;
if(nSporkID == SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT) r = SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT_DEFAULT;
if(nSporkID == SPORK_9_MASTERNODE_BUDGET_ENFORCEMENT) r = SPORK_9_MASTERNODE_BUDGET_ENFORCEMENT_DEFAULT;
if(r == 0) LogPrintf("GetSpork::Unknown Spork %d\n", nSporkID);
}