@@ -1495,10 +1495,25 @@ def ElectionEntry(self, args=None):
14951495
14961496 # Save vars to json file
14971497 self .SaveElectionVarsToJsonFile (wallet = wallet , account = account , stake = stake , maxFactor = maxFactor , fullElectorAddr = fullElectorAddr , startWorkTime = startWorkTime , validatorsElectedFor = validatorsElectedFor , endWorkTime = endWorkTime , validatorKey = validatorKey , validatorPubkey_b64 = validatorPubkey_b64 , adnlAddr = adnl_addr , var1 = var1 , validatorSignature = validatorSignature , validatorPubkey = validatorPubkey )
1498-
14991498 self .local .add_log ("ElectionEntry completed. Start work time: " + str (startWorkTime ))
1499+
1500+ self .clear_tmp ()
1501+
15001502 #end define
15011503
1504+ def clear_tmp (self ):
1505+ start = time .time ()
1506+ count = 0
1507+ week_ago = 60 * 60 * 24 * 7
1508+ dir = self .tempDir
1509+ for f in os .listdir (dir ):
1510+ ts = os .path .getmtime (os .path .join (dir , f ))
1511+ if ts < time .time () - week_ago :
1512+ count += 1
1513+ os .remove (os .path .join (dir , f ))
1514+
1515+ self .local .add_log (f"Removed { count } old files from tmp dir for { int (time .time () - start )} seconds" , "info" )
1516+
15021517 def GetValidatorKeyByTime (self , startWorkTime , endWorkTime ):
15031518 self .local .add_log ("start GetValidatorKeyByTime function" , "debug" )
15041519 # Check temp key
@@ -2950,13 +2965,22 @@ def WriteBookmarkData(self, bookmark):
29502965 bookmark ["data" ] = data
29512966 #end define
29522967
2968+ def offers_gc (self , save_offers ):
2969+ current_offers = self .GetOffers ()
2970+ current_offers_hashes = [offer .get ("hash" ) for offer in current_offers ]
2971+ for offer in save_offers :
2972+ if offer not in current_offers_hashes :
2973+ save_offers .pop (offer )
2974+ return save_offers
2975+
29532976 def GetSaveOffers (self ):
29542977 bname = "saveOffers"
2955- saveOffers = self .local .db .get (bname )
2956- if saveOffers is None :
2957- saveOffers = dict ()
2958- self .local .db [bname ] = saveOffers
2959- return saveOffers
2978+ save_offers = self .local .db .get (bname )
2979+ if save_offers is None :
2980+ save_offers = dict ()
2981+ self .local .db [bname ] = save_offers
2982+ self .offers_gc (save_offers )
2983+ return save_offers
29602984 #end define
29612985
29622986 def AddSaveOffer (self , offer ):
0 commit comments