Skip to content

Commit cb0fb12

Browse files
committed
add more traces to oracle state
1 parent a62a623 commit cb0fb12

File tree

1 file changed

+51
-54
lines changed

1 file changed

+51
-54
lines changed

src/agent/state/oracle.rs

Lines changed: 51 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,23 @@
11
#[allow(deprecated)]
22
use crate::agent::legacy_schedule::LegacySchedule;
33
use {
4-
super::{
5-
super::solana::network::Network,
6-
exporter::Exporter,
7-
},
4+
super::{super::solana::network::Network, exporter::Exporter},
85
crate::agent::{
96
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},
208
},
9+
anyhow::{anyhow, Context, Result},
2110
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,
3313
},
14+
serde::{Deserialize, Serialize},
3415
solana_client::nonblocking::rpc_client::RpcClient,
3516
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,
4018
},
4119
std::{
42-
collections::{
43-
HashMap,
44-
HashSet,
45-
},
20+
collections::{HashMap, HashSet},
4621
time::Duration,
4722
},
4823
tokio::sync::RwLock,
@@ -51,15 +26,15 @@ use {
5126

5227
#[derive(Debug, Clone)]
5328
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>,
5732
pub publish_interval: Option<Duration>,
5833
}
5934

6035
#[derive(Default, Debug, Clone)]
6136
pub struct PricePublishingMetadata {
62-
pub schedule: MarketSchedule,
37+
pub schedule: MarketSchedule,
6338
pub publish_interval: Option<Duration>,
6439
}
6540

