Skip to content

Commit

Permalink
Add funds that have left FilReserve to circ supply
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Oct 5, 2020
1 parent 8292d60 commit caf7c18
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
5 changes: 5 additions & 0 deletions build/params_shared_vals.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,20 @@ 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

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)
}
Expand Down
8 changes: 8 additions & 0 deletions build/params_testground.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var (

FilBase uint64 = 2_000_000_000
FilAllocStorageMining uint64 = 1_400_000_000
FilReserved uint64 = 1_400_000_000

FilecoinPrecision uint64 = 1_000_000_000_000_000_000

Expand All @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions chain/actors/builtin/builtin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package builtin

import (
"github.com/filecoin-project/go-address"
"github.com/ipfs/go-cid"
"golang.org/x/xerrors"

Expand All @@ -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
Expand Down Expand Up @@ -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
}
9 changes: 3 additions & 6 deletions chain/gen/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand Down
18 changes: 14 additions & 4 deletions chain/stmgr/stmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -1171,10 +1171,20 @@ 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)
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)
} else {
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
vf = big.Add(vf, big.Sub(big.NewFromGo(build.InitialFilReserved), ract.Balance))
}

return vf, nil
}
Expand Down

0 comments on commit caf7c18

Please sign in to comment.