Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add publisher caps to the validator #412

Merged
merged 51 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
5cca0d9
feat(program): match version with pythnet
Reisen Jul 5, 2024
a8e1d32
feat: validator access point (wip)
Riateche Jul 5, 2024
4245d37
feat: add price account flags
Riateche Jul 5, 2024
762ad54
feat(program): fill out validator aggregation code
Reisen Jul 8, 2024
6eaf432
feat: don't aggregate on v2, clear message buffer, report validator a…
Riateche Jul 8, 2024
27212ee
feat: return price feed messages from validator aggregation
Riateche Jul 8, 2024
847b3f5
test: enable v2 aggregation
Riateche Jul 10, 2024
c9aa1e3
test: test aggregation toggle
Reisen Jul 10, 2024
f0ac267
fix: don't aggregate in validator if already aggregated in this slot
Riateche Jul 10, 2024
17a1cf6
chore: reexport solana_program and add derive debug
Riateche Jul 11, 2024
ce71807
chore: add comments
Riateche Jul 11, 2024
9ee8058
fix: don't revert if c_upd_aggregate returns false
Riateche Jul 12, 2024
9f03544
fix: make update_price_cumulative infallible; don't generate v2 messa…
Riateche Jul 12, 2024
a59effe
chore: remove publisher sorting hack
Riateche Jul 12, 2024
9523209
chore: remove AggregationOutcome
Riateche Jul 12, 2024
064a173
fix: remove debug_assert
Riateche Jul 12, 2024
70c9559
fix: allow clearing message buffers regardless of message_sent_ flag
Riateche Jul 16, 2024
5d1b09d
test: add test_upd_price_with_validator
Riateche Jul 16, 2024
3c9feb8
checkpoint
guibescos Jul 16, 2024
b13edd7
fix import
guibescos Jul 16, 2024
7d0958f
go
guibescos Jul 16, 2024
afe2eda
try this
guibescos Jul 16, 2024
fdcad70
go
guibescos Jul 16, 2024
881a2c0
try again
guibescos Jul 16, 2024
4d13547
Checkpoint
guibescos Jul 17, 2024
f6f4e3b
go
guibescos Jul 17, 2024
fa751b4
rename
guibescos Jul 17, 2024
2c78d8c
add test
guibescos Jul 17, 2024
80a3ccf
cargo lock
guibescos Jul 17, 2024
f853cd0
go
guibescos Jul 17, 2024
170afde
go
guibescos Jul 17, 2024
ef90813
format
guibescos Jul 18, 2024
6ad4893
rename
guibescos Jul 18, 2024
a0b470b
bump again
guibescos Jul 18, 2024
14c719d
add z
guibescos Jul 18, 2024
706a29c
go
guibescos Jul 18, 2024
d949c27
chore: add missing imports and fix warnings
Riateche Jul 19, 2024
fe64764
add m
guibescos Jul 19, 2024
ee9a478
Merge branch 'accumulator-v2' into feat/publisher-caps
guibescos Jul 22, 2024
91b235b
Clippy
guibescos Jul 22, 2024
9d58ce6
Merge branch 'main' into feat/publisher-caps
guibescos Jul 24, 2024
b2320d9
Update program/rust/src/accounts/price.rs
guibescos Jul 24, 2024
0783aa5
Update program/rust/src/accounts/price.rs
guibescos Jul 24, 2024
02bbe21
Remove vector
guibescos Jul 24, 2024
d7fa02d
fix: remove unwrap
guibescos Jul 25, 2024
dbbbc06
add comments
guibescos Jul 25, 2024
546efd7
fix: undo this
guibescos Jul 25, 2024
486e558
another comment
guibescos Jul 25, 2024
f6de9ed
add comment
guibescos Jul 25, 2024
632ee45
use checked indexing
guibescos Jul 31, 2024
8195a38
fix: use crates version of pythnet-sdk
guibescos Jul 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 58 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions program/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ num-traits = "0.2"
byteorder = "1.4.3"
serde = { version = "1.0", features = ["derive"], optional = true }
strum = { version = "0.24.1", features = ["derive"], optional = true }
pythnet-sdk = { git = "https://github.com/pyth-network/pyth-crosschain", rev="60144002053a93f424be70decd8a8ccb8d618d81"}
pythnet-sdk = "2.2.0"
solana-sdk = { version = "=1.14.17", optional = true }
bitflags = { version = "2.6.0", features = ["bytemuck"] }

Expand All @@ -31,7 +31,7 @@ rand = "0.8.5"
quickcheck_macros = "1"
bincode = "1.3.3"
serde = { version = "1.0", features = ["derive"] }
pythnet-sdk = { git = "https://github.com/pyth-network/pyth-crosschain", rev="60144002053a93f424be70decd8a8ccb8d618d81", features = ["quickcheck"]}
pythnet-sdk = { version = "2.2.0" , features = ["quickcheck"]}
serde_json = "1.0"
test-generator = "0.3.1"
csv = "1.1"
Expand Down
34 changes: 29 additions & 5 deletions program/rust/src/accounts/price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ use {
},
pythnet_sdk::messages::{
PriceFeedMessage,
PublisherStakeCapsMessage,
TwapMessage,
},
solana_program::pubkey::Pubkey,
std::mem::size_of,
std::{
mem::size_of,
u16,
},
};

