Skip to content

Commit a7b045b

Browse files
committed
Move rpc_url and wss_url into network-level configuration
1 parent 648b418 commit a7b045b

File tree

3 files changed

+47
-23
lines changed

3 files changed

+47
-23
lines changed

src/agent/solana.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ pub mod network {
3434
};
3535

3636
/// Configuration for a network
37-
#[derive(Clone, Serialize, Deserialize, Debug, Default)]
37+
#[derive(Clone, Serialize, Deserialize, Debug)]
38+
#[serde(default)]
3839
pub struct Config {
40+
/// HTTP RPC endpoint
41+
pub rpc_url: String,
42+
/// WSS RPC endpoint
43+
pub wss_url: String,
3944
/// Keystore
4045
pub key_store: key_store::Config,
4146
/// Configuration for the Oracle reading data from this network
@@ -44,6 +49,18 @@ pub mod network {
4449
pub exporter: exporter::Config,
4550
}
4651

52+
impl Default for Config {
53+
fn default() -> Self {
54+
Self {
55+
rpc_url: "http://localhost:8899".to_string(),
56+
wss_url: "ws://localhost:8900".to_string(),
57+
key_store: Default::default(),
58+
oracle: Default::default(),
59+
exporter: Default::default(),
60+
}
61+
}
62+
}
63+
4764
pub fn spawn_network(
4865
config: Config,
4966
local_store_tx: Sender<store::local::Message>,
@@ -53,6 +70,8 @@ pub mod network {
5370
// Spawn the Oracle
5471
let mut jhs = oracle::spawn_oracle(
5572
config.oracle.clone(),
73+
&config.rpc_url,
74+
&config.wss_url,
5675
KeyStore::new(config.key_store.clone())?,
5776
global_store_update_tx,
5877
logger.clone(),
@@ -61,6 +80,7 @@ pub mod network {
6180
// Spawn the Exporter
6281
let exporter_jhs = exporter::spawn_exporter(
6382
config.exporter,
83+
&config.rpc_url,
6484
KeyStore::new(config.key_store.clone())?,
6585
local_store_tx,
6686
logger,

src/agent/solana/exporter.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ struct UpdPriceCmd {
8686
#[derive(Clone, Serialize, Deserialize, Debug)]
8787
#[serde(default)]
8888
pub struct Config {
89-
/// HTTP endpoint of the Solana RPC node
90-
pub rpc_endpoint: String,
9189
/// Duration of the interval at which to refresh the cached network state (current slot and blockhash).
9290
/// It is recommended to set this to slightly less than the network's block time,
9391
/// as the slot fetched will be used as the time of the price update.
@@ -114,7 +112,6 @@ pub struct Config {
114112
impl Default for Config {
115113
fn default() -> Self {
116114
Self {
117-
rpc_endpoint: "http://localhost:8899".to_string(),
118115
refresh_network_state_interval_duration: Duration::from_millis(200),
119116
publish_interval_duration: Duration::from_secs(1),
120117
staleness_threshold: Duration::from_secs(5),
@@ -130,14 +127,15 @@ impl Default for Config {
130127

131128
pub fn spawn_exporter(
132129
config: Config,
130+
rpc_url: &str,
133131
key_store: KeyStore,
134132
local_store_tx: Sender<store::local::Message>,
135133
logger: Logger,
136134
) -> Result<Vec<JoinHandle<()>>> {
137135
// Create and spawn the network state querier
138136
let (network_state_tx, network_state_rx) = watch::channel(Default::default());
139137
let mut network_state_querier = NetworkStateQuerier::new(
140-
&config.rpc_endpoint,
138+
&rpc_url,
141139
time::interval(config.refresh_network_state_interval_duration),
142140
network_state_tx,
143141
logger.clone(),
@@ -149,6 +147,7 @@ pub fn spawn_exporter(
149147
mpsc::channel(config.inflight_transactions_channel_capacity);
150148
let mut transaction_monitor = TransactionMonitor::new(
151149
config.transaction_monitor.clone(),
150+
rpc_url,
152151
transactions_rx,
153152
logger.clone(),
154153
);
@@ -157,6 +156,7 @@ pub fn spawn_exporter(
157156
// Create and spawn the exporter
158157
let mut exporter = Exporter::new(
159158
config,
159+
rpc_url,
160160
key_store,
161161
local_store_tx,
162162
network_state_rx,
@@ -203,6 +203,7 @@ pub struct Exporter {
203203
impl Exporter {
204204
pub fn new(
205205
config: Config,
206+
rpc_url: &str,
206207
key_store: KeyStore,
207208
local_store_tx: Sender<store::local::Message>,
208209
network_state_rx: watch::Receiver<NetworkState>,
@@ -211,7 +212,7 @@ impl Exporter {
211212
) -> Self {
212213
let publish_interval = time::interval(config.publish_interval_duration);
213214
Exporter {
214-
rpc_client: RpcClient::new(config.rpc_endpoint.to_string()),
215+
rpc_client: RpcClient::new(rpc_url.to_string()),
215216
config,
216217
publish_interval,
217218
key_store,
@@ -512,8 +513,6 @@ mod transaction_monitor {
512513
#[derive(Clone, Serialize, Deserialize, Debug)]
513514
#[serde(default)]
514515
pub struct Config {
515-
/// HTTP endpoint of the Solana RPC node
516-
pub rpc_endpoint: String,
517516
/// Duration of the interval with which to poll the status of transactions.
518517
/// It is recommended to set this to a value close to the Exporter's publish_interval.
519518
#[serde(with = "humantime_serde")]
@@ -527,7 +526,6 @@ mod transaction_monitor {
527526
impl Default for Config {
528527
fn default() -> Self {
529528
Self {
530-
rpc_endpoint: "http://localhost:8899".to_string(),
531529
poll_interval_duration: Duration::from_secs(4),
532530
max_transactions: 100,
533531
}
@@ -557,11 +555,12 @@ mod transaction_monitor {
557555
impl TransactionMonitor {
558556
pub fn new(
559557
config: Config,
558+
rpc_url: &str,
560559
transactions_rx: mpsc::Receiver<Signature>,
561560
logger: Logger,
562561
) -> Self {
563562
let poll_interval = time::interval(config.poll_interval_duration);
564-
let rpc_client = RpcClient::new(config.rpc_endpoint.to_string());
563+
let rpc_client = RpcClient::new(rpc_url.to_string());
565564
TransactionMonitor {
566565
config,
567566
rpc_client,

src/agent/solana/oracle.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ pub struct Oracle {
8888
pub struct Config {
8989
/// The commitment level to use when reading data from the RPC node.
9090
pub commitment: CommitmentLevel,
91-
/// RPC endpoint to send requests to.
92-
pub rpc_url: String,
9391
/// The interval with which to poll account information.
9492
#[serde(with = "humantime_serde")]
9593
pub poll_interval_duration: Duration,
@@ -105,7 +103,6 @@ impl Default for Config {
105103
fn default() -> Self {
106104
Self {
107105
commitment: CommitmentLevel::Confirmed,
108-
rpc_url: "http://localhost:8899".to_string(),
109106
poll_interval_duration: Duration::from_secs(30),
110107
subscriber_enabled: true,
111108
subscriber: Default::default(),
@@ -116,6 +113,8 @@ impl Default for Config {
116113

117114
pub fn spawn_oracle(
118115
config: Config,
116+
rpc_url: &str,
117+
wss_url: &str,
119118
key_store: KeyStore,
120119
global_store_update_tx: mpsc::Sender<global::Update>,
121120
logger: Logger,
@@ -127,6 +126,8 @@ pub fn spawn_oracle(
127126
if config.subscriber_enabled {
128127
let subscriber = Subscriber::new(
129128
config.subscriber.clone(),
129+
rpc_url.to_string(),
130+
wss_url.to_string(),
130131
key_store.program_key.clone(),
131132
updates_tx,
132133
logger.clone(),
@@ -137,6 +138,7 @@ pub fn spawn_oracle(
137138
// Create and spawn the Oracle
138139
let mut oracle = Oracle::new(
139140
config,
141+
rpc_url,
140142
key_store,
141143
updates_rx,
142144
global_store_update_tx,
@@ -150,21 +152,21 @@ pub fn spawn_oracle(
150152
impl Oracle {
151153
pub fn new(
152154
config: Config,
155+
rpc_url: &str,
153156
key_store: KeyStore,
154157
updates_rx: mpsc::Receiver<(Pubkey, solana_sdk::account::Account)>,
155158
global_store_tx: mpsc::Sender<global::Update>,
156159
logger: Logger,
157160
) -> Self {
158161
let rpc_client = RpcClient::new_with_commitment(
159-
config.rpc_url.clone(),
162+
rpc_url.to_string(),
160163
CommitmentConfig {
161164
commitment: config.commitment,
162165
},
163166
);
164167
let poll_interval = tokio::time::interval(config.poll_interval_duration);
165168

166169
Oracle {
167-
config,
168170
key_store,
169171
data: Default::default(),
170172
rpc_client,
@@ -473,18 +475,12 @@ mod subscriber {
473475
pub struct Config {
474476
/// Commitment level used to read account data
475477
pub commitment: CommitmentLevel,
476-
/// HTTP RPC endpoint
477-
pub rpc_url: String,
478-
/// WSS RPC endpoint
479-
pub wss_url: String,
480478
}
481479

482480
impl Default for Config {
483481
fn default() -> Self {
484482
Self {
485483
commitment: CommitmentLevel::Confirmed,
486-
rpc_url: "http://localhost:8899".to_string(),
487-
wss_url: "ws://localhost:8900".to_string(),
488484
}
489485
}
490486
}
@@ -494,6 +490,11 @@ mod subscriber {
494490
pub struct Subscriber {
495491
config: Config,
496492

493+
/// HTTP RPC endpoint
494+
pub rpc_url: String,
495+
/// WSS RPC endpoint
496+
pub wss_url: String,
497+
497498
/// Public key of the root account to monitor. Note that all
498499
/// accounts owned by this account are also monitored.
499500
account_key: Pubkey,
@@ -507,12 +508,16 @@ mod subscriber {
507508
impl Subscriber {
508509
pub fn new(
509510
config: Config,
511+
rpc_url: String,
512+
wss_url: String,
510513
account_key: Pubkey,
511514
updates_tx: mpsc::Sender<(Pubkey, solana_sdk::account::Account)>,
512515
logger: Logger,
513516
) -> Self {
514517
Subscriber {
515518
config,
519+
rpc_url,
520+
wss_url,
516521
account_key,
517522
updates_tx,
518523
logger,
@@ -551,8 +556,8 @@ mod subscriber {
551556
&self.account_key,
552557
SyncOptions {
553558
network: solana_shadow::Network::Custom(
554-
self.config.rpc_url.clone(),
555-
self.config.wss_url.clone(),
559+
self.rpc_url.clone(),
560+
self.wss_url.clone(),
556561
),
557562
commitment: self.config.commitment,
558563
..SyncOptions::default()

0 commit comments

Comments
 (0)