Skip to content

Commit

Permalink
Merge pull request #779 from MinterTeam/dev
Browse files Browse the repository at this point in the history
v3.0.3
  • Loading branch information
danil-lashin authored Apr 12, 2022
2 parents d6a917c + 45a811d commit daeee10
Show file tree
Hide file tree
Showing 31 changed files with 255 additions and 294 deletions.
11 changes: 2 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
# Changelog

## [v3.0.2](https://github.com/MinterTeam/minter-go-node/tree/v3.0.2)
## [v3.0.3](https://github.com/MinterTeam/minter-go-node/tree/v3.0.2)

[Full Changelog](https://github.com/MinterTeam/minter-go-node/compare/v3.0.1...v3.0.2)
[Full Changelog](https://github.com/MinterTeam/minter-go-node/compare/v3.0.0...v3.0.2)

### Fixed

- Initial emission

## [v3.0.1](https://github.com/MinterTeam/minter-go-node/tree/v3.0.1)

[Full Changelog](https://github.com/MinterTeam/minter-go-node/compare/v3.0.0...v3.0.1)

### Fixed

- API `/block` and `/blocks` for older versions.

## [v3.0.0](https://github.com/MinterTeam/minter-go-node/tree/v3.0.0)
Expand Down
3 changes: 3 additions & 0 deletions api/v2/service/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ func (s *Service) Genesis(ctx context.Context, _ *empty.Empty) (*pb.GenesisRespo
Validator: &pb.GenesisResponse_ConsensusParams_Validator{
PubKeyTypes: result.Genesis.ConsensusParams.Validator.PubKeyTypes,
},
Version: &pb.GenesisResponse_ConsensusParams_Version{
AppVersion: result.Genesis.ConsensusParams.Version.AppVersion,
},
},
AppHash: result.Genesis.AppHash.String(),
AppState: &appState,
Expand Down
12 changes: 6 additions & 6 deletions api/v2/service/price_commission.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ func priceCommissionResponse(price *commission.Price, coin *coins.Model) *pb.Pri
BurnToken: price.BurnToken.String(),
VoteCommission: price.VoteCommission.String(),
VoteUpdate: price.VoteUpdate.String(),
FailedTx: price.FailedTxPrice().String(),
AddLimitOrder: price.AddLimitOrderPrice().String(),
RemoveLimitOrder: price.RemoveLimitOrderPrice().String(),
MoveStake: price.MoveStakePrice().String(),
LockStake: price.LockStakePrice().String(),
Lock: price.LockPrice().String(),
FailedTx: price.FailedTx.String(),
AddLimitOrder: price.AddLimitOrder.String(),
RemoveLimitOrder: price.RemoveLimitOrder.String(),
MoveStake: price.MoveStake.String(),
LockStake: price.LockStake.String(),
Lock: price.Lock.String(),
}
}
25 changes: 15 additions & 10 deletions cmd/minter/cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ 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"
Expand Down Expand Up @@ -88,16 +90,19 @@ func export(cmd *cobra.Command, args []string) error {
}
log.Printf("Verify state OK\n")

appState.Version = db.GetVersionName(height)
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.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.UpdatePrice(time.Unix(0, int64(genesisTime)).UTC(), reserve0, reserve1)
t, r0, r1, reward, off := db.GetPrice()
appState.PrevReward = mtypes.RewardPrice{
Time: uint64(t.UTC().UnixNano()),
Expand Down
2 changes: 1 addition & 1 deletion cmd/minter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func main() {
rootCmd.PersistentFlags().Bool("testnet", false, "use \"true\" for testnet, mainnet is default")
rootCmd.PersistentFlags().Bool("pprof", false, "enable pprof")
rootCmd.PersistentFlags().String("pprof-addr", "0.0.0.0:6060", "pprof listen addr")
rootCmd.PersistentFlags().String("genesis", "https://github.com/MinterTeam/minter-go-node/releases/download/v2.0/genesis.json", "path with the genesis file to download")
rootCmd.PersistentFlags().String("genesis", "https://github.com/MinterTeam/minter-go-node/releases/download/v3.0.3/genesis.json", "path with the genesis file to download")
rootCmd.PersistentFlags().String("persistent-peers", "", "")
rootCmd.PersistentFlags().Bool("state-sync", false, "enable state sync snapshots")

Expand Down
1 change: 1 addition & 0 deletions coreV2/code/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
VoteAlreadyExists uint32 = 121
WrongUpdateVersionName uint32 = 122
WrongDueHeight uint32 = 123
Unavailable uint32 = 124

// coin creation
CoinHasNotReserve uint32 = 200
Expand Down
170 changes: 64 additions & 106 deletions coreV2/minter/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"github.com/MinterTeam/minter-go-node/coreV2/state/candidates"
"github.com/MinterTeam/minter-go-node/helpers"
"github.com/cosmos/cosmos-sdk/snapshots"
snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types"
"github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -143,15 +144,9 @@ func NewMinterBlockchain(storages *utils.Storage, cfg *config.Config, ctx contex
expiredOrdersPeriod: expiredOrdersPeriod,
stopOk: make(chan struct{}),
knownUpdates: map[string]struct{}{
"": {}, // default version
v230: {}, // add more for update
v250: {}, // commissions and mempool
v260: {}, // amm with orderbook
v261: {}, // hotfix
v262: {}, // hotfix
V3: {}, // tokenomics
V3: {}, // tokenomics
},
executor: GetExecutor(""),
executor: GetExecutor(V3),
}
if applicationDB.GetStartHeight() != 0 {
app.initState()
Expand All @@ -165,30 +160,21 @@ func graceForUpdate(height uint64) *upgrades.GracePeriod {

func GetExecutor(v string) transaction.ExecutorTx {
switch v {
case V3:
return transaction.NewExecutorV3(transaction.GetDataV3)
case v260, v261, v262:
return transaction.NewExecutorV250(transaction.GetDataV260)
case v250:
return transaction.NewExecutorV250(transaction.GetDataV250)
case v230:
return transaction.NewExecutor(transaction.GetDataV230)
//case V3:
// return transaction.NewExecutorV3(transaction.GetDataV3)
//case v260, v261, v262:
// return transaction.NewExecutorV250(transaction.GetDataV260)
//case v250:
// return transaction.NewExecutorV250(transaction.GetDataV250)
//case v230:
// return transaction.NewExecutor(transaction.GetDataV230)
default:
return transaction.NewExecutor(transaction.GetDataV1)
return transaction.NewExecutorV3(transaction.GetDataV3)
}
}

const haltBlockV210 = 3431238
const updateBlockV240 = 4448826

const ( // known update versions
v2 = "" // default
v230 = "v230" // remove liquidity bug
v250 = "v250" // commissions and failed txs
v260 = "v260" // orderbook
v261 = "v261" // hotfix
v262 = "v262" // hotfix (moved to V3)
V3 = "v300" // tokenomics
V3 = "v300" // tokenomics
)

func (blockchain *Blockchain) initState() {
Expand All @@ -197,21 +183,13 @@ func (blockchain *Blockchain) initState() {

var stateDeliver *state.State
var err error
if h := blockchain.appDB.GetVersionHeight(V3); h > 0 {
stateDeliver, err = state.NewStateV3(currentHeight,
blockchain.storages.StateDB(),
blockchain.eventsDB,
blockchain.cfg.StateCacheSize,
blockchain.cfg.KeepLastStates,
initialHeight)
} else {
stateDeliver, err = state.NewState(currentHeight,
blockchain.storages.StateDB(),
blockchain.eventsDB,
blockchain.cfg.StateCacheSize,
blockchain.cfg.KeepLastStates,
initialHeight)
}
stateDeliver, err = state.NewStateV3(currentHeight,
blockchain.storages.StateDB(),
blockchain.eventsDB,
blockchain.cfg.StateCacheSize,
blockchain.cfg.KeepLastStates,
initialHeight)

if err != nil {
panic(err)
}
Expand All @@ -221,18 +199,14 @@ func (blockchain *Blockchain) initState() {
blockchain.stateDeliver = stateDeliver
blockchain.stateCheck = state.NewCheckState(stateDeliver)

grace := upgrades.NewGrace()
grace.AddGracePeriods(upgrades.NewGracePeriod(initialHeight, initialHeight+120, true),
upgrades.NewGracePeriod(haltBlockV210, haltBlockV210+120, true),
upgrades.NewGracePeriod(3612653, 3612653+120, true),
upgrades.NewGracePeriod(updateBlockV240, updateBlockV240+120, true))
blockchain.grace = upgrades.NewGrace()
blockchain.grace.AddGracePeriods(upgrades.NewGracePeriod(initialHeight, initialHeight+120, true))

for _, v := range blockchain.UpdateVersions() {
grace.AddGracePeriods(graceForUpdate(v.Height))
blockchain.executor = GetExecutor(v.Name)
}
//for _, v := range blockchain.UpdateVersions() {
// blockchain.grace.AddGracePeriods(graceForUpdate(v.Height))
// blockchain.executor = GetExecutor(v.Name)
//}

blockchain.grace = grace
}

// InitChain initialize blockchain with validators and other info. Only called once.
Expand Down Expand Up @@ -268,8 +242,19 @@ func (blockchain *Blockchain) InitChain(req abciTypes.RequestInitChain) abciType
lastHeight := initialHeight
blockchain.appDB.SetLastHeight(lastHeight)

blockchain.appDB.SetEmission(helpers.StringToBigInt(genesisState.Emission))

blockchain.appDB.SetPrice(
time.Unix(0, int64(genesisState.PrevReward.Time)).UTC(),
helpers.StringToBigInt(genesisState.PrevReward.AmountBIP),
helpers.StringToBigInt(genesisState.PrevReward.AmountUSDT),
helpers.StringToBigInt(genesisState.PrevReward.Reward),
genesisState.PrevReward.Off)

blockchain.appDB.SaveStartHeight()
blockchain.appDB.SaveVersions()
blockchain.appDB.SaveEmission()
blockchain.appDB.SavePrice()

defer blockchain.appDB.FlushValidators()
return abciTypes.ResponseInitChain{
Expand All @@ -280,25 +265,24 @@ func (blockchain *Blockchain) InitChain(req abciTypes.RequestInitChain) abciType
// BeginBlock signals the beginning of a block.
func (blockchain *Blockchain) BeginBlock(req abciTypes.RequestBeginBlock) abciTypes.ResponseBeginBlock {
height := uint64(req.Header.Height)
if h := blockchain.appDB.GetVersionHeight(V3); (h > 0 && height == h) || blockchain.stateDeliver == nil {
if blockchain.stateDeliver == nil {
blockchain.initState()
}

if h := blockchain.appDB.GetVersionHeight(V3); h > 0 {
if emission := blockchain.appDB.Emission(); emission == nil || emission.Cmp(blockchain.rewardsCounter.TotalEmissionBig()) == -1 {
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)
blockchain.stateDeliver.App.SetReward(newRewards, safeReward)
blockchain.eventsDB.AddEvent(&eventsdb.UpdatedBlockRewardEvent{Value: newRewards.String(), ValueLockedStakeRewards: new(big.Int).Mul(safeReward, big.NewInt(3)).String()})
}
} else {
blockchain.stateDeliver.App.SetReward(big.NewInt(0), big.NewInt(0))
if emission := blockchain.appDB.Emission(); emission.Cmp(blockchain.rewardsCounter.TotalEmissionBig()) == -1 {
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)
blockchain.stateDeliver.App.SetReward(newRewards, safeReward)
blockchain.eventsDB.AddEvent(&eventsdb.UpdatedBlockRewardEvent{Value: newRewards.String(), ValueLockedStakeRewards: new(big.Int).Mul(safeReward, big.NewInt(3)).String()})
}

} else {
blockchain.stateDeliver.App.SetReward(big.NewInt(0), big.NewInt(0))
}

//}

blockchain.StatisticData().PushStartBlock(&statistics.StartRequest{Height: int64(height), Now: time.Now(), HeaderTime: req.Header.Time})

// compute max gas
Expand Down Expand Up @@ -341,10 +325,6 @@ func (blockchain *Blockchain) BeginBlock(req abciTypes.RequestBeginBlock) abciTy
return abciTypes.ResponseBeginBlock{}
}

if versionName == v230 && height > updateBlockV240 {
blockchain.executor = transaction.NewExecutor(transaction.GetDataV240)
}

// give penalty to Byzantine validators
for _, byzVal := range req.ByzantineValidators {
var address types.TmAddress
Expand Down Expand Up @@ -426,26 +406,13 @@ func (blockchain *Blockchain) EndBlock(req abciTypes.RequestEndBlock) abciTypes.

// accumulate rewards
var reward = big.NewInt(0)

var heightIsMaxIfIssueIsOverOrNotDynamic uint64 = math.MaxUint64
if h := blockchain.appDB.GetVersionHeight(V3); h > 0 && height > h {
emission := blockchain.appDB.Emission()
if emission == nil {
blockchain.appDB.SetEmission(blockchain.rewardsCounter.GetBeforeBlock(height - 1))
} else if emission.Cmp(blockchain.rewardsCounter.TotalEmissionBig()) == -1 {
reward, _ = blockchain.stateDeliver.App.Reward()
if reward == nil {
reward = blockchain.rewardsCounter.GetRewardForBlock(height)
} else {
heightIsMaxIfIssueIsOverOrNotDynamic = height
}
}

} else if h == height {
blockchain.appDB.SetEmission(blockchain.rewardsCounter.GetBeforeBlock(height))
} else {
reward = blockchain.rewardsCounter.GetRewardForBlock(height)
emission := blockchain.appDB.Emission()
if emission.Cmp(blockchain.rewardsCounter.TotalEmissionBig()) == -1 {
reward, _ = blockchain.stateDeliver.App.Reward()
heightIsMaxIfIssueIsOverOrNotDynamic = height
}

{
rewardWithTxs := big.NewInt(0).Add(reward, blockchain.rewards)

Expand Down Expand Up @@ -478,13 +445,9 @@ 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(V3); h > 0 {
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)
} else {
blockchain.stateDeliver.Validators.PayRewards()
}
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)
}

if heightIsMaxIfIssueIsOverOrNotDynamic != math.MaxUint64 {
Expand All @@ -499,12 +462,7 @@ func (blockchain *Blockchain) EndBlock(req abciTypes.RequestEndBlock) abciTypes.
blockchain.stateDeliver.Checker.AddCoinVolume(types.GetBaseCoinID(), reward)

{
var updateCommissionsBlockPrices []byte
if height < haltBlockV210 {
updateCommissionsBlockPrices = blockchain.isUpdateCommissionsBlock(height)
} else {
updateCommissionsBlockPrices = blockchain.isUpdateCommissionsBlockV2(height)
}
updateCommissionsBlockPrices := blockchain.isUpdateCommissionsBlockV2(height)
if prices := updateCommissionsBlockPrices; len(prices) != 0 {
blockchain.stateDeliver.Commission.SetNewCommissions(prices)
price := blockchain.stateDeliver.Commission.GetCommissions()
Expand Down Expand Up @@ -552,12 +510,12 @@ func (blockchain *Blockchain) EndBlock(req abciTypes.RequestEndBlock) abciTypes.
BurnToken: price.BurnToken.String(),
VoteCommission: price.VoteCommission.String(),
VoteUpdate: price.VoteUpdate.String(),
FailedTx: price.FailedTxPrice().String(),
AddLimitOrder: price.AddLimitOrderPrice().String(),
RemoveLimitOrder: price.RemoveLimitOrderPrice().String(),
MoveStake: price.MoveStakePrice().String(),
LockStake: price.LockStakePrice().String(),
Lock: price.LockPrice().String(),
FailedTx: price.FailedTx.String(),
AddLimitOrder: price.AddLimitOrder.String(),
RemoveLimitOrder: price.RemoveLimitOrder.String(),
MoveStake: price.MoveStake.String(),
LockStake: price.LockStake.String(),
Lock: price.Lock.String(),
})
}
blockchain.stateDeliver.Commission.Delete(height)
Expand Down
Loading

0 comments on commit daeee10

Please sign in to comment.