Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify Mint parameter #47

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions x/mint/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ func GenInflationRateChange(r *rand.Rand) sdk.Dec {

// GenInflationMax randomized InflationMax
func GenInflationMax(r *rand.Rand) sdk.Dec {
return sdk.NewDecWithPrec(12, 2)
return sdk.NewDecWithPrec(21, 2)
}

// GenInflationMin randomized InflationMin
func GenInflationMin(r *rand.Rand) sdk.Dec {
return sdk.NewDecWithPrec(6, 2)
return sdk.NewDecWithPrec(8, 2)
}

// GenGoalBonded randomized GoalBonded
Expand Down
5 changes: 2 additions & 3 deletions x/mint/types/minter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package types

import (
"fmt"

"github.com/KuChainNetwork/kuchain/chain/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down Expand Up @@ -31,10 +30,10 @@ func InitialMinter(inflation sdk.Dec) Minter {
}

// DefaultInitialMinter returns a default initial Minter object for a new chain
// which uses an inflation rate of 13%.
// which uses an inflation rate of 14%.
func DefaultInitialMinter() Minter {
return InitialMinter(
sdk.NewDecWithPrec(9, 2),
sdk.NewDecWithPrec(14, 2),
)
}

Expand Down
89 changes: 87 additions & 2 deletions x/mint/types/minter_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package types

import (
"flag"
"fmt"
StakingExported "github.com/KuChainNetwork/kuchain/x/staking/exported"
"log"
"math/rand"
"os"
"runtime"
"testing"

chainTypes "github.com/KuChainNetwork/kuchain/chain/types"
Expand All @@ -10,8 +16,14 @@ import (
)

func TestNextInflation(t *testing.T) {
minter := DefaultInitialMinter()
params := DefaultParams()
minter := InitialMinter(sdk.NewDecWithPrec(9, 2))
params := NewParams(StakingExported.DefaultBondDenom,
sdk.NewDecWithPrec(9, 2),
sdk.NewDecWithPrec(12, 2),
sdk.NewDecWithPrec(6, 2),
sdk.NewDecWithPrec(67, 2),
uint64(60*60*8766/3),
)
blocksPerYr := chainTypes.NewDec(int64(params.BlocksPerYear))

// Governing Mechanism:
Expand Down Expand Up @@ -129,3 +141,76 @@ func BenchmarkNextAnnualProvisions(b *testing.B) {
}

}

func BenchmarkTestMinting(t *testing.B) {
var (
logFileName = flag.String("log", "BenchmarkTestMinting.log", "Log file name")
)

runtime.GOMAXPROCS(runtime.NumCPU())
flag.Parse()

//set logfile Stdout
logFile, logErr := os.OpenFile(*logFileName, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0666)
if logErr != nil {
fmt.Println("Fail to find", *logFile, "cServer start Failed")
os.Exit(1)
}
log.SetOutput(logFile)
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)

minter := DefaultInitialMinter()
params := NewParams(StakingExported.DefaultBondDenom,
sdk.NewDecWithPrec(14, 2),
sdk.NewDecWithPrec(21, 2),
sdk.NewDecWithPrec(8, 2),
sdk.NewDecWithPrec(67, 2),
uint64(60*60*8766/3),
)
tests := []struct {
bondedRatio sdk.Dec
}{
{sdk.ZeroDec(),},
{sdk.NewDecWithPrec(33, 2),},
{sdk.NewDecWithPrec(5, 1),},
{sdk.NewDecWithPrec(67, 2),},
{sdk.OneDec(),},
}
for _, tc := range tests {
totalStakingSupply := sdk.NewInt(140000000)
minter.Inflation = params.InflationRateChange
for i := uint64(0); i < params.BlocksPerYear; i++ {
minter.Inflation = minter.NextInflationRate(params, tc.bondedRatio)
minter.AnnualProvisions = minter.NextAnnualProvisions(params, totalStakingSupply)

bAmount := minter.BlockProvision(params).Amount
totalStakingSupply = totalStakingSupply.Add(bAmount)
//write log
if bAmount.BigInt().Int64() <= 0 {
log.Println("bondedRatio", tc.bondedRatio, minter.Inflation, bAmount, totalStakingSupply)
}
}
fmt.Println(totalStakingSupply)
}
}

func TestMinting(t *testing.T) {
minter := DefaultInitialMinter()
params := DefaultParams()

totalStakingSupply := sdk.NewInt(140000000)
tests := []struct {
inf sdk.Dec
}{
{params.InflationMin},
{params.InflationMax},
}
for _, tc := range tests {
for i := uint64(0); i < params.BlocksPerYear; i++ {
minter.Inflation = tc.inf
minter.AnnualProvisions = minter.NextAnnualProvisions(params, totalStakingSupply)
totalStakingSupply = totalStakingSupply.Add(minter.BlockProvision(params).Amount)
}
fmt.Println(totalStakingSupply)
}
}
6 changes: 3 additions & 3 deletions x/mint/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ func NewParams(
func DefaultParams() Params {
return Params{
MintDenom: StakingExported.DefaultBondDenom,
InflationRateChange: sdk.NewDecWithPrec(9, 2),
InflationMax: sdk.NewDecWithPrec(12, 2),
InflationMin: sdk.NewDecWithPrec(6, 2),
InflationRateChange: sdk.NewDecWithPrec(14, 2),
InflationMax: sdk.NewDecWithPrec(21, 2),
InflationMin: sdk.NewDecWithPrec(8, 2),
GoalBonded: sdk.NewDecWithPrec(67, 2),
BlocksPerYear: uint64(60 * 60 * 8766 / 3), // assuming 3 second block times
}
Expand Down