Co-authored-by: mmsqe <mavis@crypto.com> Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
co-authored by
mmsqe
Julien Robert
parent
92d1d9a106
commit
4c083c6f23
@@ -727,6 +727,10 @@ func (app *BaseApp) FinalizeBlock(req *abci.RequestFinalizeBlock) (*abci.Respons
|
||||
}
|
||||
}
|
||||
|
||||
if err := app.preBlock(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
beginBlock, err := app.beginBlock(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -75,6 +75,7 @@ type BaseApp struct {
|
||||
postHandler sdk.PostHandler // post handler, optional, e.g. for tips
|
||||
|
||||
initChainer sdk.InitChainer // ABCI InitChain handler
|
||||
preBlocker sdk.PreBlocker // logic to run before BeginBlocker
|
||||
beginBlocker sdk.BeginBlocker // (legacy ABCI) BeginBlock handler
|
||||
endBlocker sdk.EndBlocker // (legacy ABCI) EndBlock handler
|
||||
processProposal sdk.ProcessProposalHandler // ABCI ProcessProposal handler
|
||||
@@ -664,6 +665,26 @@ func (app *BaseApp) cacheTxContext(ctx sdk.Context, txBytes []byte) (sdk.Context
|
||||
return ctx.WithMultiStore(msCache), msCache
|
||||
}
|
||||
|
||||
func (app *BaseApp) preBlock() error {
|
||||
if app.preBlocker != nil {
|
||||
ctx := app.finalizeBlockState.ctx
|
||||
rsp, err := app.preBlocker(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// rsp.ConsensusParamsChanged is true from preBlocker means ConsensusParams in store get changed
|
||||
// write the consensus parameters in store to context
|
||||
if rsp.ConsensusParamsChanged {
|
||||
ctx = ctx.WithConsensusParams(app.GetConsensusParams(ctx))
|
||||
// GasMeter must be set after we get a context with updated consensus params.
|
||||
gasMeter := app.getBlockGasMeter(ctx)
|
||||
ctx = ctx.WithBlockGasMeter(gasMeter)
|
||||
app.finalizeBlockState.ctx = ctx
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (app *BaseApp) beginBlock(req *abci.RequestFinalizeBlock) (sdk.BeginBlock, error) {
|
||||
var (
|
||||
resp sdk.BeginBlock
|
||||
|
||||
@@ -422,6 +422,9 @@ func TestBaseAppOptionSeal(t *testing.T) {
|
||||
require.Panics(t, func() {
|
||||
suite.baseApp.SetInitChainer(nil)
|
||||
})
|
||||
require.Panics(t, func() {
|
||||
suite.baseApp.SetPreBlocker(nil)
|
||||
})
|
||||
require.Panics(t, func() {
|
||||
suite.baseApp.SetBeginBlocker(nil)
|
||||
})
|
||||
|
||||
@@ -158,6 +158,14 @@ func (app *BaseApp) SetInitChainer(initChainer sdk.InitChainer) {
|
||||
app.initChainer = initChainer
|
||||
}
|
||||
|
||||
func (app *BaseApp) SetPreBlocker(preBlocker sdk.PreBlocker) {
|
||||
if app.sealed {
|
||||
panic("SetPreBlocker() on sealed BaseApp")
|
||||
}
|
||||
|
||||
app.preBlocker = preBlocker
|
||||
}
|
||||
|
||||
func (app *BaseApp) SetBeginBlocker(beginBlocker sdk.BeginBlocker) {
|
||||
if app.sealed {
|
||||
panic("SetBeginBlocker() on sealed BaseApp")
|
||||
|
||||
Reference in New Issue
Block a user