@@ -2,7 +2,6 @@ package core
2
2
3
3
import (
4
4
"context"
5
- "errors"
6
5
"fmt"
7
6
"io"
8
7
"sync/atomic"
@@ -13,14 +12,13 @@ import (
13
12
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
14
13
coregrpc "github.com/tendermint/tendermint/rpc/grpc"
15
14
"github.com/tendermint/tendermint/types"
15
+ "google.golang.org/grpc"
16
16
17
17
libhead "github.com/celestiaorg/go-header"
18
18
)
19
19
20
20
const newBlockSubscriber = "NewBlock/Events"
21
21
22
- var ErrClientNotRunning = errors .New ("gRPC connection to core node is not running" )
23
-
24
22
type SignedBlock struct {
25
23
Header * types.Header `json:"header"`
26
24
Commit * types.Commit `json:"commit"`
@@ -34,17 +32,17 @@ var (
34
32
)
35
33
36
34
type BlockFetcher struct {
37
- client * Client
35
+ client coregrpc. BlockAPIClient
38
36
39
37
doneCh chan struct {}
40
38
cancel context.CancelFunc
41
39
isListeningForBlocks atomic.Bool
42
40
}
43
41
44
42
// NewBlockFetcher returns a new `BlockFetcher`.
45
- func NewBlockFetcher (client * Client ) (* BlockFetcher , error ) {
43
+ func NewBlockFetcher (conn * grpc. ClientConn ) (* BlockFetcher , error ) {
46
44
return & BlockFetcher {
47
- client : client ,
45
+ client : coregrpc . NewBlockAPIClient ( conn ) ,
48
46
}, nil
49
47
}
50
48
@@ -62,10 +60,6 @@ func (f *BlockFetcher) Stop(ctx context.Context) error {
62
60
63
61
// GetBlockInfo queries Core for additional block information, like Commit and ValidatorSet.
64
62
func (f * BlockFetcher ) GetBlockInfo (ctx context.Context , height int64 ) (* types.Commit , * types.ValidatorSet , error ) {
65
- // return error if the client is still not started
66
- if ! f .client .IsRunning () {
67
- return nil , nil , ErrClientNotRunning
68
- }
69
63
commit , err := f .Commit (ctx , height )
70
64
if err != nil {
71
65
return nil , nil , fmt .Errorf ("core/fetcher: getting commit at height %d: %w" , height , err )
@@ -87,10 +81,6 @@ func (f *BlockFetcher) GetBlockInfo(ctx context.Context, height int64) (*types.C
87
81
// GetBlock queries Core for a `Block` at the given height.
88
82
// if the height is nil, use the latest height
89
83
func (f * BlockFetcher ) GetBlock (ctx context.Context , height int64 ) (* SignedBlock , error ) {
90
- // return error if the client is still not started
91
- if ! f .client .IsRunning () {
92
- return nil , ErrClientNotRunning
93
- }
94
84
stream , err := f .client .BlockByHeight (ctx , & coregrpc.BlockByHeightRequest {Height : height })
95
85
if err != nil {
96
86
return nil , err
@@ -103,10 +93,6 @@ func (f *BlockFetcher) GetBlock(ctx context.Context, height int64) (*SignedBlock
103
93
}
104
94
105
95
func (f * BlockFetcher ) GetBlockByHash (ctx context.Context , hash libhead.Hash ) (* types.Block , error ) {
106
- // return error if the client is still not started
107
- if ! f .client .IsRunning () {
108
- return nil , ErrClientNotRunning
109
- }
110
96
if hash == nil {
111
97
return nil , fmt .Errorf ("cannot get block with nil hash" )
112
98
}
@@ -125,10 +111,6 @@ func (f *BlockFetcher) GetBlockByHash(ctx context.Context, hash libhead.Hash) (*
125
111
// GetSignedBlock queries Core for a `Block` at the given height.
126
112
// if the height is nil, use the latest height.
127
113
func (f * BlockFetcher ) GetSignedBlock (ctx context.Context , height int64 ) (* SignedBlock , error ) {
128
- // return error if the client is still not started
129
- if ! f .client .IsRunning () {
130
- return nil , ErrClientNotRunning
131
- }
132
114
stream , err := f .client .BlockByHeight (ctx , & coregrpc.BlockByHeightRequest {Height : height })
133
115
if err != nil {
134
116
return nil , err
@@ -140,10 +122,6 @@ func (f *BlockFetcher) GetSignedBlock(ctx context.Context, height int64) (*Signe
140
122
// the given height.
141
123
// If the height is nil, use the latest height.
142
124
func (f * BlockFetcher ) Commit (ctx context.Context , height int64 ) (* types.Commit , error ) {
143
- // return error if the client is still not started
144
- if ! f .client .IsRunning () {
145
- return nil , ErrClientNotRunning
146
- }
147
125
res , err := f .client .Commit (ctx , & coregrpc.CommitRequest {Height : height })
148
126
if err != nil {
149
127
return nil , err
@@ -165,10 +143,6 @@ func (f *BlockFetcher) Commit(ctx context.Context, height int64) (*types.Commit,
165
143
// block at the given height.
166
144
// If the height is nil, use the latest height.
167
145
func (f * BlockFetcher ) ValidatorSet (ctx context.Context , height int64 ) (* types.ValidatorSet , error ) {
168
- // return error if the client is still not started
169
- if ! f .client .IsRunning () {
170
- return nil , ErrClientNotRunning
171
- }
172
146
res , err := f .client .ValidatorSet (ctx , & coregrpc.ValidatorSetRequest {Height : height })
173
147
if err != nil {
174
148
return nil , err
@@ -189,10 +163,6 @@ func (f *BlockFetcher) ValidatorSet(ctx context.Context, height int64) (*types.V
189
163
// SubscribeNewBlockEvent subscribes to new block events from Core, returning
190
164
// a new block event channel on success.
191
165
func (f * BlockFetcher ) SubscribeNewBlockEvent (ctx context.Context ) (<- chan types.EventDataSignedBlock , error ) {
192
- // return error if the client is still not started
193
- if ! f .client .IsRunning () {
194
- return nil , ErrClientNotRunning
195
- }
196
166
if f .isListeningForBlocks .Load () {
197
167
return nil , fmt .Errorf ("already subscribed to new blocks" )
198
168
}
@@ -252,10 +222,6 @@ func (f *BlockFetcher) SubscribeNewBlockEvent(ctx context.Context) (<-chan types
252
222
// syncing, and false for already caught up. It can also return an error
253
223
// in the case of a failed status request.
254
224
func (f * BlockFetcher ) IsSyncing (ctx context.Context ) (bool , error ) {
255
- // return error if the client is still not started
256
- if ! f .client .IsRunning () {
257
- return false , ErrClientNotRunning
258
- }
259
225
resp , err := f .client .Status (ctx , & coregrpc.StatusRequest {})
260
226
if err != nil {
261
227
return false , err
0 commit comments