Skip to content

Commit daeee10

Browse files
authored
Merge pull request #779 from MinterTeam/dev
v3.0.3
2 parents d6a917c + 45a811d commit daeee10

31 files changed

Lines changed: 255 additions & 294 deletions

CHANGELOG.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
# Changelog
22

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

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

77
### Fixed
88

99
- Initial emission
10-
11-
## [v3.0.1](https://github.com/MinterTeam/minter-go-node/tree/v3.0.1)
12-
13-
[Full Changelog](https://github.com/MinterTeam/minter-go-node/compare/v3.0.0...v3.0.1)
14-
15-
### Fixed
16-
1710
- API `/block` and `/blocks` for older versions.
1811

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

api/v2/service/genesis.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ func (s *Service) Genesis(ctx context.Context, _ *empty.Empty) (*pb.GenesisRespo
8585
Validator: &pb.GenesisResponse_ConsensusParams_Validator{
8686
PubKeyTypes: result.Genesis.ConsensusParams.Validator.PubKeyTypes,
8787
},
88+
Version: &pb.GenesisResponse_ConsensusParams_Version{
89+
AppVersion: result.Genesis.ConsensusParams.Version.AppVersion,
90+
},
8891
},
8992
AppHash: result.Genesis.AppHash.String(),
9093
AppState: &appState,

api/v2/service/price_commission.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ func priceCommissionResponse(price *commission.Price, coin *coins.Model) *pb.Pri
7676
BurnToken: price.BurnToken.String(),
7777
VoteCommission: price.VoteCommission.String(),
7878
VoteUpdate: price.VoteUpdate.String(),
79-
FailedTx: price.FailedTxPrice().String(),
80-
AddLimitOrder: price.AddLimitOrderPrice().String(),
81-
RemoveLimitOrder: price.RemoveLimitOrderPrice().String(),
82-
MoveStake: price.MoveStakePrice().String(),
83-
LockStake: price.LockStakePrice().String(),
84-
Lock: price.LockPrice().String(),
79+
FailedTx: price.FailedTx.String(),
80+
AddLimitOrder: price.AddLimitOrder.String(),
81+
RemoveLimitOrder: price.RemoveLimitOrder.String(),
82+
MoveStake: price.MoveStake.String(),
83+
LockStake: price.LockStake.String(),
84+
Lock: price.Lock.String(),
8585
}
8686
}

