1
1
#[ allow( deprecated) ]
2
2
use crate :: agent:: legacy_schedule:: LegacySchedule ;
3
3
use {
4
- super :: {
5
- super :: solana:: network:: Network ,
6
- exporter:: Exporter ,
7
- } ,
4
+ super :: { super :: solana:: network:: Network , exporter:: Exporter } ,
8
5
crate :: agent:: {
9
6
market_schedule:: MarketSchedule ,
10
- state:: {
11
- global:: Update ,
12
- Prices ,
13
- State ,
14
- } ,
15
- } ,
16
- anyhow:: {
17
- anyhow,
18
- Context ,
19
- Result ,
7
+ state:: { global:: Update , Prices , State } ,
20
8
} ,
9
+ anyhow:: { anyhow, Context , Result } ,
21
10
pyth_sdk_solana:: state:: {
22
- load_mapping_account,
23
- load_product_account,
24
- GenericPriceAccount ,
25
- MappingAccount ,
26
- PriceComp ,
27
- PythnetPriceAccount ,
28
- SolanaPriceAccount ,
29
- } ,
30
- serde:: {
31
- Deserialize ,
32
- Serialize ,
11
+ load_mapping_account, load_product_account, GenericPriceAccount , MappingAccount , PriceComp ,
12
+ PythnetPriceAccount , SolanaPriceAccount ,
33
13
} ,
14
+ serde:: { Deserialize , Serialize } ,
34
15
solana_client:: nonblocking:: rpc_client:: RpcClient ,
35
16
solana_sdk:: {
36
- account:: Account ,
37
- commitment_config:: CommitmentLevel ,
38
- pubkey:: Pubkey ,
39
- signature:: Keypair ,
17
+ account:: Account , commitment_config:: CommitmentLevel , pubkey:: Pubkey , signature:: Keypair ,
40
18
} ,
41
19
std:: {
42
- collections:: {
43
- HashMap ,
44
- HashSet ,
45
- } ,
20
+ collections:: { HashMap , HashSet } ,
46
21
time:: Duration ,
47
22
} ,
48
23
tokio:: sync:: RwLock ,
@@ -51,15 +26,15 @@ use {
51
26
52
27
#[ derive( Debug , Clone ) ]
53
28
pub struct ProductEntry {
54
- pub account_data : pyth_sdk_solana:: state:: ProductAccount ,
55
- pub schedule : MarketSchedule ,
56
- pub price_accounts : Vec < Pubkey > ,
29
+ pub account_data : pyth_sdk_solana:: state:: ProductAccount ,
30
+ pub schedule : MarketSchedule ,
31
+ pub price_accounts : Vec < Pubkey > ,
57
32
pub publish_interval : Option < Duration > ,
58
33
}
59
34
60
35
#[ derive( Default , Debug , Clone ) ]
61
36
pub struct PricePublishingMetadata {
62
- pub schedule : MarketSchedule ,
37
+ pub schedule : MarketSchedule ,
63
38
pub publish_interval : Option < Duration > ,
64
39
}
65
40
@@ -77,7 +52,7 @@ pub struct PricePublishingMetadata {
77
52
#[ derive( Copy , Clone , Debug ) ]
78
53
pub struct PriceEntry {
79
54
// We intentionally act as if we have a truncated account where the underlying memory is unavailable.
80
- account : GenericPriceAccount < 0 , ( ) > ,
55
+ account : GenericPriceAccount < 0 , ( ) > ,
81
56
pub comp : [ PriceComp ; 64 ] ,
82
57
}
83
58
@@ -129,9 +104,9 @@ impl std::ops::Deref for PriceEntry {
129
104
130
105
#[ derive( Default , Debug , Clone ) ]
131
106
pub struct Data {
132
- pub mapping_accounts : HashMap < Pubkey , MappingAccount > ,
133
- pub product_accounts : HashMap < Pubkey , ProductEntry > ,
134
- pub price_accounts : HashMap < Pubkey , PriceEntry > ,
107
+ pub mapping_accounts : HashMap < Pubkey , MappingAccount > ,
108
+ pub product_accounts : HashMap < Pubkey , ProductEntry > ,
109
+ pub price_accounts : HashMap < Pubkey , PriceEntry > ,
135
110
/// publisher => {their permissioned price accounts => price publishing metadata}
136
111
pub publisher_permissions : HashMap < Pubkey , HashMap < Pubkey , PricePublishingMetadata > > ,
137
112
}
@@ -140,16 +115,16 @@ pub struct Data {
140
115
#[ serde( default ) ]
141
116
pub struct Config {
142
117
/// The commitment level to use when reading data from the RPC node.
143
- pub commitment : CommitmentLevel ,
118
+ pub commitment : CommitmentLevel ,
144
119
/// The interval with which to poll account information.
145
120
#[ serde( with = "humantime_serde" ) ]
146
- pub poll_interval_duration : Duration ,
121
+ pub poll_interval_duration : Duration ,
147
122
/// Whether subscribing to account updates over websocket is enabled
148
- pub subscriber_enabled : bool ,
123
+ pub subscriber_enabled : bool ,
149
124
/// Capacity of the channel over which the Subscriber sends updates to the Oracle
150
125
pub updates_channel_capacity : usize ,
151
126
/// Capacity of the channel over which the Poller sends data to the Oracle
152
- pub data_channel_capacity : usize ,
127
+ pub data_channel_capacity : usize ,
153
128
154
129
/// Ask the RPC for up to this many product/price accounts in a
155
130
/// single request. Tune this setting if you're experiencing
@@ -162,12 +137,12 @@ pub struct Config {
162
137
impl Default for Config {
163
138
fn default ( ) -> Self {
164
139
Self {
165
- commitment : CommitmentLevel :: Confirmed ,
166
- poll_interval_duration : Duration :: from_secs ( 5 ) ,
167
- subscriber_enabled : true ,
140
+ commitment : CommitmentLevel :: Confirmed ,
141
+ poll_interval_duration : Duration :: from_secs ( 5 ) ,
142
+ subscriber_enabled : true ,
168
143
updates_channel_capacity : 10000 ,
169
- data_channel_capacity : 10000 ,
170
- max_lookup_batch_size : 100 ,
144
+ data_channel_capacity : 10000 ,
145
+ max_lookup_batch_size : 100 ,
171
146
}
172
147
}
173
148
}
@@ -178,6 +153,7 @@ pub struct OracleState {
178
153
179
154
impl OracleState {
180
155
pub fn new ( ) -> Self {
156
+ tracing:: info!( "Initializing OracleState" ) ;
181
157
Self {
182
158
data : Default :: default ( ) ,
183
159
}
@@ -232,6 +208,7 @@ where
232
208
// We are only interested in price account updates, all other types of updates
233
209
// will be fetched using polling.
234
210
if !data. price_accounts . contains_key ( account_key) {
211
+ tracing:: info!( "Account key not found in price accounts, skipping update." ) ;
235
212
return Ok ( ( ) ) ;
236
213
}
237
214
@@ -247,13 +224,14 @@ where
247
224
) ;
248
225
249
226
data. price_accounts . insert ( * account_key, price_entry) ;
227
+ tracing:: info!( "Updated price account for key: {}" , account_key) ;
250
228
251
229
Prices :: update_global_price (
252
230
self ,
253
231
network,
254
232
& Update :: PriceAccountUpdate {
255
233
account_key : * account_key,
256
- account : price_entry,
234
+ account : price_entry,
257
235
} ,
258
236
)
259
237
. await ?;
@@ -271,14 +249,17 @@ where
271
249
rpc_client : & RpcClient ,
272
250
max_lookup_batch_size : usize ,
273
251
) -> Result < ( ) > {
252
+ tracing:: info!( "Polling updates for network: {:?}" , network) ;
274
253
let mut publisher_permissions = HashMap :: new ( ) ;
275
254
let mapping_accounts = fetch_mapping_accounts ( rpc_client, mapping_key) . await ?;
255
+ tracing:: info!( "Fetched mapping accounts." ) ;
276
256
let ( product_accounts, price_accounts) = fetch_product_and_price_accounts (
277
257
rpc_client,
278
258
max_lookup_batch_size,
279
259
mapping_accounts. values ( ) ,
280
260
)
281
261
. await ?;
262
+ tracing:: info!( "Fetched product and price accounts." ) ;
282
263
283
264
for ( price_key, price_entry) in price_accounts. iter ( ) {
284
265
for component in price_entry. comp {
@@ -294,7 +275,7 @@ where
294
275
product_accounts. get ( & price_entry. prod )
295
276
{
296
277
PricePublishingMetadata {
297
- schedule : prod_entry. schedule . clone ( ) ,
278
+ schedule : prod_entry. schedule . clone ( ) ,
298
279
publish_interval : prod_entry. publish_interval ,
299
280
}
300
281
} else {
@@ -320,6 +301,7 @@ where
320
301
let mut data = self . into ( ) . data . write ( ) . await ;
321
302
log_data_diff ( & data, & new_data) ;
322
303
* data = new_data;
304
+ tracing:: info!( "Updated OracleState data." ) ;
323
305
324
306
Exporter :: update_permissions (
325
307
self ,
@@ -335,6 +317,7 @@ where
335
317
/// Sync Product/Price Accounts found by polling to the Global Store.
336
318
#[ instrument( skip( self ) ) ]
337
319
async fn sync_global_store ( & self , network : Network ) -> Result < ( ) > {
320
+ tracing:: info!( "Syncing global store for network: {:?}" , network) ;
338
321
for ( product_account_key, product_account) in
339
322
& self . into ( ) . data . read ( ) . await . product_accounts
340
323
{
@@ -343,7 +326,7 @@ where
343
326
network,
344
327
& Update :: ProductAccountUpdate {
345
328
account_key : * product_account_key,
346
- account : product_account. clone ( ) ,
329
+ account : product_account. clone ( ) ,
347
330
} ,
348
331
)
349
332
. await
@@ -356,13 +339,14 @@ where
356
339
network,
357
340
& Update :: PriceAccountUpdate {
358
341
account_key : * price_account_key,
359
- account : * price_account,
342
+ account : * price_account,
360
343
} ,
361
344
)
362
345
. await
363
346
. map_err ( |_| anyhow ! ( "failed to notify price account update" ) ) ?;
364
347
}
365
348
349
+ tracing:: info!( "Global store sync completed." ) ;
366
350
Ok ( ( ) )
367
351
}
368
352
}
@@ -372,6 +356,10 @@ async fn fetch_mapping_accounts(
372
356
rpc_client : & RpcClient ,
373
357
mapping_account_key : Pubkey ,
374
358
) -> Result < HashMap < Pubkey , MappingAccount > > {
359
+ tracing:: info!(
360
+ "Fetching mapping accounts starting from key: {}" ,
361
+ mapping_account_key
362
+ ) ;
375
363
let mut accounts = HashMap :: new ( ) ;
376
364
let mut account_key = mapping_account_key;
377
365
while account_key != Pubkey :: default ( ) {
@@ -384,6 +372,7 @@ async fn fetch_mapping_accounts(
384
372
accounts. insert ( account_key, account) ;
385
373
account_key = account. next ;
386
374
}
375
+ tracing:: info!( "Fetched {} mapping accounts." , accounts. len( ) ) ;
387
376
Ok ( accounts)
388
377
}
389
378
@@ -396,6 +385,7 @@ async fn fetch_product_and_price_accounts<'a, A>(
396
385
where
397
386
A : IntoIterator < Item = & ' a MappingAccount > ,
398
387
{
388
+ tracing:: info!( "Fetching product and price accounts." ) ;
399
389
let mut product_keys = vec ! [ ] ;
400
390
401
391
// Get all product keys
@@ -421,13 +411,19 @@ where
421
411
price_entries. extend ( batch_prices. drain ( ) ) ;
422
412
}
423
413
414
+ tracing:: info!(
415
+ "Fetched {} product entries and {} price entries." ,
416
+ product_entries. len( ) ,
417
+ price_entries. len( )
418
+ ) ;
424
419
Ok ( ( product_entries, price_entries) )
425
420
}
426
421
427
422
async fn fetch_batch_of_product_and_price_accounts (
428
423
rpc_client : & RpcClient ,
429
424
product_key_batch : & [ Pubkey ] ,
430
425
) -> Result < ( HashMap < Pubkey , ProductEntry > , HashMap < Pubkey , PriceEntry > ) > {
426
+ tracing:: info!( "Fetching batch of product and price accounts." ) ;
431
427
let mut product_entries = HashMap :: new ( ) ;
432
428
433
429
let product_keys = product_key_batch;
@@ -568,6 +564,7 @@ async fn fetch_batch_of_product_and_price_accounts(
568
564
569
565
todo = next_todo;
570
566
}
567
+ tracing:: info!( "Fetched batch of product and price accounts." ) ;
571
568
Ok ( ( product_entries, price_entries) )
572
569
}
573
570
0 commit comments