purge old blocks if POW increases
parent
01ed4d49d0
commit
e34b499044
|
@ -18,6 +18,7 @@ from onionrstorage import removeblock
|
||||||
from onionrblocks import onionrblacklist
|
from onionrblocks import onionrblacklist
|
||||||
from onionrblocks.storagecounter import StorageCounter
|
from onionrblocks.storagecounter import StorageCounter
|
||||||
from etc.onionrvalues import DATABASE_LOCK_TIMEOUT
|
from etc.onionrvalues import DATABASE_LOCK_TIMEOUT
|
||||||
|
from onionrproofs import hashMeetsDifficulty
|
||||||
"""
|
"""
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -44,16 +45,25 @@ def __remove_from_upload(shared_state, block_hash: str):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def __purge_block(shared_state, block_hash, add_to_blacklist = True):
|
||||||
|
blacklist = None
|
||||||
|
|
||||||
|
removeblock.remove_block(block_hash)
|
||||||
|
onionrstorage.deleteBlock(block_hash)
|
||||||
|
__remove_from_upload(shared_state, block_hash)
|
||||||
|
|
||||||
|
if add_to_blacklist:
|
||||||
|
blacklist = onionrblacklist.OnionrBlackList()
|
||||||
|
blacklist.addToDB(block_hash)
|
||||||
|
|
||||||
|
|
||||||
def clean_old_blocks(shared_state):
|
def clean_old_blocks(shared_state):
|
||||||
"""Delete expired blocks + old blocks if disk allocation is near full"""
|
"""Delete expired blocks + old blocks if disk allocation is near full"""
|
||||||
blacklist = onionrblacklist.OnionrBlackList()
|
blacklist = onionrblacklist.OnionrBlackList()
|
||||||
# Delete expired blocks
|
# Delete expired blocks
|
||||||
for bHash in blockmetadb.expiredblocks.get_expired_blocks():
|
for bHash in blockmetadb.expiredblocks.get_expired_blocks():
|
||||||
blacklist.addToDB(bHash)
|
__purge_block(shared_state, bHash, add_to_blacklist=True)
|
||||||
removeblock.remove_block(bHash)
|
logger.info('Deleted expired block: %s' % (bHash,))
|
||||||
onionrstorage.deleteBlock(bHash)
|
|
||||||
__remove_from_upload(shared_state, bHash)
|
|
||||||
logger.info('Deleted block: %s' % (bHash,))
|
|
||||||
|
|
||||||
while storage_counter.is_full():
|
while storage_counter.is_full():
|
||||||
try:
|
try:
|
||||||
|
@ -61,11 +71,8 @@ def clean_old_blocks(shared_state):
|
||||||
except IndexError:
|
except IndexError:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
blacklist.addToDB(oldest)
|
__purge_block(shared_state, bHash, add_to_blacklist=True)
|
||||||
removeblock.remove_block(oldest)
|
logger.info('Deleted block because of full storage: %s' % (oldest,))
|
||||||
onionrstorage.deleteBlock(oldest)
|
|
||||||
__remove_from_upload(shared_state, oldest)
|
|
||||||
logger.info('Deleted block: %s' % (oldest,))
|
|
||||||
|
|
||||||
|
|
||||||
def clean_keys():
|
def clean_keys():
|
||||||
|
@ -88,3 +95,14 @@ def clean_keys():
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
onionrusers.deleteExpiredKeys()
|
onionrusers.deleteExpiredKeys()
|
||||||
|
|
||||||
|
|
||||||
|
def clean_blocks_not_meeting_pow(shared_state):
|
||||||
|
"""Clean blocks not meeting min send/rec pow. Used if config.json POW changes"""
|
||||||
|
block_list = blockmetadb.get_block_list()
|
||||||
|
for block in block_list:
|
||||||
|
if not hashMeetsDifficulty(block):
|
||||||
|
logger.warn(
|
||||||
|
f"Deleting block {block} because it was stored" +
|
||||||
|
"with a POW level smaller than current.", terminal=True)
|
||||||
|
__purge_block(shared_state, block)
|
||||||
|
|
|
@ -42,6 +42,7 @@ from lan.server import LANServer
|
||||||
from sneakernet import sneakernet_import_thread
|
from sneakernet import sneakernet_import_thread
|
||||||
from onionrstatistics.devreporting import statistics_reporter
|
from onionrstatistics.devreporting import statistics_reporter
|
||||||
from setupkvvars import setup_kv
|
from setupkvvars import setup_kv
|
||||||
|
from communicatorutils.housekeeping import clean_blocks_not_meeting_pow
|
||||||
from .spawndaemonthreads import spawn_client_threads
|
from .spawndaemonthreads import spawn_client_threads
|
||||||
"""
|
"""
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
@ -222,6 +223,8 @@ def daemon():
|
||||||
'proxyPort', net.socksPort)
|
'proxyPort', net.socksPort)
|
||||||
spawn_client_threads(shared_state)
|
spawn_client_threads(shared_state)
|
||||||
|
|
||||||
|
clean_blocks_not_meeting_pow(shared_state)
|
||||||
|
|
||||||
communicator.startCommunicator(shared_state)
|
communicator.startCommunicator(shared_state)
|
||||||
|
|
||||||
clean_ephemeral_services()
|
clean_ephemeral_services()
|
||||||
|
|
Loading…
Reference in New Issue