Skip to content

Commit 7be8db8

Browse files
committed
refactor: update agent config and startup
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent a5f822c commit 7be8db8

File tree

11 files changed

+80
-134
lines changed

11 files changed

+80
-134
lines changed

Cargo.lock

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

crates/monitor/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ indexer-query = { path = "../query" }
88
indexer-allocation = { path = "../allocation" }
99
indexer-attestation = { path = "../attestation" }
1010
indexer-watcher = { path = "../watcher" }
11+
indexer-config = { path = "../config" }
1112
thiserror.workspace = true
1213
alloy.workspace = true
1314
anyhow.workspace = true

crates/monitor/src/client/mod.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,30 @@ mod monitor;
55
mod subgraph_client;
66

77
pub use subgraph_client::{DeploymentDetails, SubgraphClient};
8+
9+
use indexer_config::{GraphNodeConfig, SubgraphConfig};
10+
11+
/// Creates a static reference to a subgraph
12+
pub async fn create_subgraph_client(
13+
http_client: reqwest::Client,
14+
graph_node: &GraphNodeConfig,
15+
subgraph_config: &SubgraphConfig,
16+
) -> &'static SubgraphClient {
17+
Box::leak(Box::new(
18+
SubgraphClient::new(
19+
http_client,
20+
subgraph_config.deployment_id.map(|deployment| {
21+
DeploymentDetails::for_graph_node_url(
22+
graph_node.status_url.clone(),
23+
graph_node.query_url.clone(),
24+
deployment,
25+
)
26+
}),
27+
DeploymentDetails::for_query_url_with_token(
28+
subgraph_config.query_url.clone(),
29+
subgraph_config.query_auth_token.clone(),
30+
),
31+
)
32+
.await,
33+
))
34+
}

crates/monitor/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mod escrow_accounts;
1111
pub use crate::{
1212
allocations::{indexer_allocations, AllocationWatcher},
1313
attestation::{attestation_signers, AttestationWatcher},
14-
client::{DeploymentDetails, SubgraphClient},
14+
client::{create_subgraph_client, DeploymentDetails, SubgraphClient},
1515
deployment_to_allocation::{deployment_to_allocation, DeploymentToAllocationWatcher},
1616
dispute_manager::{dispute_manager, DisputeManagerWatcher},
1717
escrow_accounts::{

crates/service/src/service.rs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use std::time::Duration;
55

66
use anyhow::anyhow;
77
use axum::{extract::Request, serve, ServiceExt};
8-
use indexer_config::{Config, GraphNodeConfig, SubgraphConfig};
9-
use indexer_monitor::{DeploymentDetails, SubgraphClient};
8+
use indexer_config::Config;
9+
use indexer_monitor::create_subgraph_client;
1010
use release::IndexerServiceRelease;
1111
use reqwest::Url;
1212
use tap_core::tap_eip712_domain;
@@ -125,30 +125,6 @@ pub async fn run() -> anyhow::Result<()> {
125125
.await?)
126126
}
127127

128-
async fn create_subgraph_client(
129-
http_client: reqwest::Client,
130-
graph_node: &GraphNodeConfig,
131-
subgraph_config: &SubgraphConfig,
132-
) -> &'static SubgraphClient {
133-
Box::leak(Box::new(
134-
SubgraphClient::new(
135-
http_client,
136-
subgraph_config.deployment_id.map(|deployment| {
137-
DeploymentDetails::for_graph_node_url(
138-
graph_node.status_url.clone(),
139-
graph_node.query_url.clone(),
140-
deployment,
141-
)
142-
}),
143-
DeploymentDetails::for_query_url_with_token(
144-
subgraph_config.query_url.clone(),
145-
subgraph_config.query_auth_token.clone(),
146-
),
147-
)
148-
.await,
149-
))
150-
}
151-
152128
/// Graceful shutdown handler
153129
async fn shutdown_handler() {
154130
let ctrl_c = async {

crates/tap-agent/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ ractor = { version = "0.13", features = [
4444
"async-trait",
4545
], default-features = false }
4646
tap_aggregator.workspace = true
47+
typed-builder.workspace = true
4748
futures = { version = "0.3.30", default-features = false }
4849

4950
[dev-dependencies]

crates/tap-agent/src/agent.rs

Lines changed: 37 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,84 @@
11
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
22
// SPDX-License-Identifier: Apache-2.0
33

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;
128

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,
1517
};
16-
use crate::{database, CONFIG, EIP_712_DOMAIN};
17-
use sender_accounts_manager::SenderAccountsManager;
1818

1919
mod metrics;
2020
pub mod sender_account;
2121
pub mod sender_accounts_manager;
2222
pub mod sender_allocation;
2323
pub mod unaggregated_receipts;
2424

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+
);
2632
let Config {
2733
indexer: IndexerConfig {
2834
indexer_address, ..
2935
},
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+
},
6042
tap:
6143
TapConfig {
6244
// TODO: replace with a proper implementation once the gateway registry contract is ready
63-
sender_aggregator_endpoints,
45+
ref sender_aggregator_endpoints,
6446
..
6547
},
6648
..
67-
} = &*CONFIG;
49+
} = config;
6850
let pgpool = database::connect(database.clone()).await;
6951

