Skip to content

Commit

Permalink
completely remove cleanupUnusedFileContracts
Browse files Browse the repository at this point in the history
  • Loading branch information
chris124567 committed Sep 27, 2024
1 parent 7a26b3b commit c0efebd
Showing 1 changed file with 1 addition and 37 deletions.
38 changes: 1 addition & 37 deletions persist/sqlite/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit c0efebd

Please sign in to comment.