Skip to content
This repository has been archived by the owner on Jul 12, 2021. It is now read-only.

Commit

Permalink
added a reorg_limit option to handle deep reorgs in the bitcoin testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
erasmospunk committed Jul 6, 2016
1 parent 3bdce8d commit 3228c88
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions run_electrum_server.py
Expand Up @@ -105,6 +105,7 @@ def create_config(filename=None):
config.add_section('leveldb') config.add_section('leveldb')
config.set('leveldb', 'path', '/dev/shm/electrum_db') config.set('leveldb', 'path', '/dev/shm/electrum_db')
config.set('leveldb', 'pruning_limit', '100') config.set('leveldb', 'pruning_limit', '100')
config.set('leveldb', 'reorg_limit', '100')
config.set('leveldb', 'utxo_cache', str(64*1024*1024)) config.set('leveldb', 'utxo_cache', str(64*1024*1024))
config.set('leveldb', 'hist_cache', str(128*1024*1024)) config.set('leveldb', 'hist_cache', str(128*1024*1024))
config.set('leveldb', 'addr_cache', str(16*1024*1024)) config.set('leveldb', 'addr_cache', str(16*1024*1024))
Expand Down
14 changes: 10 additions & 4 deletions src/storage.py
Expand Up @@ -229,12 +229,19 @@ def __init__(self, config, shared, test_reorgs):
except: except:
self.pruning_limit = config.getint('leveldb', 'pruning_limit') self.pruning_limit = config.getint('leveldb', 'pruning_limit')
self.db_undo.put('version', repr(self.pruning_limit)) self.db_undo.put('version', repr(self.pruning_limit))
# reorg limit
try:
self.reorg_limit = ast.literal_eval(self.db_undo.get('reorg_limit'))
except:
self.reorg_limit = config.getint('leveldb', 'reorg_limit')
self.db_undo.put('reorg_limit', repr(self.reorg_limit))
# compute root hash # compute root hash
root_node = self.get_node('') root_node = self.get_node('')
self.root_hash, coins = root_node.get_hash('', None) self.root_hash, coins = root_node.get_hash('', None)
# print stuff # print stuff
print_log("Database version %d."%db_version) print_log("Database version %d."%db_version)
print_log("Pruning limit for spent outputs is %d."%self.pruning_limit) print_log("Pruning limit for spent outputs is %d."%self.pruning_limit)
print_log("Reorg limit is %d blocks."%self.reorg_limit)
print_log("Blockchain height", self.height) print_log("Blockchain height", self.height)
print_log("UTXO tree root hash:", self.root_hash.encode('hex')) print_log("UTXO tree root hash:", self.root_hash.encode('hex'))
print_log("Coins in database:", coins) print_log("Coins in database:", coins)
Expand Down Expand Up @@ -324,15 +331,14 @@ def get_address(self, txi):
return self.db_addr.get(txi) return self.db_addr.get(txi)


def get_undo_info(self, height): def get_undo_info(self, height):
s = self.db_undo.get("undo_info_%d" % (height % 100)) s = self.db_undo.get("undo_info_%d" % (height % self.reorg_limit))
if s is None: if s is None:
print_log("no undo info for ", height) print_log("no undo info for ", height)
return eval(s) return eval(s)



def write_undo_info(self, height, bitcoind_height, undo_info): def write_undo_info(self, height, bitcoind_height, undo_info):
if height > bitcoind_height - 100 or self.test_reorgs: if height > bitcoind_height - self.reorg_limit or self.test_reorgs:
self.db_undo.put("undo_info_%d" % (height % 100), repr(undo_info)) self.db_undo.put("undo_info_%d" % (height % self.reorg_limit), repr(undo_info))


@staticmethod @staticmethod
def common_prefix(word1, word2): def common_prefix(word1, word2):
Expand Down

0 comments on commit 3228c88

Please sign in to comment.