Skip to content

Commit

Permalink
store siafund pool in metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
chris124567 committed Sep 11, 2024
1 parent 70b5472 commit 5f9dcee
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions explorer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ type Metrics struct {
Index types.ChainIndex `json:"index"`
// Current difficulty
Difficulty consensus.Work `json:"difficulty"`
// Siafund pool value
SiafundPool types.Currency `json:"siafundPool"`
// Total announced hosts
TotalHosts uint64 `json:"totalHosts"`
// Number of active contracts
Expand Down
3 changes: 2 additions & 1 deletion explorer/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ func applyChainUpdate(tx UpdateTx, cau chain.ApplyUpdate) error {
if err != nil {
return err
}
state.Metrics.Difficulty = cau.State.Difficulty
state.Metrics.Index = cau.State.Index
state.Metrics.Difficulty = cau.State.Difficulty
state.Metrics.SiafundPool = cau.State.SiafundPool

return tx.ApplyIndex(state)
}
Expand Down
3 changes: 2 additions & 1 deletion persist/sqlite/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,10 +910,11 @@ func updateFileContractElements(tx *txn, revert bool, b types.Block, fces []expl
}

func addMetrics(tx *txn, s explorer.UpdateState) error {
_, err := tx.Exec(`INSERT INTO network_metrics(block_id, height, difficulty, total_hosts, active_contracts, failed_contracts, successful_contracts, storage_utilization, circulating_supply, contract_revenue) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
_, err := tx.Exec(`INSERT INTO network_metrics(block_id, height, difficulty, siafund_pool, total_hosts, active_contracts, failed_contracts, successful_contracts, storage_utilization, circulating_supply, contract_revenue) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
encode(s.Metrics.Index.ID),
s.Metrics.Index.Height,
encode(s.Metrics.Difficulty),
encode(s.Metrics.SiafundPool),
s.Metrics.TotalHosts,
s.Metrics.ActiveContracts,
s.Metrics.FailedContracts,
Expand Down
1 change: 1 addition & 0 deletions persist/sqlite/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ CREATE TABLE network_metrics (

height INTEGER NOT NULL,
difficulty BLOB NOT NULL,
siafund_pool BLOB NOT NULL,
total_hosts INTEGER NOT NULL,
active_contracts INTEGER NOT NULL,
failed_contracts INTEGER NOT NULL,
Expand Down
2 changes: 1 addition & 1 deletion persist/sqlite/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// Metrics implements explorer.Store
func (s *Store) Metrics(id types.BlockID) (result explorer.Metrics, err error) {
err = s.transaction(func(tx *txn) error {
err = tx.QueryRow(`SELECT block_id, height, difficulty, total_hosts, active_contracts, failed_contracts, successful_contracts, storage_utilization, circulating_supply, contract_revenue FROM network_metrics WHERE block_id = ?`, encode(id)).Scan(decode(&result.Index.ID), &result.Index.Height, decode(&result.Difficulty), &result.TotalHosts, &result.ActiveContracts, &result.FailedContracts, &result.SuccessfulContracts, &result.StorageUtilization, decode(&result.CirculatingSupply), decode(&result.ContractRevenue))
err = tx.QueryRow(`SELECT block_id, height, difficulty, siafund_pool, total_hosts, active_contracts, failed_contracts, successful_contracts, storage_utilization, circulating_supply, contract_revenue FROM network_metrics WHERE block_id = ?`, encode(id)).Scan(decode(&result.Index.ID), &result.Index.Height, decode(&result.Difficulty), decode(&result.SiafundPool), &result.TotalHosts, &result.ActiveContracts, &result.FailedContracts, &result.SuccessfulContracts, &result.StorageUtilization, decode(&result.CirculatingSupply), decode(&result.ContractRevenue))
if err != nil {
return fmt.Errorf("failed to get metrics: %w", err)
}
Expand Down

0 comments on commit 5f9dcee

Please sign in to comment.