Skip to content

Commit 8041263

Browse files
authored
Conditional compilation (#368)
* Yes * Make size smaller * Cleanup * Add conditional compilation * Let's go * Cleanup * Cleanup * Clarify comments * Comment * Comment
1 parent faec075 commit 8041263

File tree

7 files changed

+36
-16
lines changed

7 files changed

+36
-16
lines changed

docker/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ RUN ./pyth-client/scripts/patch-solana.sh
5757

5858
# Build and test the oracle program.
5959
RUN cd pyth-client && ./scripts/build-bpf.sh .
60-
RUN cd pyth-client && ./scripts/check-size.sh
6160

6261
ENTRYPOINT []
6362
CMD []

program/rust/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ csv = "1.1"
3434
[features]
3535
debug = []
3636
library = []
37+
pythnet = []
3738

3839
[lib]
3940
crate-type = ["cdylib", "lib"]

program/rust/src/accounts.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pub use {
6969
/// There is a single permissions account under `PERMISSIONS_SEED` that stores which keys
7070
/// are authorized to perform certain adminsitrative actions.
7171
pub const PERMISSIONS_SEED: &str = "permissions";
72+
#[cfg(feature = "pythnet")]
7273
/// The update price instruction can optionally invoke another program via CPI. The
7374
/// CPI will be signed with the PDA `[UPD_PRICE_WRITE_SEED, invoked_program_public_key]`
7475
/// such that the caller can authenticate its origin.

program/rust/src/accounts/price.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,16 @@ pub struct PriceFeedMessage {
230230
/// as some price updates on pythnet may not be sent to other chains (because the message-sending
231231
/// logic may not have triggered). We can solve this problem by making the message-sending mandatory
232232
/// (which we can do once publishers have migrated over).
233+
///
234+
/// Additionally, this field may be equal to publish_time if the message is sent on a slot where
235+
/// where the aggregation was unsuccesful. This problem will go away once all publishers have
236+
/// migrated over to a recent version of pyth-agent.
233237
pub prev_publish_time: i64,
234238
pub ema_price: i64,
235239
pub ema_conf: u64,
236240
}
237241

242+
#[allow(dead_code)]
238243
impl PriceFeedMessage {
239244
// The size of the serialized message. Note that this is not the same as the size of the struct
240245
// (because of the discriminator & struct padding/alignment).
@@ -318,6 +323,7 @@ pub struct TwapMessage {
318323
pub publish_slot: u64,
319324
}
320325

326+
#[allow(dead_code)]
321327
impl TwapMessage {
322328
// The size of the serialized message. Note that this is not the same as the size of the struct
323329
// (because of the discriminator & struct padding/alignment).

program/rust/src/processor/upd_price.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1+
#[cfg(feature = "pythnet")]
2+
use {
3+
crate::accounts::{
4+
PriceFeedMessage,
5+
TwapMessage,
6+
UPD_PRICE_WRITE_SEED,
7+
},
8+
solana_program::instruction::{
9+
AccountMeta,
10+
Instruction,
11+
},
12+
solana_program::program::invoke_signed,
13+
};
114
use {
215
crate::{
316
accounts::{
417
PriceAccount,
518
PriceAccountV2,
6-
PriceFeedMessage,
719
PriceInfo,
820
PythAccount,
9-
TwapMessage,
10-
UPD_PRICE_WRITE_SEED,
1121
},
1222
deserialize::{
1323
load,
@@ -28,17 +38,13 @@ use {
2838
account_info::AccountInfo,
2939
clock::Clock,
3040
entrypoint::ProgramResult,
31-
instruction::{
32-
AccountMeta,
33-
Instruction,
34-
},
35-
program::invoke_signed,
3641
program_error::ProgramError,
3742
pubkey::Pubkey,
3843
sysvar::Sysvar,
3944
},
4045
};
4146

47+
4248
#[cfg(target_arch = "bpf")]
4349
#[link(name = "cpyth-bpf")]
4450
extern "C" {
@@ -97,6 +103,7 @@ pub fn upd_price(
97103
) -> ProgramResult {
98104
let cmd_args = load::<UpdPriceArgs>(instruction_data)?;
99105

106+
#[allow(unused_variables)]
100107
let (funding_account, price_account, clock_account, maybe_accumulator_accounts) = match accounts
101108
{
102109
[x, y, z] => Ok((x, y, z, None)),
@@ -179,7 +186,7 @@ pub fn upd_price(
179186
price_data.message_sent_ = 0;
180187
}
181188

182-
189+
#[cfg(feature = "pythnet")]
183190
if let Some(accumulator_accounts) = maybe_accumulator_accounts {
184191
if price_data.message_sent_ == 0 {
185192
// Check that the oracle PDA is correctly configured for the program we are calling.
@@ -261,7 +268,7 @@ pub fn upd_price(
261268
Ok(())
262269
}
263270

264-
271+
#[allow(dead_code)]
265272
// Wrapper struct for the accounts required to add data to the accumulator program.
266273
struct MessageBufferAccounts<'a, 'b: 'a> {
267274
program_id: &'a AccountInfo<'b>,

scripts/build-bpf.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ set -x
2020
cd "${PYTH_DIR}"
2121
cargo clean
2222
cargo test --locked
23+
2324
cargo clean
2425
cargo-build-bpf -- --locked -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort
26+
sha256sum ./target/**/*.so
27+
echo "Checking size of pyth_oracle.so for mainnet"
28+
./scripts/check-size.sh 81760
2529

30+
cargo clean
31+
cargo-build-bpf -- --locked -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --features pythnet
2632
sha256sum ./target/**/*.so
33+
echo "Checking size of pyth_oracle.so for pythnet"
34+
./scripts/check-size.sh 88429

scripts/check-size.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
# While Solana doesn't support resizing programs, the oracle binary needs to be smaller than 81760 bytes
55
# (The available space for the oracle program on pythnet is 88429 and mainnet is 81760)
66
ORACLE_SIZE=$(wc -c ./target/deploy/pyth_oracle.so | awk '{print $1}')
7-
if [ $ORACLE_SIZE -lt 88429 ]
7+
if [ $ORACLE_SIZE -lt ${1} ]
88
then
9-
echo "Size of pyth_oracle.so is small enough to be deployed to mainnet."
10-
echo $ORACLE_SIZE
9+
echo "Size of pyth_oracle.so is small enough to be deployed, since ${ORACLE_SIZE} is less than ${1}"
1110
else
12-
echo "Size of pyth_oracle.so is too big to be deployed to mainnet."
13-
echo $ORACLE_SIZE
11+
echo "Size of pyth_oracle.so is too big to be deployed, since ${ORACLE_SIZE} is greater than ${1}"
1412
exit 1
1513
fi

0 commit comments

Comments
 (0)