From c68a70b0422da1c6d0890ea32df5ecc55d842685 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Alapont Date: Thu, 22 Sep 2022 16:57:35 -0500 Subject: [PATCH 1/2] Gate sma with test flag --- program/rust/src/rust_oracle.rs | 30 ++++++++++++++++++-------- program/rust/src/time_machine_types.rs | 4 ---- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/program/rust/src/rust_oracle.rs b/program/rust/src/rust_oracle.rs index a9180ebad..d5efc9347 100644 --- a/program/rust/src/rust_oracle.rs +++ b/program/rust/src/rust_oracle.rs @@ -127,10 +127,16 @@ pub fn resize_price_account( // Check that everything is ok check_valid_signable_account(program_id, price_account_info)?; - let mut price_account = - load_checked::(price_account_info, PC_VERSION)?; - // Initialize Time Machine - price_account.initialize_time_machine()?; + + #[cfg(test)] + // Sma feature disabled except in tests + { + let mut price_account = + load_checked::(price_account_info, PC_VERSION)?; + // Initialize Time Machine + price_account.initialize_time_machine()?; + } + Ok(()) } PriceAccountWrapper::MINIMUM_SIZE => Ok(()), @@ -251,8 +257,10 @@ pub fn upd_price( } // Try to update the aggregate + #[allow(unused_variables)] let mut aggregate_updated = false; if clock.slot > latest_aggregate_price.pub_slot_ { + #[allow(unused_assignments)] unsafe { aggregate_updated = c_upd_aggregate( price_account.try_borrow_mut_data()?.as_mut_ptr(), @@ -262,11 +270,15 @@ pub fn upd_price( } } - let account_len = price_account.try_data_len()?; - if aggregate_updated && account_len == PriceAccountWrapper::MINIMUM_SIZE { - let mut price_account = - load_checked::(price_account, cmd_args.header.version)?; - price_account.add_price_to_time_machine()?; + #[cfg(test)] + // Sma feature disabled in production for now + { + let account_len = price_account.try_data_len()?; + if aggregate_updated && account_len == PriceAccountWrapper::MINIMUM_SIZE { + let mut price_account = + load_checked::(price_account, cmd_args.header.version)?; + price_account.add_price_to_time_machine()?; + } } // Try to update the publisher's price diff --git a/program/rust/src/time_machine_types.rs b/program/rust/src/time_machine_types.rs index a186cd1a6..d3861e9ac 100644 --- a/program/rust/src/time_machine_types.rs +++ b/program/rust/src/time_machine_types.rs @@ -39,16 +39,12 @@ pub struct DataPoint { impl PriceAccountWrapper { pub fn initialize_time_machine(&mut self) -> Result<(), OracleError> { - // This is only enabled in tests while in development - #[cfg(test)] self.time_machine .initialize(THIRTY_MINUTES, PC_MAX_SEND_LATENCY.into()); Ok(()) } pub fn add_price_to_time_machine(&mut self) -> Result<(), OracleError> { - // This is only enabled in tests while in development - #[cfg(test)] self.time_machine.add_datapoint( &DataPoint{ previous_timestamp : self.price_data.prev_timestamp_, current_timestamp: self.price_data.timestamp_, From 702b66e598d8163aff4d892fe2df000d998b4d61 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Alapont Date: Thu, 22 Sep 2022 17:03:24 -0500 Subject: [PATCH 2/2] Restore current gating --- program/rust/src/time_machine_types.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/program/rust/src/time_machine_types.rs b/program/rust/src/time_machine_types.rs index d3861e9ac..a186cd1a6 100644 --- a/program/rust/src/time_machine_types.rs +++ b/program/rust/src/time_machine_types.rs @@ -39,12 +39,16 @@ pub struct DataPoint { impl PriceAccountWrapper { pub fn initialize_time_machine(&mut self) -> Result<(), OracleError> { + // This is only enabled in tests while in development + #[cfg(test)] self.time_machine .initialize(THIRTY_MINUTES, PC_MAX_SEND_LATENCY.into()); Ok(()) } pub fn add_price_to_time_machine(&mut self) -> Result<(), OracleError> { + // This is only enabled in tests while in development + #[cfg(test)] self.time_machine.add_datapoint( &DataPoint{ previous_timestamp : self.price_data.prev_timestamp_, current_timestamp: self.price_data.timestamp_,