Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use genesis file app version if it is set (backport #1227) #1232

Merged
merged 6 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions consensus/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,10 @@ func (h *Handshaker) HandshakeWithContext(ctx context.Context, proxyApp proxy.Ap
}
appHash := res.LastBlockAppHash

h.logger.Info("ABCI Handshake App Info",
"height", blockHeight,
"hash", appHash,
"software-version", res.Version,
"protocol-version", res.AppVersion,
)

// Only set the version if there is no existing state.
if h.initialState.LastBlockHeight == 0 {
appVersion := h.initialState.Version.Consensus.App
// set app version if it's not set via genesis
if h.initialState.LastBlockHeight == 0 && appVersion == 0 && res.AppVersion != 0 {
appVersion = res.AppVersion
h.initialState.Version.Consensus.App = res.AppVersion
}

Expand All @@ -277,7 +272,10 @@ func (h *Handshaker) HandshakeWithContext(ctx context.Context, proxyApp proxy.Ap
}

h.logger.Info("Completed ABCI Handshake - CometBFT and App are synced",
"appHeight", blockHeight, "appHash", appHash)
"appHeight", blockHeight,
"appHash", appHash,
"appVersion", appVersion,
)

// TODO: (on restart) replay mempool

Expand Down
26 changes: 15 additions & 11 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ var (

//-----------------------------------------------------------------------------

// InitStateVersion sets the Consensus.Block and Software versions,
// but leaves the Consensus.App version blank.
// The Consensus.App version will be set during the Handshake, once
// we hear from the app what protocol version it is running.
var InitStateVersion = cmtstate.Version{
Consensus: cmtversion.Consensus{
Block: version.BlockProtocol,
App: 0,
},
Software: version.TMCoreSemVer,
// InitStateVersion sets the Consensus.Block, Consensus.App and Software versions
func InitStateVersion(appVersion uint64) cmtstate.Version {
return cmtstate.Version{
Consensus: cmtversion.Consensus{
Block: version.BlockProtocol,
App: appVersion,
},
Software: version.TMCoreSemVer,
}
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -332,8 +331,13 @@ 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
}

return State{
Version: InitStateVersion,
Version: InitStateVersion(appVersion),
ChainID: genDoc.ChainID,
InitialHeight: genDoc.InitialHeight,

Expand Down
16 changes: 16 additions & 0 deletions state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
cmtproto "github.com/tendermint/tendermint/proto/tendermint/types"
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types"
"github.com/tendermint/tendermint/version"
)

// setupTestCase does setup common to all test cases.
Expand Down Expand Up @@ -74,6 +75,21 @@ func TestMakeGenesisStateNilValidators(t *testing.T) {
require.Equal(t, 0, len(state.NextValidators.Validators))
}

func TestMakeGenesisStateSetsAppVersion(t *testing.T) {
cp := types.DefaultConsensusParams()
appVersion := uint64(5)
cp.Version.AppVersion = appVersion
doc := types.GenesisDoc{
ChainID: "dummy",
ConsensusParams: cp,
}
require.Nil(t, doc.ValidateAndComplete())
state, err := sm.MakeGenesisState(&doc)
require.Nil(t, err)
require.Equal(t, appVersion, state.Version.Consensus.App)
require.Equal(t, version.BlockProtocol, state.Version.Consensus.Block)
}

// TestStateSaveLoad tests saving and loading State from a db.
func TestStateSaveLoad(t *testing.T) {
tearDown, stateDB, state := setupTestCase(t)
Expand Down
Loading