From f55b18eabeebc480ac3808dcc62443ed49bbce12 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Sun, 4 Oct 2020 21:38:52 -0400 Subject: [PATCH] Add funds that have left FilReserve to circ supply --- build/params_shared_vals.go | 5 +++++ build/params_testground.go | 8 ++++++++ chain/actors/builtin/builtin.go | 11 +++++++++++ chain/gen/genesis/genesis.go | 9 +++------ chain/stmgr/stmgr.go | 27 +++++++++++++++++++++++---- 5 files changed, 50 insertions(+), 10 deletions(-) diff --git a/build/params_shared_vals.go b/build/params_shared_vals.go index 4734a15ed..cc711b7bc 100644 --- a/build/params_shared_vals.go +++ b/build/params_shared_vals.go @@ -72,8 +72,10 @@ const FilBase = uint64(2_000_000_000) const FilAllocStorageMining = uint64(1_100_000_000) const FilecoinPrecision = uint64(1_000_000_000_000_000_000) +const FilReserved = uint64(300_000_000) var InitialRewardBalance *big.Int +var InitialFilReserved *big.Int // TODO: Move other important consts here @@ -81,6 +83,9 @@ func init() { InitialRewardBalance = big.NewInt(int64(FilAllocStorageMining)) InitialRewardBalance = InitialRewardBalance.Mul(InitialRewardBalance, big.NewInt(int64(FilecoinPrecision))) + InitialFilReserved = big.NewInt(int64(FilReserved)) + InitialFilReserved = InitialFilReserved.Mul(InitialFilReserved, big.NewInt(int64(FilecoinPrecision))) + if os.Getenv("LOTUS_ADDRESS_TYPE") == AddressMainnetEnvVar { SetAddressNetwork(address.Mainnet) } diff --git a/build/params_testground.go b/build/params_testground.go index 6d51100e4..162b3477c 100644 --- a/build/params_testground.go +++ b/build/params_testground.go @@ -55,6 +55,7 @@ var ( FilBase uint64 = 2_000_000_000 FilAllocStorageMining uint64 = 1_400_000_000 + FilReserved uint64 = 300_000_000 FilecoinPrecision uint64 = 1_000_000_000_000_000_000 @@ -63,6 +64,13 @@ var ( v = v.Mul(v, big.NewInt(int64(FilecoinPrecision))) return v }() + + InitialFilReserved = func() *big.Int { + v := big.NewInt(int64(FilReserved)) + v = v.Mul(v, big.NewInt(int64(FilecoinPrecision))) + return v + }() + // Actor consts // TODO: Pull from actors when its made not private MinDealDuration = abi.ChainEpoch(180 * builtin.EpochsInDay) diff --git a/chain/actors/builtin/builtin.go b/chain/actors/builtin/builtin.go index d49164486..7def78dcf 100644 --- a/chain/actors/builtin/builtin.go +++ b/chain/actors/builtin/builtin.go @@ -1,6 +1,7 @@ package builtin import ( + "github.com/filecoin-project/go-address" "github.com/ipfs/go-cid" "golang.org/x/xerrors" @@ -20,6 +21,7 @@ import ( var SystemActorAddr = builtin0.SystemActorAddr var BurntFundsActorAddr = builtin0.BurntFundsActorAddr +var ReserveAddress = makeAddress("t090") // TODO: Why does actors have 2 different versions of this? type SectorInfo = proof0.SectorInfo @@ -86,3 +88,12 @@ func IsMultisigActor(c cid.Cid) bool { func IsPaymentChannelActor(c cid.Cid) bool { return c == builtin0.PaymentChannelActorCodeID || c == builtin2.PaymentChannelActorCodeID } + +func makeAddress(addr string) address.Address { + ret, err := address.NewFromString(addr) + if err != nil { + panic(err) + } + + return ret +} diff --git a/chain/gen/genesis/genesis.go b/chain/gen/genesis/genesis.go index bb1056e2e..f532b9f5e 100644 --- a/chain/gen/genesis/genesis.go +++ b/chain/gen/genesis/genesis.go @@ -6,6 +6,8 @@ import ( "encoding/json" "fmt" + "github.com/filecoin-project/lotus/chain/actors/builtin" + "github.com/ipfs/go-cid" "github.com/ipfs/go-datastore" cbor "github.com/ipfs/go-ipld-cbor" @@ -296,14 +298,9 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge return nil, nil, xerrors.Errorf("somehow overallocated filecoin (allocated = %s)", types.FIL(totalFilAllocated)) } - remAccKey, err := address.NewIDAddress(90) - if err != nil { - return nil, nil, err - } - template.RemainderAccount.Balance = remainingFil - if err := createMultisigAccount(ctx, bs, cst, state, remAccKey, template.RemainderAccount, keyIDs); err != nil { + if err := createMultisigAccount(ctx, bs, cst, state, builtin.ReserveAddress, template.RemainderAccount, keyIDs); err != nil { return nil, nil, xerrors.Errorf("failed to set up remainder account: %w", err) } diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index e371992e8..b27bed587 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -1171,14 +1171,27 @@ func (sm *StateManager) GetFilVested(ctx context.Context, height abi.ChainEpoch, } } - // continue to use preIgnitionGenInfos, nothing changed at the Ignition epoch - vf = big.Add(vf, sm.preIgnitionGenInfos.genesisPledge) - // continue to use preIgnitionGenInfos, nothing changed at the Ignition epoch - vf = big.Add(vf, sm.preIgnitionGenInfos.genesisMarketFunds) + // After UpgradeActorsV2Height these funds are accounted for in GetFilReserveDisbursed + if height <= build.UpgradeActorsV2Height { + // continue to use preIgnitionGenInfos, nothing changed at the Ignition epoch + vf = big.Add(vf, sm.preIgnitionGenInfos.genesisPledge) + // continue to use preIgnitionGenInfos, nothing changed at the Ignition epoch + vf = big.Add(vf, sm.preIgnitionGenInfos.genesisMarketFunds) + } return vf, nil } +func GetFilReserveDisbursed(ctx context.Context, st *state.StateTree) (abi.TokenAmount, error) { + ract, err := st.GetActor(builtin.ReserveAddress) + if err != nil { + return big.Zero(), xerrors.Errorf("failed to get reserve actor: %w", err) + } + + // If money enters the reserve actor, this could lead to a negative term + return big.Sub(big.NewFromGo(build.InitialFilReserved), ract.Balance), nil +} + func GetFilMined(ctx context.Context, st *state.StateTree) (abi.TokenAmount, error) { ractor, err := st.GetActor(reward.Address) if err != nil { @@ -1266,6 +1279,11 @@ func (sm *StateManager) GetCirculatingSupplyDetailed(ctx context.Context, height return api.CirculatingSupply{}, xerrors.Errorf("failed to calculate filVested: %w", err) } + filReserveDisbursed, err := GetFilReserveDisbursed(ctx, st) + if err != nil { + return api.CirculatingSupply{}, xerrors.Errorf("failed to calculate filReserveDisbursed: %w", err) + } + filMined, err := GetFilMined(ctx, st) if err != nil { return api.CirculatingSupply{}, xerrors.Errorf("failed to calculate filMined: %w", err) @@ -1282,6 +1300,7 @@ func (sm *StateManager) GetCirculatingSupplyDetailed(ctx context.Context, height } ret := types.BigAdd(filVested, filMined) + ret = types.BigAdd(ret, filReserveDisbursed) ret = types.BigSub(ret, filBurnt) ret = types.BigSub(ret, filLocked)