chia-blockchain icon indicating copy to clipboard operation
chia-blockchain copied to clipboard

[CHIA-683] Drop unknown tables when resetting wallet sync DB

Open Quexington opened this issue 1 year ago • 3 comments

In the wallet node, there is a function called reset_sync_db the purpose of which is to delete relevant information from specific wallet tables that gives you “sync state” so that you can try again if the wallet gets into a bad state.

There’s a problem with this function, which is that it specifies a list of all existing tables and throws an error if any exist that are not mentioned in that list. When you add a table, you have to add it to that list in order for the function to work but if you downgrade then that addition is no longer in the code, but it the table remains in the DB and the function throws an error about an unexpected table.

The way I see it, there’s a few potential solutions, some more robust than others:

  1. Delete the check about unknown tables - The purpose of this is dubious at best. I can’t personally think of a reason it exists, but it must have been place in there for a reason. Maybe to force new tables to think about how to reset themselves? If so, the test checking that that list is complete should be enough.
  2. Automatically delete unknown tables - If we have downgraded, we don’t necessarily have need of these tables so maybe we can just delete them instead of erroring
  3. Store instructions for how to reset each table in the DB somehow - This is probably the most robust, although most complicated, solution. This removes the reset logic from versions, it simply lives in the DB and the code to reset remains static even as the DB schema changes

This PR takes the second approach to avoid the complexity of the third approach and provide more consistent behavior than the first approach likely provides.

Quexington avatar Jun 20 '24 21:06 Quexington