Skip to content

Commit 0045bdc

Browse files
committed
feat: update to new batch publish instruction format
1 parent 30fb3eb commit 0045bdc

File tree

5 files changed

+73
-51
lines changed

5 files changed

+73
-51
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ tracing-opentelemetry = "0.24.0"
5656
opentelemetry = "0.23.0"
5757
opentelemetry_sdk = { version = "0.23.0", features = ["rt-tokio"]}
5858
opentelemetry-otlp = { version = "0.16.0" }
59-
pyth-price-publisher = { git = "https://github.com/pyth-network/pyth-crosschain", branch = "add-publisher-program" }
59+
pyth-price-publisher = { git = "https://github.com/pyth-network/pyth-crosschain", rev = "4df7172b" }
6060
bytemuck = "1.13.0"
6161

6262
[dev-dependencies]

src/agent/services/exporter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ mod exporter {
270270
&publish_keypair,
271271
key_store.oracle_program_key,
272272
key_store.publish_program_key,
273+
key_store.publisher_buffer_key,
273274
config.exporter.max_batch_size,
274275
config.exporter.staleness_threshold,
275276
config.exporter.compute_unit_limit,

src/agent/solana.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ pub mod key_store {
103103
default
104104
)]
105105
pub publish_program_key: Option<Pubkey>,
106+
/// The public key of the publisher's buffer for the Publish program
107+
#[serde(
108+
serialize_with = "opt_pubkey_string_ser",
109+
deserialize_with = "opt_pubkey_string_de",
110+
default
111+
)]
112+
pub publisher_buffer_key: Option<Pubkey>,
106113
/// The public key of the root mapping account
107114
#[serde(
108115
serialize_with = "pubkey_string_ser",
@@ -122,15 +129,18 @@ pub mod key_store {
122129
/// The keypair used to publish price updates. When None,
123130
/// publishing will not start until a new keypair is supplied
124131
/// via the remote loading endpoint
125-
pub publish_keypair: Option<Keypair>,
132+
pub publish_keypair: Option<Keypair>,
126133
/// Public key of the Oracle program
127-
pub oracle_program_key: Pubkey,
134+
pub oracle_program_key: Pubkey,
128135
/// Public key of the Publish program
129-
pub publish_program_key: Option<Pubkey>,
136+
pub publish_program_key: Option<Pubkey>,
137+
/// Public key of the publisher's buffer for the publish program
138+
pub publisher_buffer_key: Option<Pubkey>,
139+
130140
/// Public key of the root mapping account
131-
pub mapping_key: Pubkey,
141+
pub mapping_key: Pubkey,
132142
/// Public key of the accumulator program (if provided)
133-
pub accumulator_key: Option<Pubkey>,
143+
pub accumulator_key: Option<Pubkey>,
134144
}
135145

136146
impl KeyStore {
@@ -151,6 +161,7 @@ pub mod key_store {
151161
publish_keypair,
152162
oracle_program_key: config.oracle_program_key,
153163
publish_program_key: config.publish_program_key,
164+
publisher_buffer_key: config.publisher_buffer_key,
154165
mapping_key: config.mapping_key,
155166
accumulator_key: config.accumulator_key,
156167
})

