@@ -2,18 +2,21 @@ use std::collections::{HashMap, HashSet};
2
2
use std:: fmt:: { Display , Formatter } ;
3
3
use std:: ops:: Deref ;
4
4
use std:: path:: PathBuf ;
5
+ use std:: pin:: pin;
5
6
use std:: sync:: Arc ;
6
7
use std:: thread;
7
8
use anyhow:: { bail, Context } ;
8
- use futures:: { Stream , StreamExt } ;
9
+ use async_stream:: stream;
10
+ use futures:: { pin_mut, Stream , StreamExt } ;
9
11
use itertools:: { ExactlyOneError , Itertools } ;
10
12
11
13
use log:: { debug, error, info, warn} ;
12
14
use serde:: Serializer ;
15
+ use serde_json:: de:: Read ;
13
16
use solana_client:: nonblocking:: rpc_client:: RpcClient ;
14
17
use solana_sdk:: clock:: Slot ;
15
18
use solana_sdk:: commitment_config:: CommitmentConfig ;
16
- use tokio:: select;
19
+ use tokio:: { select} ;
17
20
use tokio:: sync:: broadcast:: { Receiver , Sender } ;
18
21
use tokio:: sync:: broadcast:: error:: TryRecvError ;
19
22
use tokio:: sync:: RwLock ;
@@ -71,8 +74,10 @@ async fn create_multiplex(
71
74
72
75
let jh = tokio:: spawn ( async move {
73
76
74
- let mut green = create_geyser_stream ( grpc_addr_mainnet_triton. clone ( ) , None ) . await ;
75
- let mut blue = create_geyser_stream ( grpc_addr_mainnet_ams81. clone ( ) , None ) . await ;
77
+ let mut green = create_geyser_stream2 ( grpc_addr_mainnet_triton. clone ( ) , None ) . await ;
78
+ let mut blue = create_geyser_stream2 ( grpc_addr_mainnet_ams81. clone ( ) , None ) . await ;
79
+ pin_mut ! ( green) ;
80
+ pin_mut ! ( blue) ;
76
81
77
82
let mut current_slot = 0 as Slot ;
78
83
@@ -83,8 +88,6 @@ async fn create_multiplex(
83
88
message = green. next( ) => {
84
89
match message {
85
90
Some ( message) => {
86
- // TODO tonic errors - pull up into create_geyser_stream
87
- let message = message. expect( "TODO what to do with tonic errors?" ) ;
88
91
map_filter_block_message( current_slot, message, commitment_config)
89
92
}
90
93
None => {
@@ -96,8 +99,6 @@ async fn create_multiplex(
96
99
message = blue. next( ) => {
97
100
match message {
98
101
Some ( message) => {
99
- // TODO tonic errors
100
- let message = message. expect( "TODO what to do with tonic errors?" ) ;
101
102
map_filter_block_message( current_slot, message, commitment_config)
102
103
}
103
104
None => {
@@ -128,6 +129,7 @@ async fn create_multiplex(
128
129
return jh;
129
130
}
130
131
132
+ #[ derive( Debug ) ]
131
133
enum BlockCmd {
132
134
ForwardBlock ( ProducedBlock ) ,
133
135
DiscardBlockBehindTip ( Slot ) ,
@@ -166,7 +168,7 @@ async fn create_geyser_stream(grpc_addr: String, x_token: Option<String>) -> imp
166
168
} ,
167
169
) ;
168
170
169
- let mut stream = client
171
+ let stream = client
170
172
. subscribe_once (
171
173
HashMap :: new ( ) ,
172
174
Default :: default ( ) ,
@@ -182,4 +184,54 @@ async fn create_geyser_stream(grpc_addr: String, x_token: Option<String>) -> imp
182
184
183
185
// TODO pull tonic error handling inside this method
184
186
return stream;
185
- }
187
+ }
188
+
189
+ async fn create_geyser_stream2 ( grpc_addr : String , x_token : Option < String > ) -> impl Stream < Item = SubscribeUpdate > {
190
+
191
+
192
+ let mut client = GeyserGrpcClient :: connect ( grpc_addr, x_token, None ) . unwrap ( ) ;
193
+
194
+ let mut blocks_subs = HashMap :: new ( ) ;
195
+ blocks_subs. insert (
196
+ "client" . to_string ( ) ,
197
+ SubscribeRequestFilterBlocks {
198
+ account_include : Default :: default ( ) ,
199
+ include_transactions : Some ( true ) ,
200
+ include_accounts : Some ( false ) ,
201
+ include_entries : Some ( false ) ,
202
+ } ,
203
+ ) ;
204
+
205
+ let stream = client
206
+ . subscribe_once (
207
+ HashMap :: new ( ) ,
208
+ Default :: default ( ) ,
209
+ HashMap :: new ( ) ,
210
+ Default :: default ( ) ,
211
+ blocks_subs,
212
+ Default :: default ( ) ,
213
+ Some ( CommitmentLevel :: Confirmed ) ,
214
+ Default :: default ( ) ,
215
+ None ,
216
+ ) . await . unwrap ( ) ;
217
+
218
+ stream ! {
219
+
220
+ for await update_message in stream {
221
+
222
+ match update_message {
223
+ Ok ( update_message) => {
224
+ yield update_message;
225
+ }
226
+ Err ( status) => {
227
+ error!( ">stream: {:?}" , status) ;
228
+ }
229
+ }
230
+
231
+ }
232
+
233
+ }
234
+
235
+
236
+
237
+ }
0 commit comments