-
Notifications
You must be signed in to change notification settings - Fork 16
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
Changes from all commits
4a75b68
e54872f
0bb6502
a4cafa9
48d01f7
281e9d4
db835e4
5df9d53
cd58b05
da4eb87
f3deb0f
5f9e29f
3b3bd39
89b6c22
8e220a7
4955945
16ef4a8
d7001d3
9669965
aab935e
0dc93f6
30b1057
3aee40e
b48fa0f
7145ab7
44d13c1
063bf58
47004da
eea63f9
5f1ee90
169899f
0811f95
c234662
977fa3a
7e7e4eb
c274161
3d54ed2
a989325
7aae599
7ba1540
8e49c44
44a92ce
ca68105
430b685
9e3a803
4977752
8043020
9c9c8fe
2f5eeb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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 | ||
|
@@ -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), | ||
), | ||
] | ||
} | ||
|
||
|
@@ -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(); | ||
|
||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.