Skip to content

feat: add publisher caps to the validator #302

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

Merged
merged 49 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
4a75b68
feat: accumulator v2 (wip 1)
Riateche Jul 5, 2024
e54872f
feat: accumulator v2 (wip 2)
Reisen Jul 5, 2024
0bb6502
chore: fix some warnings and fix validator build
Riateche Jul 5, 2024
a4cafa9
feat: accumulator v2 (wip 3)
Reisen Jul 8, 2024
48d01f7
feat: skip message buffer aggregation if all price feeds use v2 aggre…
Riateche Jul 8, 2024
281e9d4
feat: combine v1 and v2 aggregation price feed messages in the merkle…
Riateche Jul 8, 2024
db835e4
refactor: clean up and avoid extra vector
Riateche Jul 9, 2024
5df9d53
fix: don't aggregate if already aggregated in the program
Riateche Jul 10, 2024
cd58b05
test: bring back old pyth tests (wip)
Riateche Jul 10, 2024
da4eb87
test: fix old pyth tests
Riateche Jul 12, 2024
f3deb0f
test: add initial v2 tests to validator
Reisen Jul 16, 2024
5f9e29f
refactor: unify env var handling
Riateche Jul 18, 2024
3b3bd39
go
guibescos Jul 16, 2024
89b6c22
go
guibescos Jul 17, 2024
8e220a7
clean
guibescos Jul 17, 2024
4955945
ready
guibescos Jul 17, 2024
16ef4a8
add info
guibescos Jul 17, 2024
d7001d3
Add new feature
guibescos Jul 18, 2024
9669965
update logs
guibescos Jul 18, 2024
aab935e
undo this change
guibescos Jul 18, 2024
0dc93f6
reset
guibescos Jul 18, 2024
30b1057
fix
guibescos Jul 18, 2024
3aee40e
bump
guibescos Jul 18, 2024
b48fa0f
add z
guibescos Jul 18, 2024
7145ab7
chore: fix build for stable Rust by ignoring lints
Riateche Jul 19, 2024
44d13c1
add m and z
guibescos Jul 19, 2024
063bf58
test: fix and expand accumulator-v2 tests
Riateche Jul 22, 2024
47004da
Merge branch 'accumulator-v2' into feat/publisher-caps
guibescos Jul 22, 2024
eea63f9
Merge branch 'pyth-v1.14.17' into feat/publisher-caps
guibescos Jul 24, 2024
5f1ee90
fix: revert file
guibescos Jul 24, 2024
169899f
cleanup
guibescos Jul 24, 2024
0811f95
fix: format
guibescos Jul 25, 2024
c234662
cleanup
guibescos Jul 25, 2024
977fa3a
fix: then some
guibescos Jul 25, 2024
7e7e4eb
fix: use default
guibescos Jul 25, 2024
c274161
fix: fmt
guibescos Jul 25, 2024
3d54ed2
go
guibescos Jul 25, 2024
a989325
fix: cargo lock
guibescos Jul 25, 2024
7aae599
Merge branch 'pyth-v1.14.17' into feat/publisher-caps
guibescos Jul 29, 2024
7ba1540
checkpoint
guibescos Jul 30, 2024
8e49c44
test: add test
guibescos Jul 30, 2024
44a92ce
clean up
guibescos Jul 30, 2024
ca68105
fmt
guibescos Jul 30, 2024
430b685
clippy
guibescos Jul 30, 2024
9e3a803
add measure
guibescos Jul 30, 2024
4977752
fix: other tests
guibescos Jul 30, 2024
8043020
fix: add bad stake parameters
guibescos Jul 30, 2024
9c9c8fe
fix: downgrade to debug
guibescos Jul 30, 2024
2f5eeb2
fix: use released version
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
96 changes: 71 additions & 25 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 runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ num-traits = { version = "0.2" }
num_cpus = "1.13.1"
once_cell = "1.12.0"
ouroboros = "0.15.0"
pyth-oracle = { git = "https://github.com/pyth-network/pyth-client", tag = "oracle-v2.32.1", features = ["library"] }
pythnet-sdk = { git = "https://github.com/pyth-network/pyth-crosschain", version = "1.13.6", rev = "e670f57f89b05398ca352e4accb1e32724a8e1b4" }
pyth-oracle = { git = "https://github.com/pyth-network/pyth-client", tag = "oracle-v2.33.0", features = ["library"] }
pythnet-sdk = { git = "https://github.com/pyth-network/pyth-crosschain", version = "1.13.6", rev = "33f901aa45f4f0005aa5a84a1479b78ca9033074" }
rand = "0.7.0"
rayon = "1.5.3"
regex = "1.5.6"
Expand Down
59 changes: 57 additions & 2 deletions runtime/src/bank/pyth_accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use {
pythnet_sdk::{
accumulators::{merkle::MerkleAccumulator, Accumulator},
hashers::keccak256_160::Keccak160,
publisher_stake_caps::StakeCapParameters,
wormhole::{AccumulatorSequenceTracker, MessageData, PostedMessageUnreliableData},
},
solana_measure::measure::Measure,
Expand Down Expand Up @@ -44,6 +45,12 @@ lazy_static! {
.parse()
.unwrap(),
);
pub static ref STAKE_CAPS_PARAMETERS_ADDR: Pubkey = env_pubkey_or(
"STAKE_CAPS_PARAMETERS_ADDR",
"879ZVNagiWaAKsWDjGVf8pLq1wUBeBz7sREjUh3hrU36"
.parse()
.unwrap(),
);
}

