Skip to content

Commit 8edbea1

Browse files
committed
refactor(agent): extract config module
1 parent 9db2592 commit 8edbea1

File tree

2 files changed

+87
-89
lines changed

2 files changed

+87
-89
lines changed

src/agent.rs

Lines changed: 2 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,18 @@ Note that there is an Oracle and Exporter for each network, but only one Local S
6363
################################################################################################################################## */
6464
use {
6565
self::{
66-
config::Config,
6766
pyth::rpc,
6867
solana::network,
6968
},
7069
anyhow::Result,
70+
config::Config,
7171
futures_util::future::join_all,
7272
lazy_static::lazy_static,
7373
std::sync::Arc,
7474
tokio::sync::watch,
7575
};
7676

77+
pub mod config;
7778
pub mod legacy_schedule;
7879
pub mod market_schedule;
7980
pub mod metrics;
@@ -177,91 +178,3 @@ impl Agent {
177178
Ok(())
178179
}
179180
}
180-
181-
pub mod config {
182-
use {
183-
super::{
184-
metrics,
185-
pyth,
186-
services,
187-
solana::network,
188-
state,
189-
},
190-
anyhow::Result,
191-
config as config_rs,
192-
config_rs::{
193-
Environment,
194-
File,
195-
},
196-
serde::Deserialize,
197-
std::path::Path,
198-
};
199-
200-
/// Configuration for all components of the Agent
201-
#[derive(Deserialize, Debug)]
202-
pub struct Config {
203-
#[serde(default)]
204-
pub channel_capacities: ChannelCapacities,
205-
pub primary_network: network::Config,
206-
pub secondary_network: Option<network::Config>,
207-
#[serde(default)]
208-
#[serde(rename = "pythd_adapter")]
209-
pub state: state::Config,
210-
#[serde(default)]
211-
pub pythd_api_server: pyth::rpc::Config,
212-
#[serde(default)]
213-
pub metrics_server: metrics::Config,
214-
#[serde(default)]
215-
pub remote_keypair_loader: services::keypairs::Config,
216-
}
217-
218-
impl Config {
219-
pub fn new(config_file: impl AsRef<Path>) -> Result<Self> {
220-
// Build a new configuration object, allowing the default values to be
221-
// overridden by those in the config_file or "AGENT_"-prefixed environment
222-
// variables.
223-
config_rs::Config::builder()
224-
.add_source(File::from(config_file.as_ref()))
225-
.add_source(Environment::with_prefix("agent"))
226-
.build()?
227-
.try_deserialize()
228-
.map_err(|e| e.into())
229-
}
230-
}
231-
232-
/// Capacities of the channels top-level components use to communicate
233-
#[derive(Deserialize, Debug)]
234-
pub struct ChannelCapacities {
235-
/// Capacity of the channel used to broadcast shutdown events to all components
236-
pub shutdown: usize,
237-
/// Capacity of the channel used to send updates from the primary Oracle to the Global Store
238-
pub primary_oracle_updates: usize,
239-
/// Capacity of the channel used to send updates from the secondary Oracle to the Global Store
240-
pub secondary_oracle_updates: usize,
241-
/// Capacity of the channel the Pythd API Adapter uses to send lookup requests to the Global Store
242-
pub global_store_lookup: usize,
243-
/// Capacity of the channel the Pythd API Adapter uses to communicate with the Local Store
244-
pub local_store_lookup: usize,
245-
/// Capacity of the channel on which the Local Store receives messages
246-
pub local_store: usize,
247-
/// Capacity of the channel on which the Pythd API Adapter receives messages
248-
pub pythd_adapter: usize,
249-
/// Capacity of the slog logging channel. Adjust this value if you see complaints about channel capacity from slog
250-
pub logger_buffer: usize,
251-
}
252-
253-
impl Default for ChannelCapacities {
254-
fn default() -> Self {
255-
Self {
256-
shutdown: 10000,
257-
primary_oracle_updates: 10000,
258-
secondary_oracle_updates: 10000,
259-
global_store_lookup: 10000,
260-
local_store_lookup: 10000,
261-
local_store: 10000,
262-
pythd_adapter: 10000,
263-
logger_buffer: 10000,
264-
}
265-
}
266-
}
267-
}

src/agent/config.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
use {
2+
super::{
3+
metrics,
4+
pyth,
5+
services,
6+
solana::network,
7+
state,
8+
},
9+
anyhow::Result,
10+
config as config_rs,
11+
config_rs::{
12+
Environment,
13+
File,
14+
},
15+
serde::Deserialize,
16+
std::path::Path,
17+
};
18+
19+
/// Configuration for all components of the Agent
20+
#[derive(Deserialize, Debug)]
21+
pub struct Config {
22+
#[serde(default)]
23+
pub channel_capacities: ChannelCapacities,
24+
pub primary_network: network::Config,
25+
pub secondary_network: Option<network::Config>,
26+
#[serde(default)]
27+
#[serde(rename = "pythd_adapter")]
28+
pub state: state::Config,
29+
#[serde(default)]
30+
pub pythd_api_server: pyth::rpc::Config,
31+
#[serde(default)]
32+
pub metrics_server: metrics::Config,
33+
#[serde(default)]
34+
pub remote_keypair_loader: services::keypairs::Config,
35+
}
36+
37+
impl Config {
38+
pub fn new(config_file: impl AsRef<Path>) -> Result<Self> {
39+
// Build a new configuration object, allowing the default values to be
40+
// overridden by those in the config_file or "AGENT_"-prefixed environment
41+
// variables.
42+
config_rs::Config::builder()
43+
.add_source(File::from(config_file.as_ref()))
44+
.add_source(Environment::with_prefix("agent"))
45+
.build()?
46+
.try_deserialize()
47+
.map_err(|e| e.into())
48+
}
49+
}
50+
51+
/// Capacities of the channels top-level components use to communicate
52+
#[derive(Deserialize, Debug)]
53+
pub struct ChannelCapacities {
54+
/// Capacity of the channel used to broadcast shutdown events to all components
55+
pub shutdown: usize,
56+
/// Capacity of the channel used to send updates from the primary Oracle to the Global Store
57+
pub primary_oracle_updates: usize,
58+
/// Capacity of the channel used to send updates from the secondary Oracle to the Global Store
59+
pub secondary_oracle_updates: usize,
60+
/// Capacity of the channel the Pythd API Adapter uses to send lookup requests to the Global Store
61+
pub global_store_lookup: usize,
62+
/// Capacity of the channel the Pythd API Adapter uses to communicate with the Local Store
63+
pub local_store_lookup: usize,
64+
/// Capacity of the channel on which the Local Store receives messages
65+
pub local_store: usize,
66+
/// Capacity of the channel on which the Pythd API Adapter receives messages
67+
pub pythd_adapter: usize,
68+
/// Capacity of the slog logging channel. Adjust this value if you see complaints about channel capacity from slog
69+
pub logger_buffer: usize,
70+
}
71+
72+
impl Default for ChannelCapacities {
73+
fn default() -> Self {
74+
Self {
75+
shutdown: 10000,
76+
primary_oracle_updates: 10000,
77+
secondary_oracle_updates: 10000,
78+
global_store_lookup: 10000,
79+
local_store_lookup: 10000,
80+
local_store: 10000,
81+
pythd_adapter: 10000,
82+
logger_buffer: 10000,
83+
}
84+
}
85+
}

0 commit comments

Comments
 (0)