@@ -66,77 +66,71 @@ bool CGovernanceObject::ProcessVote(CMasternodeMetaMan& mn_metaman, CGovernanceM
6666 // do not process already known valid votes twice
6767 if (fileVotes.HasVote (vote.GetHash ())) {
6868 // nothing to do here, not an error
69- std::ostringstream ostr;
70- ostr << " CGovernanceObject::ProcessVote -- Already known valid vote" ;
71- LogPrint (BCLog::GOBJECT, " %s\n " , ostr.str ());
72- exception = CGovernanceException (ostr.str (), GOVERNANCE_EXCEPTION_NONE);
69+ std::string msg{strprintf (" CGovernanceObject::%s -- Already known valid vote" , __func__)};
70+ LogPrint (BCLog::GOBJECT, " %s\n " , msg);
71+ exception = CGovernanceException (msg, GOVERNANCE_EXCEPTION_NONE);
7372 return false ;
7473 }
7574
7675 auto dmn = tip_mn_list.GetMNByCollateral (vote.GetMasternodeOutpoint ());
7776 if (!dmn) {
78- std::ostringstream ostr;
79- ostr << " CGovernanceObject::ProcessVote -- Masternode " << vote.GetMasternodeOutpoint ().ToStringShort () << " not found " ;
80- exception = CGovernanceException (ostr. str () , GOVERNANCE_EXCEPTION_PERMANENT_ERROR, 20 );
77+ std::string msg{ strprintf ( " CGovernanceObject::%s -- Masternode %s not found " , __func__,
78+ vote.GetMasternodeOutpoint ().ToStringShort ())} ;
79+ exception = CGovernanceException (msg , GOVERNANCE_EXCEPTION_PERMANENT_ERROR, 20 );
8180 return false ;
8281 }
8382
8483 auto it = mapCurrentMNVotes.emplace (vote_m_t::value_type (vote.GetMasternodeOutpoint (), vote_rec_t ())).first ;
8584 vote_rec_t & voteRecordRef = it->second ;
8685 vote_signal_enum_t eSignal = vote.GetSignal ();
8786 if (eSignal == VOTE_SIGNAL_NONE) {
88- std::ostringstream ostr;
89- ostr << " CGovernanceObject::ProcessVote -- Vote signal: none" ;
90- LogPrint (BCLog::GOBJECT, " %s\n " , ostr.str ());
91- exception = CGovernanceException (ostr.str (), GOVERNANCE_EXCEPTION_WARNING);
87+ std::string msg{strprintf (" CGovernanceObject::%s -- Vote signal: none" , __func__)};
88+ LogPrint (BCLog::GOBJECT, " %s\n " , msg);
89+ exception = CGovernanceException (msg, GOVERNANCE_EXCEPTION_WARNING);
9290 return false ;
9391 }
9492 if (eSignal < VOTE_SIGNAL_NONE || eSignal >= VOTE_SIGNAL_UNKNOWN) {
95- std::ostringstream ostr;
96- ostr << " CGovernanceObject::ProcessVote -- Unsupported vote signal: " << CGovernanceVoting::ConvertSignalToString (vote.GetSignal ());
97- LogPrintf (" %s\n " , ostr. str () );
98- exception = CGovernanceException (ostr. str () , GOVERNANCE_EXCEPTION_PERMANENT_ERROR, 20 );
93+ std::string msg{ strprintf ( " CGovernanceObject::%s -- Unsupported vote signal: %s " , __func__,
94+ CGovernanceVoting::ConvertSignalToString (vote.GetSignal ()))} ;
95+ LogPrintf (" %s\n " , msg );
96+ exception = CGovernanceException (msg , GOVERNANCE_EXCEPTION_PERMANENT_ERROR, 20 );
9997 return false ;
10098 }
10199 auto it2 = voteRecordRef.mapInstances .emplace (vote_instance_m_t::value_type (int (eSignal), vote_instance_t ())).first ;
102100 vote_instance_t & voteInstanceRef = it2->second ;
103101
104102 // Reject obsolete votes
105103 if (vote.GetTimestamp () < voteInstanceRef.nCreationTime ) {
106- std::ostringstream ostr;
107- ostr << " CGovernanceObject::ProcessVote -- Obsolete vote" ;
108- LogPrint (BCLog::GOBJECT, " %s\n " , ostr.str ());
109- exception = CGovernanceException (ostr.str (), GOVERNANCE_EXCEPTION_NONE);
104+ std::string msg{strprintf (" CGovernanceObject::%s -- Obsolete vote" , __func__)};
105+ LogPrint (BCLog::GOBJECT, " %s\n " , msg);
106+ exception = CGovernanceException (msg, GOVERNANCE_EXCEPTION_NONE);
110107 return false ;
111108 } else if (vote.GetTimestamp () == voteInstanceRef.nCreationTime ) {
112109 // Someone is doing something fishy, there can be no two votes from the same masternode
113110 // with the same timestamp for the same object and signal and yet different hash/outcome.
114- std::ostringstream ostr;
115- ostr << " CGovernanceObject::ProcessVote -- Invalid vote, same timestamp for the different outcome" ;
111+ std::string msg{strprintf (" CGovernanceObject::%s -- Invalid vote, same timestamp for the different outcome" , __func__)};
116112 if (vote.GetOutcome () < voteInstanceRef.eOutcome ) {
117113 // This is an arbitrary comparison, we have to agree on some way
118114 // to pick the "winning" vote.
119- ostr << " , rejected" ;
120- LogPrint (BCLog::GOBJECT, " %s\n " , ostr. str () );
121- exception = CGovernanceException (ostr. str () , GOVERNANCE_EXCEPTION_NONE);
115+ msg += " , rejected" ;
116+ LogPrint (BCLog::GOBJECT, " %s\n " , msg );
117+ exception = CGovernanceException (msg , GOVERNANCE_EXCEPTION_NONE);
122118 return false ;
123119 }
124- ostr << " , accepted" ;
125- LogPrint (BCLog::GOBJECT, " %s\n " , ostr. str () );
120+ msg += " , accepted" ;
121+ LogPrint (BCLog::GOBJECT, " %s\n " , msg );
126122 }
127123
128124 int64_t nNow = GetAdjustedTime ();
129125 int64_t nVoteTimeUpdate = voteInstanceRef.nTime ;
130126 if (govman.AreRateChecksEnabled ()) {
131127 int64_t nTimeDelta = nNow - voteInstanceRef.nTime ;
132128 if (nTimeDelta < GOVERNANCE_UPDATE_MIN) {
133- std::ostringstream ostr;
134- ostr << " CGovernanceObject::ProcessVote -- Masternode voting too often"
135- << " , MN outpoint = " << vote.GetMasternodeOutpoint ().ToStringShort ()
136- << " , governance object hash = " << GetHash ().ToString ()
137- << " , time delta = " << nTimeDelta;
138- LogPrint (BCLog::GOBJECT, " %s\n " , ostr.str ());
139- exception = CGovernanceException (ostr.str (), GOVERNANCE_EXCEPTION_TEMPORARY_ERROR);
129+ std::string msg{strprintf (" CGovernanceObject::%s -- Masternode voting too often, MN outpoint = %s, "
130+ " governance object hash = %s, time delta = %d" ,
131+ __func__, vote.GetMasternodeOutpoint ().ToStringShort (), GetHash ().ToString (), nTimeDelta)};
132+ LogPrint (BCLog::GOBJECT, " %s\n " , msg);
133+ exception = CGovernanceException (msg, GOVERNANCE_EXCEPTION_TEMPORARY_ERROR);
140134 return false ;
141135 }
142136 nVoteTimeUpdate = nNow;
@@ -146,24 +140,21 @@ bool CGovernanceObject::ProcessVote(CMasternodeMetaMan& mn_metaman, CGovernanceM
146140
147141 // Finally check that the vote is actually valid (done last because of cost of signature verification)
148142 if (!vote.IsValid (tip_mn_list, onlyVotingKeyAllowed)) {
149- std::ostringstream ostr;
150- ostr << " CGovernanceObject::ProcessVote -- Invalid vote"
151- << " , MN outpoint = " << vote.GetMasternodeOutpoint ().ToStringShort ()
152- << " , governance object hash = " << GetHash ().ToString ()
153- << " , vote hash = " << vote.GetHash ().ToString ();
154- LogPrintf (" %s\n " , ostr.str ());
155- exception = CGovernanceException (ostr.str (), GOVERNANCE_EXCEPTION_PERMANENT_ERROR, 20 );
143+ std::string msg{strprintf (" CGovernanceObject::%s -- Invalid vote, MN outpoint = %s, governance object hash = %s, "
144+ " vote hash = %s" ,
145+ __func__, vote.GetMasternodeOutpoint ().ToStringShort (), GetHash ().ToString (), vote.GetHash ().ToString ())};
146+ LogPrintf (" %s\n " , msg);
147+ exception = CGovernanceException (msg, GOVERNANCE_EXCEPTION_PERMANENT_ERROR, 20 );
156148 govman.AddInvalidVote (vote);
157149 return false ;
158150 }
159151
160152 if (!mn_metaman.AddGovernanceVote (dmn->proTxHash , vote.GetParentHash ())) {
161- std::ostringstream ostr;
162- ostr << " CGovernanceObject::ProcessVote -- Unable to add governance vote"
163- << " , MN outpoint = " << vote.GetMasternodeOutpoint ().ToStringShort ()
164- << " , governance object hash = " << GetHash ().ToString ();
165- LogPrint (BCLog::GOBJECT, " %s\n " , ostr.str ());
166- exception = CGovernanceException (ostr.str (), GOVERNANCE_EXCEPTION_PERMANENT_ERROR);
153+ std::string msg{strprintf (" CGovernanceObject::%s -- Unable to add governance vote, MN outpoint = %s, "
154+ " governance object hash = %s" ,
155+ __func__, vote.GetMasternodeOutpoint ().ToStringShort (), GetHash ().ToString ())};
156+ LogPrint (BCLog::GOBJECT, " %s\n " , msg);
157+ exception = CGovernanceException (msg, GOVERNANCE_EXCEPTION_PERMANENT_ERROR);
167158 return false ;
168159 }
169160
@@ -323,16 +314,11 @@ void CGovernanceObject::LoadData()
323314 m_obj.type = GovernanceObject (obj[" type" ].get_int ());
324315 } catch (std::exception& e) {
325316 fUnparsable = true ;
326- std::ostringstream ostr;
327- ostr << " CGovernanceObject::LoadData Error parsing JSON"
328- << " , e.what() = " << e.what ();
329- LogPrintf (" %s\n " , ostr.str ());
317+ LogPrintf (" %s\n " , strprintf (" CGovernanceObject::LoadData -- Error parsing JSON, e.what() = %s" , e.what ()));
330318 return ;
331319 } catch (...) {
332320 fUnparsable = true ;
333- std::ostringstream ostr;
334- ostr << " CGovernanceObject::LoadData Unknown Error parsing JSON" ;
335- LogPrintf (" %s\n " , ostr.str ());
321+ LogPrintf (" %s\n " , strprintf (" CGovernanceObject::LoadData -- Unknown Error parsing JSON" ));
336322 return ;
337323 }
338324}
0 commit comments