Skip to content

Commit 3811eed

Browse files
committed
refactor: remove tap-agent config
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent f0e39d3 commit 3811eed

File tree

16 files changed

+272
-349
lines changed

16 files changed

+272
-349
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.

common/src/subgraph_client/client.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,23 @@ impl DeploymentDetails {
8888
graph_node_status_url: &str,
8989
graph_node_base_url: &str,
9090
deployment: DeploymentId,
91+
) -> Result<Self, anyhow::Error> {
92+
Self::for_graph_node_url(
93+
Url::parse(graph_node_status_url)?,
94+
Url::parse(graph_node_base_url)?,
95+
deployment,
96+
)
97+
}
98+
99+
pub fn for_graph_node_url(
100+
graph_node_status_url: Url,
101+
graph_node_base_url: Url,
102+
deployment: DeploymentId,
91103
) -> Result<Self, anyhow::Error> {
92104
Ok(Self {
93105
deployment: Some(deployment),
94-
status_url: Some(Url::parse(graph_node_status_url)?),
95-
query_url: Url::parse(graph_node_base_url)?
96-
.join(&format!("subgraphs/id/{deployment}"))?,
106+
status_url: Some(graph_node_status_url),
107+
query_url: graph_node_base_url.join(&format!("subgraphs/id/{deployment}"))?,
97108
query_auth_token: None,
98109
})
99110
}
@@ -111,12 +122,19 @@ impl DeploymentDetails {
111122
query_url: &str,
112123
query_auth_token: Option<String>,
113124
) -> Result<Self, anyhow::Error> {
114-
Ok(Self {
125+
Ok(Self::for_query_url_with_token_url(
126+
Url::parse(query_url)?,
127+
query_auth_token,
128+
))
129+
}
130+
131+
pub fn for_query_url_with_token_url(query_url: Url, query_auth_token: Option<String>) -> Self {
132+
Self {
115133
deployment: None,
116134
status_url: None,
117-
query_url: Url::parse(query_url)?,
135+
query_url,
118136
query_auth_token,
119-
})
137+
}
120138
}
121139
}
122140

config/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ serde.workspace = true
99
thegraph-core.workspace = true
1010
tracing.workspace = true
1111
bigdecimal = { workspace = true, features = ["serde"] }
12-
bip39 = "2.0.0"
12+
bip39 = { version = "2.0.0", features = ["rand"] }
1313
figment = { version = "0.10.19", features = ["env", "toml"] }
1414
serde_with = { version = "3.8.1", default-features = false }
1515
serde_repr = "0.1.19"

config/src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ pub struct IndexerConfig {
209209
pub operator_mnemonic: Mnemonic,
210210
}
211211

212-
#[derive(Debug, Deserialize)]
212+
#[derive(Clone, Debug, Deserialize)]
213213
#[cfg_attr(test, derive(PartialEq))]
214214
#[serde(untagged)]
215215
#[serde(deny_unknown_fields)]
@@ -300,7 +300,7 @@ pub struct SubgraphConfig {
300300
pub syncing_interval_secs: Duration,
301301
}
302302

