Skip to content

Commit

Permalink
Get rid of contract related helper types (#1425)
Browse files Browse the repository at this point in the history
This is a cleanup of our contract database types.

Also extends the `api.ArchivedContract` type with various missing fields
which were previously not exposed at all and only persisted in the
database. Such as the `reason` for an archival.
  • Loading branch information
ChrisSchinnerl committed Aug 12, 2024
2 parents 85bd3ce + 96de237 commit 10aef61
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 164 deletions.
21 changes: 13 additions & 8 deletions api/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,23 @@ type (
// that has been moved to the archive either due to expiring or being renewed.
ArchivedContract struct {
ID types.FileContractID `json:"id"`
HostIP string `json:"hostIP"`
HostKey types.PublicKey `json:"hostKey"`
RenewedTo types.FileContractID `json:"renewedTo"`
Spending ContractSpending `json:"spending"`

ProofHeight uint64 `json:"proofHeight"`
RevisionHeight uint64 `json:"revisionHeight"`
RevisionNumber uint64 `json:"revisionNumber"`
Size uint64 `json:"size"`
StartHeight uint64 `json:"startHeight"`
State string `json:"state"`
WindowStart uint64 `json:"windowStart"`
WindowEnd uint64 `json:"windowEnd"`
ArchivalReason string `json:"archivalReason"`
ContractPrice types.Currency `json:"contractPrice"`
ProofHeight uint64 `json:"proofHeight"`
RenewedFrom types.FileContractID `json:"renewedFrom"`
RevisionHeight uint64 `json:"revisionHeight"`
RevisionNumber uint64 `json:"revisionNumber"`
Size uint64 `json:"size"`
StartHeight uint64 `json:"startHeight"`
State string `json:"state"`
TotalCost types.Currency `json:"totalCost"`
WindowStart uint64 `json:"windowStart"`
WindowEnd uint64 `json:"windowEnd"`
}
)

Expand Down
39 changes: 0 additions & 39 deletions stores/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,6 @@ var objectDeleteBatchSizes = []int64{10, 50, 100, 200, 500, 1000, 5000, 10000, 5
type (
contractState uint8

dbArchivedContract struct {
Model

ContractCommon
RenewedTo fileContractID `gorm:"index;size:32"`

Host publicKey `gorm:"index;NOT NULL;size:32"`
Reason string
}

dbContract struct {
Model

ContractCommon

HostID uint `gorm:"index"`

ContractSets []dbContractSet `gorm:"many2many:contract_set_contracts;constraint:OnDelete:CASCADE"`
}

ContractCommon struct {
FCID fileContractID `gorm:"unique;index;NOT NULL;column:fcid;size:32"`
RenewedFrom fileContractID `gorm:"index;size:32"`
Expand All @@ -100,13 +80,6 @@ type (
ListSpending currency
}

dbContractSet struct {
Model

Name string `gorm:"unique;index;"`
Contracts []dbContract `gorm:"many2many:contract_set_contracts;constraint:OnDelete:CASCADE"`
}

dbObject struct {
Model

Expand Down Expand Up @@ -157,7 +130,6 @@ type (
dbSlab struct {
Model
DBContractSetID uint `gorm:"index"`
DBContractSet dbContractSet
DBBufferedSlabID uint `gorm:"index;default: NULL"`

Health float64 `gorm:"index;default:1.0; NOT NULL"`
Expand All @@ -178,8 +150,6 @@ type (

LatestHost publicKey `gorm:"NOT NULL"`
Root []byte `gorm:"index;unique;NOT NULL;size:32"`

Contracts []dbContract `gorm:"many2many:contract_sectors;constraint:OnDelete:CASCADE"`
}

// dbContractSector is a join table between dbContract and dbSector.
Expand Down Expand Up @@ -265,21 +235,12 @@ func (s dbSlab) HealthValid() bool {
return time.Now().Before(time.Unix(s.HealthValidUntil, 0))
}

// TableName implements the gorm.Tabler interface.
func (dbArchivedContract) TableName() string { return "archived_contracts" }

// TableName implements the gorm.Tabler interface.
func (dbBucket) TableName() string { return "buckets" }

// TableName implements the gorm.Tabler interface.
func (dbContract) TableName() string { return "contracts" }

// TableName implements the gorm.Tabler interface.
func (dbContractSector) TableName() string { return "contract_sectors" }

// TableName implements the gorm.Tabler interface.
func (dbContractSet) TableName() string { return "contract_sets" }

// TableName implements the gorm.Tabler interface.
func (dbObject) TableName() string { return "objects" }

Expand Down
Loading

0 comments on commit 10aef61

Please sign in to comment.