src/agent/state/exporter.rs

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@ use {
1515
},
1616
},
1717
anyhow::{
18-
anyhow,
19-
Context,
20-
Result,
18+
anyhow, bail, Context, Result
2119
},
2220
bincode::Options,
23-
bytemuck::cast_slice,
21+
bytemuck::{bytes_of, cast_slice},
2422
chrono::Utc,
2523
futures_util::future::join_all,
26-
pyth_price_publisher::accounts::publisher_prices::PublisherPrice,
24+
pyth_price_publisher::accounts::buffer::BufferedPrice,
2725
pyth_sdk::Identifier,
2826
pyth_sdk_solana::state::PriceStatus,
2927
serde::Serialize,
@@ -451,6 +449,7 @@ pub async fn publish_batches<S>(
451449
publish_keypair: &Keypair,
452450
oracle_program_key: Pubkey,
453451
publish_program_key: Option<Pubkey>,
452+
publisher_buffer_key: Option<Pubkey>,
454453
max_batch_size: usize,
455454
staleness_threshold: Duration,
456455
compute_unit_limit: u32,
@@ -489,6 +488,7 @@ where
489488
publish_keypair,
490489
oracle_program_key,
491490
publish_program_key,
491+
publisher_buffer_key,
492492
batch,
493493
staleness_threshold,
494494
compute_unit_limit,
@@ -533,6 +533,7 @@ async fn publish_batch<S>(
533533
publish_keypair: &Keypair,
534534
oracle_program_key: Pubkey,
535535
publish_program_key: Option<Pubkey>,
536+
publisher_buffer_key: Option<Pubkey>,
536537
batch: &[PermissionedUpdate],
537538
staleness_threshold: Duration,
538539
compute_unit_limit: u32,
@@ -576,35 +577,36 @@ where
576577
}
577578

578579
if let Some(publish_program_key) = publish_program_key {
579-
let (instruction, unsupported_updates) = create_instruction_with_publish_program(
580+
let instruction = create_instruction_with_publish_program(
580581
publish_keypair.pubkey(),
581582
publish_program_key,
583+
publisher_buffer_key.context("must specify publisher_buffer_key if publish_program_key is specified")?,
582584
updates,
583585
)?;
584-
updates = unsupported_updates;
585-
instructions.push(instruction);
586-
}
587-
for update in updates {
588-
let instruction = if let Some(accumulator_program_key) = accumulator_key {
589-
create_instruction_with_accumulator(
590-
publish_keypair.pubkey(),
591-
oracle_program_key,
592-
Pubkey::from(update.feed_id.to_bytes()),
593-
&update.info,
594-
network_state.current_slot,
595-
accumulator_program_key,
596-
)?
597-
} else {
598-
create_instruction_without_accumulator(
599-
publish_keypair.pubkey(),
600-
oracle_program_key,
601-
Pubkey::from(update.feed_id.to_bytes()),
602-
&update.info,
603-
network_state.current_slot,
604-
)?
605-
};
606-
607586
instructions.push(instruction);
587+
} else {
588+
for update in updates {
589+
let instruction = if let Some(accumulator_program_key) = accumulator_key {
590+
create_instruction_with_accumulator(
591+
publish_keypair.pubkey(),
592+
oracle_program_key,
593+
Pubkey::from(update.feed_id.to_bytes()),
594+
&update.info,
595+
network_state.current_slot,
596+
accumulator_program_key,
597+
)?
598+
} else {
599+
create_instruction_without_accumulator(
600+
publish_keypair.pubkey(),
601+
oracle_program_key,
602+
Pubkey::from(update.feed_id.to_bytes()),
603+
&update.info,
604+
network_state.current_slot,
605+
)?
606+
};
607+
608+
instructions.push(instruction);
609+
}
608610
}
609611

610612
// Pay priority fees, if configured
@@ -800,28 +802,31 @@ fn create_instruction_without_accumulator(
800802
fn create_instruction_with_publish_program(
801803
publish_pubkey: Pubkey,
802804
publish_program_key: Pubkey,
805+
publisher_buffer_key: Pubkey,
803806
prices: Vec<PermissionedUpdate>,
804-
) -> Result<(Instruction, Vec<PermissionedUpdate>)> {
805-
let mut unsupported_updates = Vec::new();
806-
let (buffer_key, _buffer_bump) = Pubkey::find_program_address(
807-
&["BUFFER".as_bytes(), &publish_pubkey.to_bytes()],
807+
) -> Result<Instruction> {
808+
use pyth_price_publisher::instruction::{Instruction as PublishInstruction, SubmitPricesArgsHeader, PUBLISHER_CONFIG_SEED};
809+
let (publisher_config_key, publisher_config_bump) = Pubkey::find_program_address(
810+
&[PUBLISHER_CONFIG_SEED.as_bytes(), &publish_pubkey.to_bytes()],
808811
&publish_program_key,
809812
);
810813

811814
let mut values = Vec::new();
812815
for update in prices {
813816
if update.feed_index == 0 {
814-
unsupported_updates.push(update);
815-
} else {
816-
values.push(PublisherPrice::new(
817-
update.feed_index,
818-
(update.info.status as u8).into(),
819-
update.info.price,
820-
update.info.conf,
821-
)?);
817+
bail!("no feed index for feed {:?}", update.feed_id);
822818
}
819+
values.push(BufferedPrice::new(
820+
update.feed_index,
821+
(update.info.status as u8).into(),
822+
update.info.price,
823+
update.info.conf,
824+
)?);
823825
}
824-
let mut data = vec![1];
826+
let mut data = vec![PublishInstruction::SubmitPrices as u8];
827+
data.extend_from_slice(bytes_of(&SubmitPricesArgsHeader {
828+
publisher_config_bump,
829+
}));
825830
data.extend(cast_slice(&values));
826831

827832
let instruction = Instruction {
@@ -833,14 +838,19 @@ fn create_instruction_with_publish_program(
833838
is_writable: true,
834839
},
835840
AccountMeta {
836-
pubkey: buffer_key,
841+
pubkey: publisher_config_key,
842+
is_signer: false,
843+
is_writable: false,
844+
},
845+
AccountMeta {
846+
pubkey: publisher_buffer_key,
837847
is_signer: false,
838848
is_writable: true,
839849
},
840850
],
841851
data,
842852
};
843-
Ok((instruction, unsupported_updates))
853+
Ok(instruction)
844854
}
845855

846856
fn create_instruction_with_accumulator(

0 commit comments

Comments
 (0)