Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/budget/budgetproposal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ bool CBudgetProposal::IsPassing(int nBlockStartBudget, int nBlockEndBudget, int
bool CBudgetProposal::AddOrUpdateVote(const CBudgetVote& vote, std::string& strError)
{
std::string strAction = "New vote inserted:";
const uint256& hash = vote.GetVin().prevout.GetHash();
const COutPoint& mnId = vote.GetVin().prevout;
const int64_t voteTime = vote.GetTime();

if (mapVotes.count(hash)) {
const int64_t& oldTime = mapVotes[hash].GetTime();
if (mapVotes.count(mnId)) {
const int64_t& oldTime = mapVotes[mnId].GetTime();
if (oldTime > voteTime) {
strError = strprintf("new vote older than existing vote - %s\n", vote.GetHash().ToString());
LogPrint(BCLog::MNBUDGET, "%s: %s\n", __func__, strError);
Expand All @@ -240,7 +240,7 @@ bool CBudgetProposal::AddOrUpdateVote(const CBudgetVote& vote, std::string& strE
return false;
}

mapVotes[hash] = vote;
mapVotes[mnId] = vote;
LogPrint(BCLog::MNBUDGET, "%s: %s %s\n", __func__, strAction.c_str(), vote.GetHash().ToString().c_str());

return true;
Expand Down Expand Up @@ -271,10 +271,10 @@ void CBudgetProposal::SetSynced(bool synced)
void CBudgetProposal::CleanAndRemove()
{
LogPrint(BCLog::MNBUDGET, "Cleaning budget votes for %s. Before: YES=%d, NO=%d\n", GetName(), GetYeas(), GetNays());
std::map<uint256, CBudgetVote>::iterator it = mapVotes.begin();
auto it = mapVotes.begin();

while (it != mapVotes.end()) {
CMasternode* pmn = mnodeman.Find(it->second.GetVin().prevout);
CMasternode* pmn = mnodeman.Find(it->first);
(*it).second.SetValid(pmn != nullptr);
++it;
}
Expand Down Expand Up @@ -306,7 +306,7 @@ std::vector<uint256> CBudgetProposal::GetVotesHashes() const
{
std::vector<uint256> vRet;
for (const auto& it: mapVotes) {
vRet.push_back(it.first);
vRet.push_back(it.second.GetHash());
}
return vRet;
}
Expand Down
2 changes: 1 addition & 1 deletion src/budget/budgetproposal.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CBudgetProposal
bool CheckAddress();

protected:
std::map<uint256, CBudgetVote> mapVotes;
std::map<COutPoint, CBudgetVote> mapVotes;
std::string strProposalName;
std::string strURL;
int nBlockStart;
Expand Down
4 changes: 2 additions & 2 deletions src/budget/budgetvote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ std::string CBudgetVote::GetStrMessage() const
UniValue CBudgetVote::ToJSON() const
{
UniValue bObj(UniValue::VOBJ);
bObj.pushKV("mnId", vin.prevout.hash.ToString());
bObj.pushKV("nHash", vin.prevout.GetHash().ToString());
bObj.pushKV("mnId", vin.prevout.ToStringShort());
bObj.pushKV("nHash", GetHash().ToString());
bObj.pushKV("Vote", GetVoteString());
bObj.pushKV("nTime", nTime);
bObj.pushKV("fValid", fValid);
Expand Down
14 changes: 7 additions & 7 deletions src/budget/finalizedbudget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ bool CFinalizedBudget::ParseBroadcast(CDataStream& broadcast)

bool CFinalizedBudget::AddOrUpdateVote(const CFinalizedBudgetVote& vote, std::string& strError)
{
const uint256& hash = vote.GetVin().prevout.GetHash();
const COutPoint& mnId = vote.GetVin().prevout;
const int64_t voteTime = vote.GetTime();
std::string strAction = "New vote inserted:";

if (mapVotes.count(hash)) {
const int64_t oldTime = mapVotes[hash].GetTime();
if (mapVotes.count(mnId)) {
const int64_t oldTime = mapVotes[mnId].GetTime();
if (oldTime > voteTime) {
strError = strprintf("new vote older than existing vote - %s\n", vote.GetHash().ToString());
LogPrint(BCLog::MNBUDGET, "%s: %s\n", __func__, strError);
Expand All @@ -80,7 +80,7 @@ bool CFinalizedBudget::AddOrUpdateVote(const CFinalizedBudgetVote& vote, std::st
return false;
}

mapVotes[hash] = vote;
mapVotes[mnId] = vote;
LogPrint(BCLog::MNBUDGET, "%s: %s %s\n", __func__, strAction.c_str(), vote.GetHash().ToString().c_str());
return true;
}
Expand Down Expand Up @@ -166,10 +166,10 @@ bool CFinalizedBudget::CheckProposals(const std::map<uint256, CBudgetProposal>&
// Remove votes from masternodes which are not valid/existent anymore
void CFinalizedBudget::CleanAndRemove()
{
std::map<uint256, CFinalizedBudgetVote>::iterator it = mapVotes.begin();
auto it = mapVotes.begin();

while (it != mapVotes.end()) {
CMasternode* pmn = mnodeman.Find(it->second.GetVin().prevout);
CMasternode* pmn = mnodeman.Find(it->first);
(*it).second.SetValid(pmn != nullptr);
++it;
}
Expand Down Expand Up @@ -289,7 +289,7 @@ std::vector<uint256> CFinalizedBudget::GetVotesHashes() const
{
std::vector<uint256> vRet;
for (const auto& it: mapVotes) {
vRet.push_back(it.first);
vRet.push_back(it.second.GetHash());
}
return vRet;
}
Expand Down
2 changes: 1 addition & 1 deletion src/budget/finalizedbudget.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CFinalizedBudget
bool CheckName();

protected:
std::map<uint256, CFinalizedBudgetVote> mapVotes;
std::map<COutPoint, CFinalizedBudgetVote> mapVotes;
std::string strBudgetName;
int nBlockStart;
std::vector<CTxBudgetPayment> vecBudgetPayments;
Expand Down
2 changes: 1 addition & 1 deletion src/budget/finalizedbudgetvote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ uint256 CFinalizedBudgetVote::GetHash() const
UniValue CFinalizedBudgetVote::ToJSON() const
{
UniValue bObj(UniValue::VOBJ);
bObj.pushKV("nHash", vin.prevout.GetHash().ToString());
bObj.pushKV("nHash", GetHash().ToString());
bObj.pushKV("nTime", (int64_t) nTime);
bObj.pushKV("fValid", fValid);
return bObj;
Expand Down
5 changes: 0 additions & 5 deletions src/primitives/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ std::string BaseOutPoint::ToStringShort() const
return strprintf("%s-%u", hash.ToString().substr(0,64), n);
}

uint256 BaseOutPoint::GetHash() const
{
return Hash(BEGIN(hash), END(hash), BEGIN(n), END(n));
}

std::string COutPoint::ToString() const
{
return strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10), n);
Expand Down
2 changes: 0 additions & 2 deletions src/primitives/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ class BaseOutPoint

size_t DynamicMemoryUsage() const { return 0; }

uint256 GetHash() const;

};

/** An outpoint - a combination of a transaction hash and an index n into its vout */
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/budget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ UniValue getbudgetvotes(const JSONRPCRequest& request)
"\nResult:\n"
"[\n"
" {\n"
" \"mnId\": \"xxxx\", (string) Hash of the masternode's collateral transaction\n"
" \"mnId\": \"xxxx-x\", (string) Masternode's outpoint collateral transaction (hash-n)\n"
" \"nHash\": \"xxxx\", (string) Hash of the vote\n"
" \"Vote\": \"YES|NO\", (string) Vote cast ('YES' or 'NO')\n"
" \"nTime\": xxxx, (numeric) Time in seconds since epoch the vote was cast\n"
Expand Down
2 changes: 1 addition & 1 deletion test/functional/tiertwo_governance_sync_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def check_vote_existence(self, proposalName, mnCollateralHash, voteType):
assert(len(votesInfo) > 0)
found = False
for voteInfo in votesInfo:
if (voteInfo["mnId"] == mnCollateralHash) :
if (voteInfo["mnId"].split("-")[0] == mnCollateralHash) :
assert_equal(voteInfo["Vote"], voteType)
found = True
assert_true(found, "Error checking vote existence in node " + str(i))
Expand Down