diff --git a/persist/sqlite/consensus.go b/persist/sqlite/consensus.go index 5e9b5beb..cc2c6d9f 100644 --- a/persist/sqlite/consensus.go +++ b/persist/sqlite/consensus.go @@ -900,40 +900,6 @@ func addMetrics(tx *txn, s explorer.UpdateState) error { return err } -func cleanupUnusedFileContracts(tx *txn, fces []explorer.FileContractUpdate) error { - deleteFCEStmt, err := tx.Prepare(`DELETE FROM file_contract_elements WHERE contract_id = ? AND revision_number = ?`) - if err != nil { - return fmt.Errorf("updateFileContractElements: failed to prepare delete file_contract_elements statement: %w", err) - } - defer deleteFCEStmt.Close() - - deleteRevisionStmt, err := tx.Prepare(`DELETE FROM last_contract_revision WHERE contract_id = ?`) - if err != nil { - return fmt.Errorf("updateFileContractElements: failed to prepare delete last_contract_revision statement: %w", err) - } - defer deleteRevisionStmt.Close() - - for _, update := range fces { - // Reverting - if update.Revision != nil { - // Delete the revision - if _, err := deleteFCEStmt.Exec(encode(update.Revision.ID), encode(update.Revision.FileContract.RevisionNumber)); err != nil { - return fmt.Errorf("updateFileContractElements: failed to remove reverted revision: %w", err) - } - } else { - // Delete the original contract - if _, err := deleteRevisionStmt.Exec(encode(update.FileContractElement.ID)); err != nil { - return fmt.Errorf("updateFileContractElements: failed to remove reverted original from last_contract_revision: %w", err) - } - if _, err := deleteFCEStmt.Exec(encode(update.FileContractElement.ID), encode(update.FileContractElement.FileContract.RevisionNumber)); err != nil { - return fmt.Errorf("updateFileContractElements: failed to remove reverted original from file_contract_elements: %w", err) - } - } - } - - return nil -} - func (ut *updateTx) HostExists(pubkey types.PublicKey) (exists bool, err error) { err = ut.tx.QueryRow(`SELECT EXISTS(SELECT public_key FROM host_announcements WHERE public_key = ?)`, encode(pubkey)).Scan(&exists) return @@ -1021,9 +987,7 @@ func (ut *updateTx) RevertIndex(state explorer.UpdateState) error { return fmt.Errorf("RevertIndex: failed to delete block: %w", err) } else if err := updateStateTree(ut.tx, state.TreeUpdates); err != nil { return fmt.Errorf("RevertIndex: failed to update state tree: %w", err) - } // else if err := cleanupUnusedFileContracts(ut.tx, state.FileContractElements); err != nil { - // return fmt.Errorf("RevertIndex: failed to remove unused file contract elements: %w", err) - // } + } return nil }