6
6
api_client:: { ApiClient , Observation } ,
7
7
borsh:: BorshDeserialize ,
8
8
clap:: Parser ,
9
+ futures:: future:: join_all,
9
10
posted_message:: PostedMessageUnreliableData ,
10
11
prost:: Message ,
11
12
secp256k1:: { rand:: rngs:: OsRng , Secp256k1 } ,
@@ -41,7 +42,7 @@ struct RunListenerInput<T: Signer> {
41
42
signer : T ,
42
43
wormhole_pid : Pubkey ,
43
44
accumulator_address : Pubkey ,
44
- api_client : ApiClient ,
45
+ api_clients : Vec < ApiClient > ,
45
46
}
46
47
47
48
fn find_message_pda ( wormhole_pid : & Pubkey , slot : u64 ) -> Pubkey {
@@ -148,16 +149,22 @@ async fn run_listener<T: Signer + 'static>(
148
149
} ;
149
150
150
151
tokio:: spawn ( {
151
- let ( api_client , signer) = ( input. api_client . clone ( ) , input. signer . clone ( ) ) ;
152
+ let ( api_clients , signer) = ( input. api_clients . clone ( ) , input. signer . clone ( ) ) ;
152
153
async move {
153
154
let body = message_data_to_body ( & unreliable_data) ;
154
155
match Observation :: try_new ( body. clone ( ) , signer. clone ( ) ) {
155
156
Ok ( observation) => {
156
- if let Err ( e) = api_client. post_observation ( observation) . await {
157
- tracing:: error!( error = ?e, "Failed to post observation" ) ;
158
- } else {
159
- tracing:: info!( "Observation posted successfully" ) ;
160
- } ;
157
+ join_all ( api_clients. iter ( ) . map ( |api_client| {
158
+ let observation = observation. clone ( ) ;
159
+ let api_client = api_client. clone ( ) ;
160
+ async move {
161
+ if let Err ( e) = api_client. post_observation ( observation) . await {
162
+ tracing:: warn!( url = api_client. get_base_url( ) . to_string( ) , error = ?e, "Failed to post observation" ) ;
163
+ } else {
164
+ tracing:: info!( url = api_client. get_base_url( ) . to_string( ) , "Observation posted successfully" ) ;
165
+ }
166
+ }
167
+ } ) ) . await ;
161
168
}
162
169
Err ( e) => tracing:: error!( error = ?e, "Failed to create observation" ) ,
163
170
}
@@ -182,8 +189,13 @@ async fn run(run_options: config::RunOptions) {
182
189
. expect ( "Invalid accumulator address" ) ;
183
190
let wormhole_pid =
184
191
Pubkey :: from_str ( & run_options. wormhole_pid ) . expect ( "Invalid Wormhole program ID" ) ;
185
- let api_client =
186
- ApiClient :: try_new ( run_options. server_url , None ) . expect ( "Failed to create API client" ) ;
192
+ let api_clients: Vec < ApiClient > = run_options
193
+ . server_urls
194
+ . into_iter ( )
195
+ . map ( |server_url| {
196
+ ApiClient :: try_new ( server_url, None ) . expect ( "Failed to create API client" )
197
+ } )
198
+ . collect ( ) ;
187
199
188
200
let ( pubkey, pubkey_evm) = signer. get_public_key ( ) . expect ( "Failed to get public key" ) ;
189
201
let evm_encded_public_key = format ! ( "0x{}" , hex:: encode( pubkey_evm) ) ;
@@ -199,7 +211,7 @@ async fn run(run_options: config::RunOptions) {
199
211
signer : signer. clone ( ) ,
200
212
wormhole_pid,
201
213
accumulator_address,
202
- api_client : api_client . clone ( ) ,
214
+ api_clients : api_clients . clone ( ) ,
203
215
} )
204
216
. await
205
217
{
0 commit comments