Пример #1
0
    def __init__(self, config, shared, test_reorgs):

        self.dbpath = config.get('leveldb', 'path')
        if not os.path.exists(self.dbpath):
            os.mkdir(self.dbpath)
        self.pruning_limit = config.getint('leveldb', 'pruning_limit')
        self.shared = shared
        self.hash_list = {}
        self.parents = {}

        self.test_reorgs = test_reorgs
        try:
            self.db_utxo = plyvel.DB(
                os.path.join(self.dbpath, 'utxo'),
                create_if_missing=True,
                compression=None)
            self.db_addr = plyvel.DB(
                os.path.join(self.dbpath, 'addr'),
                create_if_missing=True,
                compression=None)
            self.db_hist = plyvel.DB(
                os.path.join(self.dbpath, 'hist'),
                create_if_missing=True,
                compression=None)
            self.db_undo = plyvel.DB(
                os.path.join(self.dbpath, 'undo'),
                create_if_missing=True,
                compression=None)
        except:
            logger.error('db init', exc_info=True)
            self.shared.stop()

        self.db_version = 3  # increase this when database needs to be updated
        try:
            self.last_hash, self.height, db_version = ast.literal_eval(
                self.db_undo.get('height'))
            print_log("Database version", self.db_version)
            print_log("Blockchain height", self.height)
        except:
            print_log('initializing database')
            self.height = 0
            self.last_hash = chainparams.get_active_chain().genesis_hash
            db_version = self.db_version
            # write root
            self.put_node('', {})

        # check version
        if self.db_version != db_version:
            print_log(
                "Your database '%s' is deprecated. Please create a new database"
                % self.dbpath)
            self.shared.stop()
            return

        # compute root hash
        d = self.get_node('')
        self.root_hash, v = self.get_node_hash('', d, None)
        print_log("UTXO tree root hash:", self.root_hash.encode('hex'))
        print_log("Coins in database:", v)
Пример #2
0
    def __init__(self, config, shared, test_reorgs):

        self.dbpath = config.get('leveldb', 'path')
        if not os.path.exists(self.dbpath):
            os.mkdir(self.dbpath)
        self.pruning_limit = config.getint('leveldb', 'pruning_limit')
        self.shared = shared
        self.hash_list = {}
        self.parents = {}

        self.test_reorgs = test_reorgs
        try:
            self.db_utxo = plyvel.DB(os.path.join(self.dbpath, 'utxo'),
                                     create_if_missing=True,
                                     compression=None)
            self.db_addr = plyvel.DB(os.path.join(self.dbpath, 'addr'),
                                     create_if_missing=True,
                                     compression=None)
            self.db_hist = plyvel.DB(os.path.join(self.dbpath, 'hist'),
                                     create_if_missing=True,
                                     compression=None)
            self.db_undo = plyvel.DB(os.path.join(self.dbpath, 'undo'),
                                     create_if_missing=True,
                                     compression=None)
        except:
            logger.error('db init', exc_info=True)
            self.shared.stop()

        self.db_version = 3  # increase this when database needs to be updated
        try:
            self.last_hash, self.height, db_version = ast.literal_eval(
                self.db_undo.get('height'))
            print_log("Database version", self.db_version)
            print_log("Blockchain height", self.height)
        except:
            print_log('initializing database')
            self.height = 0
            self.last_hash = GENESIS_HASH
            db_version = self.db_version
            # write root
            self.put_node('', {})

        # check version
        if self.db_version != db_version:
            print_log(
                "Your database '%s' is deprecated. Please create a new database"
                % self.dbpath)
            self.shared.stop()
            return

        # compute root hash
        d = self.get_node('')
        self.root_hash, v = self.get_node_hash('', d, None)
        print_log("UTXO tree root hash:", self.root_hash.encode('hex'))
        print_log("Coins in database:", v)
