@@ -11,7 +11,7 @@ import (
11
11
cmtquery "github.com/cometbft/cometbft/libs/pubsub/query"
12
12
cmtp2p "github.com/cometbft/cometbft/p2p"
13
13
cmtcrypto "github.com/cometbft/cometbft/proto/tendermint/crypto"
14
- cmtrpctypes "github.com/cometbft/cometbft/rpc/core/types"
14
+ cmtcoretypes "github.com/cometbft/cometbft/rpc/core/types"
15
15
cmttypes "github.com/cometbft/cometbft/types"
16
16
17
17
beacon "github.com/oasisprotocol/oasis-core/go/beacon/api"
@@ -20,7 +20,6 @@ import (
20
20
"github.com/oasisprotocol/oasis-core/go/common/crypto/hash"
21
21
"github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
22
22
"github.com/oasisprotocol/oasis-core/go/common/node"
23
- "github.com/oasisprotocol/oasis-core/go/common/pubsub"
24
23
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
25
24
"github.com/oasisprotocol/oasis-core/go/consensus/api/events"
26
25
"github.com/oasisprotocol/oasis-core/go/consensus/api/transaction"
@@ -157,8 +156,7 @@ func QueryForApp(eventApp string) cmtpubsub.Query {
157
156
return cmtquery .MustParse (fmt .Sprintf ("%s EXISTS" , EventTypeForApp (eventApp )))
158
157
}
159
158
160
- // BlockMeta is the CometBFT-specific per-block metadata that is
161
- // exposed via the consensus API.
159
+ // BlockMeta is the CometBFT-specific per-block metadata.
162
160
type BlockMeta struct {
163
161
// Header is the CometBFT block header.
164
162
Header * cmttypes.Header `json:"header"`
@@ -199,20 +197,85 @@ func NewBlock(blk *cmttypes.Block) *consensus.Block {
199
197
}
200
198
}
201
199
202
- // Backend is a CometBFT consensus backend.
203
- type Backend interface {
204
- consensus.Backend
200
+ // BlockResults are CometBFT-specific consensus block results.
201
+ type BlockResults struct {
202
+ // Height contains the block height.
203
+ Height int64 `json:"height"`
204
+ // Meta contains the block results metadata.
205
+ Meta * BlockResultsMeta `json:"meta"`
206
+ }
207
+
208
+ // BlockResultsMeta is the CometBFT-specific per-block results metadata.
209
+ type BlockResultsMeta struct {
210
+ TxsResults []* types.ResponseDeliverTx `json:"txs_results"`
211
+ BeginBlockEvents []types.Event `json:"begin_block_events"`
212
+ EndBlockEvents []types.Event `json:"end_block_events"`
213
+ }
214
+
215
+ // NewBlockResultsMeta converts consensus results into CometBFT-specific block
216
+ // results metadata.
217
+ func NewBlockResultsMeta (results * consensus.BlockResults ) (* BlockResultsMeta , error ) {
218
+ var meta BlockResultsMeta
219
+ if err := cbor .Unmarshal (results .Meta , & meta ); err != nil {
220
+ return nil , fmt .Errorf ("malformed block results metadata: %w" , err )
221
+ }
222
+
223
+ return & meta , nil
224
+ }
225
+
226
+ // NewBlockResults converts CometBFT-specific block results into consensus results.
227
+ func NewBlockResults (results * cmtcoretypes.ResultBlockResults ) * consensus.BlockResults {
228
+ meta := BlockResultsMeta {
229
+ TxsResults : results .TxsResults ,
230
+ BeginBlockEvents : results .BeginBlockEvents ,
231
+ EndBlockEvents : results .EndBlockEvents ,
232
+ }
233
+
234
+ return & consensus.BlockResults {
235
+ Height : results .Height ,
236
+ Meta : cbor .Marshal (meta ),
237
+ }
238
+ }
205
239
206
- // GetCometBFTBlock returns the CometBFT block at the specified height.
207
- GetCometBFTBlock (ctx context.Context , height int64 ) (* cmttypes.Block , error )
240
+ // GetBlockResults returns CometBFT-specific block results at the given height.
241
+ func GetBlockResults (ctx context.Context , height int64 , consensus consensus.Backend ) (* BlockResults , error ) {
242
+ // Optimize for CometBTF-specific consensus backends.
243
+ if cmt , ok := consensus .(Backend ); ok {
244
+ results , err := cmt .GetCometBFTBlockResults (ctx , height )
245
+ if err != nil {
246
+ return nil , err
247
+ }
248
+ return & BlockResults {
249
+ Height : results .Height ,
250
+ Meta : & BlockResultsMeta {
251
+ TxsResults : results .TxsResults ,
252
+ BeginBlockEvents : results .BeginBlockEvents ,
253
+ EndBlockEvents : results .EndBlockEvents ,
254
+ },
255
+ }, nil
256
+
257
+ }
208
258
259
+ results , err := consensus .GetBlockResults (ctx , height )
260
+ if err != nil {
261
+ return nil , err
262
+ }
263
+ meta , err := NewBlockResultsMeta (results )
264
+ if err != nil {
265
+ return nil , err
266
+ }
267
+
268
+ return & BlockResults {
269
+ Height : results .Height ,
270
+ Meta : meta ,
271
+ }, nil
272
+ }
273
+
274
+ // Backend is a CometBFT-specific consensus backend.
275
+ type Backend interface {
209
276
// GetCometBFTBlockResults returns the ABCI results from processing a block
210
277
// at a specific height.
211
- GetCometBFTBlockResults (ctx context.Context , height int64 ) (* cmtrpctypes.ResultBlockResults , error )
212
-
213
- // WatchCometBFTBlocks returns a stream of CometBFT blocks as they are
214
- // returned via the `EventDataNewBlock` query.
215
- WatchCometBFTBlocks () (<- chan * cmttypes.Block , * pubsub.Subscription , error )
278
+ GetCometBFTBlockResults (ctx context.Context , height int64 ) (* cmtcoretypes.ResultBlockResults , error )
216
279
}
217
280
218
281
// HaltHook is a function that gets called when consensus needs to halt for some reason.
@@ -297,8 +360,8 @@ type ServiceClient interface {
297
360
// ServiceDescriptor returns the consensus service descriptor.
298
361
ServiceDescriptor () ServiceDescriptor
299
362
300
- // DeliverBlock delivers a new block.
301
- DeliverBlock (ctx context.Context , blk * cmttypes. Block ) error
363
+ // DeliverHeight delivers a new block height .
364
+ DeliverHeight (ctx context.Context , height int64 ) error
302
365
303
366
// DeliverEvent delivers an event emitted by the consensus service.
304
367
DeliverEvent (ctx context.Context , height int64 , tx cmttypes.Tx , ev * types.Event ) error
@@ -308,8 +371,8 @@ type ServiceClient interface {
308
371
// all the delivery methods. Implementations should override them as needed.
309
372
type BaseServiceClient struct {}
310
373
311
- // DeliverBlock implements ServiceClient.
312
- func (bsc * BaseServiceClient ) DeliverBlock (context.Context , * cmttypes. Block ) error {
374
+ // DeliverHeight implements ServiceClient.
375
+ func (bsc * BaseServiceClient ) DeliverHeight (context.Context , int64 ) error {
313
376
return nil
314
377
}
315
378
0 commit comments