Skip to content

Commit

Permalink
Separate height to hash and sub epoch summaries files by networks.
Browse files Browse the repository at this point in the history
  • Loading branch information
AmineKhaldi committed Feb 13, 2025
1 parent 9842b8c commit 7d28d78
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
7 changes: 4 additions & 3 deletions chia/consensus/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ async def create(
*,
single_threaded: bool = False,
log_coins: bool = False,
selected_network: Optional[str] = None,
) -> Blockchain:
"""
Initializes a blockchain with the BlockRecords from disk, assuming they have all been
Expand Down Expand Up @@ -154,19 +155,19 @@ async def create(
self.coin_store = coin_store
self.block_store = block_store
self._shut_down = False
await self._load_chain_from_store(blockchain_dir)
await self._load_chain_from_store(blockchain_dir, selected_network)
self._seen_compact_proofs = set()
return self

def shut_down(self) -> None:
self._shut_down = True
self.pool.shutdown(wait=True)

async def _load_chain_from_store(self, blockchain_dir: Path) -> None:
async def _load_chain_from_store(self, blockchain_dir: Path, selected_network: Optional[str] = None) -> None:
"""
Initializes the state of the Blockchain class from the database.
"""
self.__height_map = await BlockHeightMap.create(blockchain_dir, self.block_store.db_wrapper)
self.__height_map = await BlockHeightMap.create(blockchain_dir, self.block_store.db_wrapper, selected_network)
self.__block_records = {}
self.__heights_in_cache = {}
block_records, peak = await self.block_store.get_block_records_close_to_peak(self.constants.BLOCKS_CACHE_SIZE)
Expand Down
9 changes: 6 additions & 3 deletions chia/full_node/block_height_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class BlockHeightMap:
__ses_filename: Path

@classmethod
async def create(cls, blockchain_dir: Path, db: DBWrapper2) -> BlockHeightMap:
async def create(
cls, blockchain_dir: Path, db: DBWrapper2, selected_network: Optional[str] = None
) -> BlockHeightMap:
if db.db_version != 2:
raise RuntimeError(f"BlockHeightMap does not support database schema v{db.db_version}")
self = BlockHeightMap()
Expand All @@ -66,8 +68,9 @@ async def create(cls, blockchain_dir: Path, db: DBWrapper2) -> BlockHeightMap:
self.__first_dirty = 0
self.__height_to_hash = bytearray()
self.__sub_epoch_summaries = {}
self.__height_to_hash_filename = blockchain_dir / "height-to-hash"
self.__ses_filename = blockchain_dir / "sub-epoch-summaries"
suffix = "" if (selected_network is None or selected_network == "mainnet") else f"-{selected_network}"
self.__height_to_hash_filename = blockchain_dir / f"height-to-hash{suffix}"
self.__ses_filename = blockchain_dir / f"sub-epoch-summaries{suffix}"

async with self.db.reader_no_transaction() as conn:
async with conn.execute("SELECT hash FROM current_peak WHERE key = 0") as cursor:
Expand Down
1 change: 1 addition & 0 deletions chia/full_node/full_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ async def manage(self) -> AsyncIterator[None]:
reserved_cores=reserved_cores,
single_threaded=single_threaded,
log_coins=log_coins,
selected_network=self.config.get("selected_network"),
)

self._mempool_manager = MempoolManager(
Expand Down

0 comments on commit 7d28d78

Please sign in to comment.