From 0e955157f56110c96a9420a97044d6479f86470f Mon Sep 17 00:00:00 2001 From: Matt Hauff Date: Tue, 16 May 2023 12:58:32 -0700 Subject: [PATCH] add reorg rollback to retry store --- chia/wallet/wallet_retry_store.py | 13 +++++++++++++ chia/wallet/wallet_state_manager.py | 1 + 2 files changed, 14 insertions(+) diff --git a/chia/wallet/wallet_retry_store.py b/chia/wallet/wallet_retry_store.py index a2cf0bbeacf9..5b37e764ce51 100644 --- a/chia/wallet/wallet_retry_store.py +++ b/chia/wallet/wallet_retry_store.py @@ -55,3 +55,16 @@ async def remove_state(self, state: CoinState) -> None: async with self.db_wrapper.writer_maybe_transaction() as conn: cursor = await conn.execute("DELETE FROM retry_store where coin_state=?", (bytes(state),)) await cursor.close() + + async def rollback_to_block(self, height: int) -> None: + """ + Delete all ignored states above a certain height + :param height: Reorg height + :return None: + """ + async with self.db_wrapper.writer_maybe_transaction() as conn: + cursor = await conn.execute( + "DELETE from retry_store WHERE fork_height>?", + (height,), + ) + await cursor.close() diff --git a/chia/wallet/wallet_state_manager.py b/chia/wallet/wallet_state_manager.py index b6a4a9b3e5c5..11063029884a 100644 --- a/chia/wallet/wallet_state_manager.py +++ b/chia/wallet/wallet_state_manager.py @@ -1649,6 +1649,7 @@ async def reorg_rollback(self, height: int) -> List[uint32]: Rolls back and updates the coin_store and transaction store. It's possible this height is the tip, or even beyond the tip. """ + await self.retry_store.rollback_to_block(height) await self.nft_store.rollback_to_block(height) await self.coin_store.rollback_to_block(height) reorged: List[TransactionRecord] = await self.tx_store.get_transaction_above(height)