@@ -18,6 +18,7 @@ import (
1818 tmjson "github.com/tendermint/tendermint/libs/json"
1919 tmNode "github.com/tendermint/tendermint/node"
2020 rpc "github.com/tendermint/tendermint/rpc/client/local"
21+ "log"
2122 "math/big"
2223 "sync"
2324 "sync/atomic"
@@ -64,13 +65,14 @@ type Blockchain struct {
6465 // currentMempool is responsive for prevent sending multiple transactions from one address in one block
6566 currentMempool * sync.Map
6667
67- lock sync.RWMutex
68- haltHeight uint64
69- cfg * config.Config
70- storages * utils.Storage
71- stopChan context.Context
72- stopped bool
73- grace * upgrades.Grace
68+ lock sync.RWMutex
69+ haltHeight uint64
70+ cfg * config.Config
71+ storages * utils.Storage
72+ stopChan context.Context
73+ stopped bool
74+ grace * upgrades.Grace
75+ knownUpdates map [string ]struct {}
7476}
7577
7678// NewMinterBlockchain creates Minter Blockchain instance, should be only called once
@@ -107,6 +109,12 @@ func NewMinterBlockchain(storages *utils.Storage, cfg *config.Config, ctx contex
107109 return app
108110}
109111
112+ func graceForUpdate (height uint64 ) * upgrades.GracePeriod {
113+ return upgrades .NewGracePeriod (height , height + 120 )
114+ }
115+
116+ const haltBlockV210 = 3431238
117+
110118func (blockchain * Blockchain ) initState () {
111119 initialHeight := blockchain .appDB .GetStartHeight ()
112120 currentHeight := blockchain .appDB .GetLastHeight ()
@@ -126,7 +134,15 @@ func (blockchain *Blockchain) initState() {
126134 blockchain .stateCheck = state .NewCheckState (stateDeliver )
127135
128136 grace := upgrades .NewGrace ()
129- grace .AddGracePeriods (upgrades .NewGracePeriod (initialHeight , initialHeight + 120 ))
137+ grace .AddGracePeriods (upgrades .NewGracePeriod (initialHeight , initialHeight + 120 ),
138+ upgrades .NewGracePeriod (haltBlockV210 , haltBlockV210 + 120 ))
139+ blockchain .knownUpdates = map [string ]struct {}{
140+ "" : {}, // default version
141+ // add more for update
142+ }
143+ for _ , v := range blockchain .UpdateVersions () {
144+ grace .AddGracePeriods (graceForUpdate (v .Height ))
145+ }
130146 blockchain .grace = grace
131147}
132148
@@ -196,7 +212,15 @@ func (blockchain *Blockchain) BeginBlock(req abciTypes.RequestBeginBlock) abciTy
196212
197213 blockchain .calculatePowers (blockchain .stateDeliver .Validators .GetValidators ())
198214
199- if blockchain .isApplicationHalted (height ) {
215+ if blockchain .isApplicationHalted (height ) && ! blockchain .grace .IsUpgradeBlock (height ) {
216+ log .Printf ("Application halted at height %d\n " , height )
217+ blockchain .stop ()
218+ return abciTypes.ResponseBeginBlock {}
219+ }
220+
221+ versionName := blockchain .appDB .GetVersionName (height )
222+ if _ , ok := blockchain .knownUpdates [versionName ]; ! ok {
223+ log .Printf ("Update your node binary to the latest version: %s" , versionName )
200224 blockchain .stop ()
201225 return abciTypes.ResponseBeginBlock {}
202226 }
@@ -290,64 +314,75 @@ func (blockchain *Blockchain) EndBlock(req abciTypes.RequestEndBlock) abciTypes.
290314 blockchain .stateDeliver .Validators .PayRewards ()
291315 }
292316
293- if prices := blockchain .isUpdateCommissionsBlock (height ); len (prices ) != 0 {
294- blockchain .stateDeliver .Commission .SetNewCommissions (prices )
295- price := blockchain .stateDeliver .Commission .GetCommissions ()
296- blockchain .eventsDB .AddEvent (& eventsdb.UpdateCommissionsEvent {
297- Coin : uint64 (price .Coin ),
298- PayloadByte : price .PayloadByte .String (),
299- Send : price .Send .String (),
300- BuyBancor : price .BuyBancor .String (),
301- SellBancor : price .SellBancor .String (),
302- SellAllBancor : price .SellAllBancor .String (),
303- BuyPoolBase : price .BuyPoolBase .String (),
304- BuyPoolDelta : price .BuyPoolDelta .String (),
305- SellPoolBase : price .SellPoolBase .String (),
306- SellPoolDelta : price .SellPoolDelta .String (),
307- SellAllPoolBase : price .SellAllPoolBase .String (),
308- SellAllPoolDelta : price .SellAllPoolDelta .String (),
309- CreateTicker3 : price .CreateTicker3 .String (),
310- CreateTicker4 : price .CreateTicker4 .String (),
311- CreateTicker5 : price .CreateTicker5 .String (),
312- CreateTicker6 : price .CreateTicker6 .String (),
313- CreateTicker7_10 : price .CreateTicker7to10 .String (),
314- CreateCoin : price .CreateCoin .String (),
315- CreateToken : price .CreateToken .String (),
316- RecreateCoin : price .RecreateCoin .String (),
317- RecreateToken : price .RecreateToken .String (),
318- DeclareCandidacy : price .DeclareCandidacy .String (),
319- Delegate : price .Delegate .String (),
320- Unbond : price .Unbond .String (),
321- RedeemCheck : price .RedeemCheck .String (),
322- SetCandidateOn : price .SetCandidateOn .String (),
323- SetCandidateOff : price .SetCandidateOff .String (),
324- CreateMultisig : price .CreateMultisig .String (),
325- MultisendBase : price .MultisendBase .String (),
326- MultisendDelta : price .MultisendDelta .String (),
327- EditCandidate : price .EditCandidate .String (),
328- SetHaltBlock : price .SetHaltBlock .String (),
329- EditTickerOwner : price .EditTickerOwner .String (),
330- EditMultisig : price .EditMultisig .String (),
331- EditCandidatePublicKey : price .EditCandidatePublicKey .String (),
332- CreateSwapPool : price .CreateSwapPool .String (),
333- AddLiquidity : price .AddLiquidity .String (),
334- RemoveLiquidity : price .RemoveLiquidity .String (),
335- EditCandidateCommission : price .EditCandidateCommission .String (),
336- MintToken : price .MintToken .String (),
337- BurnToken : price .BurnToken .String (),
338- VoteCommission : price .VoteCommission .String (),
339- VoteUpdate : price .VoteUpdate .String (),
340- })
341- }
342- blockchain .stateDeliver .Commission .Delete (height )
343-
344- if v , ok := blockchain .isUpdateNetworkBlock (height ); ok {
345- blockchain .appDB .AddVersion (v , height )
346- blockchain .eventsDB .AddEvent (& eventsdb.UpdateNetworkEvent {
347- Version : v ,
348- })
349- }
350- blockchain .stateDeliver .Updates .Delete (height )
317+ {
318+ var updateCommissionsBlockPrices []byte
319+ if height < haltBlockV210 {
320+ updateCommissionsBlockPrices = blockchain .isUpdateCommissionsBlock (height )
321+ } else {
322+ updateCommissionsBlockPrices = blockchain .isUpdateCommissionsBlockV2 (height )
323+ }
324+ if prices := updateCommissionsBlockPrices ; len (prices ) != 0 {
325+ blockchain .stateDeliver .Commission .SetNewCommissions (prices )
326+ price := blockchain .stateDeliver .Commission .GetCommissions ()
327+ blockchain .eventsDB .AddEvent (& eventsdb.UpdateCommissionsEvent {
328+ Coin : uint64 (price .Coin ),
329+ PayloadByte : price .PayloadByte .String (),
330+ Send : price .Send .String (),
331+ BuyBancor : price .BuyBancor .String (),
332+ SellBancor : price .SellBancor .String (),
333+ SellAllBancor : price .SellAllBancor .String (),
334+ BuyPoolBase : price .BuyPoolBase .String (),
335+ BuyPoolDelta : price .BuyPoolDelta .String (),
336+ SellPoolBase : price .SellPoolBase .String (),
337+ SellPoolDelta : price .SellPoolDelta .String (),
338+ SellAllPoolBase : price .SellAllPoolBase .String (),
339+ SellAllPoolDelta : price .SellAllPoolDelta .String (),
340+ CreateTicker3 : price .CreateTicker3 .String (),
341+ CreateTicker4 : price .CreateTicker4 .String (),
342+ CreateTicker5 : price .CreateTicker5 .String (),
343+ CreateTicker6 : price .CreateTicker6 .String (),
344+ CreateTicker7_10 : price .CreateTicker7to10 .String (),
345+ CreateCoin : price .CreateCoin .String (),
346+ CreateToken : price .CreateToken .String (),
347+ RecreateCoin : price .RecreateCoin .String (),
348+ RecreateToken : price .RecreateToken .String (),
349+ DeclareCandidacy : price .DeclareCandidacy .String (),
350+ Delegate : price .Delegate .String (),
351+ Unbond : price .Unbond .String (),
352+ RedeemCheck : price .RedeemCheck .String (),
353+ SetCandidateOn : price .SetCandidateOn .String (),
354+ SetCandidateOff : price .SetCandidateOff .String (),
355+ CreateMultisig : price .CreateMultisig .String (),
356+ MultisendBase : price .MultisendBase .String (),
357+ MultisendDelta : price .MultisendDelta .String (),
358+ EditCandidate : price .EditCandidate .String (),
359+ SetHaltBlock : price .SetHaltBlock .String (),
360+ EditTickerOwner : price .EditTickerOwner .String (),
361+ EditMultisig : price .EditMultisig .String (),
362+ EditCandidatePublicKey : price .EditCandidatePublicKey .String (),
363+ CreateSwapPool : price .CreateSwapPool .String (),
364+ AddLiquidity : price .AddLiquidity .String (),
365+ RemoveLiquidity : price .RemoveLiquidity .String (),
366+ EditCandidateCommission : price .EditCandidateCommission .String (),
367+ MintToken : price .MintToken .String (),
368+ BurnToken : price .BurnToken .String (),
369+ VoteCommission : price .VoteCommission .String (),
370+ VoteUpdate : price .VoteUpdate .String (),
371+ })
372+ }
373+ blockchain .stateDeliver .Commission .Delete (height )
374+ }
375+
376+ {
377+ if v , ok := blockchain .isUpdateNetworkBlockV2 (height ); ok {
378+ blockchain .appDB .AddVersion (v , height )
379+ blockchain .eventsDB .AddEvent (& eventsdb.UpdateNetworkEvent {
380+ Version : v ,
381+ })
382+ blockchain .grace .AddGracePeriods (graceForUpdate (height ))
383+ }
384+ blockchain .stateDeliver .Updates .Delete (height )
385+ }
351386
352387 hasChangedPublicKeys := false
353388 if blockchain .stateDeliver .Candidates .IsChangedPublicKeys () {
0 commit comments