From 2620b8eeb6514fb5e143a281bfec36e16d8d9614 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 24 Jun 2024 10:36:01 +0200 Subject: [PATCH 1/2] remove abci.go from types//errors --- baseapp/abci.go | 34 +++++++++++------------ baseapp/baseapp.go | 2 +- types/errors/abci.go => baseapp/errors.go | 14 +++++----- 3 files changed, 25 insertions(+), 25 deletions(-) rename types/errors/abci.go => baseapp/errors.go (70%) diff --git a/baseapp/abci.go b/baseapp/abci.go index 30e47214b3dc..68a65249dfd7 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -166,7 +166,7 @@ func (app *BaseApp) Query(_ context.Context, req *abci.QueryRequest) (resp *abci // Ref: https://github.com/cosmos/cosmos-sdk/pull/8039 defer func() { if r := recover(); r != nil { - resp = sdkerrors.QueryResult(errorsmod.Wrapf(sdkerrors.ErrPanic, "%v", r), app.trace) + resp = queryResult(errorsmod.Wrapf(sdkerrors.ErrPanic, "%v", r), app.trace) } }() @@ -180,7 +180,7 @@ func (app *BaseApp) Query(_ context.Context, req *abci.QueryRequest) (resp *abci defer telemetry.MeasureSince(telemetry.Now(), req.Path) if req.Path == QueryPathBroadcastTx { - return sdkerrors.QueryResult(errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "can't route a broadcast tx message"), app.trace), nil + return queryResult(errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "can't route a broadcast tx message"), app.trace), nil } // handle gRPC routes first rather than calling splitPath because '/' characters @@ -191,7 +191,7 @@ func (app *BaseApp) Query(_ context.Context, req *abci.QueryRequest) (resp *abci path := SplitABCIQueryPath(req.Path) if len(path) == 0 { - return sdkerrors.QueryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "no query path provided"), app.trace), nil + return queryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "no query path provided"), app.trace), nil } switch path[0] { @@ -206,7 +206,7 @@ func (app *BaseApp) Query(_ context.Context, req *abci.QueryRequest) (resp *abci resp = handleQueryP2P(app, path) default: - resp = sdkerrors.QueryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "unknown query path"), app.trace) + resp = queryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "unknown query path"), app.trace) } return resp, nil @@ -365,7 +365,7 @@ func (app *BaseApp) CheckTx(req *abci.CheckTxRequest) (*abci.CheckTxResponse, er gInfo, result, anteEvents, err := app.runTx(mode, req.Tx) if err != nil { - return sdkerrors.ResponseCheckTxWithEvents(err, gInfo.GasWanted, gInfo.GasUsed, anteEvents, app.trace), nil + return responseCheckTxWithEvents(err, gInfo.GasWanted, gInfo.GasUsed, anteEvents, app.trace), nil } return &abci.CheckTxResponse{ @@ -825,7 +825,7 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Finaliz // In the case where a transaction included in a block proposal is malformed, // we still want to return a default response to comet. This is because comet // expects a response for each transaction included in a block proposal. - response = sdkerrors.ResponseExecTxResultWithEvents( + response = responseExecTxResultWithEvents( sdkerrors.ErrTxDecode, 0, 0, @@ -1023,7 +1023,7 @@ func handleQueryApp(app *BaseApp, path []string, req *abci.QueryRequest) *abci.Q gInfo, res, err := app.Simulate(txBytes) if err != nil { - return sdkerrors.QueryResult(errorsmod.Wrap(err, "failed to simulate tx"), app.trace) + return queryResult(errorsmod.Wrap(err, "failed to simulate tx"), app.trace) } simRes := &sdk.SimulationResponse{ @@ -1033,7 +1033,7 @@ func handleQueryApp(app *BaseApp, path []string, req *abci.QueryRequest) *abci.Q bz, err := codec.ProtoMarshalJSON(simRes, app.interfaceRegistry) if err != nil { - return sdkerrors.QueryResult(errorsmod.Wrap(err, "failed to JSON encode simulation response"), app.trace) + return queryResult(errorsmod.Wrap(err, "failed to JSON encode simulation response"), app.trace) } return &abci.QueryResponse{ @@ -1050,11 +1050,11 @@ func handleQueryApp(app *BaseApp, path []string, req *abci.QueryRequest) *abci.Q } default: - return sdkerrors.QueryResult(errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query: %s", path), app.trace) + return queryResult(errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query: %s", path), app.trace) } } - return sdkerrors.QueryResult( + return queryResult( errorsmod.Wrap( sdkerrors.ErrUnknownRequest, "expected second parameter to be either 'simulate' or 'version', neither was present", @@ -1065,13 +1065,13 @@ func handleQueryStore(app *BaseApp, path []string, req abci.QueryRequest) *abci. // "/store" prefix for store queries queryable, ok := app.cms.(storetypes.Queryable) if !ok { - return sdkerrors.QueryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "multi-store does not support queries"), app.trace) + return queryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "multi-store does not support queries"), app.trace) } req.Path = "/" + strings.Join(path[1:], "/") if req.Height <= 1 && req.Prove { - return sdkerrors.QueryResult( + return queryResult( errorsmod.Wrap( sdkerrors.ErrInvalidRequest, "cannot query with proof when height <= 1; please provide a valid height", @@ -1081,7 +1081,7 @@ func handleQueryStore(app *BaseApp, path []string, req abci.QueryRequest) *abci. sdkReq := storetypes.RequestQuery(req) resp, err := queryable.Query(&sdkReq) if err != nil { - return sdkerrors.QueryResult(err, app.trace) + return queryResult(err, app.trace) } resp.Height = req.Height @@ -1093,7 +1093,7 @@ func handleQueryStore(app *BaseApp, path []string, req abci.QueryRequest) *abci. func handleQueryP2P(app *BaseApp, path []string) *abci.QueryResponse { // "/p2p" prefix for p2p queries if len(path) < 4 { - return sdkerrors.QueryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "path should be p2p filter "), app.trace) + return queryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "path should be p2p filter "), app.trace) } var resp *abci.QueryResponse @@ -1110,7 +1110,7 @@ func handleQueryP2P(app *BaseApp, path []string) *abci.QueryResponse { } default: - resp = sdkerrors.QueryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "expected second parameter to be 'filter'"), app.trace) + resp = queryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "expected second parameter to be 'filter'"), app.trace) } return resp @@ -1166,12 +1166,12 @@ func (app *BaseApp) getContextForProposal(ctx sdk.Context, height int64) sdk.Con func (app *BaseApp) handleQueryGRPC(handler GRPCQueryHandler, req *abci.QueryRequest) *abci.QueryResponse { ctx, err := app.CreateQueryContext(req.Height, req.Prove) if err != nil { - return sdkerrors.QueryResult(err, app.trace) + return queryResult(err, app.trace) } resp, err := handler(ctx, req) if err != nil { - resp = sdkerrors.QueryResult(gRPCErrorToSDKError(err), app.trace) + resp = queryResult(gRPCErrorToSDKError(err), app.trace) resp.Height = req.Height return resp } diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 4f1aedf1ed08..0d33a391f7f5 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -764,7 +764,7 @@ func (app *BaseApp) deliverTx(tx []byte) *abci.ExecTxResult { gInfo, result, anteEvents, err := app.runTx(execModeFinalize, tx) if err != nil { resultStr = "failed" - resp = sdkerrors.ResponseExecTxResultWithEvents( + resp = responseExecTxResultWithEvents( err, gInfo.GasWanted, gInfo.GasUsed, diff --git a/types/errors/abci.go b/baseapp/errors.go similarity index 70% rename from types/errors/abci.go rename to baseapp/errors.go index 3a1dac58e51d..fd69701da199 100644 --- a/types/errors/abci.go +++ b/baseapp/errors.go @@ -1,4 +1,4 @@ -package errors +package baseapp import ( abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" @@ -6,9 +6,9 @@ import ( errorsmod "cosmossdk.io/errors" ) -// ResponseCheckTxWithEvents returns an ABCI ResponseCheckTx object with fields filled in +// responseCheckTxWithEvents returns an ABCI ResponseCheckTx object with fields filled in // from the given error, gas values and events. -func ResponseCheckTxWithEvents(err error, gw, gu uint64, events []abci.Event, debug bool) *abci.CheckTxResponse { +func responseCheckTxWithEvents(err error, gw, gu uint64, events []abci.Event, debug bool) *abci.CheckTxResponse { space, code, log := errorsmod.ABCIInfo(err, debug) return &abci.CheckTxResponse{ Codespace: space, @@ -20,9 +20,9 @@ func ResponseCheckTxWithEvents(err error, gw, gu uint64, events []abci.Event, de } } -// ResponseExecTxResultWithEvents returns an ABCI ExecTxResult object with fields +// responseExecTxResultWithEvents returns an ABCI ExecTxResult object with fields // filled in from the given error, gas values and events. -func ResponseExecTxResultWithEvents(err error, gw, gu uint64, events []abci.Event, debug bool) *abci.ExecTxResult { +func responseExecTxResultWithEvents(err error, gw, gu uint64, events []abci.Event, debug bool) *abci.ExecTxResult { space, code, log := errorsmod.ABCIInfo(err, debug) return &abci.ExecTxResult{ Codespace: space, @@ -34,9 +34,9 @@ func ResponseExecTxResultWithEvents(err error, gw, gu uint64, events []abci.Even } } -// QueryResult returns a ResponseQuery from an error. It will try to parse ABCI +// queryResult returns a ResponseQuery from an error. It will try to parse ABCI // info from the error. -func QueryResult(err error, debug bool) *abci.QueryResponse { +func queryResult(err error, debug bool) *abci.QueryResponse { space, code, log := errorsmod.ABCIInfo(err, debug) return &abci.QueryResponse{ Codespace: space, From 48350656b6bc0aadec3375eede4aee9bd5dcc34a Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 24 Jun 2024 10:38:50 +0200 Subject: [PATCH 2/2] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa9c77f64a5d..d4c1e59256bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -191,6 +191,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (client) [#20255](https://github.com/cosmos/cosmos-sdk/pull/20255) Use comet proofOp proto type instead of sdk version to avoid needing to translate to later be proven in the merkle proof runtime. * (all) [#19726](https://github.com/cosmos/cosmos-sdk/pull/19726) Integrate comet v1 * (client) [#20616](https://github.com/cosmos/cosmos-sdk/pull/20616) gentx subcommand output goes to `cmd.ErrOrStderr()` instead of being hardcoded to `os.Stderr` +* (types/errors) [#20756](https://github.com/cosmos/cosmos-sdk/pull/20756) Remove `ResponseCheckTxWithEvents`, `ResponseExecTxResultWithEvents` & `QueryResult` from types/errors pkg. They have been moved to `baseapp/errors.go` and made private ### Client Breaking Changes