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

View File

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

View File

@ -29,10 +29,10 @@ class CBudgetVote;
#define VOTE_YES 1
#define VOTE_NO 2
extern std::map<uint256, CBudgetProposalBroadcast> mapMasternodeBudgetProposals;
extern std::map<uint256, CBudgetVote> mapMasternodeBudgetVotes;
extern std::map<uint256, CFinalizedBudgetBroadcast> mapFinalizedBudgets;
extern std::map<uint256, CFinalizedBudgetVote> mapFinalizedBudgetVotes;
extern std::map<uint256, CBudgetProposalBroadcast> mapSeenMasternodeBudgetProposals;
extern std::map<uint256, CBudgetVote> mapSeenMasternodeBudgetVotes;
extern std::map<uint256, CFinalizedBudgetBroadcast> mapSeenFinalizedBudgets;
extern std::map<uint256, CFinalizedBudgetVote> mapSeenFinalizedBudgetVotes;
extern CBudgetManager budget;
@ -123,10 +123,10 @@ public:
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
READWRITE(mapMasternodeBudgetProposals);
READWRITE(mapMasternodeBudgetVotes);
READWRITE(mapFinalizedBudgets);
READWRITE(mapMasternodeBudgetVotes);
READWRITE(mapSeenMasternodeBudgetProposals);
READWRITE(mapSeenMasternodeBudgetVotes);
READWRITE(mapSeenFinalizedBudgets);
READWRITE(mapSeenFinalizedBudgetVotes);
READWRITE(mapProposals);
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);
mapMasternodePayeeVotes.insert(make_pair(winner.GetHash(), winner));
if(masternodePayments.AddWinningMasternode(winner)){
winner.Relay();
}

View File

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