Various fixes

- Proposal submitting now works properly
- Syncing proposals now works properly
- Finalized budgets are now created correctly
This commit is contained in:
Evan Duffield 2015-07-12 10:34:21 -07:00
parent 0a02fa00bb
commit 0b3ef3c9fe
6 changed files with 46 additions and 22 deletions

View File

@ -2360,6 +2360,7 @@ void ThreadCheckDarkSendPool()
if(c % 5 == 0 && RequestedMasternodeAssets <= 5){
bool fIsInitialDownload = IsInitialBlockDownload();
if(!fIsInitialDownload) {
CBlockIndex* pindexPrev = chainActive.Tip();
if(pindexPrev != NULL) {
if(pindexPrev->nTime > GetAdjustedTime() - 60)
@ -2368,11 +2369,13 @@ void ThreadCheckDarkSendPool()
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
{
if (pnode->nVersion >= MIN_POOL_PEER_PROTO_VERSION) {
//keep track of who we've asked for the list
if(pnode->HasFulfilledRequest("mnsync")) continue;
pnode->FulfilledRequest("mnsync");
if (pnode->nVersion >= MIN_POOL_PEER_PROTO_VERSION) {
bool IsLocal = pnode->addr.IsRFC1918() || pnode->addr.IsLocal();
if(!IsLocal) {
//keep track of who we've asked for the list
if(pnode->HasFulfilledRequest("mnsync")) continue;
pnode->FulfilledRequest("mnsync");
}
//request full mn list only if Masternodes.dat was updated quite a long time ago

View File

@ -126,6 +126,7 @@ void CBudgetManager::SubmitFinalBudget()
CBlockIndex* pindexPrev = chainActive.Tip();
if(!pindexPrev) return;
int nBlockStart = pindexPrev->nHeight-(pindexPrev->nHeight % GetBudgetPaymentCycleBlocks())+GetBudgetPaymentCycleBlocks();
if(nSubmittedFinalBudget >= nBlockStart) return;
if(nBlockStart - pindexPrev->nHeight > 100) return;
@ -155,26 +156,34 @@ void CBudgetManager::SubmitFinalBudget()
if(!darkSendSigner.SetKey(strMasterNodePrivKey, errorMessage, keyMasternode, pubKeyMasternode)){
LogPrintf("SubmitFinalBudget - Error upon calling SetKey\n");
return;
}
CFinalizedBudgetBroadcast tempBudget(strBudgetName, nBlockStart, vecTxBudgetPayments, 0);
//create fee tx
uint256 hash = 0;
CTransaction tx;
if(!pwalletMain->GetBudgetSystemCollateralTX(tx, tempBudget.GetHash(), true)){
LogPrintf("SubmitFinalBudget - Can't make collateral transaction\n");
return;
}
//create the proposal incase we're the first to make it
CFinalizedBudgetBroadcast finalizedBudgetBroadcast(strBudgetName, nBlockStart, vecTxBudgetPayments, hash);
CFinalizedBudgetBroadcast finalizedBudgetBroadcast(strBudgetName, nBlockStart, vecTxBudgetPayments, tx.GetHash());
if(!finalizedBudgetBroadcast.IsValid()){
LogPrintf("SubmitFinalBudget - Invalid finalized budget broadcast (are all the hashes correct?)\n");
return;
}
mapSeenFinalizedBudgets.insert(make_pair(finalizedBudgetBroadcast.GetHash(), finalizedBudgetBroadcast));
finalizedBudgetBroadcast.Relay();
budget.AddFinalizedBudget(finalizedBudgetBroadcast);
CFinalizedBudgetVote vote(activeMasternode.vin, finalizedBudgetBroadcast.GetHash());
if(!vote.Sign(keyMasternode, pubKeyMasternode)){
LogPrintf("SubmitFinalBudget - Failure to sign.\n");
return;
}
mapSeenFinalizedBudgetVotes.insert(make_pair(vote.GetHash(), vote));
@ -696,19 +705,19 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
LOCK(cs_budget);
if (strCommand == "mnvs") { //Masternode vote sync
uint256 nProp;
vRecv >> nProp;
bool IsLocal = pfrom->addr.IsRFC1918() || pfrom->addr.IsLocal();
if(!IsLocal){
if(!IsLocal && nProp == 0){
if(pfrom->HasFulfilledRequest("mnvs")) {
LogPrintf("mnvs - peer already asked me for the list\n");
Misbehaving(pfrom->GetId(), 20);
return;
}
pfrom->FulfilledRequest("mnvs");
}
uint256 nProp;
vRecv >> nProp;
pfrom->FulfilledRequest("mnvs");
budget.Sync(pfrom, nProp);
LogPrintf("mnvs - Sent Masternode votes to %s\n", pfrom->addr.ToString());
}
@ -735,8 +744,6 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
return;
}
//delete if it exists and insert the new object
if(mapSeenMasternodeBudgetProposals.count(budgetProposalBroadcast.GetHash())) mapSeenMasternodeBudgetProposals.erase(budgetProposalBroadcast.GetHash());
mapSeenMasternodeBudgetProposals.insert(make_pair(budgetProposalBroadcast.GetHash(), budgetProposalBroadcast));
CBudgetProposal budgetProposal(budgetProposalBroadcast);
@ -797,8 +804,6 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
return;
}
//delete if it exists and insert the new object
if(mapSeenFinalizedBudgets.count(finalizedBudgetBroadcast.GetHash())) mapSeenFinalizedBudgets.erase(finalizedBudgetBroadcast.GetHash());
mapSeenFinalizedBudgets.insert(make_pair(finalizedBudgetBroadcast.GetHash(), finalizedBudgetBroadcast));
CFinalizedBudget finalizedBudget(finalizedBudgetBroadcast);
@ -1398,7 +1403,7 @@ bool CFinalizedBudget::IsValid()
if(vecProposals.size() > 100) return false;
if(strBudgetName == "") return false;
if(nBlockStart == 0) return false;
if(nFeeTXHash == 0) return false;
//can only pay out 10% of the possible coins (min value of coins)
if(GetTotalPayout() > budget.GetTotalBudget(nBlockStart)) return false;

View File

@ -166,10 +166,13 @@ void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st
if (strCommand == "mnget") { //Masternode Payments Request Sync
if(fLiteMode) return; //disable all Darksend/Masternode related functionality
if(pfrom->HasFulfilledRequest("mnget")) {
LogPrintf("mnget - peer already asked me for the list\n");
Misbehaving(pfrom->GetId(), 20);
return;
bool IsLocal = pfrom->addr.IsRFC1918() || pfrom->addr.IsLocal();
if(!IsLocal){
if(pfrom->HasFulfilledRequest("mnget")) {
LogPrintf("mnget - peer already asked me for the list\n");
Misbehaving(pfrom->GetId(), 20);
return;
}
}
pfrom->FulfilledRequest("mnget");

View File

@ -198,6 +198,7 @@ Value mnbudget(const Array& params, bool fHelp)
mapSeenMasternodeBudgetProposals.insert(make_pair(budgetProposalBroadcast.GetHash(), budgetProposalBroadcast));
budgetProposalBroadcast.Relay();
budget.AddProposal(budgetProposalBroadcast);
return budgetProposalBroadcast.GetHash().ToString().c_str();
@ -255,6 +256,7 @@ Value mnbudget(const Array& params, bool fHelp)
mapSeenMasternodeBudgetVotes.insert(make_pair(vote.GetHash(), vote));
vote.Relay();
budget.UpdateProposal(vote, NULL);
success++;
}

View File

@ -1980,6 +1980,16 @@ bool CWallet::CreateCollateralTransaction(CMutableTransaction& txCollateral, std
return true;
}
bool CWallet::GetBudgetSystemCollateralTX(CTransaction& tx, uint256 hash, bool useIX)
{
CWalletTx wtx;
if(GetBudgetSystemCollateralTX(wtx, hash, useIX)){
tx = (CTransaction)wtx;
return true;
}
return false;
}
bool CWallet::GetBudgetSystemCollateralTX(CWalletTx& tx, uint256 hash, bool useIX)
{
// make our change address

View File

@ -345,6 +345,7 @@ public:
std::set<CTxDestination> GetAccountAddresses(std::string strAccount) const;
bool GetBudgetSystemCollateralTX(CTransaction& tx, uint256 hash, bool useIX);
bool GetBudgetSystemCollateralTX(CWalletTx& tx, uint256 hash, bool useIX);
bool IsDenominated(const CTxIn &txin) const;