Co-authored-by: Marko <marko@baricevic.me>
This commit is contained in:
parent
66b46f7edf
commit
3ea9f297f4
@ -64,6 +64,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
|
||||
@ -136,31 +137,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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
return cometResp, nil
|
||||
return c.checkTxHandler(c.app.ValidateTx)
|
||||
}
|
||||
|
||||
// Info implements types.Application.
|
||||
|
||||
@ -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)
|
||||
)
|
||||
|
||||
@ -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]{} },
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user