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
166161func 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-
184176const ( // 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
194180func (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.
281266func (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