7052
let http_client = reqwest::Client::new();
7153

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;
8956

9057
let indexer_allocations = indexer_allocations(
9158
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,
9562
)
9663
.await
9764
.expect("Failed to initialize indexer_allocations watcher");
9865

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;
11667

11768
let escrow_accounts = escrow_accounts(
11869
escrow_subgraph,
119-
*indexer_address,
120-
*escrow_sync_interval,
70+
indexer_address,
71+
escrow.config.syncing_interval_secs,
12172
false,
12273
)
12374
.await
12475
.expect("Error creating escrow_accounts channel");
12576

126-
let config = Box::leak(Box::new(SenderAccountConfig::from_config(&CONFIG)));
77+
let config = SenderAccountConfig::from_config(&config);
12778

12879
let args = SenderAccountsManagerArgs {
12980
config,
130-
domain_separator: EIP_712_DOMAIN.clone(),
81+
domain_separator,
13182
pgpool,
13283
indexer_allocations,
13384
escrow_accounts,

crates/tap-agent/src/agent/sender_account.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,16 @@ pub struct SenderAccountConfig {
102102
}
103103

104104
impl SenderAccountConfig {
105-
pub fn from_config(config: &indexer_config::Config) -> Self {
106-
Self {
105+
pub fn from_config(config: &indexer_config::Config) -> &'static Self {
106+
Box::leak(Box::new(Self {
107107
rav_request_buffer: config.tap.rav_request.timestamp_buffer_secs,
108108
rav_request_receipt_limit: config.tap.rav_request.max_receipts_per_request,
109109
indexer_address: config.indexer.indexer_address,
110110
escrow_polling_interval: config.subgraphs.escrow.config.syncing_interval_secs,
111111
max_amount_willing_to_lose_grt: config.tap.max_amount_willing_to_lose_grt.get_value(),
112112
trigger_value: config.tap.get_trigger_value(),
113113
rav_request_timeout: config.tap.rav_request.request_timeout_secs,
114-
}
114+
}))
115115
}
116116
}
117117

crates/tap-agent/src/agent/sender_accounts_manager.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ pub struct SenderAccountsManagerArgs {
5555

5656
pub prefix: Option<String>,
5757
}
58-
5958
#[async_trait::async_trait]
6059
impl Actor for SenderAccountsManager {
6160
type Msg = SenderAccountsManagerMessage;

crates/tap-agent/src/lib.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use alloy::dyn_abi::Eip712Domain;
5-
use indexer_config::Config;
6-
use lazy_static::lazy_static;
7-
use tap_core::tap_eip712_domain;
8-
9-
lazy_static! {
10-
pub static ref CONFIG: Config = cli::get_config().expect("Failed to load configuration");
11-
pub static ref EIP_712_DOMAIN: Eip712Domain = tap_eip712_domain(
12-
CONFIG.blockchain.chain_id as u64,
13-
CONFIG.blockchain.receipts_verifier_address,
14-
);
15-
}
16-
174
pub mod adaptative_concurrency;
185
pub mod agent;
196
pub mod backoff;

0 commit comments

Comments
 (0)