Change build params

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
Jakub Sztandera 2019-09-27 23:42:12 +02:00
parent b611637652
commit b90f45fa60
4 changed files with 26 additions and 23 deletions

View File

@ -1,12 +0,0 @@
package build
import (
"math/big"
"testing"
)
func TestEncodeMiningRewardInitial(t *testing.T) {
i := &big.Int{}
i.SetString("153856870367821447423", 10)
t.Logf("%#v", i.Bytes())
}

View File

@ -1,5 +1,7 @@
package build
import "math/big"
// Core network constants
const UnixfsChunkSize uint64 = 1 << 20
@ -30,7 +32,9 @@ const CollateralPrecision = 100
const TotalFilecoin = 2000000000
const MiningRewardTotal = 1400000000
var MiningRewardInitialAttoFilBytes = []byte{0x8, 0x57, 0x31, 0x68, 0x6e, 0x4f, 0x52, 0x40, 0xff}
const MiningRewardInitialAttoFilString = "153856870367821447423"
var MiningRewardInitialAttoFil *big.Int
const FilecoinPrecision = 1000000000000000000
@ -42,3 +46,14 @@ const HalvingPeriodBlocks = 6 * 365 * 24 * 60 * 2
const AdjustmentPeriod = 7 * 24 * 60 * 2
// TODO: Move other important consts here
func init() {
MiningRewardInitialAttoFil = new(big.Int)
var ok bool
MiningRewardInitialAttoFil, ok = MiningRewardInitialAttoFil.
SetString(MiningRewardInitialAttoFilString, 10)
if !ok {
panic("could not parse MiningRewardInitialAttoFilString")
}
}

View File

@ -633,14 +633,13 @@ func DepositFunds(act *types.Actor, amt types.BigInt) {
act.Balance = types.BigAdd(act.Balance, amt)
}
var initialReward = types.BigInt{big.NewInt(0).SetBytes(build.MiningRewardInitialAttoFilBytes)}
var miningRewardTotal = types.FromFil(build.MiningRewardTotal)
// MiningReward returns correct mining reward
// coffer is amount of FIL in NetworkAddress
func MiningReward(remainingReward types.BigInt) types.BigInt {
ci := big.NewInt(0).Set(coffer.Int)
res := ci.Mul(ci, IV.Int)
ci := big.NewInt(0).Set(remainingReward.Int)
res := ci.Mul(ci, build.MiningRewardInitialAttoFil)
res = res.Div(res, miningRewardTotal.Int)
return types.BigInt{res}
}

View File

@ -2,6 +2,7 @@ package vm
import (
"fmt"
"math/big"
"testing"
"github.com/filecoin-project/go-lotus/build"
@ -9,19 +10,19 @@ import (
)
func TestBlockReward(t *testing.T) {
coffer := types.FromFil(build.MiningRewardTotal)
sum := types.NewInt(0)
coffer := types.FromFil(build.MiningRewardTotal).Int
sum := new(big.Int)
N := build.HalvingPeriodBlocks
for i := 0; i < N; i++ {
a := MiningReward(coffer)
sum = types.BigAdd(sum, a)
coffer = types.BigSub(coffer, a)
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(coffer, types.NewInt(build.FilecoinPrecision)))
fmt.Printf("Given out: %s\n", types.BigDiv(sum, types.NewInt(build.FilecoinPrecision)))
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)))
}