Skip to content

Commit 49cf2b9

Browse files
committed
address comments
1 parent 458f143 commit 49cf2b9

File tree

3 files changed

+8
-27
lines changed

3 files changed

+8
-27
lines changed

program/rust/src/processor/upd_price.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub fn upd_price(
128128
let clock = Clock::from_account_info(clock_account)?;
129129

130130
let mut publisher_index: usize = 0;
131-
let slots_since_last_update: u64;
131+
let slots_since_last_successful_aggregate: u64;
132132
let noninitial_price_update_after_program_upgrade: bool;
133133

134134
// The price_data borrow happens in a scope because it must be
@@ -150,15 +150,15 @@ pub fn upd_price(
150150
OracleError::PermissionViolation.into(),
151151
)?;
152152

153-
// We use last_slot_ to calculate slots_since_last_update. This is because last_slot_ is updated after the aggregate price is updated successfully.
154-
slots_since_last_update = clock.slot - price_data.last_slot_;
153+
// We use last_slot_ to calculate slots_since_last_successful_aggregate. This is because last_slot_ is updated after the aggregate price is updated successfully.
154+
slots_since_last_successful_aggregate = clock.slot - price_data.last_slot_;
155155

156156
// Check if the program upgrade has happened in the current slot and aggregate price has been updated, if so, use the old logic to update twap/twac/price_cumulative.
157157
// This is to ensure that twap/twac/price_cumulative are calculated correctly during the migration.
158158
// We check if prev_twap_.denom_ is == 0 because when the program upgrade has happened, denom_ is initialized to 0 and it can only stay the same or increase while numer_ can be negative if prices are negative.
159-
// And we check if slots_since_last_update == 0 to check if the aggregate price has been updated in the current slot.
159+
// And we check if slots_since_last_successful_aggregate == 0 to check if the aggregate price has been updated in the current slot.
160160
noninitial_price_update_after_program_upgrade =
161-
price_data.prev_twap_.denom_ == 0 && slots_since_last_update == 0;
161+
price_data.prev_twap_.denom_ == 0 && slots_since_last_successful_aggregate == 0;
162162

163163
let latest_publisher_price = price_data.comp_[publisher_index].latest_;
164164

@@ -190,7 +190,8 @@ pub fn upd_price(
190190
}
191191

192192
// If the price update is the first in the slot and the aggregate is trading, update the previous slot, price, conf, and timestamp.
193-
if slots_since_last_update > 0 && price_data.agg_.status_ == PC_STATUS_TRADING {
193+
if slots_since_last_successful_aggregate > 0 && price_data.agg_.status_ == PC_STATUS_TRADING
194+
{
194195
price_data.prev_slot_ = price_data.agg_.pub_slot_;
195196
price_data.prev_price_ = price_data.agg_.price_;
196197
price_data.prev_conf_ = price_data.agg_.conf_;
@@ -224,7 +225,7 @@ pub fn upd_price(
224225
// from the last successful aggregated price update as their basis for recalculation. This
225226
// ensures that each update within a slot builds upon the last and not the twap/twac/price_cumulative
226227
// that is calculated right after the publishers' individual price updates.
227-
if slots_since_last_update > 0 {
228+
if slots_since_last_successful_aggregate > 0 {
228229
price_data.prev_twap_ = price_data.twap_;
229230
price_data.prev_twac_ = price_data.twac_;
230231
price_data.prev_price_cumulative = price_data.price_cumulative;

program/rust/src/tests/test_full_publisher_set.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ async fn test_full_publisher_set() -> Result<(), Box<dyn std::error::Error>> {
3636
.await;
3737
let price = price_accounts["LTC"];
3838

39-
4039
let n_pubs = pub_keypairs.len();
4140

4241
// Divide publishers into two even parts (assuming the max PC_NUM_COMP size is even)
@@ -61,18 +60,6 @@ async fn test_full_publisher_set() -> Result<(), Box<dyn std::error::Error>> {
6160
sim.upd_price(second_kp, price, second_quote).await?;
6261
}
6362

64-
// Advance slot once from 1 to 2
65-
sim.warp_to_slot(2).await?;
66-
67-
// Final price update to trigger aggregation
68-
let first_kp = pub_keypairs.first().unwrap();
69-
let first_quote = Quote {
70-
price: 100,
71-
confidence: 30,
72-
status: PC_STATUS_TRADING,
73-
};
74-
sim.upd_price(first_kp, price, first_quote).await?;
75-
7663
{
7764
let price_data = sim
7865
.get_account_data_as::<PriceAccount>(price)

program/rust/src/tests/test_upd_aggregate.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,6 @@ fn test_upd_aggregate() {
115115
price_data.timestamp_ = 0;
116116
price_data.agg_.pub_slot_ = 1000;
117117
price_data.comp_[0].latest_ = p1;
118-
price_data.prev_slot_ = 0;
119-
price_data.prev_price_ = 0;
120-
price_data.prev_conf_ = 0;
121-
price_data.prev_timestamp_ = 0;
122-
price_data.agg_.price_ = 0;
123-
price_data.agg_.conf_ = 0;
124-
price_data.agg_.status_ = PC_STATUS_UNKNOWN;
125118
}
126119

127120
unsafe {

0 commit comments

Comments
 (0)