Skip to content

Commit efd6e52

Browse files
committed
refactor
1 parent 47115ab commit efd6e52

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

program/rust/src/processor/upd_price.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ pub fn upd_price(
163163

164164
// Try to update the aggregate
165165
#[allow(unused_variables)]
166-
let aggregate_updated = if clock.slot > latest_aggregate_price.pub_slot_ {
166+
if clock.slot > latest_aggregate_price.pub_slot_ {
167167
let updated = unsafe {
168168
// NOTE: c_upd_aggregate must use a raw pointer to price
169169
// data. Solana's `<account>.borrow_*` methods require exclusive
@@ -184,26 +184,22 @@ pub fn upd_price(
184184
unsafe {
185185
c_upd_twap(price_account.try_borrow_mut_data()?.as_mut_ptr(), agg_diff);
186186
}
187+
let mut price_data =
188+
load_checked::<PriceAccount>(price_account, cmd_args.header.version)?;
189+
// We want to send a message every time the aggregate price updates. However, during the migration,
190+
// not every publisher will necessarily provide the accumulator accounts. The message_sent_ flag
191+
// ensures that after every aggregate update, the next publisher who provides the accumulator accounts
192+
// will send the message.
193+
price_data.message_sent_ = 0;
194+
price_data.update_price_cumulative()?;
187195
}
188-
updated
189-
} else {
190-
false
191-
};
196+
}
192197

193198
// Reload price data as a struct after c_upd_aggregate() borrow is dropped
194199
let mut price_data = load_checked::<PriceAccount>(price_account, cmd_args.header.version)?;
195200

196201
// Feature-gated accumulator-specific code, used only on pythnet/pythtest
197202
{
198-
// We want to send a message every time the aggregate price updates. However, during the migration,
199-
// not every publisher will necessarily provide the accumulator accounts. The message_sent_ flag
200-
// ensures that after every aggregate update, the next publisher who provides the accumulator accounts
201-
// will send the message.
202-
if aggregate_updated {
203-
price_data.message_sent_ = 0;
204-
price_data.update_price_cumulative()?;
205-
}
206-
207203
if let Some(accumulator_accounts) = maybe_accumulator_accounts {
208204
if price_data.message_sent_ == 0 {
209205
// Check that the oracle PDA is correctly configured for the program we are calling.

0 commit comments

Comments
 (0)