diff --git a/server/v2/cometbft/abci.go b/server/v2/cometbft/abci.go index 02966c8747709..0ff9812e6f319 100644 --- a/server/v2/cometbft/abci.go +++ b/server/v2/cometbft/abci.go @@ -57,6 +57,7 @@ type Consensus[T transaction.Tx] struct { processProposalHandler handlers.ProcessHandler[T] verifyVoteExt handlers.VerifyVoteExtensionhandler extendVote handlers.ExtendVoteHandler + checkTxHandler handlers.CheckTxHandler[T] addrPeerFilter types.PeerFilter // filter peers by address and port idPeerFilter types.PeerFilter // filter peers by node ID @@ -122,31 +123,35 @@ func (c *Consensus[T]) CheckTx(ctx context.Context, req *abciproto.CheckTxReques return nil, err } - resp, err := c.app.ValidateTx(ctx, decodedTx) - // we do not want to return a cometbft error, but a check tx response with the error - if err != nil && !errors.Is(err, resp.Error) { - return nil, err - } + if c.checkTxHandler == nil { + resp, err := c.app.ValidateTx(ctx, decodedTx) + // we do not want to return a cometbft error, but a check tx response with the error + if err != nil && !errors.Is(err, resp.Error) { + return nil, err + } - events, err := intoABCIEvents(resp.Events, c.indexedEvents) - if err != nil { - return nil, err - } + events, err := intoABCIEvents(resp.Events, c.indexedEvents) + if err != nil { + return nil, err + } - cometResp := &abciproto.CheckTxResponse{ - Code: 0, - GasWanted: uint64ToInt64(resp.GasWanted), - GasUsed: uint64ToInt64(resp.GasUsed), - Events: events, - } - if resp.Error != nil { - space, code, log := errorsmod.ABCIInfo(resp.Error, c.cfg.AppTomlConfig.Trace) - cometResp.Code = code - cometResp.Codespace = space - cometResp.Log = log + cometResp := &abciproto.CheckTxResponse{ + Code: 0, + GasWanted: uint64ToInt64(resp.GasWanted), + GasUsed: uint64ToInt64(resp.GasUsed), + Events: events, + } + if resp.Error != nil { + space, code, log := errorsmod.ABCIInfo(resp.Error, c.cfg.AppTomlConfig.Trace) + cometResp.Code = code + cometResp.Codespace = space + cometResp.Log = log + } + + return cometResp, nil } - return cometResp, nil + return c.checkTxHandler(c.app.ValidateTx) } // Info implements types.Application. diff --git a/server/v2/cometbft/handlers/handlers.go b/server/v2/cometbft/handlers/handlers.go index 9008490f6a441..015594f469f7b 100644 --- a/server/v2/cometbft/handlers/handlers.go +++ b/server/v2/cometbft/handlers/handlers.go @@ -5,6 +5,7 @@ import ( abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" + "cosmossdk.io/core/server" "cosmossdk.io/core/store" "cosmossdk.io/core/transaction" ) @@ -27,4 +28,7 @@ type ( // It takes a context, a store reader map, and a request to extend a vote. // It returns a response to extend the vote and an error if any. ExtendVoteHandler func(context.Context, store.ReaderMap, *abci.ExtendVoteRequest) (*abci.ExtendVoteResponse, error) + + // CheckTxHandler is a function type that handles the execution of a transaction. + CheckTxHandler[T transaction.Tx] func(func(ctx context.Context, tx T) (server.TxResult, error)) (*abci.CheckTxResponse, error) ) diff --git a/server/v2/cometbft/options.go b/server/v2/cometbft/options.go index 0f5091da70a09..d5aa4872fff2f 100644 --- a/server/v2/cometbft/options.go +++ b/server/v2/cometbft/options.go @@ -18,6 +18,7 @@ type keyGenF = func() (cmtcrypto.PrivKey, error) type ServerOptions[T transaction.Tx] struct { PrepareProposalHandler handlers.PrepareHandler[T] ProcessProposalHandler handlers.ProcessHandler[T] + CheckTxHandler handlers.CheckTxHandler[T] VerifyVoteExtensionHandler handlers.VerifyVoteExtensionhandler ExtendVoteHandler handlers.ExtendVoteHandler KeygenF keyGenF @@ -35,6 +36,7 @@ func DefaultServerOptions[T transaction.Tx]() ServerOptions[T] { return ServerOptions[T]{ PrepareProposalHandler: handlers.NoOpPrepareProposal[T](), ProcessProposalHandler: handlers.NoOpProcessProposal[T](), + CheckTxHandler: nil, VerifyVoteExtensionHandler: handlers.NoOpVerifyVoteExtensionHandler(), ExtendVoteHandler: handlers.NoOpExtendVote(), Mempool: func(cfg map[string]any) mempool.Mempool[T] { return mempool.NoOpMempool[T]{} }, diff --git a/server/v2/cometbft/server.go b/server/v2/cometbft/server.go index 21b6d59ddc723..6dd5fcf6456fc 100644 --- a/server/v2/cometbft/server.go +++ b/server/v2/cometbft/server.go @@ -113,6 +113,7 @@ func (s *CometBFTServer[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logg ) consensus.prepareProposalHandler = s.serverOptions.PrepareProposalHandler consensus.processProposalHandler = s.serverOptions.ProcessProposalHandler + consensus.checkTxHandler = s.serverOptions.CheckTxHandler consensus.verifyVoteExt = s.serverOptions.VerifyVoteExtensionHandler consensus.extendVote = s.serverOptions.ExtendVoteHandler consensus.addrPeerFilter = s.serverOptions.AddrPeerFilter