@@ -6,14 +6,10 @@ import (
66 "errors"
77 "fmt"
88 "strings"
9- "sync"
109 "sync/atomic"
1110
1211 abci "github.com/cometbft/cometbft/abci/types"
1312 abciproto "github.com/cometbft/cometbft/api/cometbft/abci/v1"
14- codectypes "github.com/cosmos/cosmos-sdk/codec/types"
15- sdk "github.com/cosmos/cosmos-sdk/types"
16- txtypes "github.com/cosmos/cosmos-sdk/types/tx"
1713 gogoproto "github.com/cosmos/gogoproto/proto"
1814 protoreflect "google.golang.org/protobuf/reflect/protoreflect"
1915 "google.golang.org/protobuf/reflect/protoregistry"
@@ -37,6 +33,11 @@ import (
3733 "cosmossdk.io/server/v2/streaming"
3834 "cosmossdk.io/store/v2/snapshots"
3935 consensustypes "cosmossdk.io/x/consensus/types"
36+
37+ "github.com/cosmos/cosmos-sdk/codec"
38+ codectypes "github.com/cosmos/cosmos-sdk/codec/types"
39+ sdk "github.com/cosmos/cosmos-sdk/types"
40+ txtypes "github.com/cosmos/cosmos-sdk/types/tx"
4041)
4142
4243const (
@@ -45,22 +46,24 @@ const (
4546 QueryPathStore = "store"
4647)
4748
48- var _ abci.Application = (* Consensus [transaction.Tx ])(nil )
49+ var _ abci.Application = (* consensus [transaction.Tx ])(nil )
4950
50- type Consensus [T transaction.Tx ] struct {
51+ // consensus contains the implementation of the ABCI interface for CometBFT.
52+ type consensus [T transaction.Tx ] struct {
5153 logger log.Logger
5254 appName , version string
5355 app appmanager.AppManager [T ]
56+ appCodec codec.Codec
5457 txCodec transaction.Codec [T ]
5558 store types.Store
56- streaming streaming.Manager
5759 listener * appdata.Listener
5860 snapshotManager * snapshots.Manager
61+ streamingManager streaming.Manager
5962 mempool mempool.Mempool [T ]
6063
6164 cfg Config
62- indexedEvents map [string ]struct {}
6365 chainID string
66+ indexedEvents map [string ]struct {}
6467
6568 initialHeight uint64
6669 // this is only available after this node has committed a block (in FinalizeBlock),
@@ -81,60 +84,9 @@ type Consensus[T transaction.Tx] struct {
8184 getProtoRegistry func () (* protoregistry.Files , error )
8285}
8386
84- func NewConsensus [T transaction.Tx ](
85- logger log.Logger ,
86- appName string ,
87- app appmanager.AppManager [T ],
88- mp mempool.Mempool [T ],
89- indexedEvents map [string ]struct {},
90- queryHandlersMap map [string ]appmodulev2.Handler ,
91- store types.Store ,
92- cfg Config ,
93- txCodec transaction.Codec [T ],
94- chainId string ,
95- ) * Consensus [T ] {
96- return & Consensus [T ]{
97- appName : appName ,
98- version : getCometBFTServerVersion (),
99- app : app ,
100- cfg : cfg ,
101- store : store ,
102- logger : logger ,
103- txCodec : txCodec ,
104- streaming : streaming.Manager {},
105- snapshotManager : nil ,
106- mempool : mp ,
107- lastCommittedHeight : atomic.Int64 {},
108- prepareProposalHandler : nil ,
109- processProposalHandler : nil ,
110- verifyVoteExt : nil ,
111- extendVote : nil ,
112- chainID : chainId ,
113- indexedEvents : indexedEvents ,
114- initialHeight : 0 ,
115- queryHandlersMap : queryHandlersMap ,
116- getProtoRegistry : sync .OnceValues (gogoproto .MergedRegistry ),
117- }
118- }
119-
120- // SetStreamingManager sets the streaming manager for the consensus module.
121- func (c * Consensus [T ]) SetStreamingManager (sm streaming.Manager ) {
122- c .streaming = sm
123- }
124-
125- // RegisterSnapshotExtensions registers the given extensions with the consensus module's snapshot manager.
126- // It allows additional snapshotter implementations to be used for creating and restoring snapshots.
127- func (c * Consensus [T ]) RegisterSnapshotExtensions (extensions ... snapshots.ExtensionSnapshotter ) error {
128- if err := c .snapshotManager .RegisterExtensions (extensions ... ); err != nil {
129- return fmt .Errorf ("failed to register snapshot extensions: %w" , err )
130- }
131-
132- return nil
133- }
134-
13587// CheckTx implements types.Application.
13688// It is called by cometbft to verify transaction validity
137- func (c * Consensus [T ]) CheckTx (ctx context.Context , req * abciproto.CheckTxRequest ) (* abciproto.CheckTxResponse , error ) {
89+ func (c * consensus [T ]) CheckTx (ctx context.Context , req * abciproto.CheckTxRequest ) (* abciproto.CheckTxResponse , error ) {
13890 decodedTx , err := c .txCodec .Decode (req .Tx )
13991 if err != nil {
14092 return nil , err
@@ -172,7 +124,7 @@ func (c *Consensus[T]) CheckTx(ctx context.Context, req *abciproto.CheckTxReques
172124}
173125
174126// Info implements types.Application.
175- func (c * Consensus [T ]) Info (ctx context.Context , _ * abciproto.InfoRequest ) (* abciproto.InfoResponse , error ) {
127+ func (c * consensus [T ]) Info (ctx context.Context , _ * abciproto.InfoRequest ) (* abciproto.InfoResponse , error ) {
176128 version , _ , err := c .store .StateLatest ()
177129 if err != nil {
178130 return nil , err
@@ -212,7 +164,7 @@ func (c *Consensus[T]) Info(ctx context.Context, _ *abciproto.InfoRequest) (*abc
212164
213165// Query implements types.Application.
214166// It is called by cometbft to query application state.
215- func (c * Consensus [T ]) Query (ctx context.Context , req * abciproto.QueryRequest ) (resp * abciproto.QueryResponse , err error ) {
167+ func (c * consensus [T ]) Query (ctx context.Context , req * abciproto.QueryRequest ) (resp * abciproto.QueryResponse , err error ) {
216168 resp , isGRPC , err := c .maybeRunGRPCQuery (ctx , req )
217169 if isGRPC {
218170 return resp , err
@@ -227,7 +179,7 @@ func (c *Consensus[T]) Query(ctx context.Context, req *abciproto.QueryRequest) (
227179
228180 switch path [0 ] {
229181 case QueryPathApp :
230- resp , err = c .handlerQueryApp (ctx , path , req )
182+ resp , err = c .handleQueryApp (ctx , path , req )
231183
232184 case QueryPathStore :
233185 resp , err = c .handleQueryStore (path , req )
@@ -246,7 +198,7 @@ func (c *Consensus[T]) Query(ctx context.Context, req *abciproto.QueryRequest) (
246198 return resp , nil
247199}
248200
249- func (c * Consensus [T ]) maybeRunGRPCQuery (ctx context.Context , req * abci.QueryRequest ) (resp * abciproto.QueryResponse , isGRPC bool , err error ) {
201+ func (c * consensus [T ]) maybeRunGRPCQuery (ctx context.Context , req * abci.QueryRequest ) (resp * abciproto.QueryResponse , isGRPC bool , err error ) {
250202 // if this fails then we cannot serve queries anymore
251203 registry , err := c .getProtoRegistry ()
252204 if err != nil {
@@ -288,7 +240,7 @@ func (c *Consensus[T]) maybeRunGRPCQuery(ctx context.Context, req *abci.QueryReq
288240
289241 txResult , _ , err := c .app .Simulate (ctx , tx )
290242 if err != nil {
291- return nil , true , fmt .Errorf ("%v with gas used: '%d'" , err , txResult .GasUsed )
243+ return nil , true , fmt .Errorf ("failed with gas used: '%d': %w " , txResult .GasUsed , err )
292244 }
293245
294246 msgResponses := make ([]* codectypes.Any , 0 , len (txResult .Resp ))
@@ -337,7 +289,7 @@ func (c *Consensus[T]) maybeRunGRPCQuery(ctx context.Context, req *abci.QueryReq
337289}
338290
339291// InitChain implements types.Application.
340- func (c * Consensus [T ]) InitChain (ctx context.Context , req * abciproto.InitChainRequest ) (* abciproto.InitChainResponse , error ) {
292+ func (c * consensus [T ]) InitChain (ctx context.Context , req * abciproto.InitChainRequest ) (* abciproto.InitChainResponse , error ) {
341293 c .logger .Info ("InitChain" , "initialHeight" , req .InitialHeight , "chainID" , req .ChainId )
342294
343295 // store chainID to be used later on in execution
@@ -421,7 +373,7 @@ func (c *Consensus[T]) InitChain(ctx context.Context, req *abciproto.InitChainRe
421373
422374// PrepareProposal implements types.Application.
423375// It is called by cometbft to prepare a proposal block.
424- func (c * Consensus [T ]) PrepareProposal (
376+ func (c * consensus [T ]) PrepareProposal (
425377 ctx context.Context ,
426378 req * abciproto.PrepareProposalRequest ,
427379) (resp * abciproto.PrepareProposalResponse , err error ) {
@@ -457,7 +409,7 @@ func (c *Consensus[T]) PrepareProposal(
457409
458410// ProcessProposal implements types.Application.
459411// It is called by cometbft to process/verify a proposal block.
460- func (c * Consensus [T ]) ProcessProposal (
412+ func (c * consensus [T ]) ProcessProposal (
461413 ctx context.Context ,
462414 req * abciproto.ProcessProposalRequest ,
463415) (* abciproto.ProcessProposalResponse , error ) {
@@ -491,7 +443,7 @@ func (c *Consensus[T]) ProcessProposal(
491443
492444// FinalizeBlock implements types.Application.
493445// It is called by cometbft to finalize a block.
494- func (c * Consensus [T ]) FinalizeBlock (
446+ func (c * consensus [T ]) FinalizeBlock (
495447 ctx context.Context ,
496448 req * abciproto.FinalizeBlockRequest ,
497449) (* abciproto.FinalizeBlockResponse , error ) {
@@ -581,7 +533,7 @@ func (c *Consensus[T]) FinalizeBlock(
581533
582534// Commit implements types.Application.
583535// It is called by cometbft to notify the application that a block was committed.
584- func (c * Consensus [T ]) Commit (ctx context.Context , _ * abciproto.CommitRequest ) (* abciproto.CommitResponse , error ) {
536+ func (c * consensus [T ]) Commit (ctx context.Context , _ * abciproto.CommitRequest ) (* abciproto.CommitResponse , error ) {
585537 lastCommittedHeight := c .lastCommittedHeight .Load ()
586538
587539 c .snapshotManager .SnapshotIfApplicable (lastCommittedHeight )
@@ -599,7 +551,7 @@ func (c *Consensus[T]) Commit(ctx context.Context, _ *abciproto.CommitRequest) (
599551// Vote extensions
600552
601553// VerifyVoteExtension implements types.Application.
602- func (c * Consensus [T ]) VerifyVoteExtension (
554+ func (c * consensus [T ]) VerifyVoteExtension (
603555 ctx context.Context ,
604556 req * abciproto.VerifyVoteExtensionRequest ,
605557) (* abciproto.VerifyVoteExtensionResponse , error ) {
@@ -641,7 +593,7 @@ func (c *Consensus[T]) VerifyVoteExtension(
641593}
642594
643595// ExtendVote implements types.Application.
644- func (c * Consensus [T ]) ExtendVote (ctx context.Context , req * abciproto.ExtendVoteRequest ) (* abciproto.ExtendVoteResponse , error ) {
596+ func (c * consensus [T ]) ExtendVote (ctx context.Context , req * abciproto.ExtendVoteRequest ) (* abciproto.ExtendVoteResponse , error ) {
645597 // If vote extensions are not enabled, as a safety precaution, we return an
646598 // error.
647599 cp , err := c .GetConsensusParams (ctx )
0 commit comments