diff --git a/zcash_client_sqlite/src/wallet/init.rs b/zcash_client_sqlite/src/wallet/init.rs index c7e358ba45..f808eb2bde 100644 --- a/zcash_client_sqlite/src/wallet/init.rs +++ b/zcash_client_sqlite/src/wallet/init.rs @@ -36,6 +36,9 @@ pub enum WalletMigrationError { /// Wrapper for commitment tree invariant violations CommitmentTree(ShardTreeError), + + /// Reverting the specified migration is not supported. + CannotRevert(Uuid), } impl From for WalletMigrationError { @@ -80,6 +83,9 @@ impl fmt::Display for WalletMigrationError { WalletMigrationError::AddressGeneration(e) => { write!(f, "Address generation error: {:?}", e) } + WalletMigrationError::CannotRevert(uuid) => { + write!(f, "Reverting migration {} is not supported", uuid) + } } } } diff --git a/zcash_client_sqlite/src/wallet/init/migrations/add_account_birthdays.rs b/zcash_client_sqlite/src/wallet/init/migrations/add_account_birthdays.rs index e1893362ed..34fc2eb498 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/add_account_birthdays.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/add_account_birthdays.rs @@ -69,6 +69,6 @@ impl RusqliteMigration for Migration

{ } fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), Self::Error> { - panic!("This migration cannot be reverted."); + Err(WalletMigrationError::CannotRevert(MIGRATION_ID)) } } diff --git a/zcash_client_sqlite/src/wallet/init/migrations/add_transaction_views.rs b/zcash_client_sqlite/src/wallet/init/migrations/add_transaction_views.rs index d3eed031e1..c6b3703957 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/add_transaction_views.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/add_transaction_views.rs @@ -266,8 +266,7 @@ impl RusqliteMigration for Migration { } fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> { - // TODO: something better than just panic? - panic!("Cannot revert this migration."); + Err(WalletMigrationError::CannotRevert(MIGRATION_ID)) } } diff --git a/zcash_client_sqlite/src/wallet/init/migrations/add_utxo_account.rs b/zcash_client_sqlite/src/wallet/init/migrations/add_utxo_account.rs index 76b9d20574..41a606ff90 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/add_utxo_account.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/add_utxo_account.rs @@ -124,8 +124,7 @@ impl RusqliteMigration for Migration

{ } fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> { - // TODO: something better than just panic? - panic!("Cannot revert this migration."); + Err(WalletMigrationError::CannotRevert(MIGRATION_ID)) } } diff --git a/zcash_client_sqlite/src/wallet/init/migrations/addresses_table.rs b/zcash_client_sqlite/src/wallet/init/migrations/addresses_table.rs index ee3e0c1fea..6fdb13bcb4 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/addresses_table.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/addresses_table.rs @@ -174,8 +174,7 @@ impl RusqliteMigration for Migration

{ } fn down(&self, _transaction: &Transaction) -> Result<(), WalletMigrationError> { - // TODO: something better than just panic? - panic!("Cannot revert this migration."); + Err(WalletMigrationError::CannotRevert(MIGRATION_ID)) } } diff --git a/zcash_client_sqlite/src/wallet/init/migrations/full_account_ids.rs b/zcash_client_sqlite/src/wallet/init/migrations/full_account_ids.rs index 52c76c7f47..47406483a2 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/full_account_ids.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/full_account_ids.rs @@ -376,6 +376,6 @@ impl RusqliteMigration for Migration { } fn down(&self, _transaction: &Transaction) -> Result<(), WalletMigrationError> { - panic!("Cannot revert this migration."); + Err(WalletMigrationError::CannotRevert(MIGRATION_ID)) } } diff --git a/zcash_client_sqlite/src/wallet/init/migrations/initial_setup.rs b/zcash_client_sqlite/src/wallet/init/migrations/initial_setup.rs index 4c7387aa64..1a44749755 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/initial_setup.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/initial_setup.rs @@ -102,8 +102,6 @@ impl RusqliteMigration for Migration { } fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> { - // We should never down-migrate the first migration, as that can irreversibly - // destroy data. - panic!("Cannot revert the initial migration."); + Err(WalletMigrationError::CannotRevert(MIGRATION_ID)) } } diff --git a/zcash_client_sqlite/src/wallet/init/migrations/received_notes_nullable_nf.rs b/zcash_client_sqlite/src/wallet/init/migrations/received_notes_nullable_nf.rs index fb54fa135c..ee53388200 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/received_notes_nullable_nf.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/received_notes_nullable_nf.rs @@ -217,8 +217,7 @@ impl RusqliteMigration for Migration { } fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> { - // TODO: something better than just panic? - panic!("Cannot revert this migration."); + Err(WalletMigrationError::CannotRevert(MIGRATION_ID)) } } diff --git a/zcash_client_sqlite/src/wallet/init/migrations/receiving_key_scopes.rs b/zcash_client_sqlite/src/wallet/init/migrations/receiving_key_scopes.rs index 509cabf932..961f270d8d 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/receiving_key_scopes.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/receiving_key_scopes.rs @@ -271,8 +271,7 @@ impl RusqliteMigration for Migration

{ } fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> { - // TODO: something better than just panic? - panic!("Cannot revert this migration."); + Err(WalletMigrationError::CannotRevert(MIGRATION_ID)) } } diff --git a/zcash_client_sqlite/src/wallet/init/migrations/sapling_memo_consistency.rs b/zcash_client_sqlite/src/wallet/init/migrations/sapling_memo_consistency.rs index 07b4faa0a9..bc49a09c2b 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/sapling_memo_consistency.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/sapling_memo_consistency.rs @@ -209,6 +209,6 @@ impl RusqliteMigration for Migration

{ } fn down(&self, _: &rusqlite::Transaction) -> Result<(), Self::Error> { - panic!("Reversing this migration is not supported."); + Err(WalletMigrationError::CannotRevert(MIGRATION_ID)) } } diff --git a/zcash_client_sqlite/src/wallet/init/migrations/sent_notes_to_internal.rs b/zcash_client_sqlite/src/wallet/init/migrations/sent_notes_to_internal.rs index a647894dc3..be86cb7d23 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/sent_notes_to_internal.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/sent_notes_to_internal.rs @@ -74,7 +74,6 @@ impl RusqliteMigration for Migration { } fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> { - // TODO: something better than just panic? - panic!("Cannot revert this migration."); + Err(WalletMigrationError::CannotRevert(MIGRATION_ID)) } } diff --git a/zcash_client_sqlite/src/wallet/init/migrations/shardtree_support.rs b/zcash_client_sqlite/src/wallet/init/migrations/shardtree_support.rs index 50a0271b39..61f6cb9032 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/shardtree_support.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/shardtree_support.rs @@ -277,7 +277,6 @@ impl RusqliteMigration for Migration

{ } fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> { - // TODO: something better than just panic? - panic!("Cannot revert this migration."); + Err(WalletMigrationError::CannotRevert(MIGRATION_ID)) } } diff --git a/zcash_client_sqlite/src/wallet/init/migrations/ufvk_support.rs b/zcash_client_sqlite/src/wallet/init/migrations/ufvk_support.rs index 7fb4e2f6d6..88fd58af65 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/ufvk_support.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/ufvk_support.rs @@ -260,7 +260,6 @@ impl RusqliteMigration for Migration

{ } fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> { - // TODO: something better than just panic? - panic!("Cannot revert this migration."); + Err(WalletMigrationError::CannotRevert(MIGRATION_ID)) } } diff --git a/zcash_client_sqlite/src/wallet/init/migrations/v_transactions_net.rs b/zcash_client_sqlite/src/wallet/init/migrations/v_transactions_net.rs index d7c04adb70..ddf78b4bab 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/v_transactions_net.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/v_transactions_net.rs @@ -196,8 +196,7 @@ impl RusqliteMigration for Migration { } fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> { - // TODO: something better than just panic? - panic!("Cannot revert this migration."); + Err(WalletMigrationError::CannotRevert(MIGRATION_ID)) } } diff --git a/zcash_client_sqlite/src/wallet/init/migrations/v_transactions_note_uniqueness.rs b/zcash_client_sqlite/src/wallet/init/migrations/v_transactions_note_uniqueness.rs index 04d00296d5..c550b4d809 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/v_transactions_note_uniqueness.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/v_transactions_note_uniqueness.rs @@ -154,7 +154,7 @@ impl RusqliteMigration for Migration { } fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), Self::Error> { - panic!("This migration cannot be reverted."); + Err(WalletMigrationError::CannotRevert(MIGRATION_ID)) } } diff --git a/zcash_client_sqlite/src/wallet/init/migrations/v_transactions_shielding_balance.rs b/zcash_client_sqlite/src/wallet/init/migrations/v_transactions_shielding_balance.rs index 9a8c49cef1..c7b64b2d7d 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/v_transactions_shielding_balance.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/v_transactions_shielding_balance.rs @@ -150,6 +150,6 @@ impl RusqliteMigration for Migration { } fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), Self::Error> { - panic!("This migration cannot be reverted."); + Err(WalletMigrationError::CannotRevert(MIGRATION_ID)) } } diff --git a/zcash_client_sqlite/src/wallet/init/migrations/v_transactions_transparent_history.rs b/zcash_client_sqlite/src/wallet/init/migrations/v_transactions_transparent_history.rs index 477d58e292..70a9566f4c 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/v_transactions_transparent_history.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/v_transactions_transparent_history.rs @@ -186,6 +186,6 @@ impl RusqliteMigration for Migration { } fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), Self::Error> { - panic!("This migration cannot be reverted."); + Err(WalletMigrationError::CannotRevert(MIGRATION_ID)) } } diff --git a/zcash_client_sqlite/src/wallet/init/migrations/v_tx_outputs_use_legacy_false.rs b/zcash_client_sqlite/src/wallet/init/migrations/v_tx_outputs_use_legacy_false.rs index d4788871bd..380542747a 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/v_tx_outputs_use_legacy_false.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/v_tx_outputs_use_legacy_false.rs @@ -87,6 +87,6 @@ impl RusqliteMigration for Migration { } fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), Self::Error> { - panic!("This migration cannot be reverted."); + Err(WalletMigrationError::CannotRevert(MIGRATION_ID)) } } diff --git a/zcash_client_sqlite/src/wallet/init/migrations/wallet_summaries.rs b/zcash_client_sqlite/src/wallet/init/migrations/wallet_summaries.rs index 2be9ca15ab..6f9884c363 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/wallet_summaries.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/wallet_summaries.rs @@ -84,6 +84,6 @@ impl RusqliteMigration for Migration { } fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), Self::Error> { - panic!("This migration cannot be reverted."); + Err(WalletMigrationError::CannotRevert(MIGRATION_ID)) } }