Skip to content

Commit 09f951a

Browse files
committed
feat: get domain separator from domain config
1 parent 471b72a commit 09f951a

File tree

9 files changed

+53
-36
lines changed

9 files changed

+53
-36
lines changed

crates/service/src/service.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use indexer_dips::{
2121
use indexer_monitor::{escrow_accounts_v1, escrow_accounts_v2, DeploymentDetails, SubgraphClient};
2222
use release::IndexerServiceRelease;
2323
use reqwest::Url;
24-
use tap_core::tap_eip712_domain;
24+
use tap_core::{tap_eip712_domain, TapVersion};
2525
use tokio::{net::TcpListener, signal};
2626
use tower_http::normalize_path::NormalizePath;
2727
use tracing::info;
@@ -90,12 +90,6 @@ pub async fn run() -> anyhow::Result<()> {
9090
let database =
9191
database::connect(config.database.clone().get_formated_postgres_url().as_ref()).await;
9292

93-
let domain_separator = tap_eip712_domain(
94-
config.blockchain.chain_id as u64,
95-
config.blockchain.receipts_verifier_address,
96-
);
97-
let chain_id = config.blockchain.chain_id as u64;
98-
9993
let host_and_port = config.service.host_and_port;
10094
let indexer_address = config.indexer.indexer_address;
10195
let ipfs_url = config.service.ipfs_url.clone();
@@ -108,7 +102,7 @@ pub async fn run() -> anyhow::Result<()> {
108102
// Determine if we should check for Horizon contracts and potentially enable hybrid mode:
109103
// - If horizon.enabled = false: Pure legacy mode, no Horizon detection
110104
// - If horizon.enabled = true: Check if Horizon contracts are active in the network
111-
let is_horizon_active = if config.horizon.enabled {
105+
let horizon_is_active = if config.horizon.enabled {
112106
tracing::info!("Horizon migration support enabled - checking if Horizon contracts are active in the network");
113107
match indexer_monitor::is_horizon_active(network_subgraph).await {
114108
Ok(active) => {
@@ -135,8 +129,20 @@ pub async fn run() -> anyhow::Result<()> {
135129
false
136130
};
137131

132+
let chain_id = config.blockchain.chain_id as u64;
133+
134+
let domain_separator = tap_eip712_domain(
135+
chain_id,
136+
config.blockchain.receipts_verifier_address,
137+
if horizon_is_active {
138+
TapVersion::V2
139+
} else {
140+
TapVersion::V1
141+
},
142+
);
143+
138144
// Configure router with escrow watchers based on automatic Horizon detection
139-
let router = if is_horizon_active {
145+
let router = if horizon_is_active {
140146
tracing::info!("Horizon contracts detected - using Horizon migration mode: V2 receipts only, but processing existing V1 receipts");
141147

142148
// Create V1 escrow watcher for processing existing receipts

crates/service/src/tap/checks/receipt_max_val_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ mod tests {
6666
.unwrap();
6767

6868
let eip712_domain_separator: Eip712Domain =
69-
tap_eip712_domain(1, Address::from([0x11u8; 20]));
69+
tap_eip712_domain(1, Address::from([0x11u8; 20]), tap_core::TapVersion::V1);
7070

7171
let timestamp = SystemTime::now()
7272
.duration_since(SystemTime::UNIX_EPOCH)

crates/service/src/tap/checks/timestamp_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ mod tests {
7575
.build()
7676
.unwrap();
7777
let eip712_domain_separator: Eip712Domain =
78-
tap_eip712_domain(1, Address::from([0x11u8; 20]));
78+
tap_eip712_domain(1, Address::from([0x11u8; 20]), tap_core::TapVersion::V1);
7979
let value: u128 = 1234;
8080
let nonce: u64 = 10;
8181
let receipt = Eip712SignedMessage::new(

crates/tap-agent/src/agent.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use sender_accounts_manager::SenderAccountsManager;
4949

5050
use crate::{
5151
agent::sender_accounts_manager::{SenderAccountsManagerArgs, SenderAccountsManagerMessage},
52-
database, CONFIG, EIP_712_DOMAIN,
52+
database, CONFIG,
5353
};
5454

5555
/// Actor, Arguments, State, Messages and implementation for [crate::agent::sender_account::SenderAccount]
@@ -169,7 +169,7 @@ pub async fn start_agent() -> (ActorRef<SenderAccountsManagerMessage>, JoinHandl
169169
// Determine if we should check for Horizon contracts and potentially enable hybrid mode:
170170
// - If horizon.enabled = false: Pure legacy mode, no Horizon detection
171171
// - If horizon.enabled = true: Check if Horizon contracts are active in the network
172-
let is_horizon_enabled = if CONFIG.horizon.enabled {
172+
let horizon_is_enabled = if CONFIG.horizon.enabled {
173173
tracing::info!("Horizon migration support enabled - checking if Horizon contracts are active in the network");
174174
match indexer_monitor::is_horizon_active(network_subgraph).await {
175175
Ok(active) => {
@@ -198,7 +198,7 @@ pub async fn start_agent() -> (ActorRef<SenderAccountsManagerMessage>, JoinHandl
198198

199199
// Create V2 escrow accounts watcher only if Horizon is active
200200
// V2 escrow accounts are in the network subgraph, not a separate TAP v2 subgraph
201-
let escrow_accounts_v2 = if is_horizon_enabled {
201+
let escrow_accounts_v2 = if horizon_is_enabled {
202202
escrow_accounts_v2(
203203
network_subgraph,
204204
*indexer_address,
@@ -213,7 +213,7 @@ pub async fn start_agent() -> (ActorRef<SenderAccountsManagerMessage>, JoinHandl
213213
};
214214

215215
// In both modes we need both watchers for the hybrid processing
216-
let (escrow_accounts_v1_final, escrow_accounts_v2_final) = if is_horizon_enabled {
216+
let (escrow_accounts_v1_final, escrow_accounts_v2_final) = if horizon_is_enabled {
217217
tracing::info!("TAP Agent: Horizon migration mode - processing existing V1 receipts and new V2 receipts");
218218
(escrow_accounts_v1, escrow_accounts_v2)
219219
} else {
@@ -223,13 +223,23 @@ pub async fn start_agent() -> (ActorRef<SenderAccountsManagerMessage>, JoinHandl
223223

224224
let config = Box::leak(Box::new({
225225
let mut config = SenderAccountConfig::from_config(&CONFIG);
226-
config.horizon_enabled = is_horizon_enabled;
226+
config.horizon_enabled = horizon_is_enabled;
227227
config
228228
}));
229229

230+
let domain_separator = tap_core::tap_eip712_domain(
231+
CONFIG.blockchain.chain_id as u64,
232+
CONFIG.blockchain.receipts_verifier_address,
233+
if horizon_is_enabled {
234+
tap_core::TapVersion::V2
235+
} else {
236+
tap_core::TapVersion::V1
237+
},
238+
);
239+
230240
let args = SenderAccountsManagerArgs {
231241
config,
232-
domain_separator: EIP_712_DOMAIN.clone(),
242+
domain_separator,
233243
pgpool,
234244
indexer_allocations,
235245
escrow_accounts_v1: escrow_accounts_v1_final,

crates/tap-agent/src/lib.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,10 @@
1414
use std::sync::LazyLock;
1515

1616
use indexer_config::Config;
17-
use tap_core::tap_eip712_domain;
18-
use thegraph_core::alloy::sol_types::Eip712Domain;
1917

2018
/// Static configuration
2119
pub static CONFIG: LazyLock<Config> =
2220
LazyLock::new(|| cli::get_config().expect("Failed to load configuration"));
23-
/// Static EIP_712_DOMAIN used with config values
24-
pub static EIP_712_DOMAIN: LazyLock<Eip712Domain> = LazyLock::new(|| {
25-
tap_eip712_domain(
26-
CONFIG.blockchain.chain_id as u64,
27-
CONFIG.blockchain.receipts_verifier_address,
28-
)
29-
});
3021

3122
pub mod adaptative_concurrency;
3223
pub mod agent;

crates/tap-agent/src/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rand::{distr::Alphanumeric, rng, Rng};
1919
use reqwest::Url;
2020
use sqlx::{types::BigDecimal, PgPool};
2121
use tap_aggregator::server::run_server;
22-
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain};
22+
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain, TapVersion};
2323
use tap_graph::{Receipt, ReceiptAggregateVoucher, SignedRav, SignedReceipt};
2424
use test_assets::{flush_messages, TAP_SENDER as SENDER, TAP_SIGNER as SIGNER};
2525
use thegraph_core::alloy::{
@@ -56,7 +56,7 @@ use crate::{
5656
pub static SENDER_2: LazyLock<(PrivateKeySigner, Address)> = LazyLock::new(|| wallet(1));
5757
pub static INDEXER: LazyLock<(PrivateKeySigner, Address)> = LazyLock::new(|| wallet(3));
5858
pub static TAP_EIP712_DOMAIN_SEPARATOR: LazyLock<Eip712Domain> =
59-
LazyLock::new(|| tap_eip712_domain(1, Address::from([0x11u8; 20])));
59+
LazyLock::new(|| tap_eip712_domain(1, Address::from([0x11u8; 20]), TapVersion::V1));
6060

6161
pub const TRIGGER_VALUE: u128 = 500;
6262
pub const RECEIPT_LIMIT: u64 = 10000;

crates/test-assets/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ pub static TAP_SIGNER: LazyLock<(PrivateKeySigner, Address)> = LazyLock::new(||
372372
});
373373

374374
pub static TAP_EIP712_DOMAIN: LazyLock<Eip712Domain> =
375-
LazyLock::new(|| tap_eip712_domain(1, VERIFIER_ADDRESS));
375+
LazyLock::new(|| tap_eip712_domain(1, VERIFIER_ADDRESS, tap_core::TapVersion::V1));
376376

377377
#[derive(bon::Builder)]
378378
pub struct SignedReceiptRequest {

integration-tests/src/signature_test.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use anyhow::Result;
77
use std::str::FromStr;
8-
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain};
8+
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain, TapVersion};
99
use tap_graph::v2::Receipt as V2Receipt;
1010
use thegraph_core::{
1111
alloy::{primitives::Address, signers::local::PrivateKeySigner},
@@ -24,7 +24,11 @@ pub async fn test_v2_signature_recovery() -> Result<()> {
2424
println!("Wallet address: {wallet_address:?}");
2525

2626
// Create EIP-712 domain - V2 uses GraphTallyCollector
27-
let domain = tap_eip712_domain(CHAIN_ID, Address::from_str(GRAPH_TALLY_COLLECTOR_CONTRACT)?);
27+
let domain = tap_eip712_domain(
28+
CHAIN_ID,
29+
Address::from_str(GRAPH_TALLY_COLLECTOR_CONTRACT)?,
30+
TapVersion::V2,
31+
);
2832
println!("Using domain: chain_id={CHAIN_ID}, verifier={GRAPH_TALLY_COLLECTOR_CONTRACT}");
2933

3034
// Create a V2 receipt

integration-tests/src/utils.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rand::{rng, Rng};
1414
use reqwest::Client;
1515
use serde_json::json;
1616
use tap_aggregator::grpc;
17-
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain};
17+
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain, TapVersion};
1818
use tap_graph::Receipt;
1919
use thegraph_core::alloy::{primitives::Address, signers::local::PrivateKeySigner};
2020
use thegraph_core::CollectionId;
@@ -39,8 +39,11 @@ pub fn create_tap_receipt(
3939
let timestamp_ns = timestamp as u64;
4040

4141
// Create domain separator
42-
let eip712_domain_separator =
43-
tap_eip712_domain(chain_id, Address::from_str(verifier_contract)?);
42+
let eip712_domain_separator = tap_eip712_domain(
43+
chain_id,
44+
Address::from_str(verifier_contract)?,
45+
TapVersion::V1,
46+
);
4447

4548
// Create and sign receipt
4649
println!("Creating and signing receipt...");
@@ -80,8 +83,11 @@ pub fn create_tap_receipt_v2(
8083
let collection_id = CollectionId::from(*allocation_id);
8184

8285
// Create domain separator - V2 uses GraphTallyCollector
83-
let eip712_domain_separator =
84-
tap_eip712_domain(chain_id, Address::from_str(GRAPH_TALLY_COLLECTOR_CONTRACT)?);
86+
let eip712_domain_separator = tap_eip712_domain(
87+
chain_id,
88+
Address::from_str(GRAPH_TALLY_COLLECTOR_CONTRACT)?,
89+
TapVersion::V2,
90+
);
8591

8692
let wallet_address = wallet.address();
8793
// Create and sign V2 receipt

0 commit comments

Comments
 (0)