|
1 | 1 | // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. |
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
4 | | -use indexer_config::{ |
5 | | - Config, EscrowSubgraphConfig, GraphNodeConfig, IndexerConfig, NetworkSubgraphConfig, |
6 | | - SubgraphConfig, SubgraphsConfig, TapConfig, |
7 | | -}; |
8 | | -use indexer_monitor::{escrow_accounts, indexer_allocations, DeploymentDetails, SubgraphClient}; |
9 | | -use ractor::concurrency::JoinHandle; |
10 | | -use ractor::{Actor, ActorRef}; |
11 | | -use sender_account::SenderAccountConfig; |
| 4 | +use indexer_config::{Config, IndexerConfig, SubgraphsConfig, TapConfig}; |
| 5 | +use indexer_monitor::{create_subgraph_client, escrow_accounts, indexer_allocations}; |
| 6 | +use ractor::{concurrency::JoinHandle, Actor, ActorRef}; |
| 7 | +use tap_core::tap_eip712_domain; |
12 | 8 |
|
13 | | -use crate::agent::sender_accounts_manager::{ |
14 | | - SenderAccountsManagerArgs, SenderAccountsManagerMessage, |
| 9 | +use crate::{ |
| 10 | + agent::{ |
| 11 | + sender_account::SenderAccountConfig, |
| 12 | + sender_accounts_manager::{ |
| 13 | + SenderAccountsManager, SenderAccountsManagerArgs, SenderAccountsManagerMessage, |
| 14 | + }, |
| 15 | + }, |
| 16 | + database, |
15 | 17 | }; |
16 | | -use crate::{database, CONFIG, EIP_712_DOMAIN}; |
17 | | -use sender_accounts_manager::SenderAccountsManager; |
18 | 18 |
|
19 | 19 | mod metrics; |
20 | 20 | pub mod sender_account; |
21 | 21 | pub mod sender_accounts_manager; |
22 | 22 | pub mod sender_allocation; |
23 | 23 | pub mod unaggregated_receipts; |
24 | 24 |
|
25 | | -pub async fn start_agent() -> (ActorRef<SenderAccountsManagerMessage>, JoinHandle<()>) { |
| 25 | +pub async fn start_agent( |
| 26 | + config: Config, |
| 27 | +) -> (ActorRef<SenderAccountsManagerMessage>, JoinHandle<()>) { |
| 28 | + let domain_separator = tap_eip712_domain( |
| 29 | + config.blockchain.chain_id as u64, |
| 30 | + config.blockchain.receipts_verifier_address, |
| 31 | + ); |
26 | 32 | let Config { |
27 | 33 | indexer: IndexerConfig { |
28 | 34 | indexer_address, .. |
29 | 35 | }, |
30 | | - graph_node: |
31 | | - GraphNodeConfig { |
32 | | - status_url: graph_node_status_endpoint, |
33 | | - query_url: graph_node_query_endpoint, |
34 | | - }, |
35 | | - database, |
36 | | - subgraphs: |
37 | | - SubgraphsConfig { |
38 | | - network: |
39 | | - NetworkSubgraphConfig { |
40 | | - config: |
41 | | - SubgraphConfig { |
42 | | - query_url: network_query_url, |
43 | | - query_auth_token: network_query_auth_token, |
44 | | - deployment_id: network_deployment_id, |
45 | | - syncing_interval_secs: network_sync_interval, |
46 | | - }, |
47 | | - recently_closed_allocation_buffer_secs: recently_closed_allocation_buffer, |
48 | | - }, |
49 | | - escrow: |
50 | | - EscrowSubgraphConfig { |
51 | | - config: |
52 | | - SubgraphConfig { |
53 | | - query_url: escrow_query_url, |
54 | | - query_auth_token: escrow_query_auth_token, |
55 | | - deployment_id: escrow_deployment_id, |
56 | | - syncing_interval_secs: escrow_sync_interval, |
57 | | - }, |
58 | | - }, |
59 | | - }, |
| 36 | + ref graph_node, |
| 37 | + ref database, |
| 38 | + subgraphs: SubgraphsConfig { |
| 39 | + ref network, |
| 40 | + ref escrow, |
| 41 | + }, |
60 | 42 | tap: |
61 | 43 | TapConfig { |
62 | 44 | // TODO: replace with a proper implementation once the gateway registry contract is ready |
63 | | - sender_aggregator_endpoints, |
| 45 | + ref sender_aggregator_endpoints, |
64 | 46 | .. |
65 | 47 | }, |
66 | 48 | .. |
67 | | - } = &*CONFIG; |
| 49 | + } = config; |
68 | 50 | let pgpool = database::connect(database.clone()).await; |
69 | 51 |
|
70 | 52 | let http_client = reqwest::Client::new(); |
71 | 53 |
|
72 | | - let network_subgraph = Box::leak(Box::new( |
73 | | - SubgraphClient::new( |
74 | | - http_client.clone(), |
75 | | - network_deployment_id.map(|deployment| { |
76 | | - DeploymentDetails::for_graph_node_url( |
77 | | - graph_node_status_endpoint.clone(), |
78 | | - graph_node_query_endpoint.clone(), |
79 | | - deployment, |
80 | | - ) |
81 | | - }), |
82 | | - DeploymentDetails::for_query_url_with_token( |
83 | | - network_query_url.clone(), |
84 | | - network_query_auth_token.clone(), |
85 | | - ), |
86 | | - ) |
87 | | - .await, |
88 | | - )); |
| 54 | + let network_subgraph = |
| 55 | + create_subgraph_client(http_client.clone(), graph_node, &network.config).await; |
89 | 56 |
|
90 | 57 | let indexer_allocations = indexer_allocations( |
91 | 58 | network_subgraph, |
92 | | - *indexer_address, |
93 | | - *network_sync_interval, |
94 | | - *recently_closed_allocation_buffer, |
| 59 | + indexer_address, |
| 60 | + network.config.syncing_interval_secs, |
| 61 | + network.recently_closed_allocation_buffer_secs, |
95 | 62 | ) |
96 | 63 | .await |
97 | 64 | .expect("Failed to initialize indexer_allocations watcher"); |
98 | 65 |
|
99 | | - let escrow_subgraph = Box::leak(Box::new( |
100 | | - SubgraphClient::new( |
101 | | - http_client.clone(), |
102 | | - escrow_deployment_id.map(|deployment| { |
103 | | - DeploymentDetails::for_graph_node_url( |
104 | | - graph_node_status_endpoint.clone(), |
105 | | - graph_node_query_endpoint.clone(), |
106 | | - deployment, |
107 | | - ) |
108 | | - }), |
109 | | - DeploymentDetails::for_query_url_with_token( |
110 | | - escrow_query_url.clone(), |
111 | | - escrow_query_auth_token.clone(), |
112 | | - ), |
113 | | - ) |
114 | | - .await, |
115 | | - )); |
| 66 | + let escrow_subgraph = create_subgraph_client(http_client, graph_node, &escrow.config).await; |
116 | 67 |
|
117 | 68 | let escrow_accounts = escrow_accounts( |
118 | 69 | escrow_subgraph, |
119 | | - *indexer_address, |
120 | | - *escrow_sync_interval, |
| 70 | + indexer_address, |
| 71 | + escrow.config.syncing_interval_secs, |
121 | 72 | false, |
122 | 73 | ) |
123 | 74 | .await |
124 | 75 | .expect("Error creating escrow_accounts channel"); |
125 | 76 |
|
126 | | - let config = Box::leak(Box::new(SenderAccountConfig::from_config(&CONFIG))); |
| 77 | + let config = SenderAccountConfig::from_config(&config); |
127 | 78 |
|
128 | 79 | let args = SenderAccountsManagerArgs { |
129 | 80 | config, |
130 | | - domain_separator: EIP_712_DOMAIN.clone(), |
| 81 | + domain_separator, |
131 | 82 | pgpool, |
132 | 83 | indexer_allocations, |
133 | 84 | escrow_accounts, |
|
0 commit comments