Skip to content

Commit d25ec68

Browse files
committed
Big discrepancy in fields size on enum
1 parent 04b8cf8 commit d25ec68

File tree

4 files changed

+43
-27
lines changed

4 files changed

+43
-27
lines changed

src/agent/legacy_schedule.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ mod tests {
387387
let ok_datetimes = [
388388
NaiveDate::from_ymd_opt(2023, 11, 20)
389389
.unwrap()
390-
.and_time(MAX_TIME_INSTANT)
390+
.and_time(MAX_TIME_INSTANT.clone())
391391
.and_local_timezone(Tz::Europe__Amsterdam)
392392
.unwrap(),
393393
NaiveDateTime::parse_from_str("2023-11-21 00:00", format)?
@@ -404,7 +404,7 @@ mod tests {
404404
// confused for Wednesday 00:00 which is open.
405405
NaiveDate::from_ymd_opt(2023, 11, 21)
406406
.unwrap()
407-
.and_time(MAX_TIME_INSTANT)
407+
.and_time(MAX_TIME_INSTANT.clone())
408408
.and_local_timezone(Tz::Europe__Amsterdam)
409409
.unwrap(),
410410
];

src/agent/state.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,8 @@ mod tests {
496496
)
497497
.unwrap(),
498498
],
499-
},
499+
}
500+
.into(),
500501
),
501502
(
502503
solana_sdk::pubkey::Pubkey::from_str(
@@ -557,7 +558,8 @@ mod tests {
557558
)
558559
.unwrap(),
559560
],
560-
},
561+
}
562+
.into(),
561563
),
562564
]),
563565
price_accounts: HashMap::from([

src/agent/state/global.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ use {
3434
/// from the primary network.
3535
#[derive(Debug, Clone, Default)]
3636
pub struct AllAccountsData {
37-
pub product_accounts: HashMap<Pubkey, ProductEntry>,
38-
pub price_accounts: HashMap<Pubkey, PriceEntry>,
37+
pub product_accounts: HashMap<Pubkey, Arc<ProductEntry>>,
38+
pub price_accounts: HashMap<Pubkey, Arc<PriceEntry>>,
3939
}
4040

4141
/// AllAccountsMetadata contains the metadata for all the price and product accounts.
@@ -56,15 +56,15 @@ pub struct ProductAccountMetadata {
5656
pub price_accounts: Vec<Pubkey>,
5757
}
5858

59-
impl From<ProductEntry> for ProductAccountMetadata {
60-
fn from(product_account: ProductEntry) -> Self {
59+
impl From<&ProductEntry> for ProductAccountMetadata {
60+
fn from(product_account: &ProductEntry) -> Self {
6161
ProductAccountMetadata {
62-
attr_dict: product_account
62+
attr_dict: product_account
6363
.account_data
6464
.iter()
6565
.map(|(key, val)| (key.to_owned(), val.to_owned()))
6666
.collect(),
67-
price_accounts: product_account.price_accounts,
67+
price_accounts: product_account.price_accounts.clone(),
6868
}
6969
}
7070
}
@@ -76,8 +76,8 @@ pub struct PriceAccountMetadata {
7676
pub expo: i32,
7777
}
7878

79-
impl From<PriceEntry> for PriceAccountMetadata {
80-
fn from(price_account: PriceEntry) -> Self {
79+
impl From<&PriceEntry> for PriceAccountMetadata {
80+
fn from(price_account: &PriceEntry) -> Self {
8181
PriceAccountMetadata {
8282
expo: price_account.expo,
8383
}
@@ -88,11 +88,11 @@ impl From<PriceEntry> for PriceAccountMetadata {
8888
pub enum Update {
8989
ProductAccountUpdate {
9090
account_key: Pubkey,
91-
account: ProductEntry,
91+
account: Arc<ProductEntry>,
9292
},
9393
PriceAccountUpdate {
9494
account_key: Pubkey,
95-
account: PriceEntry,
95+
account: Arc<PriceEntry>,
9696
},
9797
}
9898

@@ -153,7 +153,7 @@ pub trait GlobalStore {
153153
&self,
154154
network: Network,
155155
price_ids: HashSet<Pubkey>,
156-
) -> Result<HashMap<Pubkey, PriceEntry>>;
156+
) -> Result<HashMap<Pubkey, Arc<PriceEntry>>>;
157157
}
158158

159159
// Allow downcasting State into GlobalStore for functions that depend on the `GlobalStore` service.
@@ -190,7 +190,7 @@ where
190190
&self,
191191
network: Network,
192192
price_ids: HashSet<Pubkey>,
193-
) -> Result<HashMap<Pubkey, PriceEntry>> {
193+
) -> Result<HashMap<Pubkey, Arc<PriceEntry>>> {
194194
let account_data = match network {
195195
Network::Primary => &self.into().account_data_primary,
196196
Network::Secondary => &self.into().account_data_secondary,
@@ -229,7 +229,7 @@ where
229229
account_key,
230230
account,
231231
} => {
232-
let attr_dict = ProductAccountMetadata::from(account.clone()).attr_dict;
232+
let attr_dict = ProductAccountMetadata::from(account.as_ref()).attr_dict;
233233
let maybe_symbol = attr_dict.get("symbol").cloned();
234234
store.product_metrics.update(account_key, maybe_symbol);
235235

@@ -269,7 +269,7 @@ where
269269
.write()
270270
.await
271271
.price_accounts
272-
.insert(*account_key, *account);
272+
.insert(*account_key, account.clone());
273273
}
274274
}
275275

@@ -292,7 +292,7 @@ where
292292
.write()
293293
.await
294294
.product_accounts_metadata
295-
.insert(*account_key, account.clone().into());
295+
.insert(*account_key, account.as_ref().into());
296296

297297
Ok(())
298298
}
@@ -305,7 +305,7 @@ where
305305
.write()
306306
.await
307307
.price_accounts_metadata
308-
.insert(*account_key, (*account).into());
308+
.insert(*account_key, account.as_ref().into());
309309

310310
Ok(())
311311
}

src/agent/state/oracle.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::sync::Arc;
2+
13
#[allow(deprecated)]
24
use crate::agent::legacy_schedule::LegacySchedule;
35
use {
@@ -130,8 +132,8 @@ impl std::ops::Deref for PriceEntry {
130132

131133
#[derive(Default, Debug, Clone)]
132134
pub struct Data {
133-
pub product_accounts: HashMap<Pubkey, ProductEntry>,
134-
pub price_accounts: HashMap<Pubkey, PriceEntry>,
135+
pub product_accounts: HashMap<Pubkey, Arc<ProductEntry>>,
136+
pub price_accounts: HashMap<Pubkey, Arc<PriceEntry>>,
135137
/// publisher => {their permissioned price accounts => price publishing metadata}
136138
pub publisher_permissions: HashMap<Pubkey, HashMap<Pubkey, PricePublishingMetadata>>,
137139
pub publisher_buffer_key: Option<Pubkey>,
@@ -239,14 +241,14 @@ where
239241
"Observed on-chain price account update.",
240242
);
241243

242-
data.price_accounts.insert(*account_key, price_entry);
244+
data.price_accounts.insert(*account_key, price_entry.into());
243245

244246
Prices::update_global_price(
245247
self,
246248
network,
247249
&Update::PriceAccountUpdate {
248250
account_key: *account_key,
249-
account: price_entry,
251+
account: Arc::new(price_entry),
250252
},
251253
)
252254
.await?;
@@ -369,7 +371,7 @@ where
369371
network,
370372
&Update::PriceAccountUpdate {
371373
account_key: *price_account_key,
372-
account: *price_account,
374+
account: price_account.clone(),
373375
},
374376
)
375377
.await
@@ -401,7 +403,10 @@ async fn fetch_product_and_price_accounts(
401403
rpc_client: &RpcClient,
402404
oracle_program_key: Pubkey,
403405
max_lookup_batch_size: usize,
404-
) -> Result<(HashMap<Pubkey, ProductEntry>, HashMap<Pubkey, PriceEntry>)> {
406+
) -> Result<(
407+
HashMap<Pubkey, Arc<ProductEntry>>,
408+
HashMap<Pubkey, Arc<PriceEntry>>,
409+
)> {
405410
let mut product_entries = HashMap::new();
406411
let mut price_entries = HashMap::new();
407412

@@ -502,7 +507,16 @@ async fn fetch_product_and_price_accounts(
502507
}
503508
}
504509

505-
Ok((product_entries, price_entries))
510+
Ok((
511+
product_entries
512+
.into_iter()
513+
.map(|(x, y)| (x, Arc::new(y)))
514+
.collect(),
515+
price_entries
516+
.into_iter()
517+
.map(|(x, y)| (x, Arc::new(y)))
518+
.collect(),
519+
))
506520
}
507521

508522
#[instrument(skip(rpc_client, product_key_batch))]

0 commit comments

Comments
 (0)