303-
#[derive(Debug, Deserialize_repr, Clone)]
303+
#[derive(Debug, Deserialize_repr, Clone, Copy)]
304304
#[cfg_attr(test, derive(PartialEq))]
305305
#[repr(u64)]
306306
pub enum TheGraphChainId {

config/src/grt.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@
44
use bigdecimal::{BigDecimal, ToPrimitive};
55
use serde::{de::Error, Deserialize};
66

7-
#[derive(Debug, PartialEq)]
7+
#[derive(Debug, PartialEq, Default)]
88
pub struct NonZeroGRT(u128);
99

1010
impl NonZeroGRT {
11+
pub fn new(value: u128) -> Result<Self, String> {
12+
if value == 0 {
13+
Err("GRT value cannot be represented as a u128 GRT wei value".into())
14+
} else {
15+
Ok(NonZeroGRT(value))
16+
}
17+
}
18+
1119
pub fn get_value(&self) -> u128 {
1220
self.0
1321
}

config/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ mod grt;
66

77
pub use config::*;
88
pub use grt::*;
9+
pub use bip39::Mnemonic;

service/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl From<MainConfig> for Config {
6969
recently_closed_allocation_buffer_seconds: 0,
7070
},
7171
graph_network: GraphNetworkConfig {
72-
chain_id: value.blockchain.chain_id.clone() as u64,
72+
chain_id: value.blockchain.chain_id as u64,
7373
},
7474
tap: TapConfig {
7575
chain_id: value.blockchain.chain_id as u64,

tap-agent/src/agent.rs

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

4-
use std::time::Duration;
5-
64
use indexer_common::prelude::{
75
escrow_accounts, indexer_allocations, DeploymentDetails, SubgraphClient,
86
};
7+
use indexer_config::{
8+
Config, EscrowSubgraphConfig, GraphNodeConfig, IndexerConfig, NetworkSubgraphConfig,
9+
SubgraphConfig, SubgraphsConfig, TapConfig,
10+
};
911
use ractor::concurrency::JoinHandle;
1012
use ractor::{Actor, ActorRef};
13+
use sender_account::SenderAccountConfig;
1114

1215
use crate::agent::sender_accounts_manager::{
1316
SenderAccountsManagerArgs, SenderAccountsManagerMessage,
1417
};
15-
use crate::config::{
16-
Config, EscrowSubgraph, Ethereum, IndexerInfrastructure, NetworkSubgraph, Tap,
17-
};
1818
use crate::{database, CONFIG, EIP_712_DOMAIN};
1919
use sender_accounts_manager::SenderAccountsManager;
2020

@@ -25,95 +25,105 @@ pub mod unaggregated_receipts;
2525

2626
pub async fn start_agent() -> (ActorRef<SenderAccountsManagerMessage>, JoinHandle<()>) {
2727
let Config {
28-
ethereum: Ethereum { indexer_address },
29-
indexer_infrastructure:
30-
IndexerInfrastructure {
31-
graph_node_query_endpoint,
32-
graph_node_status_endpoint,
33-
..
34-
},
35-
postgres,
36-
network_subgraph:
37-
NetworkSubgraph {
38-
network_subgraph_deployment,
39-
network_subgraph_endpoint,
40-
network_subgraph_auth_token,
41-
allocation_syncing_interval_ms,
42-
recently_closed_allocation_buffer_seconds,
28+
indexer: IndexerConfig {
29+
indexer_address, ..
30+
},
31+
graph_node:
32+
GraphNodeConfig {
33+
status_url: graph_node_status_endpoint,
34+
query_url: graph_node_query_endpoint,
4335
},
44-
escrow_subgraph:
45-
EscrowSubgraph {
46-
escrow_subgraph_deployment,
47-
escrow_subgraph_endpoint,
48-
escrow_subgraph_auth_token,
49-
escrow_syncing_interval_ms,
36+
database,
37+
subgraphs:
38+
SubgraphsConfig {
39+
network:
40+
NetworkSubgraphConfig {
41+
config:
42+
SubgraphConfig {
43+
query_url: network_query_url,
44+
query_auth_token: network_query_auth_token,
45+
deployment_id: network_deployment_id,
46+
syncing_interval_secs: network_sync_interval,
47+
},
48+
recently_closed_allocation_buffer_secs: recently_closed_allocation_buffer,
49+
},
50+
escrow:
51+
EscrowSubgraphConfig {
52+
config:
53+
SubgraphConfig {
54+
query_url: escrow_query_url,
55+
query_auth_token: escrow_query_auth_token,
56+
deployment_id: escrow_deployment_id,
57+
syncing_interval_secs: escrow_sync_interval,
58+
},
59+
},
5060
},
5161
tap:
52-
Tap {
62+
TapConfig {
5363
// TODO: replace with a proper implementation once the gateway registry contract is ready
5464
sender_aggregator_endpoints,
5565
..
5666
},
5767
..
5868
} = &*CONFIG;
59-
let pgpool = database::connect(postgres).await;
69+
let pgpool = database::connect(database.clone()).await;
6070

6171
let http_client = reqwest::Client::new();
6272

6373
let network_subgraph = Box::leak(Box::new(SubgraphClient::new(
6474
http_client.clone(),
65-
network_subgraph_deployment
75+
network_deployment_id
6676
.map(|deployment| {
67-
DeploymentDetails::for_graph_node(
68-
graph_node_status_endpoint,
69-
graph_node_query_endpoint,
77+
DeploymentDetails::for_graph_node_url(
78+
graph_node_status_endpoint.clone(),
79+
graph_node_query_endpoint.clone(),
7080
deployment,
7181
)
7282
})
7383
.transpose()
7484
.expect("Failed to parse graph node query endpoint and network subgraph deployment"),
75-
DeploymentDetails::for_query_url_with_token(
76-
network_subgraph_endpoint,
77-
network_subgraph_auth_token.clone(),
78-
)
79-
.expect("Failed to parse network subgraph endpoint"),
85+
DeploymentDetails::for_query_url_with_token_url(
86+
network_query_url.clone(),
87+
network_query_auth_token.clone(),
88+
),
8089
)));
8190

8291
let indexer_allocations = indexer_allocations(
8392
network_subgraph,
8493
*indexer_address,
85-
Duration::from_millis(*allocation_syncing_interval_ms),
86-
Duration::from_secs(*recently_closed_allocation_buffer_seconds),
94+
*network_sync_interval,
95+
*recently_closed_allocation_buffer,
8796
);
8897

8998
let escrow_subgraph = Box::leak(Box::new(SubgraphClient::new(
9099
http_client.clone(),
91-
escrow_subgraph_deployment
100+
escrow_deployment_id
92101
.map(|deployment| {
93-
DeploymentDetails::for_graph_node(
94-
graph_node_status_endpoint,
95-
graph_node_query_endpoint,
102+
DeploymentDetails::for_graph_node_url(
103+
graph_node_status_endpoint.clone(),
104+
graph_node_query_endpoint.clone(),
96105
deployment,
97106
)
98107
})
99108
.transpose()
100109
.expect("Failed to parse graph node query endpoint and escrow subgraph deployment"),
101-
DeploymentDetails::for_query_url_with_token(
102-
escrow_subgraph_endpoint,
103-
escrow_subgraph_auth_token.clone(),
104-
)
105-
.expect("Failed to parse escrow subgraph endpoint"),
110+
DeploymentDetails::for_query_url_with_token_url(
111+
escrow_query_url.clone(),
112+
escrow_query_auth_token.clone(),
113+
),
106114
)));
107115

108116
let escrow_accounts = escrow_accounts(
109117
escrow_subgraph,
110118
*indexer_address,
111-
Duration::from_millis(*escrow_syncing_interval_ms),
119+
*escrow_sync_interval,
112120
false,
113121
);
114122

123+
let config = Box::leak(Box::new(SenderAccountConfig::from_config(&CONFIG)));
124+
115125
let args = SenderAccountsManagerArgs {
116-
config: &CONFIG,
126+
config,
117127
domain_separator: EIP_712_DOMAIN.clone(),
118128
pgpool,
119129
indexer_allocations,

0 commit comments

Comments
 (0)