@@ -224,12 +224,15 @@ void CRecoveredSigsDb::WriteRecoveredSig(const llmq::CRecoveredSig& recSig)
224224{
225225 CDBBatch batch (db);
226226
227+ uint32_t curTime = GetAdjustedTime ();
228+
227229 // we put these close to each other to leverage leveldb's key compaction
228230 // this way, the second key can be used for fast HasRecoveredSig checks while the first key stores the recSig
229231 auto k1 = std::make_tuple (std::string (" rs_r" ), recSig.llmqType , recSig.id );
230232 auto k2 = std::make_tuple (std::string (" rs_r" ), recSig.llmqType , recSig.id , recSig.msgHash );
231233 batch.Write (k1, recSig);
232- batch.Write (k2, (uint8_t )1 );
234+ // this key is also used to store the current time, so that we can easily get to the "rs_t" key when we have the id
235+ batch.Write (k2, curTime);
233236
234237 // store by object hash
235238 auto k3 = std::make_tuple (std::string (" rs_h" ), recSig.GetHash ());
@@ -241,7 +244,7 @@ void CRecoveredSigsDb::WriteRecoveredSig(const llmq::CRecoveredSig& recSig)
241244 batch.Write (k4, (uint8_t )1 );
242245
243246 // store by current time. Allows fast cleanup of old recSigs
244- auto k5 = std::make_tuple (std::string (" rs_t" ), (uint32_t )htobe32 (GetAdjustedTime () ), recSig.llmqType , recSig.id );
247+ auto k5 = std::make_tuple (std::string (" rs_t" ), (uint32_t )htobe32 (curTime ), recSig.llmqType , recSig.id );
245248 batch.Write (k5, (uint8_t )1 );
246249
247250 db.WriteBatch (batch);
@@ -256,6 +259,50 @@ void CRecoveredSigsDb::WriteRecoveredSig(const llmq::CRecoveredSig& recSig)
256259 }
257260}
258261
262+ void CRecoveredSigsDb::RemoveRecoveredSig (CDBBatch& batch, Consensus::LLMQType llmqType, const uint256& id, bool deleteTimeKey)
263+ {
264+ AssertLockHeld (cs);
265+
266+ CRecoveredSig recSig;
267+ if (!ReadRecoveredSig (llmqType, id, recSig)) {
268+ return ;
269+ }
270+
271+ auto signHash = CLLMQUtils::BuildSignHash (recSig);
272+
273+ auto k1 = std::make_tuple (std::string (" rs_r" ), recSig.llmqType , recSig.id );
274+ auto k2 = std::make_tuple (std::string (" rs_r" ), recSig.llmqType , recSig.id , recSig.msgHash );
275+ auto k3 = std::make_tuple (std::string (" rs_h" ), recSig.GetHash ());
276+ auto k4 = std::make_tuple (std::string (" rs_s" ), signHash);
277+ batch.Erase (k1);
278+ batch.Erase (k2);
279+ batch.Erase (k3);
280+ batch.Erase (k4);
281+
282+ if (deleteTimeKey) {
283+ CDataStream writeTimeDs (SER_DISK, CLIENT_VERSION);
284+ // TODO remove the size() == sizeof(uint32_t) in a future version (when we stop supporting upgrades from < 0.14.1)
285+ if (db.ReadDataStream (k2, writeTimeDs) && writeTimeDs.size () == sizeof (uint32_t )) {
286+ uint32_t writeTime;
287+ writeTimeDs >> writeTime;
288+ auto k5 = std::make_tuple (std::string (" rs_t" ), (uint32_t ) htobe32 (writeTime), recSig.llmqType , recSig.id );
289+ batch.Erase (k5);
290+ }
291+ }
292+
293+ hasSigForIdCache.erase (std::make_pair ((Consensus::LLMQType)recSig.llmqType , recSig.id ));
294+ hasSigForSessionCache.erase (signHash);
295+ hasSigForHashCache.erase (recSig.GetHash ());
296+ }
297+
298+ void CRecoveredSigsDb::RemoveRecoveredSig (Consensus::LLMQType llmqType, const uint256& id)
299+ {
300+ LOCK (cs);
301+ CDBBatch batch (db);
302+ RemoveRecoveredSig (batch, llmqType, id, true );
303+ db.WriteBatch (batch);
304+ }
305+
259306void CRecoveredSigsDb::CleanupOldRecoveredSigs (int64_t maxAge)
260307{
261308 std::unique_ptr<CDBIterator> pcursor (db.NewIterator ());
@@ -292,25 +339,7 @@ void CRecoveredSigsDb::CleanupOldRecoveredSigs(int64_t maxAge)
292339 {
293340 LOCK (cs);
294341 for (auto & e : toDelete) {
295- CRecoveredSig recSig;
296- if (!ReadRecoveredSig (e.first , e.second , recSig)) {
297- continue ;
298- }
299-
300- auto signHash = CLLMQUtils::BuildSignHash (recSig);
301-
302- auto k1 = std::make_tuple (std::string (" rs_r" ), recSig.llmqType , recSig.id );
303- auto k2 = std::make_tuple (std::string (" rs_r" ), recSig.llmqType , recSig.id , recSig.msgHash );
304- auto k3 = std::make_tuple (std::string (" rs_h" ), recSig.GetHash ());
305- auto k4 = std::make_tuple (std::string (" rs_s" ), signHash);
306- batch.Erase (k1);
307- batch.Erase (k2);
308- batch.Erase (k3);
309- batch.Erase (k4);
310-
311- hasSigForIdCache.erase (std::make_pair ((Consensus::LLMQType)recSig.llmqType , recSig.id ));
312- hasSigForSessionCache.erase (signHash);
313- hasSigForHashCache.erase (recSig.GetHash ());
342+ RemoveRecoveredSig (batch, e.first , e.second , false );
314343
315344 if (batch.SizeEstimate () >= (1 << 24 )) {
316345 db.WriteBatch (batch);
@@ -680,6 +709,11 @@ void CSigningManager::PushReconstructedRecoveredSig(const llmq::CRecoveredSig& r
680709 pendingReconstructedRecoveredSigs.emplace_back (recoveredSig, quorum);
681710}
682711
712+ void CSigningManager::RemoveRecoveredSig (Consensus::LLMQType llmqType, const uint256& id)
713+ {
714+ db.RemoveRecoveredSig (llmqType, id);
715+ }
716+
683717void CSigningManager::Cleanup ()
684718{
685719 int64_t now = GetTimeMillis ();
0 commit comments