@@ -63,22 +63,23 @@ Note that there is an Oracle and Exporter for each network, but only one Local S
63
63
################################################################################################################################## */
64
64
use {
65
65
self :: {
66
- config:: Config ,
67
66
pyth:: rpc,
68
67
solana:: network,
69
- state:: notifier,
70
68
} ,
71
69
anyhow:: Result ,
70
+ config:: Config ,
72
71
futures_util:: future:: join_all,
73
72
lazy_static:: lazy_static,
74
73
std:: sync:: Arc ,
75
74
tokio:: sync:: watch,
76
75
} ;
77
76
77
+ pub mod config;
78
78
pub mod legacy_schedule;
79
79
pub mod market_schedule;
80
80
pub mod metrics;
81
81
pub mod pyth;
82
+ pub mod services;
82
83
pub mod solana;
83
84
pub mod state;
84
85
@@ -125,26 +126,38 @@ impl Agent {
125
126
let mut jhs = vec ! [ ] ;
126
127
127
128
// Create the Application State.
128
- let state = Arc :: new ( state:: State :: new ( self . config . state . clone ( ) ) . await ) ;
129
+ let state = Arc :: new ( state:: State :: new ( & self . config ) . await ) ;
129
130
130
- // Spawn the primary network
131
- jhs. extend ( network :: spawn_network (
131
+ // Spawn the primary network Oracle.
132
+ jhs. push ( tokio :: spawn ( services :: oracle (
132
133
self . config . primary_network . clone ( ) ,
133
134
network:: Network :: Primary ,
134
135
state. clone ( ) ,
135
- ) ?) ;
136
+ ) ) ) ;
137
+
138
+ jhs. push ( tokio:: spawn ( services:: exporter (
139
+ self . config . primary_network . clone ( ) ,
140
+ network:: Network :: Primary ,
141
+ state. clone ( ) ,
142
+ ) ) ) ;
136
143
137
- // Spawn the secondary network, if needed
144
+ // Spawn the secondary network Oracle , if needed.
138
145
if let Some ( config) = & self . config . secondary_network {
139
- jhs. extend ( network :: spawn_network (
146
+ jhs. push ( tokio :: spawn ( services :: oracle (
140
147
config. clone ( ) ,
141
148
network:: Network :: Secondary ,
142
149
state. clone ( ) ,
143
- ) ?) ;
150
+ ) ) ) ;
151
+
152
+ jhs. push ( tokio:: spawn ( services:: exporter (
153
+ config. clone ( ) ,
154
+ network:: Network :: Secondary ,
155
+ state. clone ( ) ,
156
+ ) ) ) ;
144
157
}
145
158
146
159
// Create the Notifier task for the Pythd RPC.
147
- jhs. push ( tokio:: spawn ( notifier ( state. clone ( ) ) ) ) ;
160
+ jhs. push ( tokio:: spawn ( services :: notifier ( state. clone ( ) ) ) ) ;
148
161
149
162
// Spawn the Pythd API Server
150
163
jhs. push ( tokio:: spawn ( rpc:: run (
@@ -159,7 +172,7 @@ impl Agent {
159
172
160
173
// Spawn the remote keypair loader endpoint for both networks
161
174
jhs. append (
162
- & mut state :: keypairs:: spawn (
175
+ & mut services :: keypairs (
163
176
self . config . primary_network . rpc_url . clone ( ) ,
164
177
self . config
165
178
. secondary_network
@@ -177,90 +190,3 @@ impl Agent {
177
190
Ok ( ( ) )
178
191
}
179
192
}
180
-
181
- pub mod config {
182
- use {
183
- super :: {
184
- metrics,
185
- pyth,
186
- solana:: network,
187
- state,
188
- } ,
189
- anyhow:: Result ,
190
- config as config_rs,
191
- config_rs:: {
192
- Environment ,
193
- File ,
194
- } ,
195
- serde:: Deserialize ,
196
- std:: path:: Path ,
197
- } ;
198
-
199
- /// Configuration for all components of the Agent
200
- #[ derive( Deserialize , Debug ) ]
201
- pub struct Config {
202
- #[ serde( default ) ]
203
- pub channel_capacities : ChannelCapacities ,
204
- pub primary_network : network:: Config ,
205
- pub secondary_network : Option < network:: Config > ,
206
- #[ serde( default ) ]
207
- #[ serde( rename = "pythd_adapter" ) ]
208
- pub state : state:: Config ,
209
- #[ serde( default ) ]
210
- pub pythd_api_server : pyth:: rpc:: Config ,
211
- #[ serde( default ) ]
212
- pub metrics_server : metrics:: Config ,
213
- #[ serde( default ) ]
214
- pub remote_keypair_loader : state:: keypairs:: Config ,
215
- }
216
-
217
- impl Config {
218
- pub fn new ( config_file : impl AsRef < Path > ) -> Result < Self > {
219
- // Build a new configuration object, allowing the default values to be
220
- // overridden by those in the config_file or "AGENT_"-prefixed environment
221
- // variables.
222
- config_rs:: Config :: builder ( )
223
- . add_source ( File :: from ( config_file. as_ref ( ) ) )
224
- . add_source ( Environment :: with_prefix ( "agent" ) )
225
- . build ( ) ?
226
- . try_deserialize ( )
227
- . map_err ( |e| e. into ( ) )
228
- }
229
- }
230
-
231
- /// Capacities of the channels top-level components use to communicate
232
- #[ derive( Deserialize , Debug ) ]
233
- pub struct ChannelCapacities {
234
- /// Capacity of the channel used to broadcast shutdown events to all components
235
- pub shutdown : usize ,
236
- /// Capacity of the channel used to send updates from the primary Oracle to the Global Store
237
- pub primary_oracle_updates : usize ,
238
- /// Capacity of the channel used to send updates from the secondary Oracle to the Global Store
239
- pub secondary_oracle_updates : usize ,
240
- /// Capacity of the channel the Pythd API Adapter uses to send lookup requests to the Global Store
241
- pub global_store_lookup : usize ,
242
- /// Capacity of the channel the Pythd API Adapter uses to communicate with the Local Store
243
- pub local_store_lookup : usize ,
244
- /// Capacity of the channel on which the Local Store receives messages
245
- pub local_store : usize ,
246
- /// Capacity of the channel on which the Pythd API Adapter receives messages
247
- pub pythd_adapter : usize ,
248
- /// Capacity of the slog logging channel. Adjust this value if you see complaints about channel capacity from slog
249
- pub logger_buffer : usize ,
250
- }
251
-
252
- impl Default for ChannelCapacities {
253
- fn default ( ) -> Self {
254
- Self {
255
- shutdown : 10000 ,
256
- primary_oracle_updates : 10000 ,
257
- secondary_oracle_updates : 10000 ,
258
- global_store_lookup : 10000 ,
259
- local_store_lookup : 10000 ,
260
- local_store : 10000 ,
261
- pythd_adapter : 10000 ,
262
- logger_buffer : 10000 ,
263
- }
264
- }
265
- }
266
- }
0 commit comments