cmd/minter/cmd/export.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package cmd
33
import (
44
"crypto/sha256"
55
"encoding/json"
6+
"github.com/MinterTeam/minter-go-node/coreV2/minter"
7+
"github.com/MinterTeam/minter-go-node/coreV2/rewards"
68
"github.com/MinterTeam/minter-go-node/version"
79
"github.com/tendermint/go-amino"
810
"io"
@@ -88,16 +90,19 @@ func export(cmd *cobra.Command, args []string) error {
8890
}
8991
log.Printf("Verify state OK\n")
9092

91-
appState.Version = db.GetVersionName(height)
92-
versions := db.GetVersions()
93-
for _, v := range versions {
94-
appState.Versions = append(appState.Versions, mtypes.Version{
95-
Height: v.Height,
96-
Name: v.Name,
97-
})
98-
}
99-
100-
appState.Emission = db.Emission().String()
93+
appState.Version = minter.V3
94+
//versions := db.GetVersions()
95+
//for _, v := range versions {
96+
// appState.Versions = append(appState.Versions, mtypes.Version{
97+
// Height: v.Height,
98+
// Name: v.Name,
99+
// })
100+
//}
101+
102+
//appState.Emission = db.Emission().String()
103+
appState.Emission = rewards.NewReward().GetBeforeBlock(height).String()
104+
reserve0, reserve1 := currentState.Swap().GetSwapper(0, 1993).Reserves()
105+
db.UpdatePrice(time.Unix(0, int64(genesisTime)).UTC(), reserve0, reserve1)
101106
t, r0, r1, reward, off := db.GetPrice()
102107
appState.PrevReward = mtypes.RewardPrice{
103108
Time: uint64(t.UTC().UnixNano()),

cmd/minter/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func main() {
3535
rootCmd.PersistentFlags().Bool("testnet", false, "use \"true\" for testnet, mainnet is default")
3636
rootCmd.PersistentFlags().Bool("pprof", false, "enable pprof")
3737
rootCmd.PersistentFlags().String("pprof-addr", "0.0.0.0:6060", "pprof listen addr")
38-
rootCmd.PersistentFlags().String("genesis", "https://github.com/MinterTeam/minter-go-node/releases/download/v2.0/genesis.json", "path with the genesis file to download")
38+
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")
3939
rootCmd.PersistentFlags().String("persistent-peers", "", "")
4040
rootCmd.PersistentFlags().Bool("state-sync", false, "enable state sync snapshots")
4141

coreV2/code/code.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const (
2929
VoteAlreadyExists uint32 = 121
3030
WrongUpdateVersionName uint32 = 122
3131
WrongDueHeight uint32 = 123
32+
Unavailable uint32 = 124
3233

3334
// coin creation
3435
CoinHasNotReserve uint32 = 200

coreV2/minter/blockchain.go

Lines changed: 64 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"github.com/MinterTeam/minter-go-node/coreV2/state/candidates"
7+
"github.com/MinterTeam/minter-go-node/helpers"
78
"github.com/cosmos/cosmos-sdk/snapshots"
89
snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types"
910
"github.com/cosmos/cosmos-sdk/types/errors"
@@ -143,15 +144,9 @@ func NewMinterBlockchain(storages *utils.Storage, cfg *config.Config, ctx contex
143144
expiredOrdersPeriod: expiredOrdersPeriod,
144145
stopOk: make(chan struct{}),
145146
knownUpdates: map[string]struct{}{
146-
"": {}, // default version
147-
v230: {}, // add more for update
148-
v250: {}, // commissions and mempool
149-
v260: {}, // amm with orderbook
150-
v261: {}, // hotfix
151-
v262: {}, // hotfix
152-
V3: {}, // tokenomics
147+
V3: {}, // tokenomics
153148
},
154-
executor: GetExecutor(""),
149+
executor: GetExecutor(V3),
155150
}
156151
if applicationDB.GetStartHeight() != 0 {
157152
app.initState()
@@ -165,30 +160,21 @@ func graceForUpdate(height uint64) *upgrades.GracePeriod {
165160

166161
func GetExecutor(v string) transaction.ExecutorTx {
167162
switch v {
168-
case V3:
169-
return transaction.NewExecutorV3(transaction.GetDataV3)
170-
case v260, v261, v262:
171-
return transaction.NewExecutorV250(transaction.GetDataV260)
172-
case v250:
173-
return transaction.NewExecutorV250(transaction.GetDataV250)
174-
case v230:
175-
return transaction.NewExecutor(transaction.GetDataV230)
163+
//case V3:
164+
// return transaction.NewExecutorV3(transaction.GetDataV3)
165+
//case v260, v261, v262:
166+
// return transaction.NewExecutorV250(transaction.GetDataV260)
167+
//case v250:
168+
// return transaction.NewExecutorV250(transaction.GetDataV250)
169+
//case v230:
170+
// return transaction.NewExecutor(transaction.GetDataV230)
176171
default:
177-
return transaction.NewExecutor(transaction.GetDataV1)
172+
return transaction.NewExecutorV3(transaction.GetDataV3)
178173
}
179174
}
180175

181-
const haltBlockV210 = 3431238
182-
const updateBlockV240 = 4448826
183-
184176
const ( // known update versions
185-
v2 = "" // default
186-
v230 = "v230" // remove liquidity bug
187-
v250 = "v250" // commissions and failed txs
188-
v260 = "v260" // orderbook
189-
v261 = "v261" // hotfix
190-
v262 = "v262" // hotfix (moved to V3)
191-
V3 = "v300" // tokenomics
177+
V3 = "v300" // tokenomics
192178
)
193179

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

198184
var stateDeliver *state.State
199185
var err error
200-
if h := blockchain.appDB.GetVersionHeight(V3); h > 0 {
201-
stateDeliver, err = state.NewStateV3(currentHeight,
202-
blockchain.storages.StateDB(),
203-
blockchain.eventsDB,
204-
blockchain.cfg.StateCacheSize,
205-
blockchain.cfg.KeepLastStates,
206-
initialHeight)
207-
} else {
208-
stateDeliver, err = state.NewState(currentHeight,
209-
blockchain.storages.StateDB(),
210-
blockchain.eventsDB,
211-
blockchain.cfg.StateCacheSize,
212-
blockchain.cfg.KeepLastStates,
213-
initialHeight)
214-
}
186+
stateDeliver, err = state.NewStateV3(currentHeight,
187+
blockchain.storages.StateDB(),
188+
blockchain.eventsDB,
189+
blockchain.cfg.StateCacheSize,
190+
blockchain.cfg.KeepLastStates,
191+
initialHeight)
192+
215193
if err != nil {
216194
panic(err)
217195
}
@@ -221,18 +199,14 @@ func (blockchain *Blockchain) initState() {
221199
blockchain.stateDeliver = stateDeliver
222200
blockchain.stateCheck = state.NewCheckState(stateDeliver)
223201

224-
grace := upgrades.NewGrace()
225-
grace.AddGracePeriods(upgrades.NewGracePeriod(initialHeight, initialHeight+120, true),
226-
upgrades.NewGracePeriod(haltBlockV210, haltBlockV210+120, true),
227-
upgrades.NewGracePeriod(3612653, 3612653+120, true),
228-
upgrades.NewGracePeriod(updateBlockV240, updateBlockV240+120, true))
202+
blockchain.grace = upgrades.NewGrace()
203+
blockchain.grace.AddGracePeriods(upgrades.NewGracePeriod(initialHeight, initialHeight+120, true))
229204

230-
for _, v := range blockchain.UpdateVersions() {
231-
grace.AddGracePeriods(graceForUpdate(v.Height))
232-
blockchain.executor = GetExecutor(v.Name)
233-
}
205+
//for _, v := range blockchain.UpdateVersions() {
206+
// blockchain.grace.AddGracePeriods(graceForUpdate(v.Height))
207+
// blockchain.executor = GetExecutor(v.Name)
208+
//}
234209

235-
blockchain.grace = grace
236210
}
237211

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

245+
blockchain.appDB.SetEmission(helpers.StringToBigInt(genesisState.Emission))
246+
247+
blockchain.appDB.SetPrice(
248+
time.Unix(0, int64(genesisState.PrevReward.Time)).UTC(),
249+
helpers.StringToBigInt(genesisState.PrevReward.AmountBIP),
250+
helpers.StringToBigInt(genesisState.PrevReward.AmountUSDT),
251+
helpers.StringToBigInt(genesisState.PrevReward.Reward),
252+
genesisState.PrevReward.Off)
253+
271254
blockchain.appDB.SaveStartHeight()
272255
blockchain.appDB.SaveVersions()
256+
blockchain.appDB.SaveEmission()
257+
blockchain.appDB.SavePrice()
273258

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

287-
if h := blockchain.appDB.GetVersionHeight(V3); h > 0 {
288-
if emission := blockchain.appDB.Emission(); emission == nil || emission.Cmp(blockchain.rewardsCounter.TotalEmissionBig()) == -1 {
289-
t, _, _, _, _ := blockchain.appDB.GetPrice()
290-
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) {
291-
reserve0, reserve1 := blockchain.stateCheck.Swap().GetSwapper(0, types.USDTID).Reserves()
292-
newRewards, safeReward := blockchain.appDB.UpdatePrice(req.Header.Time, reserve0, reserve1)
293-
blockchain.stateDeliver.App.SetReward(newRewards, safeReward)
294-
blockchain.eventsDB.AddEvent(&eventsdb.UpdatedBlockRewardEvent{Value: newRewards.String(), ValueLockedStakeRewards: new(big.Int).Mul(safeReward, big.NewInt(3)).String()})
295-
}
296-
} else {
297-
blockchain.stateDeliver.App.SetReward(big.NewInt(0), big.NewInt(0))
272+
if emission := blockchain.appDB.Emission(); emission.Cmp(blockchain.rewardsCounter.TotalEmissionBig()) == -1 {
273+
t, _, _, _, _ := blockchain.appDB.GetPrice()
274+
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) {
275+
reserve0, reserve1 := blockchain.stateCheck.Swap().GetSwapper(0, types.USDTID).Reserves()
276+
newRewards, safeReward := blockchain.appDB.UpdatePrice(req.Header.Time, reserve0, reserve1)
277+
blockchain.stateDeliver.App.SetReward(newRewards, safeReward)
278+
blockchain.eventsDB.AddEvent(&eventsdb.UpdatedBlockRewardEvent{Value: newRewards.String(), ValueLockedStakeRewards: new(big.Int).Mul(safeReward, big.NewInt(3)).String()})
298279
}
299-
280+
} else {
281+
blockchain.stateDeliver.App.SetReward(big.NewInt(0), big.NewInt(0))
300282
}
301283

284+
//}
285+
302286
blockchain.StatisticData().PushStartBlock(&statistics.StartRequest{Height: int64(height), Now: time.Now(), HeaderTime: req.Header.Time})
303287

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

344-
if versionName == v230 && height > updateBlockV240 {
345-
blockchain.executor = transaction.NewExecutor(transaction.GetDataV240)
346-
}
347-
348328
// give penalty to Byzantine validators
349329
for _, byzVal := range req.ByzantineValidators {
350330
var address types.TmAddress
@@ -426,26 +406,13 @@ func (blockchain *Blockchain) EndBlock(req abciTypes.RequestEndBlock) abciTypes.
426406

427407
// accumulate rewards
428408
var reward = big.NewInt(0)
429-
430409
var heightIsMaxIfIssueIsOverOrNotDynamic uint64 = math.MaxUint64
431-
if h := blockchain.appDB.GetVersionHeight(V3); h > 0 && height > h {
432-
emission := blockchain.appDB.Emission()
433-
if emission == nil {
434-
blockchain.appDB.SetEmission(blockchain.rewardsCounter.GetBeforeBlock(height - 1))
435-
} else if emission.Cmp(blockchain.rewardsCounter.TotalEmissionBig()) == -1 {
436-
reward, _ = blockchain.stateDeliver.App.Reward()
437-
if reward == nil {
438-
reward = blockchain.rewardsCounter.GetRewardForBlock(height)
439-
} else {
440-
heightIsMaxIfIssueIsOverOrNotDynamic = height
441-
}
442-
}
443-
444-
} else if h == height {
445-
blockchain.appDB.SetEmission(blockchain.rewardsCounter.GetBeforeBlock(height))
446-
} else {
447-
reward = blockchain.rewardsCounter.GetRewardForBlock(height)
410+
emission := blockchain.appDB.Emission()
411+
if emission.Cmp(blockchain.rewardsCounter.TotalEmissionBig()) == -1 {
412+
reward, _ = blockchain.stateDeliver.App.Reward()
413+
heightIsMaxIfIssueIsOverOrNotDynamic = height
448414
}
415+
449416
{
450417
rewardWithTxs := big.NewInt(0).Add(reward, blockchain.rewards)
451418

@@ -478,13 +445,9 @@ func (blockchain *Blockchain) EndBlock(req abciTypes.RequestEndBlock) abciTypes.
478445
// pay rewards
479446
var moreRewards = big.NewInt(0)
480447
if height%blockchain.updateStakesAndPayRewardsPeriod == 0 {
481-
if h := blockchain.appDB.GetVersionHeight(V3); h > 0 {
482-
moreRewards = blockchain.stateDeliver.Validators.PayRewardsV3(heightIsMaxIfIssueIsOverOrNotDynamic, int64(blockchain.updateStakesAndPayRewardsPeriod))
483-
blockchain.appDB.SetEmission(big.NewInt(0).Add(blockchain.appDB.Emission(), moreRewards))
484-
blockchain.stateDeliver.Checker.AddCoinVolume(types.GetBaseCoinID(), moreRewards)
485-
} else {
486-
blockchain.stateDeliver.Validators.PayRewards()
487-
}
448+
moreRewards = blockchain.stateDeliver.Validators.PayRewardsV3(heightIsMaxIfIssueIsOverOrNotDynamic, int64(blockchain.updateStakesAndPayRewardsPeriod))
449+
blockchain.appDB.SetEmission(big.NewInt(0).Add(blockchain.appDB.Emission(), moreRewards))
450+
blockchain.stateDeliver.Checker.AddCoinVolume(types.GetBaseCoinID(), moreRewards)
488451
}
489452

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

501464
{
502-
var updateCommissionsBlockPrices []byte
503-
if height < haltBlockV210 {
504-
updateCommissionsBlockPrices = blockchain.isUpdateCommissionsBlock(height)
505-
} else {
506-
updateCommissionsBlockPrices = blockchain.isUpdateCommissionsBlockV2(height)
507-
}
465+
updateCommissionsBlockPrices := blockchain.isUpdateCommissionsBlockV2(height)
508466
if prices := updateCommissionsBlockPrices; len(prices) != 0 {
509467
blockchain.stateDeliver.Commission.SetNewCommissions(prices)
510468
price := blockchain.stateDeliver.Commission.GetCommissions()
@@ -552,12 +510,12 @@ func (blockchain *Blockchain) EndBlock(req abciTypes.RequestEndBlock) abciTypes.
552510
BurnToken: price.BurnToken.String(),
553511
VoteCommission: price.VoteCommission.String(),
554512
VoteUpdate: price.VoteUpdate.String(),
555-
FailedTx: price.FailedTxPrice().String(),
556-
AddLimitOrder: price.AddLimitOrderPrice().String(),
557-
RemoveLimitOrder: price.RemoveLimitOrderPrice().String(),
558-
MoveStake: price.MoveStakePrice().String(),
559-
LockStake: price.LockStakePrice().String(),
560-
Lock: price.LockPrice().String(),
513+
FailedTx: price.FailedTx.String(),
514+
AddLimitOrder: price.AddLimitOrder.String(),
515+
RemoveLimitOrder: price.RemoveLimitOrder.String(),
516+
MoveStake: price.MoveStake.String(),
517+
LockStake: price.LockStake.String(),
518+
Lock: price.Lock.String(),
561519
})
562520
}
563521
blockchain.stateDeliver.Commission.Delete(height)

0 commit comments

Comments
 (0)