Include more info in StateCirculatingSupply
This commit is contained in:
parent
4a0171d26a
commit
0359a458e4
@ -359,7 +359,7 @@ type FullNode interface {
|
|||||||
StateDealProviderCollateralBounds(context.Context, abi.PaddedPieceSize, bool, types.TipSetKey) (DealCollateralBounds, error)
|
StateDealProviderCollateralBounds(context.Context, abi.PaddedPieceSize, bool, types.TipSetKey) (DealCollateralBounds, error)
|
||||||
|
|
||||||
// StateCirculatingSupply returns the circulating supply of Filecoin at the given tipset
|
// 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
|
// MethodGroup: Msig
|
||||||
// The Msig methods are used to interact with multisig wallets on the
|
// The Msig methods are used to interact with multisig wallets on the
|
||||||
@ -674,6 +674,14 @@ type DealCollateralBounds struct {
|
|||||||
Max abi.TokenAmount
|
Max abi.TokenAmount
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CirculatingSupply struct {
|
||||||
|
FilVested abi.TokenAmount
|
||||||
|
FilMined abi.TokenAmount
|
||||||
|
FilBurnt abi.TokenAmount
|
||||||
|
FilLocked abi.TokenAmount
|
||||||
|
FilCirculating abi.TokenAmount
|
||||||
|
}
|
||||||
|
|
||||||
type MiningBaseInfo struct {
|
type MiningBaseInfo struct {
|
||||||
MinerPower types.BigInt
|
MinerPower types.BigInt
|
||||||
NetworkPower types.BigInt
|
NetworkPower types.BigInt
|
||||||
|
@ -181,7 +181,7 @@ type FullNodeStruct struct {
|
|||||||
StateCompute func(context.Context, abi.ChainEpoch, []*types.Message, types.TipSetKey) (*api.ComputeStateOutput, error) `perm:"read"`
|
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"`
|
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"`
|
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"`
|
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"`
|
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)
|
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)
|
return c.Internal.StateCirculatingSupply(ctx, tsk)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -984,34 +984,34 @@ func GetFilBurnt(ctx context.Context, st *state.StateTree) (abi.TokenAmount, err
|
|||||||
return burnt.Balance, nil
|
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()
|
sm.genesisMsigLk.Lock()
|
||||||
defer sm.genesisMsigLk.Unlock()
|
defer sm.genesisMsigLk.Unlock()
|
||||||
if sm.genInfo == nil {
|
if sm.genInfo == nil {
|
||||||
err := sm.setupGenesisActors(ctx)
|
err := sm.setupGenesisActors(ctx)
|
||||||
if err != nil {
|
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)
|
filVested, err := sm.GetFilVested(ctx, height, st)
|
||||||
if err != nil {
|
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)
|
filMined, err := GetFilMined(ctx, st)
|
||||||
if err != nil {
|
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)
|
filBurnt, err := GetFilBurnt(ctx, st)
|
||||||
if err != nil {
|
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)
|
filLocked, err := sm.GetFilLocked(ctx, st)
|
||||||
if err != nil {
|
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)
|
ret := types.BigAdd(filVested, filMined)
|
||||||
@ -1022,5 +1022,20 @@ func (sm *StateManager) GetCirculatingSupply(ctx context.Context, height abi.Cha
|
|||||||
ret = big.Zero()
|
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
|
||||||
}
|
}
|
||||||
|
@ -1515,7 +1515,11 @@ var stateCircSupplyCmd = &cli.Command{
|
|||||||
return err
|
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
|
return nil
|
||||||
},
|
},
|
||||||
|
@ -287,7 +287,8 @@ func (s *Syncer) storeCirculatingSupply(ctx context.Context, tipset *types.TipSe
|
|||||||
|
|
||||||
if _, err := s.db.Exec(fmt.Sprintf(ceInsert,
|
if _, err := s.db.Exec(fmt.Sprintf(ceInsert,
|
||||||
tipset.ParentState().String(),
|
tipset.ParentState().String(),
|
||||||
supply.String(),
|
// TODO: Include all the details maybe?
|
||||||
|
supply.FilCirculating.String(),
|
||||||
)); err != nil {
|
)); err != nil {
|
||||||
return xerrors.Errorf("insert circulating supply for tipset (%s): %w", tipset.Key().String(), err)
|
return xerrors.Errorf("insert circulating supply for tipset (%s): %w", tipset.Key().String(), err)
|
||||||
}
|
}
|
||||||
|
@ -1052,7 +1052,7 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr
|
|||||||
powerState.ThisEpochPledgeCollateral,
|
powerState.ThisEpochPledgeCollateral,
|
||||||
rewardState.ThisEpochRewardSmoothed,
|
rewardState.ThisEpochRewardSmoothed,
|
||||||
powerState.ThisEpochQAPowerSmoothed,
|
powerState.ThisEpochQAPowerSmoothed,
|
||||||
circSupply,
|
circSupply.FilCirculating,
|
||||||
)
|
)
|
||||||
|
|
||||||
return types.BigDiv(types.BigMul(initialPledge, initialPledgeNum), initialPledgeDen), nil
|
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")
|
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{
|
return api.DealCollateralBounds{
|
||||||
Min: types.BigDiv(types.BigMul(min, dealProviderCollateralNum), dealProviderCollateralDen),
|
Min: types.BigDiv(types.BigMul(min, dealProviderCollateralNum), dealProviderCollateralDen),
|
||||||
Max: max,
|
Max: max,
|
||||||
}, nil
|
}, 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)
|
ts, err := a.Chain.GetTipSetFromKey(tsk)
|
||||||
if err != nil {
|
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)
|
st, _, err := a.StateManager.TipSetState(ctx, ts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return big.Zero(), err
|
return api.CirculatingSupply{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cst := cbor.NewCborStore(a.Chain.Blockstore())
|
cst := cbor.NewCborStore(a.Chain.Blockstore())
|
||||||
sTree, err := state.LoadStateTree(cst, st)
|
sTree, err := state.LoadStateTree(cst, st)
|
||||||
|
|
||||||
return a.StateManager.GetCirculatingSupply(ctx, ts.Height(), sTree)
|
return a.StateManager.GetCirculatingSupplyDetailed(ctx, ts.Height(), sTree)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user