Skip to content

Commit 7d5cd84

Browse files
committed
Change Oracle to use Key Store keys instead of those defined manually in config
1 parent 403d3ea commit 7d5cd84

File tree

5 files changed

+42
-115
lines changed

5 files changed

+42
-115
lines changed

Cargo.lock

Lines changed: 0 additions & 72 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ config = "0.13.3"
3535
thiserror = "1.0.32"
3636
solana-shadow = "0.2.4"
3737
clap = { version = "4.0.32", features = ["derive"] }
38-
serde_with = "2.2.0"
3938
humantime-serde = "1.1.1"
4039

4140
[dev-dependencies]

integration-tests/agent_conf.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
[primary_network]
22
key_store.root_path = "keystore"
33
oracle.poll_interval_duration = "1s"
4-
oracle.oracle_account_key = "BujGr9ChcuaCJhxeFEvGvaCFTxSV1CUCSVHL1SVFpU4i"
5-
oracle.mapping_account_key = "BTJKZngp3vzeJiRmmT9PitQH4H29dhQZ1GNhxFfDi4kw"
6-
oracle.subscriber.account_key = "BujGr9ChcuaCJhxeFEvGvaCFTxSV1CUCSVHL1SVFpU4i"
74
exporter.transaction_monitor.poll_interval_duration = "1s"

