From 37c5f95548865e8f5a12cf5b67668cc3a4665d74 Mon Sep 17 00:00:00 2001 From: Facundo Date: Tue, 21 Nov 2023 10:26:25 +0100 Subject: [PATCH] fix: allow empty consensus params --- baseapp/baseapp.go | 6 +++++- baseapp/baseapp_test.go | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 5036ae5c20fa..2d1e878c5a1d 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -522,7 +522,11 @@ func (app *BaseApp) GetConsensusParams(ctx sdk.Context) cmtproto.ConsensusParams cp, err := app.paramStore.Get(ctx) if err != nil { - panic(fmt.Errorf("consensus key is nil: %w", err)) + // This could happen while migrating from v0.45/v0.46 to v0.50, we should + // allow it to happen so during preblock the upgrade plan can be executed + // and the consensus params set for the first time in the new format. + app.logger.Error("couldn't get consensus params", "err", err) + return cmtproto.ConsensusParams{} } return cp diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 67414a9c12d2..dd389f48a88b 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -720,6 +720,17 @@ func TestGetMaximumBlockGas(t *testing.T) { require.Panics(t, func() { suite.baseApp.GetMaximumBlockGas(ctx) }) } +func TestGetEmptyConsensusParmas(t *testing.T) { + suite := NewBaseAppSuite(t) + _, err := suite.baseApp.InitChain(&abci.RequestInitChain{}) + require.NoError(t, err) + ctx := suite.baseApp.NewContext(true) + + cp := suite.baseApp.GetConsensusParams(ctx) + require.Equal(t, cmtproto.ConsensusParams{}, cp) + require.Equal(t, uint64(0), suite.baseApp.GetMaximumBlockGas(ctx)) +} + func TestLoadVersionPruning(t *testing.T) { logger := log.NewNopLogger() pruningOptions := pruningtypes.NewCustomPruningOptions(10, 15)