Commit ebb29735 authored by Volodymyr Shamray's avatar Volodymyr Shamray

Merge branch '196-automatic-budget-finalization' into 'Current-dev'

Resolve "Automatic budget finalization"

See merge request !130
parents bba9f1f5 7d4a4486
......@@ -169,7 +169,7 @@ fi
if test "x$CXXFLAGS_overridden" = "xno"; then
CXXFLAGS="$CXXFLAGS -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter -Wno-self-assign"
fi
CPPFLAGS="$CPPFLAGS -DBOOST_NO_CXX11_SCOPED_ENUMS -DBOOST_SPIRIT_THREADSAFE -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS"
CPPFLAGS="$CPPFLAGS -DBOOST_SPIRIT_THREADSAFE -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS"
AC_ARG_WITH([utils],
[AS_HELP_STRING([--with-utils],
......
......@@ -4083,13 +4083,13 @@ bool static AlreadyHave(const CInv& inv)
}
return false;
case MSG_BUDGET_FINALIZED_VOTE:
if(budget.mapSeenFinalizedBudgetVotes.count(inv.hash)) {
if(budget.mapSeenBudgetDraftVotes.count(inv.hash)) {
masternodeSync.AddedBudgetItem(inv.hash);
return true;
}
return false;
case MSG_BUDGET_FINALIZED:
if(budget.mapSeenFinalizedBudgets.count(inv.hash)) {
if(budget.mapSeenBudgetDrafts.count(inv.hash)) {
masternodeSync.AddedBudgetItem(inv.hash);
return true;
}
......@@ -4287,20 +4287,20 @@ void static ProcessGetData(CNode* pfrom)
}
if (!pushed && inv.type == MSG_BUDGET_FINALIZED_VOTE) {
if(budget.mapSeenFinalizedBudgetVotes.count(inv.hash)){
if(budget.mapSeenBudgetDraftVotes.count(inv.hash)){
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss.reserve(1000);
ss << budget.mapSeenFinalizedBudgetVotes[inv.hash];
ss << budget.mapSeenBudgetDraftVotes[inv.hash];
pfrom->PushMessage("fbvote", ss);
pushed = true;
}
}
if (!pushed && inv.type == MSG_BUDGET_FINALIZED) {
if(budget.mapSeenFinalizedBudgets.count(inv.hash)){
if(budget.mapSeenBudgetDrafts.count(inv.hash)){
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss.reserve(1000);
ss << budget.mapSeenFinalizedBudgets[inv.hash];
ss << budget.mapSeenBudgetDrafts[inv.hash];
pfrom->PushMessage("fbs", ss);
pushed = true;
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -110,7 +110,7 @@ void CMasternodeSync::AddedMasternodeWinner(uint256 hash)
void CMasternodeSync::AddedBudgetItem(uint256 hash)
{
if(budget.mapSeenMasternodeBudgetProposals.count(hash) || budget.mapSeenMasternodeBudgetVotes.count(hash) ||
budget.mapSeenFinalizedBudgets.count(hash) || budget.mapSeenFinalizedBudgetVotes.count(hash)) {
budget.mapSeenBudgetDrafts.count(hash) || budget.mapSeenBudgetDraftVotes.count(hash)) {
if(mapSeenSyncBudget[hash] < MASTERNODE_SYNC_THRESHOLD) {
lastBudgetItem = GetTime();
mapSeenSyncBudget[hash]++;
......
......@@ -616,7 +616,7 @@ Value mnfinalbudget(const Array& params, bool fHelp)
}
CFinalizedBudgetVote vote(pmn->vin, hash);
BudgetDraftVote vote(pmn->vin, hash);
if(!vote.Sign(keyMasternode, pubKeyMasternode)){
failed++;
statusObj.push_back(Pair("result", "failed"));
......@@ -626,8 +626,8 @@ Value mnfinalbudget(const Array& params, bool fHelp)
}
std::string strError = "";
if(budget.UpdateFinalizedBudget(vote, NULL, strError)){
budget.mapSeenFinalizedBudgetVotes.insert(make_pair(vote.GetHash(), vote));
if(budget.UpdateBudgetDraft(vote, NULL, strError)){
budget.mapSeenBudgetDraftVotes.insert(make_pair(vote.GetHash(), vote));
vote.Relay();
success++;
statusObj.push_back(Pair("result", "success"));
......@@ -670,14 +670,14 @@ Value mnfinalbudget(const Array& params, bool fHelp)
return "Failure to find masternode in list : " + activeMasternode.vin.ToString();
}
CFinalizedBudgetVote vote(activeMasternode.vin, hash);
BudgetDraftVote vote(activeMasternode.vin, hash);
if(!vote.Sign(keyMasternode, pubKeyMasternode)){
return "Failure to sign.";
}
std::string strError = "";
if(budget.UpdateFinalizedBudget(vote, NULL, strError)){
budget.mapSeenFinalizedBudgetVotes.insert(make_pair(vote.GetHash(), vote));
if(budget.UpdateBudgetDraft(vote, NULL, strError)){
budget.mapSeenBudgetDraftVotes.insert(make_pair(vote.GetHash(), vote));
vote.Relay();
return "success";
} else {
......@@ -690,23 +690,24 @@ Value mnfinalbudget(const Array& params, bool fHelp)
{
Object resultObj;
std::vector<CFinalizedBudget*> winningFbs = budget.GetFinalizedBudgets();
BOOST_FOREACH(CFinalizedBudget* finalizedBudget, winningFbs)
std::vector<BudgetDraft*> drafts = budget.GetBudgetDrafts();
BOOST_FOREACH(BudgetDraft* budgetDraft, drafts)
{
Object bObj;
bObj.push_back(Pair("FeeTX", finalizedBudget->GetFeeTxHash().ToString()));
bObj.push_back(Pair("Hash", finalizedBudget->GetHash().ToString()));
bObj.push_back(Pair("BlockStart", (int64_t)finalizedBudget->GetBlockStart()));
bObj.push_back(Pair("BlockEnd", (int64_t)finalizedBudget->GetBlockStart())); // Budgets are paid in a single block !
bObj.push_back(Pair("Proposals", finalizedBudget->GetProposals()));
bObj.push_back(Pair("VoteCount", (int64_t)finalizedBudget->GetVoteCount()));
bObj.push_back(Pair("Status", finalizedBudget->GetStatus()));
bObj.push_back(Pair("IsSubmittedManually", budgetDraft->IsSubmittedManually()));
bObj.push_back(Pair("Hash", budgetDraft->GetHash().ToString()));
bObj.push_back(Pair("BlockStart", (int64_t)budgetDraft->GetBlockStart()));
bObj.push_back(Pair("BlockEnd", (int64_t)budgetDraft->GetBlockStart())); // Budgets are paid in a single block !
bObj.push_back(Pair("Proposals", budgetDraft->GetProposals()));
bObj.push_back(Pair("VoteCount", (int64_t)budgetDraft->GetVoteCount()));
bObj.push_back(Pair("Status", budgetDraft->GetStatus()));
std::string strError = "";
bObj.push_back(Pair("IsValid", finalizedBudget->IsValid(strError)));
bObj.push_back(Pair("IsValid", budgetDraft->IsValid(strError)));
bObj.push_back(Pair("IsValidReason", strError.c_str()));
if (budgetDraft->IsSubmittedManually())
bObj.push_back(Pair("FeeTX", budgetDraft->GetFeeTxHash().ToString()));
resultObj.push_back(Pair(finalizedBudget->GetName(), bObj));
resultObj.push_back(Pair(budgetDraft->GetHash().ToString(), bObj));
}
return resultObj;
......@@ -723,17 +724,29 @@ Value mnfinalbudget(const Array& params, bool fHelp)
Object obj;
CFinalizedBudget* pfinalBudget = budget.FindFinalizedBudget(hash);
BudgetDraft* pbudgetDraft = budget.FindBudgetDraft(hash);
if(pbudgetDraft == NULL) return "Unknown budget hash";
const std::map<uint256, BudgetDraftVote>& fbVotes = pbudgetDraft->GetVotes();
for (std::map<uint256, BudgetDraftVote>::const_iterator i = fbVotes.begin(); i != fbVotes.end(); ++i)
{
Object bObj;
bObj.push_back(Pair("nHash", i->first.ToString().c_str()));
bObj.push_back(Pair("nTime", static_cast<int64_t>(i->second.nTime)));
bObj.push_back(Pair("fValid", i->second.fValid));
if(pfinalBudget == NULL) return "Unknown budget hash";
obj.push_back(Pair(i->second.vin.prevout.ToStringShort(), bObj));
}
const std::map<uint256, CFinalizedBudgetVote>& fbVotes = pfinalBudget->GetVotes();
for (std::map<uint256, CFinalizedBudgetVote>::const_iterator i = fbVotes.begin(); i != fbVotes.end(); ++i)
const std::map<uint256, BudgetDraftVote>& oldVotes = pbudgetDraft->GetObsoleteVotes();
for (std::map<uint256, BudgetDraftVote>::const_iterator i = oldVotes.begin(); i != oldVotes.end(); ++i)
{
Object bObj;
bObj.push_back(Pair("nHash", i->first.ToString().c_str()));
bObj.push_back(Pair("nTime", static_cast<int64_t>(i->second.nTime)));
bObj.push_back(Pair("fValid", i->second.fValid));
bObj.push_back(Pair("obsolete", true));
obj.push_back(Pair(i->second.vin.prevout.ToStringShort(), bObj));
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment