Add current power to the stats

This commit is contained in:
Peter Rabbitson 2021-07-14 08:11:23 +02:00
parent dd09666399
commit 677c193e6c

View File

@ -2,10 +2,12 @@ package main
import ( import (
"encoding/json" "encoding/json"
corebig "math/big"
"os" "os"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/abi"
filbig "github.com/filecoin-project/go-state-types/big"
lcli "github.com/filecoin-project/lotus/cli" lcli "github.com/filecoin-project/lotus/cli"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
@ -21,13 +23,16 @@ type networkTotalsOutput struct {
} }
type networkTotals struct { type networkTotals struct {
UniqueCids int `json:"total_unique_cids"` QaNetworkPower filbig.Int `json:"total_qa_power"`
UniqueProviders int `json:"total_unique_providers"` RawNetworkPower filbig.Int `json:"total_raw_capacity"`
UniqueClients int `json:"total_unique_clients"` CapacityCarryingData float64 `json:"capacity_fraction_carrying_data"`
TotalDeals int `json:"total_num_deals"` UniqueCids int `json:"total_unique_cids"`
TotalBytes int64 `json:"total_stored_data_size"` UniqueProviders int `json:"total_unique_providers"`
FilplusTotalDeals int `json:"filplus_total_num_deals"` UniqueClients int `json:"total_unique_clients"`
FilplusTotalBytes int64 `json:"filplus_total_stored_data_size"` TotalDeals int `json:"total_num_deals"`
TotalBytes int64 `json:"total_stored_data_size"`
FilplusTotalDeals int `json:"filplus_total_num_deals"`
FilplusTotalBytes int64 `json:"filplus_total_stored_data_size"`
seenClient map[address.Address]bool seenClient map[address.Address]bool
seenProvider map[address.Address]bool seenProvider map[address.Address]bool
@ -66,6 +71,11 @@ var storageStatsCmd = &cli.Command{
return err return err
} }
power, err := api.StateMinerPower(ctx, address.Address{}, head.Key())
if err != nil {
return err
}
netTotals := networkTotals{ netTotals := networkTotals{
seenClient: make(map[address.Address]bool), seenClient: make(map[address.Address]bool),
seenProvider: make(map[address.Address]bool), seenProvider: make(map[address.Address]bool),
@ -103,6 +113,13 @@ var storageStatsCmd = &cli.Command{
netTotals.UniqueClients = len(netTotals.seenClient) netTotals.UniqueClients = len(netTotals.seenClient)
netTotals.UniqueProviders = len(netTotals.seenProvider) netTotals.UniqueProviders = len(netTotals.seenProvider)
netTotals.QaNetworkPower = power.TotalPower.QualityAdjPower
netTotals.RawNetworkPower = power.TotalPower.RawBytePower
netTotals.CapacityCarryingData, _ = new(corebig.Rat).SetFrac(
corebig.NewInt(netTotals.TotalBytes),
power.TotalPower.RawBytePower.Int,
).Float64()
return json.NewEncoder(os.Stdout).Encode( return json.NewEncoder(os.Stdout).Encode(
networkTotalsOutput{ networkTotalsOutput{
Epoch: int64(head.Height()), Epoch: int64(head.Height()),