Browse Source

More robust init

master
Neil Booth 8 years ago
parent
commit
5653bf75f5
  1. 21
      server/db.py
  2. 2
      server/server.py

21
server/db.py

@ -323,21 +323,26 @@ class DB(object):
.format(self.flush_MB))
def open_db(self, coin):
self.headers_file = self.open_file('headers', True)
self.txcount_file = self.open_file('txcount', True)
is_new = self.headers_file.seek(0, 2) == 0
if is_new != (self.txcount_file.seek(0, 2) == 0):
raise self.Error('just one metadata file is zero-length')
db_name = '{}-{}'.format(coin.NAME, coin.NET)
db = plyvel.DB(db_name, create_if_missing=is_new,
error_if_exists=is_new, compression=None)
is_new = False
try:
db = plyvel.DB(db_name, create_if_missing=False,
error_if_exists=False, compression=None)
except:
db = plyvel.DB(db_name, create_if_missing=True,
error_if_exists=True, compression=None)
is_new = True
if is_new:
self.logger.info('created new database {}'.format(db_name))
self.flush_state(db)
else:
self.logger.info('successfully opened database {}'.format(db_name))
self.read_state(db)
self.headers_file = self.open_file('headers', is_new)
self.txcount_file = self.open_file('txcount', is_new)
return db
def flush_state(self, batch):

2
server/server.py

@ -125,7 +125,7 @@ class BlockCache(object):
return False
# Convert hex string to bytes and put in memoryview
blocks = [memoryview(bytes.fromhex(block)) for block in blocks]
blocks = [bytes.fromhex(block) for block in blocks]
# Reverse order and place at front of list
self.blocks = list(reversed(blocks)) + self.blocks

Loading…
Cancel
Save