delete expired blocks
parent
761dc9eb95
commit
b344c53563
|
@ -620,9 +620,22 @@ class Core:
|
||||||
for row in c.execute(execute, args):
|
for row in c.execute(execute, args):
|
||||||
for i in row:
|
for i in row:
|
||||||
rows.append(i)
|
rows.append(i)
|
||||||
|
|
||||||
return rows
|
return rows
|
||||||
|
|
||||||
|
def getExpiredBlocks(self):
|
||||||
|
'''Returns a list of expired blocks'''
|
||||||
|
conn = sqlite3.connect(self.blockDB, timeout=10)
|
||||||
|
c = conn.cursor()
|
||||||
|
date = int(self._utils.getEpoch())
|
||||||
|
|
||||||
|
execute = 'SELECT hash FROM hashes WHERE expire >= %s ORDER BY dateReceived;' % (date,)
|
||||||
|
|
||||||
|
rows = list()
|
||||||
|
for row in c.execute(execute):
|
||||||
|
for i in row:
|
||||||
|
rows.append(i)
|
||||||
|
return rows
|
||||||
|
|
||||||
def setBlockType(self, hash, blockType):
|
def setBlockType(self, hash, blockType):
|
||||||
'''
|
'''
|
||||||
Sets the type of block
|
Sets the type of block
|
||||||
|
@ -648,9 +661,10 @@ class Core:
|
||||||
sig - optional signature by the author (not optional if author is specified)
|
sig - optional signature by the author (not optional if author is specified)
|
||||||
author - multi-round partial sha3-256 hash of authors public key
|
author - multi-round partial sha3-256 hash of authors public key
|
||||||
dateClaimed - timestamp claimed inside the block, only as trustworthy as the block author is
|
dateClaimed - timestamp claimed inside the block, only as trustworthy as the block author is
|
||||||
|
expire - expire date for a block
|
||||||
'''
|
'''
|
||||||
|
|
||||||
if key not in ('dateReceived', 'decrypted', 'dataType', 'dataFound', 'dataSaved', 'sig', 'author', 'dateClaimed'):
|
if key not in ('dateReceived', 'decrypted', 'dataType', 'dataFound', 'dataSaved', 'sig', 'author', 'dateClaimed', 'expire'):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
conn = sqlite3.connect(self.blockDB, timeout=10)
|
conn = sqlite3.connect(self.blockDB, timeout=10)
|
||||||
|
|
|
@ -91,6 +91,7 @@ class DBCreator:
|
||||||
sig - optional signature by the author (not optional if author is specified)
|
sig - optional signature by the author (not optional if author is specified)
|
||||||
author - multi-round partial sha3-256 hash of authors public key
|
author - multi-round partial sha3-256 hash of authors public key
|
||||||
dateClaimed - timestamp claimed inside the block, only as trustworthy as the block author is
|
dateClaimed - timestamp claimed inside the block, only as trustworthy as the block author is
|
||||||
|
expire int - block expire date in epoch
|
||||||
'''
|
'''
|
||||||
if os.path.exists(self.core.blockDB):
|
if os.path.exists(self.core.blockDB):
|
||||||
raise Exception("Block database already exists")
|
raise Exception("Block database already exists")
|
||||||
|
@ -105,7 +106,8 @@ class DBCreator:
|
||||||
dataSaved int,
|
dataSaved int,
|
||||||
sig text,
|
sig text,
|
||||||
author text,
|
author text,
|
||||||
dateClaimed int
|
dateClaimed int,
|
||||||
|
expire int
|
||||||
);
|
);
|
||||||
''')
|
''')
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
|
@ -65,12 +65,17 @@ class DaemonTools:
|
||||||
self.daemon.decrementThreadCount('netCheck')
|
self.daemon.decrementThreadCount('netCheck')
|
||||||
|
|
||||||
def cleanOldBlocks(self):
|
def cleanOldBlocks(self):
|
||||||
'''Delete old blocks if our disk allocation is full/near full'''
|
'''Delete old blocks if our disk allocation is full/near full, and also expired blocks'''
|
||||||
|
|
||||||
while self.daemon._core._utils.storageCounter.isFull():
|
while self.daemon._core._utils.storageCounter.isFull():
|
||||||
oldest = self.daemon._core.getBlockList()[0]
|
oldest = self.daemon._core.getBlockList()[0]
|
||||||
self.daemon._core._blacklist.addToDB(oldest)
|
self.daemon._core._blacklist.addToDB(oldest)
|
||||||
self.daemon._core.removeBlock(oldest)
|
self.daemon._core.removeBlock(oldest)
|
||||||
logger.info('Deleted block: %s' % (oldest,))
|
logger.info('Deleted block: %s' % (oldest,))
|
||||||
|
# Delete expired blocks
|
||||||
|
for bHash in self.daemon._core.getExpiredBlocks():
|
||||||
|
self.daemon._core._blacklist.addToDB(bHash)
|
||||||
|
self.daemon._core.removeBlock(bHash)
|
||||||
self.daemon.decrementThreadCount('cleanOldBlocks')
|
self.daemon.decrementThreadCount('cleanOldBlocks')
|
||||||
|
|
||||||
def cooldownPeer(self):
|
def cooldownPeer(self):
|
||||||
|
|
|
@ -270,12 +270,18 @@ class OnionrUtils:
|
||||||
try:
|
try:
|
||||||
if len(blockType) <= 10:
|
if len(blockType) <= 10:
|
||||||
self._core.updateBlockInfo(blockHash, 'dataType', blockType)
|
self._core.updateBlockInfo(blockHash, 'dataType', blockType)
|
||||||
|
|
||||||
onionrevents.event('processblocks', data = {'block': myBlock, 'type': blockType, 'signer': signer, 'validSig': valid}, onionr = None)
|
onionrevents.event('processblocks', data = {'block': myBlock, 'type': blockType, 'signer': signer, 'validSig': valid}, onionr = None)
|
||||||
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
logger.warn("Missing block information")
|
logger.warn("Missing block information")
|
||||||
pass
|
pass
|
||||||
|
# Set block expire time if specified
|
||||||
|
try:
|
||||||
|
expireTime = myBlock.getMetadata('expire')
|
||||||
|
assert len(int(expireTime)) < 20 # test that expire time is an integer of sane length (for epoch)
|
||||||
|
except (AssertionError, ValueError) as e:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self._core.updateBlockInfo(blockHash, 'expire', expireTime)
|
||||||
else:
|
else:
|
||||||
logger.debug('Not processing metadata on encrypted block we cannot decrypt.')
|
logger.debug('Not processing metadata on encrypted block we cannot decrypt.')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue