Skip to content

Commit 9eceb21

Browse files
committed
[Refactor] Move finalized budget vote submission to budget-manager
1 parent 001f15d commit 9eceb21

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

src/masternode-budget.cpp

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,35 @@ bool CBudgetManager::FillBlockPayee(CMutableTransaction& txNew, bool fProofOfSta
689689
return true;
690690
}
691691

692+
void CBudgetManager::SubmitVote(const uint256& nBudgetHash)
693+
{
694+
// function called only from initialized masternodes
695+
assert(fMasterNode && activeMasternode.vin != nullopt);
696+
697+
CPubKey pubKeyMasternode;
698+
CKey keyMasternode;
699+
if (!CMessageSigner::GetKeysFromSecret(strMasterNodePrivKey, keyMasternode, pubKeyMasternode)) {
700+
LogPrint(BCLog::MNBUDGET,"%s: Error upon calling GetKeysFromSecret\n", __func__);
701+
return;
702+
}
703+
704+
CFinalizedBudgetVote vote(*(activeMasternode.vin), nBudgetHash);
705+
if (!vote.Sign(keyMasternode, pubKeyMasternode)) {
706+
LogPrint(BCLog::MNBUDGET,"%s: Failure to sign.", __func__);
707+
return;
708+
}
709+
710+
std::string strError = "";
711+
if (!UpdateFinalizedBudget(vote, NULL, strError)) {
712+
LogPrintf("%s: Error submitting vote - %s\n", __func__, strError);
713+
return;
714+
}
715+
716+
LogPrint(BCLog::MNBUDGET,"%s: new finalized budget vote signed: %s\n", __func__, vote.GetHash().ToString());
717+
AddSeenFinalizedBudgetVote(vote);
718+
vote.Relay();
719+
}
720+
692721
CFinalizedBudget* CBudgetManager::FindFinalizedBudget(const uint256& nHash)
693722
{
694723
AssertLockHeld(cs_budgets);
@@ -1960,7 +1989,8 @@ void CFinalizedBudget::CheckAndVote()
19601989
}
19611990

19621991
LogPrint(BCLog::MNBUDGET,"%s: Finalized Budget Matches! Submitting Vote.\n", __func__);
1963-
SubmitVote();
1992+
// TODO: move CheckAndVote to budget manager
1993+
g_budgetman.SubmitVote(GetHash());
19641994
}
19651995
}
19661996

@@ -2208,37 +2238,6 @@ bool CFinalizedBudget::GetPayeeAndAmount(int64_t nBlockHeight, CScript& payee, C
22082238
return true;
22092239
}
22102240

2211-
void CFinalizedBudget::SubmitVote()
2212-
{
2213-
// function called only from initialized masternodes
2214-
assert(fMasterNode && activeMasternode.vin != nullopt);
2215-
2216-
std::string strError = "";
2217-
CPubKey pubKeyMasternode;
2218-
CKey keyMasternode;
2219-
2220-
if (!CMessageSigner::GetKeysFromSecret(strMasterNodePrivKey, keyMasternode, pubKeyMasternode)) {
2221-
LogPrint(BCLog::MNBUDGET,"%s: Error upon calling GetKeysFromSecret\n", __func__);
2222-
return;
2223-
}
2224-
2225-
CFinalizedBudgetVote vote(*(activeMasternode.vin), GetHash());
2226-
if (!vote.Sign(keyMasternode, pubKeyMasternode)) {
2227-
LogPrint(BCLog::MNBUDGET,"%s: Failure to sign.", __func__);
2228-
return;
2229-
}
2230-
2231-
// !TODO: move to CBudgetManager
2232-
if (g_budgetman.UpdateFinalizedBudget(vote, NULL, strError)) {
2233-
LogPrint(BCLog::MNBUDGET,"%s: new finalized budget vote - %s\n", __func__, vote.GetHash().ToString());
2234-
2235-
g_budgetman.AddSeenFinalizedBudgetVote(vote);
2236-
vote.Relay();
2237-
} else {
2238-
LogPrint(BCLog::MNBUDGET,"%s: Error submitting vote - %s\n", __func__, strError);
2239-
}
2240-
}
2241-
22422241
// return broadcast serialization
22432242
CDataStream CFinalizedBudget::GetBroadcast() const
22442243
{

src/masternode-budget.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ class CBudgetManager
299299
std::string GetRequiredPaymentsString(int nBlockHeight);
300300
bool FillBlockPayee(CMutableTransaction& txNew, bool fProofOfStake) const;
301301

302+
// Only initialized masternodes: sign and submit vote on a finalized budget with given key
303+
void SubmitVote(const uint256& nBudgetHash);
304+
302305
void CheckOrphanVotes();
303306
void Clear()
304307
{
@@ -457,8 +460,6 @@ class CFinalizedBudget
457460
void CheckAndVote();
458461
//total pivx paid out by this budget
459462
CAmount GetTotalPayout() const;
460-
//vote on this finalized budget as a masternode
461-
void SubmitVote();
462463

463464
uint256 GetHash() const
464465
{

0 commit comments

Comments
 (0)