Skip to content

Commit 056eb3a

Browse files
authored
Revert "Log time and ema (#212)" (#216)
This reverts commit f0bb36c.
1 parent f0bb36c commit 056eb3a

File tree

6 files changed

+27
-99
lines changed

6 files changed

+27
-99
lines changed

program/rust/build.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ fn main() {
1212
parser.register_traits("pc_acc", borsh_derives.to_vec());
1313
parser.register_traits("pc_price_info", borsh_derives.to_vec());
1414
parser.register_traits("cmd_upd_price", borsh_derives.to_vec());
15-
parser.register_traits("pc_ema", borsh_derives.to_vec());
1615

1716
//generate and write bindings
1817
let bindings = Builder::default()

program/rust/src/deserialize.rs

Lines changed: 0 additions & 36 deletions
This file was deleted.

program/rust/src/error.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ pub type OracleResult = Result<u64, ProgramError>;
1010
pub enum OracleError {
1111
/// Generic catch all error
1212
#[error("Generic")]
13-
Generic = 600,
13+
Generic = 600,
1414
/// integer casting error
1515
#[error("IntegerCastingError")]
16-
IntegerCastingError = 601,
16+
IntegerCastingError = 601,
1717
/// c_entrypoint returned an unexpected value
1818
#[error("UnknownCError")]
19-
UnknownCError = 602,
20-
#[error("UnrecognizedInstruction")]
21-
UnrecognizedInstruction = 603,
19+
UnknownCError = 602,
2220
}
2321

2422
impl From<OracleError> for ProgramError {

program/rust/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
mod c_oracle_header;
2-
mod deserialize;
32
mod error;
43
mod log;
54
mod processor;

program/rust/src/log.rs

Lines changed: 24 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,46 @@
11
use crate::c_oracle_header::*;
2-
use crate::deserialize::{
3-
deserialize_single_field_from_account,
4-
deserialize_single_field_from_buffer,
5-
};
62
use crate::error::OracleError;
73
use borsh::BorshDeserialize;
84
use solana_program::account_info::AccountInfo;
9-
use solana_program::clock::Clock;
105
use solana_program::entrypoint::ProgramResult;
116
use solana_program::msg;
12-
use solana_program::program_error::ProgramError;
13-
use solana_program::sysvar::Sysvar;
7+
use std::mem::size_of;
148

159
pub fn pre_log(accounts: &[AccountInfo], instruction_data: &[u8]) -> ProgramResult {
1610
msg!("Pyth oracle contract");
1711

18-
let instruction_header: cmd_hdr =
19-
deserialize_single_field_from_buffer::<cmd_hdr>(&instruction_data, None)?;
12+
let instruction_header: cmd_hdr = cmd_hdr::try_from_slice(&instruction_data[..8])?;
2013
let instruction_id: u32 = instruction_header
2114
.cmd_
2215
.try_into()
23-
.map_err(|_| OracleError::IntegerCastingError)?;
24-
25-
16+
.map_err(|_| OracleError::Generic)?;
2617
match instruction_id {
2718
command_t_e_cmd_upd_price | command_t_e_cmd_agg_price => {
2819
let instruction: cmd_upd_price = cmd_upd_price::try_from_slice(instruction_data)?;
29-
// Account 1 is price_info in this instruction
30-
let expo: i32 = deserialize_single_field_from_account::<i32>(
31-
accounts,
32-
1,
33-
Some(PRICE_T_EXPO_OFFSET),
34-
)?;
3520
msg!(
36-
"UpdatePrice: publisher={:}, price_account={:}, price={:}, conf={:}, expo={:}, status={:}, slot={:}, solana_time={:}",
21+
"UpdatePrice: publisher={:}, price_account={:}, price={:}, conf={:}, status={:}, slot={:}",
3722
accounts.get(0)
38-
.ok_or(ProgramError::NotEnoughAccountKeys)?.key,
23+
.ok_or(OracleError::Generic)?.key,
3924
accounts.get(1)
40-
.ok_or(ProgramError::NotEnoughAccountKeys)?.key,
25+
.ok_or(OracleError::Generic)?.key,
4126
instruction.price_,
4227
instruction.conf_,
43-
expo,
4428
instruction.status_,
45-
instruction.pub_slot_,
46-
Clock::get()?.unix_timestamp
29+
instruction.pub_slot_
4730
);
4831
}
4932
command_t_e_cmd_upd_price_no_fail_on_error => {
5033
let instruction: cmd_upd_price = cmd_upd_price::try_from_slice(instruction_data)?;
51-
// Account 1 is price_info in this instruction
52-
let expo: i32 = deserialize_single_field_from_account::<i32>(
53-
accounts,
54-
1,
55-
Some(PRICE_T_EXPO_OFFSET),
56-
)?;
5734
msg!(
58-
"UpdatePriceNoFailOnError: publisher={:}, price_account={:}, price={:}, conf={:}, expo={:}, status={:}, slot={:}, solana_time={:}",
35+
"UpdatePriceNoFailOnError: publisher={:}, price_account={:}, price={:}, conf={:}, status={:}, slot={:}",
5936
accounts.get(0)
60-
.ok_or(ProgramError::NotEnoughAccountKeys)?.key,
37+
.ok_or(OracleError::Generic)?.key,
6138
accounts.get(1)
62-
.ok_or(ProgramError::NotEnoughAccountKeys)?.key,
39+
.ok_or(OracleError::Generic)?.key,
6340
instruction.price_,
6441
instruction.conf_,
65-
expo,
6642
instruction.status_,
67-
instruction.pub_slot_,
68-
Clock::get()?.unix_timestamp
43+
instruction.pub_slot_
6944
);
7045
}
7146
command_t_e_cmd_add_mapping => {
@@ -98,37 +73,31 @@ pub fn pre_log(accounts: &[AccountInfo], instruction_data: &[u8]) -> ProgramResu
9873
}
9974
_ => {
10075
msg!("UnrecognizedInstruction");
101-
return Err(OracleError::UnrecognizedInstruction.into());
76+
return Err(OracleError::Generic.into());
10277
}
10378
}
10479
Ok(())
10580
}
10681

10782
pub fn post_log(c_ret_val: u64, accounts: &[AccountInfo]) -> ProgramResult {
10883
if c_ret_val == SUCCESSFULLY_UPDATED_AGGREGATE {
109-
// We trust that the C oracle has properly checked account 1, we can only get here through
110-
// the update price instructions
111-
let aggregate_price_info: pc_price_info = deserialize_single_field_from_account::<
112-
pc_price_info,
113-
>(
114-
accounts, 1, Some(PRICE_T_AGGREGATE_OFFSET)
84+
let start: usize = PRICE_T_AGGREGATE_OFFSET
85+
.try_into()
86+
.map_err(|_| OracleError::Generic)?;
87+
// We trust that the C oracle has properly checked this account
88+
let aggregate_price_info: pc_price_info = pc_price_info::try_from_slice(
89+
&accounts
90+
.get(1)
91+
.ok_or(OracleError::Generic)?
92+
.try_borrow_data()?[start..(start + size_of::<pc_price_info>())],
11593
)?;
116-
let ema_info: pc_ema =
117-
deserialize_single_field_from_account::<pc_ema>(accounts, 1, Some(PRICE_T_EMA_OFFSET))?;
118-
let expo: i32 =
119-
deserialize_single_field_from_account::<i32>(accounts, 1, Some(PRICE_T_EXPO_OFFSET))?;
120-
12194
msg!(
122-
"UpdateAggregate : price_account={:}, price={:}, conf={:}, expo={:}, status={:}, slot={:}, solana_time={:}, ema={:}",
123-
accounts.get(1)
124-
.ok_or(ProgramError::NotEnoughAccountKeys)?.key,
95+
"UpdateAggregate : price_account={:}, price={:}, conf={:}, status={:}, slot={:}",
96+
accounts.get(1).ok_or(OracleError::Generic)?.key,
12597
aggregate_price_info.price_,
12698
aggregate_price_info.conf_,
127-
expo,
12899
aggregate_price_info.status_,
129-
aggregate_price_info.pub_slot_,
130-
Clock::get()?.unix_timestamp,
131-
ema_info.val_
100+
aggregate_price_info.pub_slot_
132101
);
133102
}
134103
Ok(())

program/rust/src/price_t_offsets.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const size_t PRICE_T_AGGREGATE_OFFSET = offsetof(struct pc_price, agg_);
99
const size_t PRICE_T_AGGREGATE_CONF_OFFSET = offsetof(struct pc_price, agg_) + offsetof(struct pc_price_info, conf_);
1010
const size_t PRICE_T_AGGREGATE_PRICE_OFFSET = offsetof(struct pc_price, agg_) + offsetof(struct pc_price_info, price_);
1111
const size_t PRICE_T_AGGREGATE_STATUS_OFFSET = offsetof(struct pc_price, agg_) + offsetof(struct pc_price_info, status_);
12-
const size_t PRICE_T_EMA_OFFSET = offsetof(struct pc_price, twap_);
1312
const size_t PRICE_T_PREV_TIMESTAMP_OFFSET = offsetof(struct pc_price, prev_timestamp_);
1413
const size_t PRICE_T_PREV_CONF_OFFSET = offsetof(struct pc_price, prev_conf_);
1514
const size_t PRICE_T_PREV_AGGREGATE_OFFSET = offsetof(struct pc_price, prev_price_);

0 commit comments

Comments
 (0)