From 34ad13fc22c1a0edd67dfa5cf826a3a8095df240 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Fri, 6 Mar 2020 17:33:24 -0800 Subject: [PATCH] fix initial reward actor balance --- build/params_shared.go | 16 ++++------------ chain/gen/genesis/t02_reward.go | 2 +- chain/vm/vm.go | 14 -------------- chain/vm/vm_test.go | 33 --------------------------------- 4 files changed, 5 insertions(+), 60 deletions(-) delete mode 100644 chain/vm/vm_test.go diff --git a/build/params_shared.go b/build/params_shared.go index a4c986e1b..2cecd4aef 100644 --- a/build/params_shared.go +++ b/build/params_shared.go @@ -84,23 +84,15 @@ const CollateralPrecision = 1000 const TotalFilecoin = 2_000_000_000 const MiningRewardTotal = 1_400_000_000 -const InitialRewardStr = "153856861913558700202" - -var InitialReward *big.Int - const FilecoinPrecision = 1_000_000_000_000_000_000 +var InitialRewardBalance *big.Int + // TODO: Move other important consts here func init() { - InitialReward = new(big.Int) - - var ok bool - InitialReward, ok = InitialReward. - SetString(InitialRewardStr, 10) - if !ok { - panic("could not parse InitialRewardStr") - } + InitialRewardBalance = big.NewInt(MiningRewardTotal) + InitialRewardBalance = InitialRewardBalance.Mul(InitialRewardBalance, big.NewInt(FilecoinPrecision)) } // Sync diff --git a/chain/gen/genesis/t02_reward.go b/chain/gen/genesis/t02_reward.go index 5d1acade3..2525f43f1 100644 --- a/chain/gen/genesis/t02_reward.go +++ b/chain/gen/genesis/t02_reward.go @@ -30,7 +30,7 @@ func SetupRewardActor(bs bstore.Blockstore) (*types.Actor, error) { return &types.Actor{ Code: builtin.RewardActorCodeID, - Balance: types.BigInt{Int: build.InitialReward}, + Balance: types.BigInt{Int: build.InitialRewardBalance}, Head: hcid, }, nil } diff --git a/chain/vm/vm.go b/chain/vm/vm.go index ccb4719b4..56308ec92 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -29,7 +29,6 @@ import ( "github.com/filecoin-project/specs-actors/actors/runtime" "github.com/filecoin-project/specs-actors/actors/runtime/exitcode" - "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors/aerrors" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/types" @@ -775,16 +774,3 @@ func deductFunds(act *types.Actor, amt types.BigInt) error { func depositFunds(act *types.Actor, amt types.BigInt) { act.Balance = types.BigAdd(act.Balance, amt) } - -var miningRewardTotal = types.FromFil(build.MiningRewardTotal) -var blocksPerEpoch = types.NewInt(build.BlocksPerEpoch) - -// MiningReward returns correct mining reward -// coffer is amount of FIL in NetworkAddress -func MiningReward(remainingReward types.BigInt) types.BigInt { - ci := big.NewInt(0).Set(remainingReward.Int) - res := ci.Mul(ci, build.InitialReward) - res = res.Div(res, miningRewardTotal.Int) - res = res.Div(res, blocksPerEpoch.Int) - return types.BigInt{Int: res} -} diff --git a/chain/vm/vm_test.go b/chain/vm/vm_test.go deleted file mode 100644 index af72e4d83..000000000 --- a/chain/vm/vm_test.go +++ /dev/null @@ -1,33 +0,0 @@ -package vm - -import ( - "fmt" - "math/big" - "testing" - - "github.com/filecoin-project/lotus/build" - "github.com/filecoin-project/lotus/chain/types" - - _ "github.com/filecoin-project/lotus/lib/sigs/secp" -) - -const HalvingPeriodEpochs = 6 * 365 * 24 * 60 * 2 - -func TestBlockReward(t *testing.T) { - t.Skip() - coffer := types.FromFil(build.MiningRewardTotal).Int - sum := new(big.Int) - N := HalvingPeriodEpochs - for i := 0; i < N; i++ { - a := MiningReward(types.BigInt{coffer}) - sum = sum.Add(sum, a.Int) - coffer = coffer.Sub(coffer, a.Int) - } - - //sum = types.BigMul(sum, types.NewInt(60)) - - fmt.Println("After a halving period") - fmt.Printf("Total reward: %d\n", build.MiningRewardTotal) - fmt.Printf("Remaining: %s\n", types.BigDiv(types.BigInt{coffer}, types.NewInt(build.FilecoinPrecision))) - fmt.Printf("Given out: %s\n", types.BigDiv(types.BigInt{sum}, types.NewInt(build.FilecoinPrecision))) -}