Skip to content

Commit

Permalink
feat: support batch publish (#140)
Browse files Browse the repository at this point in the history
* feat: support batch publish

* feat: update to new batch publish instruction format

* feat: fetch publisher buffer key

* chore: update publisher program dependency

* chore: bump agent version to 2.11.0
  • Loading branch information
Riateche authored Sep 10, 2024
1 parent 2872c68 commit bcd190e
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 80 deletions.
14 changes: 13 additions & 1 deletion Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyth-agent"
version = "2.10.4"
version = "2.11.0"
edition = "2021"

[[bin]]
Expand Down Expand Up @@ -56,6 +56,8 @@ tracing-opentelemetry = "0.24.0"
opentelemetry = "0.23.0"
opentelemetry_sdk = { version = "0.23.0", features = ["rt-tokio"]}
opentelemetry-otlp = { version = "0.16.0" }
pyth-price-store = "0.1.0"
bytemuck = "1.13.0"

[dev-dependencies]
tokio-util = { version = "0.7.10", features = ["full"] }
Expand Down
5 changes: 4 additions & 1 deletion src/agent/services/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,17 @@ mod exporter {
config.exporter.staleness_threshold,
config.exporter.unchanged_publish_threshold,
).await {
let publisher_buffer_key = Exporter::get_publisher_buffer_key(&*state).await;
if let Err(err) = publish_batches(
state.clone(),
client.clone(),
network,
&network_state_rx,
key_store.accumulator_key,
&publish_keypair,
key_store.program_key,
key_store.oracle_program_key,
key_store.publish_program_key,
publisher_buffer_key,
config.exporter.max_batch_size,
config.exporter.staleness_threshold,
config.exporter.compute_unit_limit,
Expand Down
5 changes: 4 additions & 1 deletion src/agent/services/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ where
state.clone(),
key_store.mapping_key,
key_store.publish_keypair,
key_store.publish_program_key,
config.oracle.max_lookup_batch_size,
)));

Expand All @@ -73,7 +74,7 @@ where
config.clone(),
network,
state.clone(),
key_store.program_key,
key_store.oracle_program_key,
)
.await
{
Expand Down Expand Up @@ -159,6 +160,7 @@ async fn poller<S>(
state: Arc<S>,
mapping_key: Pubkey,
publish_keypair: Option<Keypair>,
publish_program_key: Option<Pubkey>,
max_lookup_batch_size: usize,
) where
S: Oracle,
Expand All @@ -183,6 +185,7 @@ async fn poller<S>(
network,
mapping_key,
publish_keypair.as_ref(),
publish_program_key,
&client,
max_lookup_batch_size,
)
Expand Down
25 changes: 18 additions & 7 deletions src/agent/solana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,17 @@ pub mod key_store {
/// The public key of the Oracle program
#[serde(
serialize_with = "pubkey_string_ser",
deserialize_with = "pubkey_string_de"
deserialize_with = "pubkey_string_de",
alias = "program_key" // for compatibility
)]
pub oracle_program_key: Pubkey,
/// The public key of the Publish program
#[serde(
serialize_with = "opt_pubkey_string_ser",
deserialize_with = "opt_pubkey_string_de",
default
)]
pub program_key: Pubkey,
pub publish_program_key: Option<Pubkey>,
/// The public key of the root mapping account
#[serde(
serialize_with = "pubkey_string_ser",
Expand All @@ -114,13 +122,15 @@ pub mod key_store {
/// The keypair used to publish price updates. When None,
/// publishing will not start until a new keypair is supplied
/// via the remote loading endpoint
pub publish_keypair: Option<Keypair>,
pub publish_keypair: Option<Keypair>,
/// Public key of the Oracle program
pub program_key: Pubkey,
pub oracle_program_key: Pubkey,
/// Public key of the Publish program
pub publish_program_key: Option<Pubkey>,
/// Public key of the root mapping account
pub mapping_key: Pubkey,
pub mapping_key: Pubkey,
/// Public key of the accumulator program (if provided)
pub accumulator_key: Option<Pubkey>,
pub accumulator_key: Option<Pubkey>,
}

impl KeyStore {
Expand All @@ -139,7 +149,8 @@ pub mod key_store {

Ok(KeyStore {
publish_keypair,
program_key: config.program_key,
oracle_program_key: config.oracle_program_key,
publish_program_key: config.publish_program_key,
mapping_key: config.mapping_key,
accumulator_key: config.accumulator_key,
})
Expand Down
Loading

0 comments on commit bcd190e

Please sign in to comment.