/// Accumulator specific error type. It would be nice to use `transaction::Error` but it does
Expand Down Expand Up @@ -121,6 +128,10 @@ pub fn get_accumulator_keys() -> Vec<(
("ACCUMULATOR_SEQUENCE_ADDR", Ok(*ACCUMULATOR_SEQUENCE_ADDR)),
("WORMHOLE_PID", Ok(*WORMHOLE_PID)),
("ORACLE_PID", Ok(*ORACLE_PID)),
(
"STAKE_CAPS_PARAMETERS_ADDR",
Ok(*STAKE_CAPS_PARAMETERS_ADDR),
),
]
}

Expand Down Expand Up @@ -408,11 +419,16 @@ pub fn update_v2(bank: &Bank) -> std::result::Result<(), AccumulatorUpdateErrorV
measure.as_us()
);

let mut measure = Measure::start("update_v2_aggregate_price");

let mut any_v1_aggregations = false;
let mut v2_messages = Vec::new();

if let Some(publisher_stake_caps_message) = compute_publisher_stake_caps(bank, &accounts) {
info!("PublisherStakeCaps: Adding publisher stake caps to the accumulator");
v2_messages.push(publisher_stake_caps_message);
}

let mut measure = Measure::start("update_v2_aggregate_price");

for (pubkey, mut account) in accounts {
let mut price_account_data = account.data().to_owned();

Expand Down Expand Up @@ -446,3 +462,42 @@ pub fn update_v2(bank: &Bank) -> std::result::Result<(), AccumulatorUpdateErrorV

update_v1(bank, &v2_messages, any_v1_aggregations)
}

pub fn compute_publisher_stake_caps(
bank: &Bank,
accounts: &[(Pubkey, AccountSharedData)],
) -> Option<Vec<u8>> {
let mut measure = Measure::start("compute_publisher_stake_caps");

let parameters: StakeCapParameters = {
let data = bank
.get_account_with_fixed_root(&STAKE_CAPS_PARAMETERS_ADDR)
.unwrap_or_default();
let data = data.data();
solana_sdk::borsh::try_from_slice_unchecked(data).unwrap_or_default()
};

let message = pyth_oracle::validator::compute_publisher_stake_caps(
accounts.iter().map(|(_, account)| account.data()),
bank.clock().unix_timestamp,
parameters.m,
parameters.z,
);

measure.stop();
debug!(
"PublisherStakeCaps: Computed publisher stake caps with m : {} and z : {} in {} us",
parameters.m,
parameters.z,
measure.as_us()
);

if bank

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small detail: Checking this at the beginning and exiting early if the feature set is deactivated would avoid some unnecessary computations if it is deactivated.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be useful so that we detect errors in the logic before the feature activation or before a majority of nodes have updated.

.feature_set
.is_active(&feature_set::add_publisher_stake_caps_to_the_accumulator::id())
{
Some(message)
} else {
None
}
}
Loading