Skip to content

Commit

Permalink
fix: mocha block sync (#1469)
Browse files Browse the repository at this point in the history
  • Loading branch information
rootulp authored Sep 5, 2024
1 parent 44dea31 commit aef3227
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
15 changes: 11 additions & 4 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,7 @@ func MakeGenesisState(genDoc *types.GenesisDoc) (State, error) {
nextValidatorSet = types.NewValidatorSet(validators).CopyIncrementProposerPriority(1)
}

appVersion := uint64(0)
if genDoc.ConsensusParams != nil {
appVersion = genDoc.ConsensusParams.Version.AppVersion
}
appVersion := getAppVersion(genDoc)

return State{
Version: InitStateVersion(appVersion),
Expand All @@ -356,3 +353,13 @@ func MakeGenesisState(genDoc *types.GenesisDoc) (State, error) {
AppHash: genDoc.AppHash,
}, nil
}

func getAppVersion(genDoc *types.GenesisDoc) uint64 {
if genDoc.ConsensusParams != nil &&
genDoc.ConsensusParams.Version.AppVersion != 0 {
return genDoc.ConsensusParams.Version.AppVersion
}
// Default to app version 1 because some chains (e.g. mocha-4) did not set
// an explicit app version in genesis.json.
return uint64(1)
}
12 changes: 12 additions & 0 deletions state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ func TestMakeGenesisStateSetsAppVersion(t *testing.T) {
require.Nil(t, err)
require.Equal(t, appVersion, state.Version.Consensus.App)
require.Equal(t, version.BlockProtocol, state.Version.Consensus.Block)
t.Run("MakeGenesisState defaults to 1 if app version is not set", func(t *testing.T) {
cp := types.DefaultConsensusParams()
cp.Version = cmtproto.VersionParams{} // zero value
doc := types.GenesisDoc{
ChainID: "chain-id",
ConsensusParams: cp,
}
require.NoError(t, doc.ValidateAndComplete())
state, err := sm.MakeGenesisState(&doc)
require.NoError(t, err)
require.Equal(t, uint64(1), state.Version.Consensus.App)
})
}

// TestStateSaveLoad tests saving and loading State from a db.
Expand Down

0 comments on commit aef3227

Please sign in to comment.