Пример #3
0
 def __init__(self, config, shared, test_reorgs):
     self.shared = shared
     self.hash_list = {}
     self.parents = {}
     self.skip_batch = {}
     self.test_reorgs = test_reorgs
     # init path
     self.dbpath = config.get('leveldb', 'path')
     if not os.path.exists(self.dbpath):
         os.mkdir(self.dbpath)
     try:
         self.db_utxo = DB(self.dbpath, 'utxo', config.getint('leveldb', 'utxo_cache'))
         self.db_hist = DB(self.dbpath, 'hist', config.getint('leveldb', 'hist_cache'))
         self.db_addr = DB(self.dbpath, 'addr', config.getint('leveldb', 'addr_cache'))
         self.db_undo = DB(self.dbpath, 'undo', None)
     except:
         logger.error('db init', exc_info=True)
         self.shared.stop()
     try:
         self.last_hash, self.height, db_version = ast.literal_eval(self.db_undo.get('height'))
     except:
         print_log('Initializing database')
         self.height = 0
         self.last_hash = GENESIS_HASH
         self.pruning_limit = config.getint('leveldb', 'pruning_limit')
         db_version = DB_VERSION
         self.put_node('', Node.from_dict({}))
     # check version
     if db_version != DB_VERSION:
         print_log("Your database '%s' is deprecated. Please create a new database"%self.dbpath)
         self.shared.stop()
         return
     # pruning limit
     try:
         self.pruning_limit = ast.literal_eval(self.db_undo.get('limit'))
     except:
         self.pruning_limit = config.getint('leveldb', '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
     root_node = self.get_node('')
     self.root_hash, coins = root_node.get_hash('', None)
     # print stuff
     print_log("Database version %d."%db_version)
     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("UTXO tree root hash:", self.root_hash.encode('hex'))
     print_log("Coins in database:", coins)
Пример #4
0
 def __init__(self, config, shared, test_reorgs):
     self.shared = shared
     self.hash_list = {}
     self.parents = {}
     self.skip_batch = {}
     self.test_reorgs = test_reorgs
     # init path
     self.dbpath = config.get('leveldb', 'path')
     if not os.path.exists(self.dbpath):
         os.mkdir(self.dbpath)
     try:
         self.db_utxo = DB(self.dbpath, 'utxo',
                           config.getint('leveldb', 'utxo_cache'))
         self.db_hist = DB(self.dbpath, 'hist',
                           config.getint('leveldb', 'hist_cache'))
         self.db_addr = DB(self.dbpath, 'addr',
                           config.getint('leveldb', 'addr_cache'))
         self.db_undo = DB(self.dbpath, 'undo', None)
     except:
         logger.error('db init', exc_info=True)
         self.shared.stop()
     try:
         self.last_hash, self.height, db_version = ast.literal_eval(
             self.db_undo.get('height'))
     except:
         print_log('Initializing database')
         self.height = 0
         self.last_hash = GENESIS_HASH
         self.pruning_limit = config.getint('leveldb', 'pruning_limit')
         db_version = DB_VERSION
         self.put_node('', Node.from_dict({}))
     # check version
     if db_version != DB_VERSION:
         print_log(
             "Your database '%s' is deprecated. Please create a new database"
             % self.dbpath)
         self.shared.stop()
         return
     # pruning limit
     try:
         self.pruning_limit = ast.literal_eval(self.db_undo.get('limit'))
     except:
         self.pruning_limit = config.getint('leveldb', 'pruning_limit')
         self.db_undo.put('version', repr(self.pruning_limit))
     # compute root hash
     root_node = self.get_node('')
     self.root_hash, coins = root_node.get_hash('', None)
     # print stuff
     print_log("Database version %d." % db_version)
     print_log("Pruning limit for spent outputs is %d." %
               self.pruning_limit)
     print_log("Blockchain height", self.height)
     print_log("UTXO tree root hash:", self.root_hash.encode('hex'))
     print_log("Coins in database:", coins)