working on correct block reward

This commit is contained in:
whyrusleeping 2019-09-20 17:22:28 -07:00
parent 78fa12d2b9
commit 47d12417b3
5 changed files with 47 additions and 4 deletions

View File

@ -28,6 +28,12 @@ const PerCapitaCollateralProportion = 5
const CollateralPrecision = 100
const TotalFilecoin = 2000000000
const MiningRewardTotal = 1400000000
const FilecoinPrecision = 1000000000000000000
// six years
const HalvingPeriodBlocks = 6 * 365 * 24 * 60 * 2
const AdjustmentPeriod = 7 * 24 * 60 * 2
// TODO: Move other important consts here

View File

@ -44,7 +44,7 @@ func MinerCreateBlock(ctx context.Context, sm *stmgr.StateManager, w *wallet.Wal
}
// apply miner reward
if err := vmi.TransferFunds(actors.NetworkAddress, owner, vm.MiningRewardForBlock(parents)); err != nil {
if err := vmi.TransferFunds(actors.NetworkAddress, owner, vm.MiningRewardForBlock(height)); err != nil {
return nil, err
}

View File

@ -442,7 +442,7 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err
return xerrors.Errorf("getting miner owner for block miner failed: %w", err)
}
if err := vmi.TransferFunds(actors.NetworkAddress, owner, vm.MiningRewardForBlock(baseTs)); err != nil {
if err := vmi.TransferFunds(actors.NetworkAddress, owner, vm.MiningRewardForBlock(h.Height)); err != nil {
return xerrors.Errorf("fund transfer failed: %w", err)
}

View File

@ -3,7 +3,10 @@ package vm
import (
"context"
"fmt"
"math"
"math/big"
"github.com/filecoin-project/go-lotus/build"
"github.com/filecoin-project/go-lotus/chain/actors"
"github.com/filecoin-project/go-lotus/chain/actors/aerrors"
"github.com/filecoin-project/go-lotus/chain/address"
@ -631,6 +634,18 @@ func DepositFunds(act *types.Actor, amt types.BigInt) {
act.Balance = types.BigAdd(act.Balance, amt)
}
func MiningRewardForBlock(base *types.TipSet) types.BigInt {
return types.NewInt(10000)
func MiningRewardForBlock(height uint64) types.BigInt {
//decay := e^(ln(0.5) / (HalvingPeriodBlocks / AdjustmentPeriod)
decay := 0.9977869135615522
totalMiningReward := types.FromFil(build.MiningRewardTotal)
dval := big.NewFloat(math.Pow(decay, float64(uint64(height/build.AdjustmentPeriod))))
iv := big.NewFloat(0).Mul(big.NewFloat(0).SetInt(totalMiningReward.Int), big.NewFloat(1-decay))
reward, _ := iv.Mul(iv, dval).Int(nil)
return types.BigInt{reward}
}

22
chain/vm/vm_test.go Normal file
View File

@ -0,0 +1,22 @@
package vm
import (
"fmt"
"testing"
"github.com/filecoin-project/go-lotus/build"
"github.com/filecoin-project/go-lotus/chain/types"
)
func TestBlockReward(t *testing.T) {
sum := types.NewInt(0)
for i := 0; i < 500000000; i += 60 {
sum = types.BigAdd(sum, MiningRewardForBlock(uint64(i)))
}
sum = types.BigMul(sum, types.NewInt(60))
fmt.Println(sum)
fmt.Println(types.BigDiv(sum, types.NewInt(build.FilecoinPrecision)))
}