@@ -6,14 +6,10 @@ import (
6
6
"errors"
7
7
"fmt"
8
8
"strings"
9
- "sync"
10
9
"sync/atomic"
11
10
12
11
abci "github.com/cometbft/cometbft/abci/types"
13
12
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"
17
13
gogoproto "github.com/cosmos/gogoproto/proto"
18
14
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
19
15
"google.golang.org/protobuf/reflect/protoregistry"
@@ -37,6 +33,11 @@ import (
37
33
"cosmossdk.io/server/v2/streaming"
38
34
"cosmossdk.io/store/v2/snapshots"
39
35
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"
40
41
)
41
42
42
43
const (
@@ -45,22 +46,24 @@ const (
45
46
QueryPathStore = "store"
46
47
)
47
48
48
- var _ abci.Application = (* Consensus [transaction.Tx ])(nil )
49
+ var _ abci.Application = (* consensus [transaction.Tx ])(nil )
49
50
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 {
51
53
logger log.Logger
52
54
appName , version string
53
55
app appmanager.AppManager [T ]
56
+ appCodec codec.Codec
54
57
txCodec transaction.Codec [T ]
55
58
store types.Store
56
- streaming streaming.Manager
57
59
listener * appdata.Listener
58
60
snapshotManager * snapshots.Manager
61
+ streamingManager streaming.Manager
59
62
mempool mempool.Mempool [T ]
60
63
61
64
cfg Config
62
- indexedEvents map [string ]struct {}
63
65
chainID string
66
+ indexedEvents map [string ]struct {}
64
67
65
68
initialHeight uint64
66
69
// this is only available after this node has committed a block (in FinalizeBlock),
@@ -81,60 +84,9 @@ type Consensus[T transaction.Tx] struct {
81
84
getProtoRegistry func () (* protoregistry.Files , error )
82
85
}
83
86
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
-
135
87
// CheckTx implements types.Application.
136
88
// 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 ) {
138
90
decodedTx , err := c .txCodec .Decode (req .Tx )
139
91
if err != nil {
140
92
return nil , err
@@ -172,7 +124,7 @@ func (c *Consensus[T]) CheckTx(ctx context.Context, req *abciproto.CheckTxReques
172
124
}
173
125
174
126
// 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 ) {
176
128
version , _ , err := c .store .StateLatest ()
177
129
if err != nil {
178
130
return nil , err
@@ -212,7 +164,7 @@ func (c *Consensus[T]) Info(ctx context.Context, _ *abciproto.InfoRequest) (*abc
212
164
213
165
// Query implements types.Application.
214
166
// 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 ) {
216
168
resp , isGRPC , err := c .maybeRunGRPCQuery (ctx , req )
217
169
if isGRPC {
218
170
return resp , err
@@ -227,7 +179,7 @@ func (c *Consensus[T]) Query(ctx context.Context, req *abciproto.QueryRequest) (
227
179
228
180
switch path [0 ] {
229
181
case QueryPathApp :
230
- resp , err = c .handlerQueryApp (ctx , path , req )
182
+ resp , err = c .handleQueryApp (ctx , path , req )
231
183
232
184
case QueryPathStore :
233
185
resp , err = c .handleQueryStore (path , req )
@@ -246,7 +198,7 @@ func (c *Consensus[T]) Query(ctx context.Context, req *abciproto.QueryRequest) (
246
198
return resp , nil
247
199
}
248
200
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 ) {
250
202
// if this fails then we cannot serve queries anymore
251
203
registry , err := c .getProtoRegistry ()
252
204
if err != nil {
@@ -288,7 +240,7 @@ func (c *Consensus[T]) maybeRunGRPCQuery(ctx context.Context, req *abci.QueryReq
288
240
289
241
txResult , _ , err := c .app .Simulate (ctx , tx )
290
242
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 )
292
244
}
293
245
294
246
msgResponses := make ([]* codectypes.Any , 0 , len (txResult .Resp ))
@@ -337,7 +289,7 @@ func (c *Consensus[T]) maybeRunGRPCQuery(ctx context.Context, req *abci.QueryReq
337
289
}
338
290
339
291
// 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 ) {
341
293
c .logger .Info ("InitChain" , "initialHeight" , req .InitialHeight , "chainID" , req .ChainId )
342
294
343
295
// store chainID to be used later on in execution
@@ -421,7 +373,7 @@ func (c *Consensus[T]) InitChain(ctx context.Context, req *abciproto.InitChainRe
421
373
422
374
// PrepareProposal implements types.Application.
423
375
// It is called by cometbft to prepare a proposal block.
424
- func (c * Consensus [T ]) PrepareProposal (
376
+ func (c * consensus [T ]) PrepareProposal (
425
377
ctx context.Context ,
426
378
req * abciproto.PrepareProposalRequest ,
427
379
) (resp * abciproto.PrepareProposalResponse , err error ) {
@@ -457,7 +409,7 @@ func (c *Consensus[T]) PrepareProposal(
457
409
458
410
// ProcessProposal implements types.Application.
459
411
// It is called by cometbft to process/verify a proposal block.
460
- func (c * Consensus [T ]) ProcessProposal (
412
+ func (c * consensus [T ]) ProcessProposal (
461
413
ctx context.Context ,
462
414
req * abciproto.ProcessProposalRequest ,
463
415
) (* abciproto.ProcessProposalResponse , error ) {
@@ -491,7 +443,7 @@ func (c *Consensus[T]) ProcessProposal(
491
443
492
444
// FinalizeBlock implements types.Application.
493
445
// It is called by cometbft to finalize a block.
494
- func (c * Consensus [T ]) FinalizeBlock (
446
+ func (c * consensus [T ]) FinalizeBlock (
495
447
ctx context.Context ,
496
448
req * abciproto.FinalizeBlockRequest ,
497
449
) (* abciproto.FinalizeBlockResponse , error ) {
@@ -581,7 +533,7 @@ func (c *Consensus[T]) FinalizeBlock(
581
533
582
534
// Commit implements types.Application.
583
535
// 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 ) {
585
537
lastCommittedHeight := c .lastCommittedHeight .Load ()
586
538
587
539
c .snapshotManager .SnapshotIfApplicable (lastCommittedHeight )
@@ -599,7 +551,7 @@ func (c *Consensus[T]) Commit(ctx context.Context, _ *abciproto.CommitRequest) (
599
551
// Vote extensions
600
552
601
553
// VerifyVoteExtension implements types.Application.
602
- func (c * Consensus [T ]) VerifyVoteExtension (
554
+ func (c * consensus [T ]) VerifyVoteExtension (
603
555
ctx context.Context ,
604
556
req * abciproto.VerifyVoteExtensionRequest ,
605
557
) (* abciproto.VerifyVoteExtensionResponse , error ) {
@@ -641,7 +593,7 @@ func (c *Consensus[T]) VerifyVoteExtension(
641
593
}
642
594
643
595
// 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 ) {
645
597
// If vote extensions are not enabled, as a safety precaution, we return an
646
598
// error.
647
599
cp , err := c .GetConsensusParams (ctx )
0 commit comments