Fix PR1135 bugs (#1140)
* Move vote relaying into ProcessVote so that local votes are relayed * Change signature of Insert method to return indication of whether insertion succeeded * Only process orphan votes once * Fix function name in log messages
This commit is contained in:
commit
714f9a4f0d
@ -89,7 +89,7 @@ public:
|
|||||||
return nCurrentSize;
|
return nCurrentSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Insert(const K& key, const V& value)
|
bool Insert(const K& key, const V& value)
|
||||||
{
|
{
|
||||||
if(nCurrentSize == nMaxSize) {
|
if(nCurrentSize == nMaxSize) {
|
||||||
PruneLast();
|
PruneLast();
|
||||||
@ -102,7 +102,7 @@ public:
|
|||||||
|
|
||||||
if(mapIt.count(value) > 0) {
|
if(mapIt.count(value) > 0) {
|
||||||
// Don't insert duplicates
|
// Don't insert duplicates
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
listItems.push_front(item_t(key, value));
|
listItems.push_front(item_t(key, value));
|
||||||
@ -110,6 +110,7 @@ public:
|
|||||||
|
|
||||||
mapIt[value] = lit;
|
mapIt[value] = lit;
|
||||||
++nCurrentSize;
|
++nCurrentSize;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HasKey(const K& key) const
|
bool HasKey(const K& key) const
|
||||||
|
@ -223,7 +223,6 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
|
|||||||
CGovernanceException exception;
|
CGovernanceException exception;
|
||||||
if(ProcessVote(pfrom, vote, exception)) {
|
if(ProcessVote(pfrom, vote, exception)) {
|
||||||
LogPrint("gobject", "CGovernanceManager -- Accepted vote\n");
|
LogPrint("gobject", "CGovernanceManager -- Accepted vote\n");
|
||||||
vote.Relay();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LogPrint("gobject", "CGovernanceManager -- Rejected vote, error = %s\n", exception.what());
|
LogPrint("gobject", "CGovernanceManager -- Rejected vote, error = %s\n", exception.what());
|
||||||
@ -619,14 +618,18 @@ bool CGovernanceManager::ProcessVote(CNode* pfrom, const CGovernanceVote& vote,
|
|||||||
uint256 nHashGovobj = vote.GetParentHash();
|
uint256 nHashGovobj = vote.GetParentHash();
|
||||||
object_m_it it = mapObjects.find(nHashGovobj);
|
object_m_it it = mapObjects.find(nHashGovobj);
|
||||||
if(it == mapObjects.end()) {
|
if(it == mapObjects.end()) {
|
||||||
mapOrphanVotes.Insert(nHashGovobj, vote);
|
|
||||||
RequestGovernanceObject(pfrom, nHashGovobj);
|
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
ostr << "CGovernanceManager::ProcessVote -- Unknown parent object "
|
ostr << "CGovernanceManager::ProcessVote -- Unknown parent object "
|
||||||
<< ", MN outpoint = " << vote.GetVinMasternode().prevout.ToStringShort()
|
<< ", MN outpoint = " << vote.GetVinMasternode().prevout.ToStringShort()
|
||||||
<< ", governance object hash = " << vote.GetParentHash().ToString() << "\n";
|
<< ", governance object hash = " << vote.GetParentHash().ToString() << "\n";
|
||||||
LogPrintf(ostr.str().c_str());
|
|
||||||
exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_WARNING);
|
exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_WARNING);
|
||||||
|
if(mapOrphanVotes.Insert(nHashGovobj, vote)) {
|
||||||
|
RequestGovernanceObject(pfrom, nHashGovobj);
|
||||||
|
LogPrintf(ostr.str().c_str());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogPrint("gobject", ostr.str().c_str());
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -638,6 +641,8 @@ bool CGovernanceManager::ProcessVote(CNode* pfrom, const CGovernanceVote& vote,
|
|||||||
if(govobj.GetObjectType() == GOVERNANCE_OBJECT_WATCHDOG) {
|
if(govobj.GetObjectType() == GOVERNANCE_OBJECT_WATCHDOG) {
|
||||||
mnodeman.UpdateWatchdogVoteTime(vote.GetVinMasternode());
|
mnodeman.UpdateWatchdogVoteTime(vote.GetVinMasternode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vote.Relay();
|
||||||
}
|
}
|
||||||
return fOk;
|
return fOk;
|
||||||
}
|
}
|
||||||
@ -813,14 +818,18 @@ bool CGovernanceObject::ProcessVote(CNode* pfrom,
|
|||||||
{
|
{
|
||||||
int nMNIndex = governance.GetMasternodeIndex(vote.GetVinMasternode());
|
int nMNIndex = governance.GetMasternodeIndex(vote.GetVinMasternode());
|
||||||
if(nMNIndex < 0) {
|
if(nMNIndex < 0) {
|
||||||
mapOrphanVotes.Insert(vote.GetVinMasternode(), vote);
|
|
||||||
if(pfrom) {
|
|
||||||
mnodeman.AskForMN(pfrom, vote.GetVinMasternode());
|
|
||||||
}
|
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
ostr << "CGovernanceObject::UpdateVote -- Masternode index not found\n";
|
ostr << "CGovernanceObject::ProcessVote -- Masternode index not found\n";
|
||||||
LogPrintf(ostr.str().c_str());
|
|
||||||
exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_WARNING);
|
exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_WARNING);
|
||||||
|
if(mapOrphanVotes.Insert(vote.GetVinMasternode(), vote)) {
|
||||||
|
if(pfrom) {
|
||||||
|
mnodeman.AskForMN(pfrom, vote.GetVinMasternode());
|
||||||
|
}
|
||||||
|
LogPrintf(ostr.str().c_str());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogPrint("gobject", ostr.str().c_str());
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -832,14 +841,14 @@ bool CGovernanceObject::ProcessVote(CNode* pfrom,
|
|||||||
vote_signal_enum_t eSignal = vote.GetSignal();
|
vote_signal_enum_t eSignal = vote.GetSignal();
|
||||||
if(eSignal == VOTE_SIGNAL_NONE) {
|
if(eSignal == VOTE_SIGNAL_NONE) {
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
ostr << "CGovernanceObject::UpdateVote -- Vote signal: none" << "\n";
|
ostr << "CGovernanceObject::ProcessVote -- Vote signal: none" << "\n";
|
||||||
LogPrint("gobject", ostr.str().c_str());
|
LogPrint("gobject", ostr.str().c_str());
|
||||||
exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_WARNING);
|
exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_WARNING);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(eSignal > MAX_SUPPORTED_VOTE_SIGNAL) {
|
if(eSignal > MAX_SUPPORTED_VOTE_SIGNAL) {
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
ostr << "CGovernanceObject::UpdateVote -- Unsupported vote signal:" << CGovernanceVoting::ConvertSignalToString(vote.GetSignal()) << "\n";
|
ostr << "CGovernanceObject::ProcessVote -- Unsupported vote signal:" << CGovernanceVoting::ConvertSignalToString(vote.GetSignal()) << "\n";
|
||||||
LogPrintf(ostr.str().c_str());
|
LogPrintf(ostr.str().c_str());
|
||||||
exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_PERMANENT_ERROR, 20);
|
exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_PERMANENT_ERROR, 20);
|
||||||
return false;
|
return false;
|
||||||
@ -853,7 +862,7 @@ bool CGovernanceObject::ProcessVote(CNode* pfrom,
|
|||||||
int64_t nTimeDelta = nNow - voteInstance.nTime;
|
int64_t nTimeDelta = nNow - voteInstance.nTime;
|
||||||
if(nTimeDelta < GOVERNANCE_UPDATE_MIN) {
|
if(nTimeDelta < GOVERNANCE_UPDATE_MIN) {
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
ostr << "CGovernanceObject::UpdateVote -- Masternode voting too often "
|
ostr << "CGovernanceObject::ProcessVote -- Masternode voting too often "
|
||||||
<< ", MN outpoint = " << vote.GetVinMasternode().prevout.ToStringShort()
|
<< ", MN outpoint = " << vote.GetVinMasternode().prevout.ToStringShort()
|
||||||
<< ", governance object hash = " << GetHash().ToString()
|
<< ", governance object hash = " << GetHash().ToString()
|
||||||
<< ", time delta = " << nTimeDelta << "\n";
|
<< ", time delta = " << nTimeDelta << "\n";
|
||||||
@ -864,7 +873,7 @@ bool CGovernanceObject::ProcessVote(CNode* pfrom,
|
|||||||
// Finally check that the vote is actually valid (done last because of cost of signature verification)
|
// Finally check that the vote is actually valid (done last because of cost of signature verification)
|
||||||
if(!vote.IsValid(true)) {
|
if(!vote.IsValid(true)) {
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
ostr << "CGovernanceObject::UpdateVote -- Invalid vote "
|
ostr << "CGovernanceObject::ProcessVote -- Invalid vote "
|
||||||
<< ", MN outpoint = " << vote.GetVinMasternode().prevout.ToStringShort()
|
<< ", MN outpoint = " << vote.GetVinMasternode().prevout.ToStringShort()
|
||||||
<< ", governance object hash = " << GetHash().ToString()
|
<< ", governance object hash = " << GetHash().ToString()
|
||||||
<< ", vote hash = " << vote.GetHash().ToString() << "\n";
|
<< ", vote hash = " << vote.GetHash().ToString() << "\n";
|
||||||
|
Loading…
Reference in New Issue
Block a user