44
55#include < spork.h>
66
7- #include < flat-database.h>
8- #include < util/helpers.h>
9-
107#include < chainparams.h>
8+ #include < flat-database.h>
119#include < key_io.h>
1210#include < logging.h>
1311#include < messagesigner.h>
14- #include < net.h>
1512#include < protocol.h>
1613#include < script/standard.h>
1714#include < timedata.h>
15+ #include < util/helpers.h>
1816#include < util/message.h> // for MESSAGE_MAGIC
1917#include < util/string.h>
2018
@@ -125,49 +123,37 @@ void CSporkManager::CheckAndRemove()
125123 }
126124}
127125
128- MessageProcessingResult CSporkManager::ProcessMessage (CNode& peer, CConnman& connman, std::string_view msg_type, CDataStream& vRecv )
126+ bool CSporkManager::IsSporkValid ( const CSporkMessage& spork )
129127{
130- if (msg_type == NetMsgType::SPORK ) {
131- return ProcessSpork (peer.GetId (), vRecv);
132- }
133- return {};
134- }
135-
136- MessageProcessingResult CSporkManager::ProcessSpork (NodeId from, CDataStream& vRecv)
137- {
138- CSporkMessage spork;
139- vRecv >> spork;
140-
141- uint256 hash = spork.GetHash ();
142-
143- MessageProcessingResult ret{};
144- ret.m_to_erase = CInv{MSG_SPORK , hash};
145-
146128 if (spork.nTimeSigned > GetAdjustedTime () + 2 * 60 * 60 ) {
147129 LogPrint (BCLog::SPORK , " CSporkManager::ProcessSpork -- ERROR: too far into the future\n " );
148- ret.m_error = MisbehavingError{100 };
149- return ret;
130+ return false ;
150131 }
151132
152133 auto opt_keyIDSigner = spork.GetSignerKeyID ();
153134
154135 if (opt_keyIDSigner == std::nullopt || WITH_LOCK (cs, return !setSporkPubKeyIDs.count (*opt_keyIDSigner))) {
155136 LogPrint (BCLog::SPORK , " CSporkManager::ProcessSpork -- ERROR: invalid signature\n " );
156- ret.m_error = MisbehavingError{100 };
157- return ret;
137+ return false ;
158138 }
139+ return true ;
140+ }
159141
160- std::string strLogMsg{strprintf (" SPORK -- hash: %s id: %d value: %10d peer=%d" , hash.ToString (), spork.nSporkID ,
161- spork.nValue , from)};
162- auto keyIDSigner = *opt_keyIDSigner;
142+ bool CSporkManager::ProcessSpork (const CSporkMessage& spork)
143+ {
144+ uint256 hash = spork.GetHash ();
145+ std::string strLogMsg{strprintf (" SPORK -- hash: %s id: %d value: %10d" , hash.ToString (), spork.nSporkID ,
146+ spork.nValue )};
147+ assert (spork.GetSignerKeyID ().has_value ());
148+ auto keyIDSigner = spork.GetSignerKeyID ().value ();
163149
164150 {
165151 LOCK (cs); // make sure to not lock this together with cs_main
166152 if (mapSporksActive.count (spork.nSporkID )) {
167153 if (mapSporksActive[spork.nSporkID ].count (keyIDSigner)) {
168154 if (mapSporksActive[spork.nSporkID ][keyIDSigner].nTimeSigned >= spork.nTimeSigned ) {
169155 LogPrint (BCLog::SPORK , " %s seen\n " , strLogMsg);
170- return ret ;
156+ return false ;
171157 } else {
172158 LogPrintf (" %s updated\n " , strLogMsg);
173159 }
@@ -188,8 +174,7 @@ MessageProcessingResult CSporkManager::ProcessSpork(NodeId from, CDataStream& vR
188174 }
189175 }
190176
191- ret.m_inventory .emplace_back (MSG_SPORK , hash);
192- return ret;
177+ return true ;
193178}
194179
195180std::unordered_map<SporkId, std::map<CKeyID, CSporkMessage>> CSporkManager::ActiveSporks () const
0 commit comments