From 184d11264a8c28ccfffc0494b8295f7f7875d336 Mon Sep 17 00:00:00 2001 From: klim0v Date: Fri, 22 Apr 2022 19:22:49 +0300 Subject: [PATCH 1/9] smooth increase in rewards after the fall --- CHANGELOG.md | 8 +++++++ cmd/minter/cmd/export.go | 2 +- coreV2/appdb/appdb.go | 46 ++++++++++++++++++++++++++++++++++++- coreV2/minter/blockchain.go | 7 +++++- tests/helpers_test.go | 16 ++++++++++++- tests/reward3_test.go | 22 +++++++++++++----- version/version.go | 2 +- 7 files changed, 92 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b632bc313..c63c072e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [v3.2.0](https://github.com/MinterTeam/minter-go-node/tree/v3.2.0) + +[Full Changelog](https://github.com/MinterTeam/minter-go-node/compare/v3.1.1...v3.2.0) + +### Fixed + +- Smooth increase in rewards after the fall + ## [v3.1.1](https://github.com/MinterTeam/minter-go-node/tree/v3.1.1) [Full Changelog](https://github.com/MinterTeam/minter-go-node/compare/v3.1.0...v3.1.1) diff --git a/cmd/minter/cmd/export.go b/cmd/minter/cmd/export.go index 7bbbbf112..9a5e0371b 100644 --- a/cmd/minter/cmd/export.go +++ b/cmd/minter/cmd/export.go @@ -102,7 +102,7 @@ func export(cmd *cobra.Command, args []string) error { //appState.Emission = db.Emission().String() appState.Emission = rewards.NewReward().GetBeforeBlock(height).String() reserve0, reserve1 := currentState.Swap().GetSwapper(0, 1993).Reserves() - db.UpdatePrice(time.Unix(0, int64(genesisTime)).UTC(), reserve0, reserve1) + db.UpdatePriceBug(time.Unix(0, int64(genesisTime)).UTC(), reserve0, reserve1) t, r0, r1, reward, off := db.GetPrice() appState.PrevReward = mtypes.RewardPrice{ Time: uint64(t.UTC().UnixNano()), diff --git a/coreV2/appdb/appdb.go b/coreV2/appdb/appdb.go index 7d2bcf971..e95f2378b 100644 --- a/coreV2/appdb/appdb.go +++ b/coreV2/appdb/appdb.go @@ -447,7 +447,51 @@ type TimePrice struct { Last *big.Int } -func (appDB *AppDB) UpdatePrice(t time.Time, r0, r1 *big.Int) (reward, safeReward *big.Int) { +func (appDB *AppDB) UpdatePriceFix(t time.Time, r0, r1 *big.Int) (reward, safeReward *big.Int) { + tOld, reserve0, reserve1, last, off := appDB.GetPrice() + + fNew := big.NewRat(1, 1).SetFrac(r1, r0) + // Price ^ (1/4) * 350 + priceCount, _ := new(big.Float).Mul(new(big.Float).Mul(math.Pow(new(big.Float).SetRat(fNew), big.NewFloat(0.25)), big.NewFloat(350)), big.NewFloat(1e18)).Int(nil) + if tOld.IsZero() { + appDB.SetPrice(t, r0, r1, priceCount, false) + return new(big.Int).Set(priceCount), new(big.Int).Set(priceCount) + } + + defer func() { appDB.SetPrice(t, r0, r1, last, off) }() + + fOld := big.NewRat(1, 1).SetFrac(reserve1, reserve0) + + rat := new(big.Rat).Mul(new(big.Rat).Quo(new(big.Rat).Sub(fNew, fOld), fOld), new(big.Rat).SetInt64(100)) + diff := big.NewInt(0).Div(rat.Num(), rat.Denom()) + + if diff.Cmp(big.NewInt(-10)) != 1 { + last.SetInt64(0) + off = true + return last, new(big.Int).Set(priceCount) + } + + if off && last.Cmp(priceCount) == -1 { + last.Add(last, big.NewInt(5e18)) + last.Add(last, big.NewInt(5e18)) + burn := big.NewInt(0).Sub(priceCount, last) + if burn.Sign() != 1 { + last.Set(priceCount) + off = false + return new(big.Int).Set(last), new(big.Int).Set(priceCount) + } + return new(big.Int).Set(last), new(big.Int).Set(priceCount) + } + + off = false + last.Set(priceCount) + + return new(big.Int).Set(last), new(big.Int).Set(priceCount) +} + +// UpdatePriceBug +// Deprecated +func (appDB *AppDB) UpdatePriceBug(t time.Time, r0, r1 *big.Int) (reward, safeReward *big.Int) { tOld, reserve0, reserve1, last, off := appDB.GetPrice() fNew := big.NewRat(1, 1).SetFrac(r1, r0) diff --git a/coreV2/minter/blockchain.go b/coreV2/minter/blockchain.go index 6b1e8f80d..f120ed9a2 100644 --- a/coreV2/minter/blockchain.go +++ b/coreV2/minter/blockchain.go @@ -177,6 +177,7 @@ func GetExecutor(v string) transaction.ExecutorTx { const ( // known update versions V3 = "v300" // tokenomics V310 = "v310" // hotfix + V320 = "v320" // hotfix ) func (blockchain *Blockchain) initState() { @@ -275,7 +276,11 @@ func (blockchain *Blockchain) BeginBlock(req abciTypes.RequestBeginBlock) abciTy t, _, _, _, _ := blockchain.appDB.GetPrice() if height%blockchain.updateStakesAndPayRewardsPeriod == 1 && (t.IsZero() || (req.Header.Time.Hour() >= 12 && req.Header.Time.Hour() <= 14) && req.Header.Time.Sub(t) > 3*time.Hour) { reserve0, reserve1 := blockchain.stateCheck.Swap().GetSwapper(0, types.USDTID).Reserves() - newRewards, safeReward := blockchain.appDB.UpdatePrice(req.Header.Time, reserve0, reserve1) + funcUpdatePrice := blockchain.appDB.UpdatePriceBug + if h := blockchain.appDB.GetVersionHeight(V320); h > 0 && height > h { + funcUpdatePrice = blockchain.appDB.UpdatePriceFix + } + newRewards, safeReward := funcUpdatePrice(req.Header.Time, reserve0, reserve1) blockchain.stateDeliver.App.SetReward(newRewards, safeReward) blockchain.eventsDB.AddEvent(&eventsdb.UpdatedBlockRewardEvent{Value: newRewards.String(), ValueLockedStakeRewards: new(big.Int).Mul(safeReward, big.NewInt(3)).String()}) } diff --git a/tests/helpers_test.go b/tests/helpers_test.go index 25d0dde47..e9c018721 100644 --- a/tests/helpers_test.go +++ b/tests/helpers_test.go @@ -173,13 +173,14 @@ func CreateAddress() (types.Address, *ecdsa.PrivateKey) { // DefaultAppState returns new AppState with some predefined values func DefaultAppState() types.AppState { return types.AppState{ - Version: "v260", Note: "", Validators: nil, Candidates: nil, BlockListCandidates: nil, + DeletedCandidates: nil, Waitlist: nil, Pools: nil, + NextOrderID: 0, Accounts: nil, Coins: nil, FrozenFunds: nil, @@ -231,11 +232,24 @@ func DefaultAppState() types.AppState { FailedTx: "10000000000000000", AddLimitOrder: "100000000000000000", RemoveLimitOrder: "100000000000000000", + MoveStake: "100000000000000000", + LockStake: "100000000000000000", + Lock: "100000000000000000", }, CommissionVotes: nil, UpdateVotes: nil, UsedChecks: nil, MaxGas: 0, TotalSlashed: "0", + Emission: "9999", + PrevReward: types.RewardPrice{ + Time: 0, + AmountBIP: "350", + AmountUSDT: "1", + Off: false, + Reward: "74000000000000000000", + }, + Version: "v300", + Versions: nil, } } diff --git a/tests/reward3_test.go b/tests/reward3_test.go index 0a336bf53..3bee0007a 100644 --- a/tests/reward3_test.go +++ b/tests/reward3_test.go @@ -246,7 +246,7 @@ func TestReward_Update_Down(t *testing.T) { Balance: []types.Balance{ { Coin: uint64(types.GetBaseCoinID()), - Value: helpers.StringToBigInt("1000000000100000000000000000").String(), + Value: helpers.StringToBigInt("1000000000300000000000000000").String(), }, }, Nonce: 0, @@ -373,11 +373,15 @@ func TestReward_Update_Down(t *testing.T) { SendCommit(app) SendBeginBlock(app, 14, time.Unix(1646308803, 0).UTC()) // send BeginBlock { - //tx := CreateTx(app, address, transaction.TypeSend, transaction.SendData{}, types.USDTID) - //response := SendTx(app, SignTx(pk, tx)) // compose and send tx - //if response.Code != code.OK { - // t.Fatalf("Response code is not OK: %s, %d", response.Log, response.Code) - //} + tx := CreateTx(app, address, transaction.TypeSellSwapPool, transaction.SellSwapPoolDataV260{ + Coins: []types.CoinID{0, types.USDTID}, + ValueToSell: helpers.StringToBigInt("100000000000000000"), + MinimumValueToBuy: helpers.StringToBigInt("1"), + }, 0) + response := SendTx(app, SignTx(pk, tx)) // compose and send tx + if response.Code != code.OK { + t.Fatalf("Response code is not OK: %s, %d", response.Log, response.Code) + } } SendEndBlock(app, 14) // send EndBlock SendCommit(app) // send Commit @@ -390,6 +394,12 @@ func TestReward_Update_Down(t *testing.T) { t.Log(app.GetEventsDB().LoadEvents(14)[3]) //t.Log(app.GetEventsDB().LoadEvents(14)[4]) t.Log(app.CurrentState().App().Reward()) + + SendBeginBlock(app, 15, time.Unix(1650628838, 0).UTC()) // send BeginBlock + SendEndBlock(app, 15) // send EndBlock + SendCommit(app) + + t.Log(app.CurrentState().App().Reward()) } func TestReward_Update_Up(t *testing.T) { diff --git a/version/version.go b/version/version.go index 4f8cf517d..c5a1533f1 100755 --- a/version/version.go +++ b/version/version.go @@ -7,7 +7,7 @@ const ( var ( // Version must be a string because scripts like dist.sh read this file. - Version = "3.1.1" + Version = "3.2.0" // GitCommit is the current HEAD set using ldflags. GitCommit string From 416d34247d86c2bcbc89d2c460d20b98dcaaebab Mon Sep 17 00:00:00 2001 From: klim0v Date: Tue, 26 Apr 2022 12:50:15 +0300 Subject: [PATCH 2/9] wip todo: regular rewards + x3 --- coreV2/state/validators/validators.go | 196 +++++++++++++++++++++++++- 1 file changed, 195 insertions(+), 1 deletion(-) diff --git a/coreV2/state/validators/validators.go b/coreV2/state/validators/validators.go index 08fa5914d..b60a0d5c9 100644 --- a/coreV2/state/validators/validators.go +++ b/coreV2/state/validators/validators.go @@ -431,7 +431,201 @@ func (v *Validators) PayRewardsV3(height uint64, period int64) (moreRewards *big return moreRewards } -// PayRewardsV4 distributes accumulated rewards between validator, delegators, DAO and developers addresses +// PayRewardsV5 distributes accumulated rewards between validator, delegators, DAO and developers addresses +func (v *Validators) PayRewardsV5(height uint64, period int64) (moreRewards *big.Int) { + moreRewards = big.NewInt(0) + + vals := v.GetValidators() + + calcReward, safeReward := v.bus.App().Reward() + var totalAccumRewards = big.NewInt(0) + for _, validator := range vals { + totalAccumRewards = totalAccumRewards.Add(totalAccumRewards, validator.GetAccumReward()) + } + + var totalStakes = big.NewInt(0) + if totalAccumRewards.Sign() != 1 { + for _, validator := range vals { + totalStakes = totalStakes.Add(totalStakes, validator.GetTotalBipStake()) + } + } + + for _, validator := range vals { + candidate := v.bus.Candidates().GetCandidate(validator.PubKey) + + totalReward := big.NewInt(0).Set(validator.GetAccumReward()) + remainder := big.NewInt(0).Set(validator.GetAccumReward()) + + // pay commission to DAO + + DAOReward := big.NewInt(0).Set(totalReward) + DAOReward.Mul(DAOReward, big.NewInt(int64(dao.Commission))) + DAOReward.Div(DAOReward, big.NewInt(100)) + + // pay commission to Developers + + DevelopersReward := big.NewInt(0).Set(totalReward) + DevelopersReward.Mul(DevelopersReward, big.NewInt(int64(developers.Commission))) + DevelopersReward.Div(DevelopersReward, big.NewInt(100)) + + totalReward.Sub(totalReward, DevelopersReward) + totalReward.Sub(totalReward, DAOReward) + remainder.Sub(remainder, DAOReward) + remainder.Sub(remainder, DevelopersReward) + + // pay commission to validator + validatorReward := big.NewInt(0).Set(totalReward) + validatorReward.Mul(validatorReward, big.NewInt(int64(candidate.Commission))) + validatorReward.Div(validatorReward, big.NewInt(100)) + totalReward.Sub(totalReward, validatorReward) + + candidate.AddUpdate(types.GetBaseCoinID(), validatorReward, validatorReward, candidate.RewardAddress) + v.bus.Checker().AddCoin(types.GetBaseCoinID(), validatorReward) + + remainder.Sub(remainder, validatorReward) + v.bus.Events().AddEvent(&eventsdb.RewardEvent{ + Role: eventsdb.RoleValidator.String(), + Address: candidate.RewardAddress, + Amount: validatorReward.String(), + ValidatorPubKey: validator.PubKey, + ForCoin: 0, + }) + + DAOx3rewards := big.NewInt(0) + DEVx3rewards := big.NewInt(0) + + stakes := v.bus.Candidates().GetStakes(validator.PubKey) + for _, stake := range stakes { + if stake.BipValue.Sign() == 0 { + continue + } + + reward := big.NewInt(0).Set(totalReward) + reward.Mul(reward, stake.BipValue) + + reward.Div(reward, validator.GetTotalBipStake()) + + remainder.Sub(remainder, reward) + + safeRewardVariable := big.NewInt(0).Set(reward) + if validator.bus.Accounts().IsX3Mining(stake.Owner, height) { + if totalAccumRewards.Sign() == 1 && validator.GetAccumReward().Sign() == 1 { + safeRewards := big.NewInt(0).Mul(safeReward, big.NewInt(period)) + safeRewards.Mul(safeRewards, stake.BipValue) + safeRewards.Mul(safeRewards, big.NewInt(3)) + safeRewards.Mul(safeRewards, validator.GetAccumReward()) + safeRewards.Div(safeRewards, validator.GetTotalBipStake()) + + taxDAO := big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(developers.Commission))), big.NewInt(100)) + taxDEV := big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(dao.Commission))), big.NewInt(100)) + + DAOx3rewards.Add(DAOx3rewards, taxDAO) + DEVx3rewards.Add(DEVx3rewards, taxDEV) + + safeRewards.Sub(safeRewards, taxDAO) + safeRewards.Sub(safeRewards, taxDEV) + safeRewards.Sub(safeRewards, big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(candidate.Commission))), big.NewInt(100))) + safeRewards.Div(safeRewards, totalAccumRewards) + + calcRewards := big.NewInt(0).Mul(calcReward, big.NewInt(period)) + calcRewards.Mul(calcRewards, stake.BipValue) + calcRewards.Mul(calcRewards, validator.GetAccumReward()) + calcRewards.Div(calcRewards, validator.GetTotalBipStake()) + calcRewards.Sub(calcRewards, big.NewInt(0).Div(big.NewInt(0).Mul(calcRewards, big.NewInt(int64(developers.Commission+dao.Commission))), big.NewInt(100))) + calcRewards.Sub(calcRewards, big.NewInt(0).Div(big.NewInt(0).Mul(calcRewards, big.NewInt(int64(candidate.Commission))), big.NewInt(100))) + calcRewards.Div(calcRewards, totalAccumRewards) + + feeRewards := big.NewInt(0).Sub(reward, calcRewards) + safeRewardVariable.Set(big.NewInt(0).Add(safeRewards, feeRewards)) + } else if totalAccumRewards.Sign() != 1 && validator.GetAccumReward().Sign() != 1 { + safeRewards := big.NewInt(0).Mul(safeReward, big.NewInt(period)) + safeRewards.Mul(safeRewards, stake.BipValue) + safeRewards.Mul(safeRewards, big.NewInt(3)) + + taxDAO := big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(developers.Commission))), big.NewInt(100)) + taxDEV := big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(dao.Commission))), big.NewInt(100)) + + DAOx3rewards.Add(DAOx3rewards, taxDAO) + DEVx3rewards.Add(DEVx3rewards, taxDEV) + + safeRewards.Sub(safeRewards, taxDAO) + safeRewards.Sub(safeRewards, taxDEV) + + safeRewards.Sub(safeRewards, big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(candidate.Commission))), big.NewInt(100))) + safeRewards.Div(safeRewards, totalStakes) + + safeRewardVariable.Set(safeRewards) + } + + if safeRewardVariable.Sign() < 1 { + continue + } + + moreRewards.Add(moreRewards, new(big.Int).Sub(safeRewardVariable, reward)) + } + + if safeRewardVariable.Sign() < 1 { + continue + } + + candidate.AddUpdate(types.GetBaseCoinID(), safeRewardVariable, safeRewardVariable, stake.Owner) + v.bus.Checker().AddCoin(types.GetBaseCoinID(), safeRewardVariable) + + v.bus.Events().AddEvent(&eventsdb.RewardEvent{ + Role: eventsdb.RoleDelegator.String(), + Address: stake.Owner, + Amount: safeRewardVariable.String(), + ValidatorPubKey: validator.PubKey, + ForCoin: uint64(stake.Coin), + }) + } + + if diffDAO := big.NewInt(0).Sub(DAOx3rewards, DAOReward); diffDAO.Sign() == 1 { + DAOReward.Set(DAOx3rewards) + moreRewards.Add(moreRewards, diffDAO) + } + if diffDEV := big.NewInt(0).Sub(DEVx3rewards, DevelopersReward); diffDEV.Sign() == 1 { + DevelopersReward.Set(DEVx3rewards) + moreRewards.Add(moreRewards, diffDEV) + } + { + candidate.AddUpdate(types.GetBaseCoinID(), DAOReward, DAOReward, dao.Address) + v.bus.Checker().AddCoin(types.GetBaseCoinID(), DAOReward) + v.bus.Events().AddEvent(&eventsdb.RewardEvent{ + Role: eventsdb.RoleDAO.String(), + Address: dao.Address, + Amount: DAOReward.String(), + ValidatorPubKey: validator.PubKey, + ForCoin: 0, + }) + } + + { + candidate.AddUpdate(types.GetBaseCoinID(), DevelopersReward, DevelopersReward, developers.Address) + v.bus.Checker().AddCoin(types.GetBaseCoinID(), DevelopersReward) + v.bus.Events().AddEvent(&eventsdb.RewardEvent{ + Role: eventsdb.RoleDevelopers.String(), + Address: developers.Address, + Amount: DevelopersReward.String(), + ValidatorPubKey: validator.PubKey, + ForCoin: 0, + }) + } + + validator.SetAccumReward(big.NewInt(0)) + + if remainder.Sign() != -1 { + v.bus.App().AddTotalSlashed(remainder) + } else { + panic(fmt.Sprintf("Negative remainder: %s", remainder.String())) + } + } + + return moreRewards +} + +// PayRewardsV4 +// Deprecated func (v *Validators) PayRewardsV4(height uint64, period int64) (moreRewards *big.Int) { moreRewards = big.NewInt(0) From 4d993cf601974a2bb2667066bfbea60775bb6ecf Mon Sep 17 00:00:00 2001 From: klim0v Date: Tue, 26 Apr 2022 13:14:25 +0300 Subject: [PATCH 3/9] regular rewards + x3 --- coreV2/state/validators/validators.go | 40 +++++++++++++-------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/coreV2/state/validators/validators.go b/coreV2/state/validators/validators.go index b60a0d5c9..ea3168164 100644 --- a/coreV2/state/validators/validators.go +++ b/coreV2/state/validators/validators.go @@ -491,9 +491,6 @@ func (v *Validators) PayRewardsV5(height uint64, period int64) (moreRewards *big ForCoin: 0, }) - DAOx3rewards := big.NewInt(0) - DEVx3rewards := big.NewInt(0) - stakes := v.bus.Candidates().GetStakes(validator.PubKey) for _, stake := range stakes { if stake.BipValue.Sign() == 0 { @@ -516,14 +513,11 @@ func (v *Validators) PayRewardsV5(height uint64, period int64) (moreRewards *big safeRewards.Mul(safeRewards, validator.GetAccumReward()) safeRewards.Div(safeRewards, validator.GetTotalBipStake()) - taxDAO := big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(developers.Commission))), big.NewInt(100)) - taxDEV := big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(dao.Commission))), big.NewInt(100)) - - DAOx3rewards.Add(DAOx3rewards, taxDAO) - DEVx3rewards.Add(DEVx3rewards, taxDEV) + taxDAOx3 := big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(developers.Commission))), big.NewInt(100)) + taxDEVx3 := big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(dao.Commission))), big.NewInt(100)) - safeRewards.Sub(safeRewards, taxDAO) - safeRewards.Sub(safeRewards, taxDEV) + safeRewards.Sub(safeRewards, taxDAOx3) + safeRewards.Sub(safeRewards, taxDEVx3) safeRewards.Sub(safeRewards, big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(candidate.Commission))), big.NewInt(100))) safeRewards.Div(safeRewards, totalAccumRewards) @@ -531,10 +525,24 @@ func (v *Validators) PayRewardsV5(height uint64, period int64) (moreRewards *big calcRewards.Mul(calcRewards, stake.BipValue) calcRewards.Mul(calcRewards, validator.GetAccumReward()) calcRewards.Div(calcRewards, validator.GetTotalBipStake()) + + taxDAO := big.NewInt(0).Div(big.NewInt(0).Mul(calcRewards, big.NewInt(int64(developers.Commission))), big.NewInt(100)) + taxDEV := big.NewInt(0).Div(big.NewInt(0).Mul(calcRewards, big.NewInt(int64(dao.Commission))), big.NewInt(100)) + + calcRewards.Sub(calcRewards, taxDAO) + calcRewards.Sub(calcRewards, taxDEV) calcRewards.Sub(calcRewards, big.NewInt(0).Div(big.NewInt(0).Mul(calcRewards, big.NewInt(int64(developers.Commission+dao.Commission))), big.NewInt(100))) calcRewards.Sub(calcRewards, big.NewInt(0).Div(big.NewInt(0).Mul(calcRewards, big.NewInt(int64(candidate.Commission))), big.NewInt(100))) calcRewards.Div(calcRewards, totalAccumRewards) + diffDAO := big.NewInt(0).Sub(taxDAOx3, taxDAO) + diffDEV := big.NewInt(0).Sub(taxDAOx3, taxDEV) + DAOReward.Add(DAOReward, diffDAO) + DevelopersReward.Add(DevelopersReward, diffDEV) + + moreRewards.Add(moreRewards, diffDAO) + moreRewards.Add(moreRewards, diffDEV) + feeRewards := big.NewInt(0).Sub(reward, calcRewards) safeRewardVariable.Set(big.NewInt(0).Add(safeRewards, feeRewards)) } else if totalAccumRewards.Sign() != 1 && validator.GetAccumReward().Sign() != 1 { @@ -545,8 +553,8 @@ func (v *Validators) PayRewardsV5(height uint64, period int64) (moreRewards *big taxDAO := big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(developers.Commission))), big.NewInt(100)) taxDEV := big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(dao.Commission))), big.NewInt(100)) - DAOx3rewards.Add(DAOx3rewards, taxDAO) - DEVx3rewards.Add(DEVx3rewards, taxDEV) + DAOReward.Add(DAOReward, taxDAO) + DAOReward.Add(DAOReward, taxDEV) safeRewards.Sub(safeRewards, taxDAO) safeRewards.Sub(safeRewards, taxDEV) @@ -580,14 +588,6 @@ func (v *Validators) PayRewardsV5(height uint64, period int64) (moreRewards *big }) } - if diffDAO := big.NewInt(0).Sub(DAOx3rewards, DAOReward); diffDAO.Sign() == 1 { - DAOReward.Set(DAOx3rewards) - moreRewards.Add(moreRewards, diffDAO) - } - if diffDEV := big.NewInt(0).Sub(DEVx3rewards, DevelopersReward); diffDEV.Sign() == 1 { - DevelopersReward.Set(DEVx3rewards) - moreRewards.Add(moreRewards, diffDEV) - } { candidate.AddUpdate(types.GetBaseCoinID(), DAOReward, DAOReward, dao.Address) v.bus.Checker().AddCoin(types.GetBaseCoinID(), DAOReward) From 5dc23b72daa76343740ecf9ea8bad37e5e2228d0 Mon Sep 17 00:00:00 2001 From: klim0v Date: Tue, 26 Apr 2022 13:16:08 +0300 Subject: [PATCH 4/9] CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c63c072e0..1b279f83c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Fixed - Smooth increase in rewards after the fall +- Accruals for DAOs and developers, taking into account blocked stakes ## [v3.1.1](https://github.com/MinterTeam/minter-go-node/tree/v3.1.1) From d272a0a51d0e8e96d93e06e9c6daa3c4256ea958 Mon Sep 17 00:00:00 2001 From: klim0v Date: Tue, 26 Apr 2022 13:17:39 +0300 Subject: [PATCH 5/9] CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b279f83c..fa4921ea8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ ### Fixed - Find coins with last symbol `-` -- Accrual of rewards x3 with `GetAccumReward == 0` +- Accrual of rewards x3 with candidate's `AccumReward` is 0 ## [v3.1.0](https://github.com/MinterTeam/minter-go-node/tree/v3.1.0) From 1fd27143f190e58642a636afabd14f1bdea74228 Mon Sep 17 00:00:00 2001 From: klim0v Date: Tue, 26 Apr 2022 13:23:31 +0300 Subject: [PATCH 6/9] refactor --- coreV2/state/validators/validators.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/coreV2/state/validators/validators.go b/coreV2/state/validators/validators.go index ea3168164..d3e9c9b6c 100644 --- a/coreV2/state/validators/validators.go +++ b/coreV2/state/validators/validators.go @@ -554,7 +554,9 @@ func (v *Validators) PayRewardsV5(height uint64, period int64) (moreRewards *big taxDEV := big.NewInt(0).Div(big.NewInt(0).Mul(safeRewards, big.NewInt(int64(dao.Commission))), big.NewInt(100)) DAOReward.Add(DAOReward, taxDAO) - DAOReward.Add(DAOReward, taxDEV) + DevelopersReward.Add(DevelopersReward, taxDEV) + moreRewards.Add(moreRewards, taxDAO) + moreRewards.Add(moreRewards, taxDEV) safeRewards.Sub(safeRewards, taxDAO) safeRewards.Sub(safeRewards, taxDEV) From 446d32698c07ff88ade718b50eb924c8b8f7676b Mon Sep 17 00:00:00 2001 From: klim0v Date: Tue, 26 Apr 2022 13:27:24 +0300 Subject: [PATCH 7/9] refactor --- coreV2/minter/blockchain.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/coreV2/minter/blockchain.go b/coreV2/minter/blockchain.go index f120ed9a2..7595439c3 100644 --- a/coreV2/minter/blockchain.go +++ b/coreV2/minter/blockchain.go @@ -450,15 +450,17 @@ func (blockchain *Blockchain) EndBlock(req abciTypes.RequestEndBlock) abciTypes. // pay rewards var moreRewards = big.NewInt(0) if height%blockchain.updateStakesAndPayRewardsPeriod == 0 { - if h := blockchain.appDB.GetVersionHeight(V310); h > 0 && height > h { - moreRewards = blockchain.stateDeliver.Validators.PayRewardsV4(heightIsMaxIfIssueIsOverOrNotDynamic, int64(blockchain.updateStakesAndPayRewardsPeriod)) - blockchain.appDB.SetEmission(big.NewInt(0).Add(blockchain.appDB.Emission(), moreRewards)) - blockchain.stateDeliver.Checker.AddCoinVolume(types.GetBaseCoinID(), moreRewards) - } else { - moreRewards = blockchain.stateDeliver.Validators.PayRewardsV3(heightIsMaxIfIssueIsOverOrNotDynamic, int64(blockchain.updateStakesAndPayRewardsPeriod)) - blockchain.appDB.SetEmission(big.NewInt(0).Add(blockchain.appDB.Emission(), moreRewards)) - blockchain.stateDeliver.Checker.AddCoinVolume(types.GetBaseCoinID(), moreRewards) + PayRewards := blockchain.stateDeliver.Validators.PayRewardsV3 + if h := blockchain.appDB.GetVersionHeight(V320); h > 0 && height > h { + PayRewards = blockchain.stateDeliver.Validators.PayRewardsV5 + } else if h := blockchain.appDB.GetVersionHeight(V310); h > 0 && height > h { + PayRewards = blockchain.stateDeliver.Validators.PayRewardsV4 } + + moreRewards = PayRewards(heightIsMaxIfIssueIsOverOrNotDynamic, int64(blockchain.updateStakesAndPayRewardsPeriod)) + blockchain.appDB.SetEmission(big.NewInt(0).Add(blockchain.appDB.Emission(), moreRewards)) + blockchain.stateDeliver.Checker.AddCoinVolume(types.GetBaseCoinID(), moreRewards) + } if heightIsMaxIfIssueIsOverOrNotDynamic != math.MaxUint64 { From 8a8b5f3b8e2ceee94b7cc02b6b6ddbe917f96d44 Mon Sep 17 00:00:00 2001 From: klim0v Date: Wed, 27 Apr 2022 12:16:59 +0300 Subject: [PATCH 8/9] refactor --- coreV2/minter/blockchain.go | 1 + 1 file changed, 1 insertion(+) diff --git a/coreV2/minter/blockchain.go b/coreV2/minter/blockchain.go index 7595439c3..69dca2701 100644 --- a/coreV2/minter/blockchain.go +++ b/coreV2/minter/blockchain.go @@ -146,6 +146,7 @@ func NewMinterBlockchain(storages *utils.Storage, cfg *config.Config, ctx contex knownUpdates: map[string]struct{}{ V3: {}, // tokenomics V310: {}, // hotfix + V320: {}, }, executor: GetExecutor(V3), } From f355045c4ac852a4d25496fd14f0dfe8fdc3ad6c Mon Sep 17 00:00:00 2001 From: klim0v Date: Wed, 27 Apr 2022 15:22:25 +0300 Subject: [PATCH 9/9] refactor export.go --- cmd/minter/cmd/export.go | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/cmd/minter/cmd/export.go b/cmd/minter/cmd/export.go index 9a5e0371b..6eef5218e 100644 --- a/cmd/minter/cmd/export.go +++ b/cmd/minter/cmd/export.go @@ -3,8 +3,6 @@ package cmd import ( "crypto/sha256" "encoding/json" - "github.com/MinterTeam/minter-go-node/coreV2/minter" - "github.com/MinterTeam/minter-go-node/coreV2/rewards" "github.com/MinterTeam/minter-go-node/version" "github.com/tendermint/go-amino" "io" @@ -90,19 +88,16 @@ func export(cmd *cobra.Command, args []string) error { } log.Printf("Verify state OK\n") - appState.Version = minter.V3 - //versions := db.GetVersions() - //for _, v := range versions { - // appState.Versions = append(appState.Versions, mtypes.Version{ - // Height: v.Height, - // Name: v.Name, - // }) - //} - - //appState.Emission = db.Emission().String() - appState.Emission = rewards.NewReward().GetBeforeBlock(height).String() - reserve0, reserve1 := currentState.Swap().GetSwapper(0, 1993).Reserves() - db.UpdatePriceBug(time.Unix(0, int64(genesisTime)).UTC(), reserve0, reserve1) + //appState.Version = minter.V3 + versions := db.GetVersions() + for _, v := range versions { + appState.Versions = append(appState.Versions, mtypes.Version{ + Height: v.Height, + Name: v.Name, + }) + } + + appState.Emission = db.Emission().String() t, r0, r1, reward, off := db.GetPrice() appState.PrevReward = mtypes.RewardPrice{ Time: uint64(t.UTC().UnixNano()),