Stable budget implementation

- All budgeting code seems to be rather stable now. Serialization/caching is working rather well.
- Fixed some ambiguous variable names within the budgeting system that were causing the file caching to not work all of the time
This commit is contained in:
Evan Duffield 2015-05-27 09:28:55 -07:00
parent efe377fa69
commit 41eb74dc82
5 changed files with 43 additions and 43 deletions

View File

@ -3945,17 +3945,17 @@ bool static AlreadyHave(const CInv& inv)
case MSG_SPORK: case MSG_SPORK:
return mapSporks.count(inv.hash); return mapSporks.count(inv.hash);
case MSG_MASTERNODE_WINNER: case MSG_MASTERNODE_WINNER:
return true; // mapMasternodePayeeVotes.count(inv.hash); return mapMasternodePayeeVotes.count(inv.hash);
case MSG_MASTERNODE_SCANNING_ERROR: case MSG_MASTERNODE_SCANNING_ERROR:
return mapMasternodeScanningErrors.count(inv.hash); return mapMasternodeScanningErrors.count(inv.hash);
case MSG_BUDGET_VOTE: case MSG_BUDGET_VOTE:
return mapMasternodeBudgetVotes.count(inv.hash); return mapSeenMasternodeBudgetVotes.count(inv.hash);
case MSG_BUDGET_PROPOSAL: case MSG_BUDGET_PROPOSAL:
return mapMasternodeBudgetProposals.count(inv.hash); return mapSeenMasternodeBudgetProposals.count(inv.hash);
case MSG_BUDGET_FINALIZED_VOTE: case MSG_BUDGET_FINALIZED_VOTE:
return mapFinalizedBudgetVotes.count(inv.hash); return mapSeenFinalizedBudgetVotes.count(inv.hash);
case MSG_BUDGET_FINALIZED: case MSG_BUDGET_FINALIZED:
return mapFinalizedBudgets.count(inv.hash); return mapSeenFinalizedBudgets.count(inv.hash);
case MSG_MASTERNODE_ANNOUNCE: case MSG_MASTERNODE_ANNOUNCE:
return mapSeenMasternodeBroadcast.count(inv.hash); return mapSeenMasternodeBroadcast.count(inv.hash);
case MSG_MASTERNODE_PING: case MSG_MASTERNODE_PING:
@ -4130,40 +4130,40 @@ void static ProcessGetData(CNode* pfrom)
} }
if (!pushed && inv.type == MSG_BUDGET_VOTE) { if (!pushed && inv.type == MSG_BUDGET_VOTE) {
if(mapMasternodeBudgetVotes.count(inv.hash)){ if(mapSeenMasternodeBudgetVotes.count(inv.hash)){
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss.reserve(1000); ss.reserve(1000);
ss << mapMasternodeBudgetVotes[inv.hash]; ss << mapSeenMasternodeBudgetVotes[inv.hash];
pfrom->PushMessage("mvote", ss); pfrom->PushMessage("mvote", ss);
pushed = true; pushed = true;
} }
} }
if (!pushed && inv.type == MSG_BUDGET_PROPOSAL) { if (!pushed && inv.type == MSG_BUDGET_PROPOSAL) {
if(mapMasternodeBudgetProposals.count(inv.hash)){ if(mapSeenMasternodeBudgetProposals.count(inv.hash)){
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss.reserve(1000); ss.reserve(1000);
ss << mapMasternodeBudgetProposals[inv.hash]; ss << mapSeenMasternodeBudgetProposals[inv.hash];
pfrom->PushMessage("mprop", ss); pfrom->PushMessage("mprop", ss);
pushed = true; pushed = true;
} }
} }
if (!pushed && inv.type == MSG_BUDGET_FINALIZED_VOTE) { if (!pushed && inv.type == MSG_BUDGET_FINALIZED_VOTE) {
if(mapFinalizedBudgetVotes.count(inv.hash)){ if(mapSeenFinalizedBudgetVotes.count(inv.hash)){
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss.reserve(1000); ss.reserve(1000);
ss << mapFinalizedBudgetVotes[inv.hash]; ss << mapSeenFinalizedBudgetVotes[inv.hash];
pfrom->PushMessage("fbvote", ss); pfrom->PushMessage("fbvote", ss);
pushed = true; pushed = true;
} }
} }
if (!pushed && inv.type == MSG_BUDGET_FINALIZED) { if (!pushed && inv.type == MSG_BUDGET_FINALIZED) {
if(mapFinalizedBudgets.count(inv.hash)){ if(mapSeenFinalizedBudgets.count(inv.hash)){
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss.reserve(1000); ss.reserve(1000);
ss << mapFinalizedBudgets[inv.hash]; ss << mapSeenFinalizedBudgets[inv.hash];
pfrom->PushMessage("fbs", ss); pfrom->PushMessage("fbs", ss);
pushed = true; pushed = true;
} }

View File

@ -14,10 +14,10 @@
CBudgetManager budget; CBudgetManager budget;
CCriticalSection cs_budget; CCriticalSection cs_budget;
std::map<uint256, CBudgetProposalBroadcast> mapMasternodeBudgetProposals; std::map<uint256, CBudgetProposalBroadcast> mapSeenMasternodeBudgetProposals;
std::map<uint256, CBudgetVote> mapMasternodeBudgetVotes; std::map<uint256, CBudgetVote> mapSeenMasternodeBudgetVotes;
std::map<uint256, CFinalizedBudgetBroadcast> mapFinalizedBudgets; std::map<uint256, CFinalizedBudgetBroadcast> mapSeenFinalizedBudgets;
std::map<uint256, CFinalizedBudgetVote> mapFinalizedBudgetVotes; std::map<uint256, CFinalizedBudgetVote> mapSeenFinalizedBudgetVotes;
int GetBudgetPaymentCycleBlocks(){ int GetBudgetPaymentCycleBlocks(){
if(Params().NetworkID() == CBaseChainParams::MAIN) return 16616; //(60*24*30)/2.6 if(Params().NetworkID() == CBaseChainParams::MAIN) return 16616; //(60*24*30)/2.6
@ -355,7 +355,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
CBudgetProposalBroadcast prop; CBudgetProposalBroadcast prop;
vRecv >> prop; vRecv >> prop;
if(mapMasternodeBudgetProposals.count(prop.GetHash())){ if(mapSeenMasternodeBudgetProposals.count(prop.GetHash())){
return; return;
} }
@ -376,7 +376,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
return; return;
} }
mapMasternodeBudgetProposals.insert(make_pair(prop.GetHash(), prop)); mapSeenMasternodeBudgetProposals.insert(make_pair(prop.GetHash(), prop));
if(IsSyncingMasternodeAssets() || pmn->nVotedTimes < 100){ if(IsSyncingMasternodeAssets() || pmn->nVotedTimes < 100){
CBudgetProposal p(prop); CBudgetProposal p(prop);
budget.AddProposal(p); budget.AddProposal(p);
@ -393,7 +393,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
CBudgetVote vote; CBudgetVote vote;
vRecv >> vote; vRecv >> vote;
if(mapMasternodeBudgetVotes.count(vote.GetHash())){ if(mapSeenMasternodeBudgetVotes.count(vote.GetHash())){
return; return;
} }
@ -409,7 +409,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
return; return;
} }
mapMasternodeBudgetVotes.insert(make_pair(vote.GetHash(), vote)); mapSeenMasternodeBudgetVotes.insert(make_pair(vote.GetHash(), vote));
if(IsSyncingMasternodeAssets() || pmn->nVotedTimes < 100){ if(IsSyncingMasternodeAssets() || pmn->nVotedTimes < 100){
budget.UpdateProposal(vote); budget.UpdateProposal(vote);
vote.Relay(); vote.Relay();
@ -426,7 +426,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
printf("34\n"); printf("34\n");
if(mapFinalizedBudgets.count(prop.GetHash())){ if(mapSeenFinalizedBudgets.count(prop.GetHash())){
return; return;
} }
@ -453,7 +453,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
return; return;
} }
mapFinalizedBudgets.insert(make_pair(prop.GetHash(), prop)); mapSeenFinalizedBudgets.insert(make_pair(prop.GetHash(), prop));
if(IsSyncingMasternodeAssets() || pmn->nVotedTimes < 100){ if(IsSyncingMasternodeAssets() || pmn->nVotedTimes < 100){
printf("42\n"); printf("42\n");
@ -474,7 +474,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
CFinalizedBudgetVote vote; CFinalizedBudgetVote vote;
vRecv >> vote; vRecv >> vote;
if(mapFinalizedBudgetVotes.count(vote.GetHash())){ if(mapSeenFinalizedBudgetVotes.count(vote.GetHash())){
return; return;
} }
@ -490,7 +490,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
return; return;
} }
mapFinalizedBudgetVotes.insert(make_pair(vote.GetHash(), vote)); mapSeenFinalizedBudgetVotes.insert(make_pair(vote.GetHash(), vote));
if(IsSyncingMasternodeAssets() || pmn->nVotedTimes < 100){ if(IsSyncingMasternodeAssets() || pmn->nVotedTimes < 100){
budget.UpdateFinalizedBudget(vote); budget.UpdateFinalizedBudget(vote);
vote.Relay(); vote.Relay();

View File

@ -29,10 +29,10 @@ class CBudgetVote;
#define VOTE_YES 1 #define VOTE_YES 1
#define VOTE_NO 2 #define VOTE_NO 2
extern std::map<uint256, CBudgetProposalBroadcast> mapMasternodeBudgetProposals; extern std::map<uint256, CBudgetProposalBroadcast> mapSeenMasternodeBudgetProposals;
extern std::map<uint256, CBudgetVote> mapMasternodeBudgetVotes; extern std::map<uint256, CBudgetVote> mapSeenMasternodeBudgetVotes;
extern std::map<uint256, CFinalizedBudgetBroadcast> mapFinalizedBudgets; extern std::map<uint256, CFinalizedBudgetBroadcast> mapSeenFinalizedBudgets;
extern std::map<uint256, CFinalizedBudgetVote> mapFinalizedBudgetVotes; extern std::map<uint256, CFinalizedBudgetVote> mapSeenFinalizedBudgetVotes;
extern CBudgetManager budget; extern CBudgetManager budget;
@ -123,10 +123,10 @@ 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(mapMasternodeBudgetProposals); READWRITE(mapSeenMasternodeBudgetProposals);
READWRITE(mapMasternodeBudgetVotes); READWRITE(mapSeenMasternodeBudgetVotes);
READWRITE(mapFinalizedBudgets); READWRITE(mapSeenFinalizedBudgets);
READWRITE(mapMasternodeBudgetVotes); READWRITE(mapSeenFinalizedBudgetVotes);
READWRITE(mapProposals); READWRITE(mapProposals);
READWRITE(mapFinalizedBudgets); READWRITE(mapFinalizedBudgets);

View File

@ -98,6 +98,7 @@ void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st
if(fDebug) LogPrintf("mnw - winning vote - Addr %s Height %d bestHeight %d\n", address2.ToString().c_str(), winner.nBlockHeight, chainActive.Tip()->nHeight); if(fDebug) LogPrintf("mnw - winning vote - Addr %s Height %d bestHeight %d\n", address2.ToString().c_str(), winner.nBlockHeight, chainActive.Tip()->nHeight);
mapMasternodePayeeVotes.insert(make_pair(winner.GetHash(), winner));
if(masternodePayments.AddWinningMasternode(winner)){ if(masternodePayments.AddWinningMasternode(winner)){
winner.Relay(); winner.Relay();
} }

View File

@ -1,5 +1,4 @@
// Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2014-2015 The Dash Developers
// Copyright (c) 2009-2012 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -118,7 +117,7 @@ Value mnbudget(const Array& params, bool fHelp)
if(!prop.Sign(keyMasternode, pubKeyMasternode)){ if(!prop.Sign(keyMasternode, pubKeyMasternode)){
return "Failure to sign."; return "Failure to sign.";
} }
mapMasternodeBudgetProposals.insert(make_pair(prop.GetHash(), prop)); mapSeenMasternodeBudgetProposals.insert(make_pair(prop.GetHash(), prop));
prop.Relay(); prop.Relay();
CBudgetVote vote(pmn->vin, prop.GetHash(), nVote); CBudgetVote vote(pmn->vin, prop.GetHash(), nVote);
@ -126,7 +125,7 @@ Value mnbudget(const Array& params, bool fHelp)
return "Failure to sign."; return "Failure to sign.";
} }
mapMasternodeBudgetVotes.insert(make_pair(vote.GetHash(), vote)); mapSeenMasternodeBudgetVotes.insert(make_pair(vote.GetHash(), vote));
vote.Relay(); vote.Relay();
success++; success++;
@ -193,7 +192,7 @@ Value mnbudget(const Array& params, bool fHelp)
return "Failure to sign."; return "Failure to sign.";
} }
mapMasternodeBudgetProposals.insert(make_pair(prop.GetHash(), prop)); mapSeenMasternodeBudgetProposals.insert(make_pair(prop.GetHash(), prop));
prop.Relay(); prop.Relay();
budget.AddProposal(prop); budget.AddProposal(prop);
@ -202,7 +201,7 @@ Value mnbudget(const Array& params, bool fHelp)
return "Failure to sign."; return "Failure to sign.";
} }
mapMasternodeBudgetVotes.insert(make_pair(vote.GetHash(), vote)); mapSeenMasternodeBudgetVotes.insert(make_pair(vote.GetHash(), vote));
vote.Relay(); vote.Relay();
budget.UpdateProposal(vote); budget.UpdateProposal(vote);
@ -362,7 +361,7 @@ Value mnfinalbudget(const Array& params, bool fHelp)
if(!prop.IsValid()) if(!prop.IsValid())
return "Invalid prop (are all the hashes correct?)"; return "Invalid prop (are all the hashes correct?)";
mapFinalizedBudgets.insert(make_pair(prop.GetHash(), prop)); mapSeenFinalizedBudgets.insert(make_pair(prop.GetHash(), prop));
prop.Relay(); prop.Relay();
budget.AddFinalizedBudget(prop); budget.AddFinalizedBudget(prop);
@ -371,7 +370,7 @@ Value mnfinalbudget(const Array& params, bool fHelp)
return "Failure to sign."; return "Failure to sign.";
} }
mapFinalizedBudgetVotes.insert(make_pair(vote.GetHash(), vote)); mapSeenFinalizedBudgetVotes.insert(make_pair(vote.GetHash(), vote));
vote.Relay(); vote.Relay();
budget.UpdateFinalizedBudget(vote); budget.UpdateFinalizedBudget(vote);
@ -426,7 +425,7 @@ Value mnfinalbudget(const Array& params, bool fHelp)
continue; continue;
} }
mapFinalizedBudgetVotes.insert(make_pair(vote.GetHash(), vote)); mapSeenFinalizedBudgetVotes.insert(make_pair(vote.GetHash(), vote));
vote.Relay(); vote.Relay();
budget.UpdateFinalizedBudget(vote); budget.UpdateFinalizedBudget(vote);
@ -459,7 +458,7 @@ Value mnfinalbudget(const Array& params, bool fHelp)
return "Failure to sign."; return "Failure to sign.";
} }
mapFinalizedBudgetVotes.insert(make_pair(vote.GetHash(), vote)); mapSeenFinalizedBudgetVotes.insert(make_pair(vote.GetHash(), vote));
vote.Relay(); vote.Relay();
budget.UpdateFinalizedBudget(vote); budget.UpdateFinalizedBudget(vote);