From 049731bb3c84d551af3c6e911ca5ca379695d47f Mon Sep 17 00:00:00 2001 From: Alexander Bezobchuk Date: Thu, 20 Aug 2020 07:28:40 -0400 Subject: [PATCH] Send Consensus Params during EndBlock (#7107) * add cp to endblock * fix build * add test: TestBaseApp_EndBlock Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- baseapp/abci.go | 6 +++++- baseapp/baseapp_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index c784124138..c414c34081 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -163,7 +163,11 @@ func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBloc res = app.endBlocker(app.deliverState.ctx, req) } - return + if cp := app.GetConsensusParams(app.deliverState.ctx); cp != nil { + res.ConsensusParamUpdates = cp + } + + return res } // CheckTx implements the ABCI interface and executes a tx in CheckTx mode. In diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index c41c26488b..931e7ef500 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -1678,3 +1678,35 @@ func TestWithRouter(t *testing.T) { app.Commit() } } + +func TestBaseApp_EndBlock(t *testing.T) { + db := dbm.NewMemDB() + name := t.Name() + logger := defaultLogger() + + cp := &abci.ConsensusParams{ + Block: &abci.BlockParams{ + MaxGas: 5000000, + }, + } + + app := NewBaseApp(name, logger, db, nil) + app.SetParamStore(¶mStore{db: dbm.NewMemDB()}) + app.InitChain(abci.RequestInitChain{ + ConsensusParams: cp, + }) + + app.SetEndBlocker(func(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock { + return abci.ResponseEndBlock{ + ValidatorUpdates: []abci.ValidatorUpdate{ + {Power: 100}, + }, + } + }) + app.Seal() + + res := app.EndBlock(abci.RequestEndBlock{}) + require.Len(t, res.GetValidatorUpdates(), 1) + require.Equal(t, int64(100), res.GetValidatorUpdates()[0].Power) + require.Equal(t, cp.Block.MaxGas, res.ConsensusParamUpdates.Block.MaxGas) +}