@@ -77,7 +52,7 @@ pub struct PricePublishingMetadata {
7752
#[derive(Copy, Clone, Debug)]
7853
pub struct PriceEntry {
7954
// We intentionally act as if we have a truncated account where the underlying memory is unavailable.
80-
account: GenericPriceAccount<0, ()>,
55+
account: GenericPriceAccount<0, ()>,
8156
pub comp: [PriceComp; 64],
8257
}
8358

@@ -129,9 +104,9 @@ impl std::ops::Deref for PriceEntry {
129104

130105
#[derive(Default, Debug, Clone)]
131106
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>,
135110
/// publisher => {their permissioned price accounts => price publishing metadata}
136111
pub publisher_permissions: HashMap<Pubkey, HashMap<Pubkey, PricePublishingMetadata>>,
137112
}
@@ -140,16 +115,16 @@ pub struct Data {
140115
#[serde(default)]
141116
pub struct Config {
142117
/// The commitment level to use when reading data from the RPC node.
143-
pub commitment: CommitmentLevel,
118+
pub commitment: CommitmentLevel,
144119
/// The interval with which to poll account information.
145120
#[serde(with = "humantime_serde")]
146-
pub poll_interval_duration: Duration,
121+
pub poll_interval_duration: Duration,
147122
/// Whether subscribing to account updates over websocket is enabled
148-
pub subscriber_enabled: bool,
123+
pub subscriber_enabled: bool,
149124
/// Capacity of the channel over which the Subscriber sends updates to the Oracle
150125
pub updates_channel_capacity: usize,
151126
/// 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,
153128

154129
/// Ask the RPC for up to this many product/price accounts in a
155130
/// single request. Tune this setting if you're experiencing
@@ -162,12 +137,12 @@ pub struct Config {
162137
impl Default for Config {
163138
fn default() -> Self {
164139
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,
168143
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,
171146
}
172147
}
173148
}
@@ -178,6 +153,7 @@ pub struct OracleState {
178153

179154
impl OracleState {
180155
pub fn new() -> Self {
156+
tracing::info!("Initializing OracleState");
181157
Self {
182158
data: Default::default(),
183159
}
@@ -232,6 +208,7 @@ where
232208
// We are only interested in price account updates, all other types of updates
233209
// will be fetched using polling.
234210
if !data.price_accounts.contains_key(account_key) {
211+
tracing::info!("Account key not found in price accounts, skipping update.");
235212
return Ok(());
236213
}
237214

@@ -247,13 +224,14 @@ where
247224
);
248225

249226
data.price_accounts.insert(*account_key, price_entry);
227+
tracing::info!("Updated price account for key: {}", account_key);
250228

251229
Prices::update_global_price(
252230
self,
253231
network,
254232
&Update::PriceAccountUpdate {
255233
account_key: *account_key,
256-
account: price_entry,
234+
account: price_entry,
257235
},
258236
)
259237
.await?;
@@ -271,14 +249,17 @@ where
271249
rpc_client: &RpcClient,
272250
max_lookup_batch_size: usize,
273251
) -> Result<()> {
252+
tracing::info!("Polling updates for network: {:?}", network);
274253
let mut publisher_permissions = HashMap::new();
275254
let mapping_accounts = fetch_mapping_accounts(rpc_client, mapping_key).await?;
255+
tracing::info!("Fetched mapping accounts.");
276256
let (product_accounts, price_accounts) = fetch_product_and_price_accounts(
277257
rpc_client,
278258
max_lookup_batch_size,
279259
mapping_accounts.values(),
280260
)
281261
.await?;
262+
tracing::info!("Fetched product and price accounts.");
282263

283264
for (price_key, price_entry) in price_accounts.iter() {
284265
for component in price_entry.comp {
@@ -294,7 +275,7 @@ where
294275
product_accounts.get(&price_entry.prod)
295276
{
296277
PricePublishingMetadata {
297-
schedule: prod_entry.schedule.clone(),
278+
schedule: prod_entry.schedule.clone(),
298279
publish_interval: prod_entry.publish_interval,
299280
}
300281
} else {
@@ -320,6 +301,7 @@ where
320301
let mut data = self.into().data.write().await;
321302
log_data_diff(&data, &new_data);
322303
*data = new_data;
304+
tracing::info!("Updated OracleState data.");
323305

324306
Exporter::update_permissions(
325307
self,
@@ -335,6 +317,7 @@ where
335317
/// Sync Product/Price Accounts found by polling to the Global Store.
336318
#[instrument(skip(self))]
337319
async fn sync_global_store(&self, network: Network) -> Result<()> {
320+
tracing::info!("Syncing global store for network: {:?}", network);
338321
for (product_account_key, product_account) in
339322
&self.into().data.read().await.product_accounts
340323
{
@@ -343,7 +326,7 @@ where
343326
network,
344327
&Update::ProductAccountUpdate {
345328
account_key: *product_account_key,
346-
account: product_account.clone(),
329+
account: product_account.clone(),
347330
},
348331
)
349332
.await
@@ -356,13 +339,14 @@ where
356339
network,
357340
&Update::PriceAccountUpdate {
358341
account_key: *price_account_key,
359-
account: *price_account,
342+
account: *price_account,
360343
},
361344
)
362345
.await
363346
.map_err(|_| anyhow!("failed to notify price account update"))?;
364347
}
365348

349+
tracing::info!("Global store sync completed.");
366350
Ok(())
367351
}
368352
}
@@ -372,6 +356,10 @@ async fn fetch_mapping_accounts(
372356
rpc_client: &RpcClient,
373357
mapping_account_key: Pubkey,
374358
) -> Result<HashMap<Pubkey, MappingAccount>> {
359+
tracing::info!(
360+
"Fetching mapping accounts starting from key: {}",
361+
mapping_account_key
362+
);
375363
let mut accounts = HashMap::new();
376364
let mut account_key = mapping_account_key;
377365
while account_key != Pubkey::default() {
@@ -384,6 +372,7 @@ async fn fetch_mapping_accounts(
384372
accounts.insert(account_key, account);
385373
account_key = account.next;
386374
}
375+
tracing::info!("Fetched {} mapping accounts.", accounts.len());
387376
Ok(accounts)
388377
}
389378

@@ -396,6 +385,7 @@ async fn fetch_product_and_price_accounts<'a, A>(
396385
where
397386
A: IntoIterator<Item = &'a MappingAccount>,
398387
{
388+
tracing::info!("Fetching product and price accounts.");
399389
let mut product_keys = vec![];
400390

401391
// Get all product keys
@@ -421,13 +411,19 @@ where
421411
price_entries.extend(batch_prices.drain());
422412
}
423413

414+
tracing::info!(
415+
"Fetched {} product entries and {} price entries.",
416+
product_entries.len(),
417+
price_entries.len()
418+
);
424419
Ok((product_entries, price_entries))
425420
}
426421

427422
async fn fetch_batch_of_product_and_price_accounts(
428423
rpc_client: &RpcClient,
429424
product_key_batch: &[Pubkey],
430425
) -> Result<(HashMap<Pubkey, ProductEntry>, HashMap<Pubkey, PriceEntry>)> {
426+
tracing::info!("Fetching batch of product and price accounts.");
431427
let mut product_entries = HashMap::new();
432428

433429
let product_keys = product_key_batch;
@@ -568,6 +564,7 @@ async fn fetch_batch_of_product_and_price_accounts(
568564

569565
todo = next_todo;
570566
}
567+
tracing::info!("Fetched batch of product and price accounts.");
571568
Ok((product_entries, price_entries))
572569
}
573570

0 commit comments

Comments
 (0)