diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d47390899d5..ffb10ea817db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -177,6 +177,7 @@ extension interfaces. `module.Manager.Modules` is now of type `map[string]interf `cosmossdk.io/core/appmodule.AppModule` API. * (x/group) [#13876](https://github.com/cosmos/cosmos-sdk/pull/13876) Add `GetMinExecutionPeriod` method on DecisionPolicy interface. * (x/auth)[#13780](https://github.com/cosmos/cosmos-sdk/pull/13780) Querying with `id` (type of int64) in `AccountAddressByID` grpc query now throws error, use account-id(type of uint64) instead. +* (baseapp) [#14050](https://github.com/cosmos/cosmos-sdk/pull/14050) refactor `ABCIListener` interface to accept go contexts ### CLI Breaking Changes diff --git a/baseapp/abci.go b/baseapp/abci.go index a5e1e5f9c52e..707f55f4cbba 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -201,7 +201,10 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg // call the hooks with the BeginBlock messages for _, streamingListener := range app.abciListeners { - if err := streamingListener.ListenBeginBlock(app.deliverState.ctx, req, res); err != nil { + + goCtx := sdk.WrapSDKContext(app.deliverState.ctx) + + if err := streamingListener.ListenBeginBlock(goCtx, req, res); err != nil { app.logger.Error("BeginBlock listening hook failed", "height", req.Header.Height, "err", err) } } @@ -226,7 +229,9 @@ func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBloc // call the streaming service hooks with the EndBlock messages for _, streamingListener := range app.abciListeners { - if err := streamingListener.ListenEndBlock(app.deliverState.ctx, req, res); err != nil { + goCtx := sdk.WrapSDKContext(app.deliverState.ctx) + + if err := streamingListener.ListenEndBlock(goCtx, req, res); err != nil { app.logger.Error("EndBlock listening hook failed", "height", req.Height, "err", err) } } @@ -329,7 +334,9 @@ func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) (res abci.ResponseDeliv defer func() { for _, streamingListener := range app.abciListeners { - if err := streamingListener.ListenDeliverTx(app.deliverState.ctx, req, res); err != nil { + goCtx := sdk.WrapSDKContext(app.deliverState.ctx) + + if err := streamingListener.ListenDeliverTx(goCtx, req, res); err != nil { app.logger.Error("DeliverTx listening hook failed", "err", err) } } diff --git a/baseapp/streaming.go b/baseapp/streaming.go index 39e0f1ca6e9b..766e9488be0a 100644 --- a/baseapp/streaming.go +++ b/baseapp/streaming.go @@ -1,23 +1,23 @@ package baseapp import ( + "context" "io" "sync" abci "github.com/tendermint/tendermint/abci/types" store "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/types" ) // ABCIListener interface used to hook into the ABCI message processing of the BaseApp type ABCIListener interface { // ListenBeginBlock updates the streaming service with the latest BeginBlock messages - ListenBeginBlock(ctx types.Context, req abci.RequestBeginBlock, res abci.ResponseBeginBlock) error + ListenBeginBlock(ctx context.Context, req abci.RequestBeginBlock, res abci.ResponseBeginBlock) error // ListenEndBlock updates the steaming service with the latest EndBlock messages - ListenEndBlock(ctx types.Context, req abci.RequestEndBlock, res abci.ResponseEndBlock) error + ListenEndBlock(ctx context.Context, req abci.RequestEndBlock, res abci.ResponseEndBlock) error // ListenDeliverTx updates the steaming service with the latest DeliverTx messages - ListenDeliverTx(ctx types.Context, req abci.RequestDeliverTx, res abci.ResponseDeliverTx) error + ListenDeliverTx(ctx context.Context, req abci.RequestDeliverTx, res abci.ResponseDeliverTx) error } // StreamingService interface for registering WriteListeners with the BaseApp and updating the service with the ABCI messages using the hooks diff --git a/store/streaming/file/service.go b/store/streaming/file/service.go index 2f7664af1b86..3874702925b2 100644 --- a/store/streaming/file/service.go +++ b/store/streaming/file/service.go @@ -1,6 +1,7 @@ package file import ( + "context" "errors" "fmt" "os" @@ -13,7 +14,6 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" ) var _ baseapp.StreamingService = &StreamingService{} @@ -87,7 +87,7 @@ func (fss *StreamingService) Listeners() map[types.StoreKey][]types.WriteListene // ListenBeginBlock satisfies the baseapp.ABCIListener interface // It writes the received BeginBlock request and response and the resulting state changes // out to a file as described in the above the naming schema -func (fss *StreamingService) ListenBeginBlock(ctx sdk.Context, req abci.RequestBeginBlock, res abci.ResponseBeginBlock) (rerr error) { +func (fss *StreamingService) ListenBeginBlock(ctx context.Context, req abci.RequestBeginBlock, res abci.ResponseBeginBlock) (rerr error) { // generate the new file dstFile, err := fss.openBeginBlockFile(req) if err != nil { @@ -142,7 +142,7 @@ func (fss *StreamingService) openBeginBlockFile(req abci.RequestBeginBlock) (*os // ListenDeliverTx satisfies the baseapp.ABCIListener interface // It writes the received DeliverTx request and response and the resulting state changes // out to a file as described in the above the naming schema -func (fss *StreamingService) ListenDeliverTx(ctx sdk.Context, req abci.RequestDeliverTx, res abci.ResponseDeliverTx) (rerr error) { +func (fss *StreamingService) ListenDeliverTx(ctx context.Context, req abci.RequestDeliverTx, res abci.ResponseDeliverTx) (rerr error) { // generate the new file dstFile, err := fss.openDeliverTxFile() if err != nil { @@ -196,7 +196,7 @@ func (fss *StreamingService) openDeliverTxFile() (*os.File, error) { // ListenEndBlock satisfies the baseapp.ABCIListener interface // It writes the received EndBlock request and response and the resulting state changes // out to a file as described in the above the naming schema -func (fss *StreamingService) ListenEndBlock(ctx sdk.Context, req abci.RequestEndBlock, res abci.ResponseEndBlock) (rerr error) { +func (fss *StreamingService) ListenEndBlock(ctx context.Context, req abci.RequestEndBlock, res abci.ResponseEndBlock) (rerr error) { // generate the new file dstFile, err := fss.openEndBlockFile() if err != nil {