File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -331,10 +331,7 @@ func MakeGenesisState(genDoc *types.GenesisDoc) (State, error) {
331
331
nextValidatorSet = types .NewValidatorSet (validators ).CopyIncrementProposerPriority (1 )
332
332
}
333
333
334
- appVersion := uint64 (0 )
335
- if genDoc .ConsensusParams != nil {
336
- appVersion = genDoc .ConsensusParams .Version .AppVersion
337
- }
334
+ appVersion := getAppVersion (genDoc )
338
335
339
336
return State {
340
337
Version : InitStateVersion (appVersion ),
@@ -356,3 +353,13 @@ func MakeGenesisState(genDoc *types.GenesisDoc) (State, error) {
356
353
AppHash : genDoc .AppHash ,
357
354
}, nil
358
355
}
356
+
357
+ func getAppVersion (genDoc * types.GenesisDoc ) uint64 {
358
+ if genDoc .ConsensusParams != nil &&
359
+ genDoc .ConsensusParams .Version .AppVersion != 0 {
360
+ return genDoc .ConsensusParams .Version .AppVersion
361
+ }
362
+ // Default to app version 1 because some chains (e.g. mocha-4) did not set
363
+ // an explicit app version in genesis.json.
364
+ return uint64 (1 )
365
+ }
Original file line number Diff line number Diff line change @@ -88,6 +88,18 @@ func TestMakeGenesisStateSetsAppVersion(t *testing.T) {
88
88
require .Nil (t , err )
89
89
require .Equal (t , appVersion , state .Version .Consensus .App )
90
90
require .Equal (t , version .BlockProtocol , state .Version .Consensus .Block )
91
+ t .Run ("MakeGenesisState defaults to 1 if app version is not set" , func (t * testing.T ) {
92
+ cp := types .DefaultConsensusParams ()
93
+ cp .Version = cmtproto.VersionParams {} // zero value
94
+ doc := types.GenesisDoc {
95
+ ChainID : "chain-id" ,
96
+ ConsensusParams : cp ,
97
+ }
98
+ require .NoError (t , doc .ValidateAndComplete ())
99
+ state , err := sm .MakeGenesisState (& doc )
100
+ require .NoError (t , err )
101
+ require .Equal (t , uint64 (1 ), state .Version .Consensus .App )
102
+ })
91
103
}
92
104
93
105
// TestStateSaveLoad tests saving and loading State from a db.
You can’t perform that action at this time.
0 commit comments