src/agent/solana.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,21 @@ pub mod network {
5050
global_store_update_tx: mpsc::Sender<global::Update>,
5151
logger: Logger,
5252
) -> Result<Vec<JoinHandle<()>>> {
53-
// Create the key store
54-
let key_store = KeyStore::new(config.key_store.clone())?;
55-
5653
// Spawn the Oracle
5754
let mut jhs = oracle::spawn_oracle(
5855
config.oracle.clone(),
56+
KeyStore::new(config.key_store.clone())?,
5957
global_store_update_tx,
6058
logger.clone(),
6159
);
6260

6361
// Spawn the Exporter
64-
let exporter_jhs =
65-
exporter::spawn_exporter(config.exporter, key_store, local_store_tx, logger)?;
62+
let exporter_jhs = exporter::spawn_exporter(
63+
config.exporter,
64+
KeyStore::new(config.key_store.clone())?,
65+
local_store_tx,
66+
logger,
67+
)?;
6668
jhs.extend(exporter_jhs);
6769

6870
Ok(jhs)

src/agent/solana/oracle.rs

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use {
55
self::subscriber::Subscriber,
6+
super::key_store::KeyStore,
67
crate::agent::store::global,
78
anyhow::{
89
anyhow,
@@ -18,10 +19,6 @@ use {
1819
Deserialize,
1920
Serialize,
2021
},
21-
serde_with::{
22-
serde_as,
23-
DisplayFromStr,
24-
},
2522
slog::Logger,
2623
solana_client::nonblocking::rpc_client::RpcClient,
2724
solana_sdk::{
@@ -65,6 +62,9 @@ pub type PriceAccount = pyth_sdk_solana::state::PriceAccount;
6562
pub struct Oracle {
6663
config: Config,
6764

65+
// The Key Store
66+
key_store: KeyStore,
67+
6868
// The Solana account data
6969
data: Data,
7070

@@ -85,18 +85,11 @@ pub struct Oracle {
8585
logger: Logger,
8686
}
8787

88-
#[serde_as]
8988
#[derive(Clone, Serialize, Deserialize, Debug)]
9089
#[serde(default)]
9190
pub struct Config {
9291
/// The commitment level to use when reading data from the RPC node.
9392
pub commitment: CommitmentLevel,
94-
/// Public key of the Oracle program.
95-
#[serde_as(as = "DisplayFromStr")]
96-
pub oracle_account_key: Pubkey,
97-
/// Public key of the root mapping account.
98-
#[serde_as(as = "DisplayFromStr")]
99-
pub mapping_account_key: Pubkey,
10093
/// RPC endpoint to send requests to.
10194
pub rpc_url: String,
10295
/// The interval with which to poll account information.
@@ -114,8 +107,6 @@ impl Default for Config {
114107
fn default() -> Self {
115108
Self {
116109
commitment: CommitmentLevel::Confirmed,
117-
oracle_account_key: Default::default(),
118-
mapping_account_key: Default::default(),
119110
rpc_url: "http://localhost:8899".to_string(),
120111
poll_interval_duration: Duration::from_secs(30),
121112
subscriber_enabled: true,
@@ -127,6 +118,7 @@ impl Default for Config {
127118

128119
pub fn spawn_oracle(
129120
config: Config,
121+
key_store: KeyStore,
130122
global_store_update_tx: mpsc::Sender<global::Update>,
131123
logger: Logger,
132124
) -> Vec<JoinHandle<()>> {
@@ -135,12 +127,23 @@ pub fn spawn_oracle(
135127
// Create and spawn the account subscriber
136128
let (updates_tx, updates_rx) = mpsc::channel(config.updates_channel_capacity);
137129
if config.subscriber_enabled {
138-
let subscriber = Subscriber::new(config.subscriber.clone(), updates_tx, logger.clone());
130+
let subscriber = Subscriber::new(
131+
config.subscriber.clone(),
132+
key_store.program_key.clone(),
133+
updates_tx,
134+
logger.clone(),
135+
);
139136
jhs.push(tokio::spawn(async move { subscriber.run().await }));
140137
}
141138

142139
// Create and spawn the Oracle
143-
let mut oracle = Oracle::new(config, updates_rx, global_store_update_tx, logger);
140+
let mut oracle = Oracle::new(
141+
config,
142+
key_store,
143+
updates_rx,
144+
global_store_update_tx,
145+
logger,
146+
);
144147
jhs.push(tokio::spawn(async move { oracle.run().await }));
145148

146149
jhs
@@ -149,6 +152,7 @@ pub fn spawn_oracle(
149152
impl Oracle {
150153
pub fn new(
151154
config: Config,
155+
key_store: KeyStore,
152156
updates_rx: mpsc::Receiver<(Pubkey, solana_sdk::account::Account)>,
153157
global_store_tx: mpsc::Sender<global::Update>,
154158
logger: Logger,
@@ -163,6 +167,7 @@ impl Oracle {
163167

164168
Oracle {
165169
config,
170+
key_store,
166171
data: Default::default(),
167172
rpc_client,
168173
poll_interval,
@@ -200,7 +205,7 @@ impl Oracle {
200205
.cloned()
201206
.collect::<HashSet<_>>();
202207
self.data.mapping_accounts = self
203-
.fetch_mapping_accounts(self.config.mapping_account_key)
208+
.fetch_mapping_accounts(self.key_store.mapping_key)
204209
.await?;
205210
info!(self.logger, "fetched mapping accounts"; "new" => format!("{:?}", self
206211
.data
@@ -449,10 +454,6 @@ mod subscriber {
449454
Deserialize,
450455
Serialize,
451456
},
452-
serde_with::{
453-
serde_as,
454-
DisplayFromStr,
455-
},
456457
slog::Logger,
457458
solana_sdk::{
458459
account::Account,
@@ -469,29 +470,23 @@ mod subscriber {
469470
},
470471
};
471472

472-
#[serde_as]
473473
#[derive(Clone, Serialize, Deserialize, Debug)]
474474
#[serde(default)]
475475
pub struct Config {
476476
/// Commitment level used to read account data
477-
pub commitment: CommitmentLevel,
478-
/// Public key of the root account to monitor. Note that all
479-
/// accounts owned by this account are also monitored.
480-
#[serde_as(as = "DisplayFromStr")]
481-
pub account_key: Pubkey,
477+
pub commitment: CommitmentLevel,
482478
/// HTTP RPC endpoint
483-
pub rpc_url: String,
479+
pub rpc_url: String,
484480
/// WSS RPC endpoint
485-
pub wss_url: String,
481+
pub wss_url: String,
486482
}
487483

488484
impl Default for Config {
489485
fn default() -> Self {
490486
Self {
491-
commitment: CommitmentLevel::Confirmed,
492-
account_key: Default::default(),
493-
rpc_url: "http://localhost:8899".to_string(),
494-
wss_url: "ws://localhost:8900".to_string(),
487+
commitment: CommitmentLevel::Confirmed,
488+
rpc_url: "http://localhost:8899".to_string(),
489+
wss_url: "ws://localhost:8900".to_string(),
495490
}
496491
}
497492
}
@@ -501,7 +496,11 @@ mod subscriber {
501496
pub struct Subscriber {
502497
config: Config,
503498

504-
// Channel on which updates are sent
499+
/// Public key of the root account to monitor. Note that all
500+
/// accounts owned by this account are also monitored.
501+
account_key: Pubkey,
502+
503+
/// Channel on which updates are sent
505504
updates_tx: mpsc::Sender<(Pubkey, solana_sdk::account::Account)>,
506505

507506
logger: Logger,
@@ -510,11 +509,13 @@ mod subscriber {
510509
impl Subscriber {
511510
pub fn new(
512511
config: Config,
512+
account_key: Pubkey,
513513
updates_tx: mpsc::Sender<(Pubkey, solana_sdk::account::Account)>,
514514
logger: Logger,
515515
) -> Self {
516516
Subscriber {
517517
config,
518+
account_key,
518519
updates_tx,
519520
logger,
520521
}
@@ -549,7 +550,7 @@ mod subscriber {
549550
&self,
550551
) -> Result<broadcast::Receiver<(Pubkey, solana_sdk::account::Account)>> {
551552
let shadow = BlockchainShadow::new_for_program(
552-
&self.config.account_key,
553+
&self.account_key,
553554
SyncOptions {
554555
network: solana_shadow::Network::Custom(
555556
self.config.rpc_url.clone(),

0 commit comments

Comments
 (0)