Skip to content

Commit 14fbdef

Browse files
authored
refactor: remove pythnet feature flag (#399)
* remove solana specific code * remove default feature * fix ci * fix readme * refactor * try fix * address comments * fix ci * remove PC_PYTHNET flag * refactor * address comments * address comments * remove comment
1 parent 7c14e9e commit 14fbdef

File tree

17 files changed

+86
-280
lines changed

17 files changed

+86
-280
lines changed

.github/workflows/docker.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,7 @@ jobs:
6161
run : |
6262
docker create -ti --name container "${DOCKER_IMAGE}" bash
6363
docker cp container:/home/pyth/pyth-client/target/pyth/pythnet/pyth_oracle_pythnet.so .
64-
docker cp container:/home/pyth/pyth-client/target/pyth/solana/pyth_oracle_solana.so .
6564
docker rm -f container
66-
67-
- name : Publish Solana binary
68-
if : env.IS_ORACLE_RELEASE == 'true'
69-
uses: svenstaro/upload-release-action@133984371c30d34e38222a64855679a414cb7575
70-
with:
71-
repo_token: ${{ secrets.GITHUB_TOKEN }}
72-
file: ./pyth_oracle_solana.so
73-
asset_name: pyth_oracle_solana.so
74-
tag: ${{ github.ref }}
7565
7666
- name : Publish Pythnet binary
7767
if : env.IS_ORACLE_RELEASE == 'true'

.pre-commit-config.yaml

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
repos:
2-
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v3.2.0
4-
hooks:
5-
- id: trailing-whitespace
6-
files : program/
7-
- id: end-of-file-fixer
8-
files : program/
9-
- id: check-added-large-files
10-
- repo: local
11-
hooks:
12-
- id: cargo-fmt
13-
name: Cargo Fmt
14-
language: "rust"
15-
entry: cargo +nightly-2023-03-01 fmt
16-
pass_filenames: false
17-
- id: cargo-clippy-solana
18-
name: Cargo Clippy Solana
19-
language: "rust"
20-
entry : cargo +nightly-2023-03-01 clippy --tests --features check -- -D warnings
21-
pass_filenames : false
22-
- id: cargo-clippy-pythnet
23-
name: Cargo Clippy Pythnet
24-
language: "rust"
25-
entry : cargo +nightly-2023-03-01 clippy --tests --features pythnet,check -- -D warnings
26-
pass_filenames : false
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v3.2.0
4+
hooks:
5+
- id: trailing-whitespace
6+
files: program/
7+
- id: end-of-file-fixer
8+
files: program/
9+
- id: check-added-large-files
10+
- repo: local
11+
hooks:
12+
- id: cargo-fmt
13+
name: Cargo Fmt
14+
language: "rust"
15+
entry: cargo +nightly-2023-03-01 fmt
16+
pass_filenames: false
17+
- id: cargo-clippy-pythnet
18+
name: Cargo Clippy Pythnet
19+
language: "rust"
20+
entry: cargo +nightly-2023-03-01 clippy --tests --features check -- -D warnings
21+
pass_filenames: false

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ Finally, in docker extension inside VS Code click right and choose "Attach VS Co
155155

156156
Oracle program upgrades are managed by the Pythian Council multisig. The steps to deploy a new version are:
157157

158-
1. Create a release branch from `main`. This should include binaries for both the Solana mainnet and Pythnet oracle programs (`pyth_oracle_solana.so` and `pyth_oracle_pythnet.so`).
158+
1. Create a release branch from `main`. This should include the binary for the Pythnet oracle program (`pyth_oracle_pythnet.so`).
159159
2. [Install Solana CLI](https://docs.solana.com/cli/install-solana-cli-tools#use-solanas-install-tool) if not already installed.
160160
3. Set Solana config for the target network, e.g., devnet: `solana config set --url https://api.devnet.solana.com`.
161-
4. Execute `solana program write-buffer <ORACLE_PROGRAM_BINARY_FILENAME>` where `<ORACLE_PROGRAM_BINARY_FILENAME>` can be `pyth_oracle_solana.so` or `pyth_oracle_pythnet.so` to obtain the buffer address.
161+
4. Execute `solana program write-buffer pyth_oracle_pythnet.so` to obtain the buffer address.
162162
5. Run `solana program show <ORACLE_PROGRAM_PUBKEY>` to obtain the authority of the current program.
163163
6. Use `solana program set-buffer-authority <BUFFER_PUBKEY> --new-buffer-authority <NEW_BUFFER_AUTHORITY>` to assign the upgrade authority from the previous step to the buffer address.
164164
7. Submit a proposal with [`xc-admin`](https://github.com/pyth-network/pyth-crosschain/tree/main/governance/xc_admin/packages/xc_admin_cli) for program upgrade using the `upgrade-program` command.

program/c/makefile

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,7 @@ else
1111
include $(SOLANA)/sdk/sbf/c/sbf.mk
1212
endif
1313

14-
# Propagate the PC_PYTHNET feature by conditionally defining it in a
15-
# features.h header. The makefile included from Solana SDK does not
16-
# have an easy way to pass extra C flags which motivates this approach.
17-
ifdef PC_PYTHNET
18-
FEATURES_H_BODY:="\#pragma once\n\#define PC_PYTHNET 1"
19-
else
20-
FEATURES_H_BODY:="\#pragma once"
21-
endif
14+
FEATURES_H_BODY:="\#pragma once"
2215

2316

2417
.PHONY: features.h # Putting this in .PHONY makes sure the header is always regenerated

program/c/src/oracle/native/upd_aggregate.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ char heap_start[8192];
99
#include "../upd_aggregate.h"
1010
#include "../features.h"
1111

12-
#ifdef PC_PYTHNET
1312
extern bool c_upd_aggregate_pythnet( pc_price_t *ptr, uint64_t slot, int64_t timestamp ){
14-
#else
15-
extern bool c_upd_aggregate_solana( pc_price_t *ptr, uint64_t slot, int64_t timestamp ){
16-
#endif
1713
return upd_aggregate(ptr, slot, timestamp );
1814
}
1915

program/c/src/oracle/oracle.h

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,12 @@ extern "C" {
2323
#define PC_MAP_TABLE_SIZE 640
2424

2525
// Total price component slots available
26-
#define PC_NUM_COMP_SOLANA 32
2726
#define PC_NUM_COMP_PYTHNET 128
2827

2928
// PC_NUM_COMP - number of price components in use
30-
#ifdef PC_PYTHNET
3129
// Not whole PC_NUM_COMP_PYTHNET because of stack issues appearing in upd_aggregate()
3230
#define PC_NUM_COMP 64
33-
#else
34-
#define PC_NUM_COMP PC_NUM_COMP_SOLANA
35-
#endif
31+
3632

3733
#define PC_PROD_ACC_SIZE 512
3834
#define PC_EXP_DECAY -9
@@ -209,20 +205,47 @@ typedef struct pc_price
209205
pc_price_comp_t comp_[PC_NUM_COMP];// component prices
210206
} pc_price_t;
211207

212-
#ifdef PC_PYTHNET
213208

214-
// Replace Solana component size's contribution with Pythnet's
215-
#define PC_EXPECTED_PRICE_T_SIZE_PYTHNET (3312 \
216-
- PC_NUM_COMP_SOLANA * sizeof(pc_price_comp_t) \
209+
/*
210+
The value 240 is derived from the fixed size of the pc_price_t struct excluding the size of the comp_ array.
211+
Here is the breakdown of the sizes (in bytes) for each field within the pc_price_t struct:
212+
213+
- magic_ (uint32_t): 4 bytes
214+
- ver_ (uint32_t): 4 bytes
215+
- type_ (uint32_t): 4 bytes
216+
- size_ (uint32_t): 4 bytes
217+
- ptype_ (uint32_t): 4 bytes
218+
- expo_ (int32_t): 4 bytes
219+
- num_ (uint32_t): 4 bytes
220+
- num_qt_ (uint32_t): 4 bytes
221+
- last_slot_ (uint64_t): 8 bytes
222+
- valid_slot_ (uint64_t): 8 bytes
223+
- twap_ (pc_ema_t): 24 bytes (3 fields of int64_t each taking 8 bytes)
224+
- twac_ (pc_ema_t): 24 bytes (similar to twap_)
225+
- timestamp_ (int64_t): 8 bytes
226+
- min_pub_ (uint8_t): 1 byte
227+
- message_sent_ (int8_t): 1 byte
228+
- max_latency_ (uint8_t): 1 byte
229+
- drv3_ (int8_t): 1 byte
230+
- drv4_ (int32_t): 4 bytes
231+
- prod_ (pc_pub_key_t): 32 bytes (assuming pc_pub_key_t is a 32-byte array or struct)
232+
- next_ (pc_pub_key_t): 32 bytes (similar to prod_)
233+
- prev_slot_ (uint64_t): 8 bytes
234+
- prev_price_ (int64_t): 8 bytes
235+
- prev_conf_ (uint64_t): 8 bytes
236+
- prev_timestamp_ (int64_t): 8 bytes
237+
- agg_ (pc_price_info_t): 32 bytes
238+
239+
Adding up all these sizes gives us a total of 240 bytes for the fixed part of the pc_price_t struct.
240+
The size of the comp_ array is variable and depends on PC_NUM_COMP, hence it is calculated separately and added to the base size of 240 bytes.
241+
*/
242+
#define PC_EXPECTED_PRICE_T_SIZE_PYTHNET (240 \
217243
+ PC_NUM_COMP * sizeof(pc_price_comp_t) \
218244
)
219245

220246
static_assert( sizeof( pc_price_t ) == PC_EXPECTED_PRICE_T_SIZE_PYTHNET, "" );
221-
#undef PC_EXPECTED_PRICE_SIZE_PYTHNET
247+
#undef PC_EXPECTED_PRICE_T_SIZE_PYTHNET
222248

223-
#else
224-
static_assert( sizeof( pc_price_t ) == 3312, "" );
225-
#endif
226249

227250
// This constant needs to be an upper bound of the price account size, it is used within pythd for ztsd.
228251
// It is set tighly to the current price account + 96 component prices + 48 bytes for cumulative sums

program/c/src/oracle/upd_aggregate.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66
#include "upd_aggregate.h"
77
#include "features.h"
88

9-
// Dynamically deciding the name prevents linking the wrong C binary flavor
10-
#ifdef PC_PYTHNET
9+
1110
extern bool c_upd_aggregate_pythnet( pc_price_t *ptr, uint64_t slot, int64_t timestamp ){
12-
#else
13-
extern bool c_upd_aggregate_solana( pc_price_t *ptr, uint64_t slot, int64_t timestamp ){
14-
#endif
1511
return upd_aggregate(ptr, slot, timestamp );
1612
}
1713

program/rust/Cargo.toml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,11 @@ pythnet-sdk = { git = "https://github.com/pyth-network/pyth-crosschain", rev="60
3333
serde_json = "1.0"
3434
test-generator = "0.3.1"
3535
csv = "1.1"
36-
lazy_static = "1.4.0"
3736

38-
# IMPORTANT: Features which affect oracle business logic must be added
39-
# to the `lazy_static` macro call in `pyth_simulator.rs`.
40-
#
41-
# Context: We perform a cargo-build-bpf call as part of running tests
42-
# to obtain a BPF binary for testing. Desired features are not known
43-
# to cargo-build-bpf at that point - we manually capture them at
44-
# compile-time and pass on to the child process.
4537
[features]
4638
check = [] # Skips make build in build.rs, use with cargo-clippy and cargo-check
4739
debug = []
4840
library = []
49-
pythnet = [] # logic-affecting features start with this one
5041

5142
[lib]
5243
crate-type = ["cdylib", "lib"]

program/rust/build.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use {
1212
fn main() {
1313
let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
1414

15-
let has_feat_pythnet = std::env::var("CARGO_FEATURE_PYTHNET").is_ok();
1615
let has_feat_check = std::env::var("CARGO_FEATURE_CHECK").is_ok();
1716

1817
// OUT_DIR is the path cargo provides to a build directory under `target/` specifically for
@@ -25,17 +24,6 @@ fn main() {
2524
eprintln!("OUT_DIR is {}", out_dir);
2625
let out_dir = PathBuf::from(out_dir);
2726

28-
let mut make_extra_flags = vec![];
29-
let mut clang_extra_flags = vec![];
30-
31-
if has_feat_pythnet {
32-
// Define PC_PYTHNET for the C binary build
33-
make_extra_flags.push("PC_PYTHNET=1");
34-
35-
// Define PC_PYTHNET for the bindings build
36-
clang_extra_flags.push("-DPC_PYTHNET=1");
37-
}
38-
3927
let mut make_targets = vec![];
4028
if target_arch == "bpf" {
4129
make_targets.push("cpyth-bpf");
@@ -51,7 +39,7 @@ fn main() {
5139
if has_feat_check {
5240
eprintln!("WARNING: `check` feature active, make build is skipped");
5341
} else {
54-
do_make_build(make_extra_flags, make_targets, &out_dir);
42+
do_make_build(make_targets, &out_dir);
5543

5644
// Link against the right library for the architecture
5745
if target_arch == "bpf" {
@@ -74,7 +62,6 @@ fn main() {
7462
// Generate and write bindings
7563
let bindings = Builder::default()
7664
.clang_arg(format!("-I{:}", get_solana_inc_path().display()))
77-
.clang_args(clang_extra_flags)
7865
.header("./src/bindings.h")
7966
.rustfmt_bindings(true)
8067
.generate()
@@ -88,14 +75,13 @@ fn main() {
8875
println!("cargo:rerun-if-changed=../");
8976
}
9077

91-
fn do_make_build(extra_flags: Vec<&str>, targets: Vec<&str>, out_dir: &Path) {
78+
fn do_make_build(targets: Vec<&str>, out_dir: &Path) {
9279
// We must forward OUT_DIR as an env variable to the make script otherwise it will output
9380
// its artifacts to the wrong place.
9481
let make_output = std::process::Command::new("make")
9582
.env("VERBOSE", "1")
9683
.env("OUT_DIR", out_dir.display().to_string())
9784
.current_dir("../c")
98-
.args(extra_flags)
9985
.args(targets)
10086
.output()
10187
.expect("Failed to run make for C oracle program");

program/rust/src/accounts.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ mod product;
4343
// Some types only exist during use as a library.
4444
#[cfg(feature = "strum")]
4545
pub use price::MessageType;
46-
#[cfg(feature = "pythnet")]
47-
pub use price::PriceCumulative;
4846
#[cfg(test)]
4947
pub use product::{
5048
account_has_key_values,
@@ -56,6 +54,7 @@ pub use {
5654
price::{
5755
PriceAccount,
5856
PriceComponent,
57+
PriceCumulative,
5958
PriceEma,
6059
PriceInfo,
6160
PythOracleSerialize,
@@ -72,7 +71,6 @@ pub use {
7271
/// are authorized to perform certain administrative actions.
7372
pub const PERMISSIONS_SEED: &str = "permissions";
7473

75-
#[cfg(feature = "pythnet")]
7674
/// The update price instruction can optionally invoke another program via CPI. The
7775
/// CPI will be signed with the PDA `[UPD_PRICE_WRITE_SEED, invoked_program_public_key]`
7876
/// such that the caller can authenticate its origin.

0 commit comments

Comments
 (0)