Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small SpendSim persistence fix #10885

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions chia/clvm/spend_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ class SpendSim:
defaults: ConsensusConstants

@classmethod
async def create(cls, db_path=":memory:", defaults=DEFAULT_CONSTANTS):
async def create(cls, db_path=None, defaults=DEFAULT_CONSTANTS):
self = cls()
uri = f"file:db_{random.randint(0, 99999999)}?mode=memory&cache=shared"
if db_path is None:
uri = f"file:db_{random.randint(0, 99999999)}?mode=memory&cache=shared"
else:
uri = f"file:{db_path}"
connection = await aiosqlite.connect(uri, uri=True)
self.db_wrapper = DBWrapper2(connection)
await self.db_wrapper.add_connection(await aiosqlite.connect(uri, uri=True))
Expand All @@ -111,6 +114,7 @@ async def create(cls, db_path=":memory:", defaults=DEFAULT_CONSTANTS):
self.block_height = store_data.block_height
self.block_records = store_data.block_records
self.blocks = store_data.blocks
self.mempool_manager.peak = self.block_records[-1]
else:
self.timestamp = 1
self.block_height = 0
Expand Down Expand Up @@ -269,6 +273,20 @@ async def push_tx(self, spend_bundle: SpendBundle) -> Tuple[MempoolInclusionStat
async def get_coin_record_by_name(self, name: bytes32) -> CoinRecord:
return await self.service.mempool_manager.coin_store.get_coin_record(name)

async def get_coin_records_by_names(
self,
names: List[bytes32],
start_height: Optional[int] = None,
end_height: Optional[int] = None,
include_spent_coins: bool = False,
) -> List[CoinRecord]:
kwargs: Dict[str, Any] = {"include_spent_coins": include_spent_coins, "names": names}
if start_height is not None:
kwargs["start_height"] = start_height
if end_height is not None:
kwargs["end_height"] = end_height
return await self.service.mempool_manager.coin_store.get_coin_records_by_names(**kwargs)

async def get_coin_records_by_parent_ids(
self,
parent_ids: List[bytes32],
Expand Down