/// Pythnet-specific PriceAccount implementation
Expand Down Expand Up @@ -111,7 +115,7 @@ mod price_pythnet {
};

PriceFeedMessage {
id: key.to_bytes(),
feed_id: key.to_bytes(),
price,
conf,
exponent: self.exponent,
Expand Down Expand Up @@ -141,7 +145,7 @@ mod price_pythnet {
};

TwapMessage {
id: key.to_bytes(),
feed_id: key.to_bytes(),
cumulative_price: self.price_cumulative.price,
cumulative_conf: self.price_cumulative.conf,
num_down_slots: self.price_cumulative.num_down_slots,
Expand Down Expand Up @@ -270,7 +274,7 @@ impl PythOracleSerialize for PriceFeedMessage {
bytes[i..i + 1].clone_from_slice(&[DISCRIMINATOR]);
i += 1;

bytes[i..i + 32].clone_from_slice(&self.id[..]);
bytes[i..i + 32].clone_from_slice(&self.feed_id[..]);
i += 32;

bytes[i..i + 8].clone_from_slice(&self.price.to_be_bytes());
Expand Down Expand Up @@ -313,7 +317,7 @@ impl PythOracleSerialize for TwapMessage {
bytes[i..i + 1].clone_from_slice(&[DISCRIMINATOR]);
i += 1;

bytes[i..i + 32].clone_from_slice(&self.id[..]);
bytes[i..i + 32].clone_from_slice(&self.feed_id[..]);
i += 32;

bytes[i..i + 16].clone_from_slice(&self.cumulative_price.to_be_bytes());
Expand All @@ -340,3 +344,23 @@ impl PythOracleSerialize for TwapMessage {
bytes.to_vec()
}
}

impl PythOracleSerialize for PublisherStakeCapsMessage {
fn to_bytes(self) -> Vec<u8> {
const DISCRIMINATOR: u8 = 2;
let mut result = vec![DISCRIMINATOR];
result.extend_from_slice(&self.publish_time.to_be_bytes());
result.extend_from_slice(
&u16::try_from(self.caps.as_ref().len())
.unwrap_or(u16::MAX)
.to_be_bytes(),
);

for cap in self.caps {
result.extend_from_slice(&cap.publisher);
result.extend_from_slice(&cap.cap.to_be_bytes());
}

result
}
}
27 changes: 27 additions & 0 deletions program/rust/src/tests/test_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ use {
messages::{
Message,
PriceFeedMessage,
PublisherStakeCapsMessage,
TwapMessage,
},
wire::from_slice,
},
quickcheck::{
Gen,
QuickCheck,
},
quickcheck_macros::quickcheck,
};

Expand Down Expand Up @@ -38,3 +43,25 @@ fn test_twap_message_roundtrip(input: TwapMessage) -> bool {
_ => false,
}
}


fn prop_publisher_caps_message_roundtrip(input: PublisherStakeCapsMessage) -> bool {
let reconstructed = from_slice::<BigEndian, Message>(&input.clone().to_bytes()).unwrap();

println!("Failed test case:");
println!("{:?}", input);
println!("{:?}", reconstructed);

match reconstructed {
Message::PublisherStakeCapsMessage(reconstructed) => reconstructed == input,
_ => false,
}
}

#[test]
fn test_publisher_caps_message_roundtrip() {
// Configure the size parameter for the generator
QuickCheck::new()
.gen(Gen::new(1024))
.quickcheck(prop_publisher_caps_message_roundtrip as fn(PublisherStakeCapsMessage) -> bool);
}
8 changes: 4 additions & 4 deletions program/rust/src/tests/test_upd_price_with_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn test_upd_price_with_validator() {
.unwrap();
let expected_messages1 = [
PriceFeedMessage {
id: price_account.key.to_bytes(),
feed_id: price_account.key.to_bytes(),
price: 42,
conf: 2,
exponent: 0,
Expand All @@ -141,7 +141,7 @@ fn test_upd_price_with_validator() {
}
.to_bytes(),
TwapMessage {
id: price_account.key.to_bytes(),
feed_id: price_account.key.to_bytes(),
cumulative_price: 42,
cumulative_conf: 2,
num_down_slots: 0,
Expand All @@ -161,7 +161,7 @@ fn test_upd_price_with_validator() {

let expected_messages2 = [
PriceFeedMessage {
id: price_account.key.to_bytes(),
feed_id: price_account.key.to_bytes(),
price: 42,
conf: 2,
exponent: 0,
Expand All @@ -172,7 +172,7 @@ fn test_upd_price_with_validator() {
}
.to_bytes(),
TwapMessage {
id: price_account.key.to_bytes(),
feed_id: price_account.key.to_bytes(),
cumulative_price: 84,
cumulative_conf: 4,
num_down_slots: 0,
Expand Down
Loading
Loading