From 0359a458e4b41c3920e5768c11f63671ee1b67ca Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Fri, 14 Aug 2020 16:44:33 -0400 Subject: [PATCH] Include more info in StateCirculatingSupply --- api/api_full.go | 10 +++++++++- api/apistruct/struct.go | 4 ++-- chain/stmgr/stmgr.go | 29 ++++++++++++++++++++++------- cli/state.go | 6 +++++- cmd/lotus-chainwatch/syncer/sync.go | 3 ++- node/impl/full/state.go | 12 ++++++------ 6 files changed, 46 insertions(+), 18 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index fe61afa26..2a1d830ed 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -359,7 +359,7 @@ type FullNode interface { StateDealProviderCollateralBounds(context.Context, abi.PaddedPieceSize, bool, types.TipSetKey) (DealCollateralBounds, error) // StateCirculatingSupply returns the circulating supply of Filecoin at the given tipset - StateCirculatingSupply(context.Context, types.TipSetKey) (abi.TokenAmount, error) + StateCirculatingSupply(context.Context, types.TipSetKey) (CirculatingSupply, error) // MethodGroup: Msig // The Msig methods are used to interact with multisig wallets on the @@ -674,6 +674,14 @@ type DealCollateralBounds struct { Max abi.TokenAmount } +type CirculatingSupply struct { + FilVested abi.TokenAmount + FilMined abi.TokenAmount + FilBurnt abi.TokenAmount + FilLocked abi.TokenAmount + FilCirculating abi.TokenAmount +} + type MiningBaseInfo struct { MinerPower types.BigInt NetworkPower types.BigInt diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index 4ecea5bde..952cef8ce 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -181,7 +181,7 @@ type FullNodeStruct struct { StateCompute func(context.Context, abi.ChainEpoch, []*types.Message, types.TipSetKey) (*api.ComputeStateOutput, error) `perm:"read"` StateVerifiedClientStatus func(context.Context, address.Address, types.TipSetKey) (*verifreg.DataCap, error) `perm:"read"` StateDealProviderCollateralBounds func(context.Context, abi.PaddedPieceSize, bool, types.TipSetKey) (api.DealCollateralBounds, error) `perm:"read"` - StateCirculatingSupply func(context.Context, types.TipSetKey) (abi.TokenAmount, error) `perm:"read"` + StateCirculatingSupply func(context.Context, types.TipSetKey) (api.CirculatingSupply, error) `perm:"read"` MsigGetAvailableBalance func(context.Context, address.Address, types.TipSetKey) (types.BigInt, error) `perm:"read"` MsigCreate func(context.Context, uint64, []address.Address, abi.ChainEpoch, types.BigInt, address.Address, types.BigInt) (cid.Cid, error) `perm:"sign"` @@ -801,7 +801,7 @@ func (c *FullNodeStruct) StateDealProviderCollateralBounds(ctx context.Context, return c.Internal.StateDealProviderCollateralBounds(ctx, size, verified, tsk) } -func (c *FullNodeStruct) StateCirculatingSupply(ctx context.Context, tsk types.TipSetKey) (abi.TokenAmount, error) { +func (c *FullNodeStruct) StateCirculatingSupply(ctx context.Context, tsk types.TipSetKey) (api.CirculatingSupply, error) { return c.Internal.StateCirculatingSupply(ctx, tsk) } diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index a3bd9e023..f4943cba3 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -984,34 +984,34 @@ func GetFilBurnt(ctx context.Context, st *state.StateTree) (abi.TokenAmount, err return burnt.Balance, nil } -func (sm *StateManager) GetCirculatingSupply(ctx context.Context, height abi.ChainEpoch, st *state.StateTree) (abi.TokenAmount, error) { +func (sm *StateManager) GetCirculatingSupplyDetailed(ctx context.Context, height abi.ChainEpoch, st *state.StateTree) (api.CirculatingSupply, error) { sm.genesisMsigLk.Lock() defer sm.genesisMsigLk.Unlock() if sm.genInfo == nil { err := sm.setupGenesisActors(ctx) if err != nil { - return big.Zero(), xerrors.Errorf("failed to setup genesis information: %w", err) + return api.CirculatingSupply{}, xerrors.Errorf("failed to setup genesis information: %w", err) } } filVested, err := sm.GetFilVested(ctx, height, st) if err != nil { - return big.Zero(), xerrors.Errorf("failed to calculate filVested: %w", err) + return api.CirculatingSupply{}, xerrors.Errorf("failed to calculate filVested: %w", err) } filMined, err := GetFilMined(ctx, st) if err != nil { - return big.Zero(), xerrors.Errorf("failed to calculate filMined: %w", err) + return api.CirculatingSupply{}, xerrors.Errorf("failed to calculate filMined: %w", err) } filBurnt, err := GetFilBurnt(ctx, st) if err != nil { - return big.Zero(), xerrors.Errorf("failed to calculate filBurnt: %w", err) + return api.CirculatingSupply{}, xerrors.Errorf("failed to calculate filBurnt: %w", err) } filLocked, err := sm.GetFilLocked(ctx, st) if err != nil { - return big.Zero(), xerrors.Errorf("failed to calculate filLocked: %w", err) + return api.CirculatingSupply{}, xerrors.Errorf("failed to calculate filLocked: %w", err) } ret := types.BigAdd(filVested, filMined) @@ -1022,5 +1022,20 @@ func (sm *StateManager) GetCirculatingSupply(ctx context.Context, height abi.Cha ret = big.Zero() } - return ret, nil + return api.CirculatingSupply{ + FilVested: filVested, + FilMined: filMined, + FilBurnt: filBurnt, + FilLocked: filLocked, + FilCirculating: ret, + }, nil +} + +func (sm *StateManager) GetCirculatingSupply(ctx context.Context, height abi.ChainEpoch, st *state.StateTree) (abi.TokenAmount, error) { + csi, err := sm.GetCirculatingSupplyDetailed(ctx, height, st) + if err != nil { + return big.Zero(), err + } + + return csi.FilCirculating, nil } diff --git a/cli/state.go b/cli/state.go index 57b1409c2..0354131f9 100644 --- a/cli/state.go +++ b/cli/state.go @@ -1515,7 +1515,11 @@ var stateCircSupplyCmd = &cli.Command{ return err } - fmt.Println(types.FIL(circ)) + fmt.Println("Circulating supply: ", circ.FilCirculating) + fmt.Println("Mined: ", circ.FilMined) + fmt.Println("Vested: ", circ.FilVested) + fmt.Println("Burnt: ", circ.FilBurnt) + fmt.Println("Locked: ", circ.FilLocked) return nil }, diff --git a/cmd/lotus-chainwatch/syncer/sync.go b/cmd/lotus-chainwatch/syncer/sync.go index 99c0220b0..81cd9e269 100644 --- a/cmd/lotus-chainwatch/syncer/sync.go +++ b/cmd/lotus-chainwatch/syncer/sync.go @@ -287,7 +287,8 @@ func (s *Syncer) storeCirculatingSupply(ctx context.Context, tipset *types.TipSe if _, err := s.db.Exec(fmt.Sprintf(ceInsert, tipset.ParentState().String(), - supply.String(), + // TODO: Include all the details maybe? + supply.FilCirculating.String(), )); err != nil { return xerrors.Errorf("insert circulating supply for tipset (%s): %w", tipset.Key().String(), err) } diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 4f08d324d..5140ba22a 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -1052,7 +1052,7 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr powerState.ThisEpochPledgeCollateral, rewardState.ThisEpochRewardSmoothed, powerState.ThisEpochQAPowerSmoothed, - circSupply, + circSupply.FilCirculating, ) return types.BigDiv(types.BigMul(initialPledge, initialPledgeNum), initialPledgeDen), nil @@ -1149,26 +1149,26 @@ func (a *StateAPI) StateDealProviderCollateralBounds(ctx context.Context, size a return api.DealCollateralBounds{}, xerrors.Errorf("getting total circulating supply: %w") } - min, max := market.DealProviderCollateralBounds(size, verified, powerState.ThisEpochQualityAdjPower, rewardState.ThisEpochBaselinePower, circ) + min, max := market.DealProviderCollateralBounds(size, verified, powerState.ThisEpochQualityAdjPower, rewardState.ThisEpochBaselinePower, circ.FilCirculating) return api.DealCollateralBounds{ Min: types.BigDiv(types.BigMul(min, dealProviderCollateralNum), dealProviderCollateralDen), Max: max, }, nil } -func (a *StateAPI) StateCirculatingSupply(ctx context.Context, tsk types.TipSetKey) (abi.TokenAmount, error) { +func (a *StateAPI) StateCirculatingSupply(ctx context.Context, tsk types.TipSetKey) (api.CirculatingSupply, error) { ts, err := a.Chain.GetTipSetFromKey(tsk) if err != nil { - return abi.TokenAmount{}, xerrors.Errorf("loading tipset %s: %w", tsk, err) + return api.CirculatingSupply{}, xerrors.Errorf("loading tipset %s: %w", tsk, err) } st, _, err := a.StateManager.TipSetState(ctx, ts) if err != nil { - return big.Zero(), err + return api.CirculatingSupply{}, err } cst := cbor.NewCborStore(a.Chain.Blockstore()) sTree, err := state.LoadStateTree(cst, st) - return a.StateManager.GetCirculatingSupply(ctx, ts.Height(), sTree) + return a.StateManager.GetCirculatingSupplyDetailed(ctx, ts.Height(), sTree) }