Example #1
0
    async def _open_dbs(self, for_sync, compacting):
        assert self.utxo_db is None

        # First UTXO DB
        self.utxo_db = self.db_class('utxo', for_sync)
        if self.utxo_db.is_new:
            self.logger.info('created new database')
            self.logger.info('creating metadata directory')
            os.mkdir(os.path.join(self.env.db_dir, 'meta'))
            coin_path = os.path.join(self.env.db_dir, 'meta', 'COIN')
            with util.open_file(coin_path, create=True) as f:
                f.write(f'ElectrumX databases and metadata for '
                        f'{self.coin.NAME} {self.coin.NET}'.encode())
            if not self.coin.STATIC_BLOCK_HEADERS:
                self.headers_offsets_file.write(0, bytes(8))
        else:
            self.logger.info(f'opened UTXO DB (for sync: {for_sync})')
        self.read_utxo_state()

        # Then history DB
        self.utxo_flush_count = self.history.open_db(self.db_class, for_sync,
                                                     self.utxo_flush_count,
                                                     compacting)
        self.clear_excess_undo_info()

        # Read TX counts (requires meta directory)
        await self._read_tx_counts()
Example #2
0
    async def _open_dbs(self, for_sync, compacting):
        if self.executor is None:
            self.executor = ThreadPoolExecutor(max(1, os.cpu_count() - 1))
        coin_path = os.path.join(self.env.db_dir, 'COIN')
        if not os.path.isfile(coin_path):
            with util.open_file(coin_path, create=True) as f:
                f.write(f'ElectrumX databases and metadata for '
                        f'{self.coin.NAME} {self.coin.NET}'.encode())

        assert self.headers_db is None
        self.headers_db = self.db_class('headers', for_sync)
        if self.headers_db.is_new:
            self.logger.info('created new headers db')
        self.logger.info(f'opened headers DB (for sync: {for_sync})')

        assert self.tx_count_db is None
        self.tx_count_db = self.db_class('tx_count', for_sync)
        if self.tx_count_db.is_new:
            self.logger.info('created new tx count db')
        self.logger.info(f'opened tx count DB (for sync: {for_sync})')

        assert self.hashes_db is None
        self.hashes_db = self.db_class('hashes', for_sync)
        if self.hashes_db.is_new:
            self.logger.info('created new tx hashes db')
        self.logger.info(f'opened tx hashes DB (for sync: {for_sync})')

        assert self.utxo_db is None
        # First UTXO DB
        self.utxo_db = self.db_class('utxo', for_sync)
        if self.utxo_db.is_new:
            self.logger.info('created new utxo db')
        self.logger.info(f'opened utxo db (for sync: {for_sync})')
        self.read_utxo_state()

        # Then history DB
        self.utxo_flush_count = self.history.open_db(self.db_class, for_sync,
                                                     self.utxo_flush_count,
                                                     compacting)
        self.clear_excess_undo_info()

        # Read TX counts (requires meta directory)
        await self._read_tx_counts()
Example #3
0
 def read():
     with util.open_file(self.raw_block_path(height)) as f:
         return f.read(-1)
Example #4
0
 def read_raw_block(self, height):
     """Returns a raw block read from disk.  Raises FileNotFoundError
     if the block isn't on-disk."""
     with util.open_file(self.raw_block_path(height)) as f:
         return f.read(-1)