Skip to content

Commit 8cfa4d2

Browse files
committed
feat: support no default accumulator v2
we have no default accumulator v2 in Pythtest conformance
1 parent e4d5f1d commit 8cfa4d2

File tree

7 files changed

+55
-14
lines changed

7 files changed

+55
-14
lines changed

.github/workflows/docker.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ jobs:
7272
asset_name: pyth_oracle_pythnet.so
7373
tag: ${{ github.ref }}
7474

75+
- name : Publish Pythnet No Default Accumulator v2 binary
76+
if : env.IS_ORACLE_RELEASE == 'true'
77+
uses: svenstaro/upload-release-action@133984371c30d34e38222a64855679a414cb7575
78+
with:
79+
repo_token: ${{ secrets.GITHUB_TOKEN }}
80+
file: ./pyth_oracle_pythnet_no_accumulator.so
81+
asset_name: pyth_oracle_pythnet_no_default_accumulator_v2.so
82+
tag: ${{ github.ref }}
83+
7584
pinning:
7685
runs-on: ubuntu-latest
7786
steps:

program/rust/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ time = "=0.3.7"
4545
check = [] # Skips make build in build.rs, use with cargo-clippy and cargo-check
4646
debug = []
4747
library = ["solana-sdk"]
48+
no-default-accumulator-v2 = []
4849

4950
[lib]
5051
crate-type = ["cdylib", "lib"]

program/rust/src/processor/add_price.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,12 @@ pub fn add_price(
8484
price_data.next_price_account = product_data.first_price_account;
8585
price_data.min_pub_ = PRICE_ACCOUNT_DEFAULT_MIN_PUB;
8686
price_data.feed_index = reserve_new_price_feed_index(permissions_account)?;
87-
price_data
88-
.flags
89-
.insert(PriceAccountFlags::ACCUMULATOR_V2 | PriceAccountFlags::MESSAGE_BUFFER_CLEARED);
87+
88+
if !cfg!(feature = "no-default-accumulator_v2") {
89+
price_data
90+
.flags
91+
.insert(PriceAccountFlags::ACCUMULATOR_V2 | PriceAccountFlags::MESSAGE_BUFFER_CLEARED);
92+
}
9093

9194
product_data.first_price_account = *price_account.key;
9295

program/rust/src/tests/test_full_publisher_set.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,13 @@ async fn test_full_publisher_set() -> Result<(), Box<dyn std::error::Error>> {
7979
.await
8080
.unwrap();
8181

82-
assert_eq!(price_data.agg_.price_, 0);
83-
assert_eq!(price_data.agg_.conf_, 0);
82+
if cfg!(feature = "no-default-accumulator-v2") {
83+
assert_eq!(price_data.agg_.price_, 110);
84+
assert_eq!(price_data.agg_.conf_, 20);
85+
} else {
86+
assert_eq!(price_data.agg_.price_, 0);
87+
assert_eq!(price_data.agg_.conf_, 0);
88+
}
8489
}
8590

8691
Ok(())

program/rust/src/tests/test_publish.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,14 @@ async fn test_publish() {
102102
assert_eq!(price_data.comp_[0].latest_.conf_, 0);
103103
assert_eq!(price_data.comp_[0].latest_.status_, PC_STATUS_UNKNOWN);
104104

105-
assert_eq!(price_data.comp_[0].agg_.price_, 0);
106-
assert_eq!(price_data.comp_[0].agg_.conf_, 0);
107-
assert_eq!(price_data.comp_[0].agg_.status_, PC_STATUS_UNKNOWN);
105+
if cfg!(feature = "no-default-accumulator-v2") {
106+
assert_eq!(price_data.agg_.price_, 150);
107+
assert_eq!(price_data.agg_.conf_, 7);
108+
assert_eq!(price_data.agg_.status_, PC_STATUS_TRADING);
109+
} else {
110+
assert_eq!(price_data.agg_.price_, 0);
111+
assert_eq!(price_data.agg_.conf_, 0);
112+
assert_eq!(price_data.agg_.status_, PC_STATUS_UNKNOWN);
113+
}
108114
}
109115
}

program/rust/src/tests/test_publish_batch.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ async fn test_publish_batch() {
111111
.get_account_data_as::<PriceAccount>(*price)
112112
.await
113113
.unwrap();
114-
let _quote = quotes.get(key).unwrap();
114+
let quote = quotes.get(key).unwrap();
115115
let new_quote = new_quotes.get(key).unwrap();
116116

117117
assert_eq!(price_data.comp_[0].latest_.price_, new_quote.price);
@@ -125,8 +125,18 @@ async fn test_publish_batch() {
125125
)
126126
.unwrap()
127127
);
128-
assert_eq!(price_data.comp_[0].agg_.price_, 0);
129-
assert_eq!(price_data.comp_[0].agg_.conf_, 0);
130-
assert_eq!(price_data.comp_[0].agg_.status_, PC_STATUS_UNKNOWN);
128+
if cfg!(feature = "no-default-accumulator-v2") {
129+
assert_eq!(price_data.comp_[0].agg_.price_, quote.price);
130+
assert_eq!(price_data.comp_[0].agg_.conf_, quote.confidence);
131+
assert_eq!(
132+
price_data.comp_[0].agg_.status_,
133+
get_status_for_conf_price_ratio(quote.price, quote.confidence, quote.status)
134+
.unwrap()
135+
);
136+
} else {
137+
assert_eq!(price_data.comp_[0].agg_.price_, 0);
138+
assert_eq!(price_data.comp_[0].agg_.conf_, 0);
139+
assert_eq!(price_data.comp_[0].agg_.status_, PC_STATUS_UNKNOWN);
140+
}
131141
}
132142
}

scripts/build-bpf.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,19 @@ set -x
1919
# Build both parts of the program (both C and rust) via Cargo
2020
cd "${PYTH_DIR}"
2121

22-
# Re-run tests affected by features
2322
cargo-test-bpf
24-
2523
cargo-build-bpf -- --locked -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort
2624
sha256sum ./target/**/*.so
2725
echo "Checking size of pyth_oracle.so for pythnet"
2826
./scripts/check-size.sh 88429
2927
mkdir -p target/pyth/pythnet/
3028
mv target/deploy/pyth_oracle.so target/pyth/pythnet/pyth_oracle_pythnet.so
29+
30+
# Re-run tests affected by features
31+
cargo-test-bpf -- --features no-default-accumulator-v2
32+
cargo-build-bpf -- --locked -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --features no-default-accumulator-v2
33+
sha256sum ./target/**/*.so
34+
echo "Checking size of pyth_oracle.so for pythnet with no accumulator"
35+
./scripts/check-size.sh 88429
36+
mkdir -p target/pyth/pythnet/
37+
mv target/deploy/pyth_oracle.so target/pyth/pythnet/pyth_oracle_pythnet_no_accumulator_v2.so

0 commit comments

Comments
 (0)