Skip to content

Commit aef3227

Browse files
authored
fix: mocha block sync (#1469)
Unblocks celestiaorg/celestia-app#3843
1 parent 44dea31 commit aef3227

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

state/state.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,7 @@ func MakeGenesisState(genDoc *types.GenesisDoc) (State, error) {
331331
nextValidatorSet = types.NewValidatorSet(validators).CopyIncrementProposerPriority(1)
332332
}
333333

334-
appVersion := uint64(0)
335-
if genDoc.ConsensusParams != nil {
336-
appVersion = genDoc.ConsensusParams.Version.AppVersion
337-
}
334+
appVersion := getAppVersion(genDoc)
338335

339336
return State{
340337
Version: InitStateVersion(appVersion),
@@ -356,3 +353,13 @@ func MakeGenesisState(genDoc *types.GenesisDoc) (State, error) {
356353
AppHash: genDoc.AppHash,
357354
}, nil
358355
}
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+
}

state/state_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ func TestMakeGenesisStateSetsAppVersion(t *testing.T) {
8888
require.Nil(t, err)
8989
require.Equal(t, appVersion, state.Version.Consensus.App)
9090
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+
})
91103
}
92104

93105
// TestStateSaveLoad tests saving and loading State from a db.

0 commit comments

Comments
 (0)