Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Calculate potential values at startup #2886

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions modules/host/persist.go
Expand Up @@ -172,12 +172,15 @@ func (h *Host) load() error {
return err
}

// Get the contract count and locked collateral by observing all of the incomplete
// storage obligations in the database.
// TODO: both contract count and locked collateral are not correctly updated during
// contract renewals. This leads to an offset to the real value over time.
// Get the contract count, locked collateral, potential contract compensation
// and potential storage revenue by observing all of the incomplete storage
// obligations in the database.
// TODO: host financial metrics are not correctly updated if there are errors
// during contract renewals. This leads to an offset to the real value over time.
h.financialMetrics.ContractCount = 0
h.financialMetrics.LockedStorageCollateral = types.NewCurrency64(0)
h.financialMetrics.PotentialContractCompensation = types.NewCurrency64(0)
h.financialMetrics.PotentialStorageRevenue = types.NewCurrency64(0)
err = h.db.View(func(tx *bolt.Tx) error {
cursor := tx.Bucket(bucketStorageObligations).Cursor()
for k, v := cursor.First(); k != nil; k, v = cursor.Next() {
Expand All @@ -189,6 +192,8 @@ func (h *Host) load() error {
if so.ObligationStatus == obligationUnresolved {
h.financialMetrics.ContractCount++
h.financialMetrics.LockedStorageCollateral = h.financialMetrics.LockedStorageCollateral.Add(so.LockedCollateral)
h.financialMetrics.PotentialContractCompensation = h.financialMetrics.PotentialContractCompensation.Add(so.ContractCost)
h.financialMetrics.PotentialStorageRevenue = h.financialMetrics.PotentialStorageRevenue.Add(so.PotentialStorageRevenue)
}
}
return nil
Expand Down