Skip to content

feat: inject domain version and fix routing in local-network tests #820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
302 changes: 151 additions & 151 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ sqlx = { version = "0.8.2", features = [
"uuid",
], default-features = false }
stdext = "0.3.3"
tap_aggregator = { version = "0.5.8", default-features = false, features = [
tap_aggregator = { version = "0.5.9", default-features = false, features = [
"v2",
] }
tap_core = { version = "4.1.4", default-features = false }
tap_core = { version = "5.0.0", default-features = false }
tap_graph = { version = "0.3.4", features = ["v2"] }
tempfile = "3.8.0"
test-log = { version = "0.2.12", default-features = false }
Expand Down
24 changes: 15 additions & 9 deletions crates/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use indexer_dips::{
use indexer_monitor::{escrow_accounts_v1, escrow_accounts_v2, DeploymentDetails, SubgraphClient};
use release::IndexerServiceRelease;
use reqwest::Url;
use tap_core::tap_eip712_domain;
use tap_core::{tap_eip712_domain, TapVersion};
use tokio::{net::TcpListener, signal};
use tower_http::normalize_path::NormalizePath;
use tracing::info;
Expand Down Expand Up @@ -90,12 +90,6 @@ pub async fn run() -> anyhow::Result<()> {
let database =
database::connect(config.database.clone().get_formated_postgres_url().as_ref()).await;

let domain_separator = tap_eip712_domain(
config.blockchain.chain_id as u64,
config.blockchain.receipts_verifier_address,
);
let chain_id = config.blockchain.chain_id as u64;

let host_and_port = config.service.host_and_port;
let indexer_address = config.indexer.indexer_address;
let ipfs_url = config.service.ipfs_url.clone();
Expand All @@ -108,7 +102,7 @@ pub async fn run() -> anyhow::Result<()> {
// Determine if we should check for Horizon contracts and potentially enable hybrid mode:
// - If horizon.enabled = false: Pure legacy mode, no Horizon detection
// - If horizon.enabled = true: Check if Horizon contracts are active in the network
let is_horizon_active = if config.horizon.enabled {
let horizon_is_active = if config.horizon.enabled {
tracing::info!("Horizon migration support enabled - checking if Horizon contracts are active in the network");
match indexer_monitor::is_horizon_active(network_subgraph).await {
Ok(active) => {
Expand All @@ -135,8 +129,20 @@ pub async fn run() -> anyhow::Result<()> {
false
};

let chain_id = config.blockchain.chain_id as u64;

let domain_separator = tap_eip712_domain(
chain_id,
config.blockchain.receipts_verifier_address,
if horizon_is_active {
TapVersion::V2
} else {
TapVersion::V1
},
);

// Configure router with escrow watchers based on automatic Horizon detection
let router = if is_horizon_active {
let router = if horizon_is_active {
tracing::info!("Horizon contracts detected - using Horizon migration mode: V2 receipts only, but processing existing V1 receipts");

// Create V1 escrow watcher for processing existing receipts
Expand Down
2 changes: 1 addition & 1 deletion crates/service/src/tap/checks/receipt_max_val_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ mod tests {
.unwrap();

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

let timestamp = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
Expand Down
2 changes: 1 addition & 1 deletion crates/service/src/tap/checks/timestamp_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ mod tests {
.build()
.unwrap();
let eip712_domain_separator: Eip712Domain =
tap_eip712_domain(1, Address::from([0x11u8; 20]));
tap_eip712_domain(1, Address::from([0x11u8; 20]), tap_core::TapVersion::V1);
let value: u128 = 1234;
let nonce: u64 = 10;
let receipt = Eip712SignedMessage::new(
Expand Down
22 changes: 16 additions & 6 deletions crates/tap-agent/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use sender_accounts_manager::SenderAccountsManager;

use crate::{
agent::sender_accounts_manager::{SenderAccountsManagerArgs, SenderAccountsManagerMessage},
database, CONFIG, EIP_712_DOMAIN,
database, CONFIG,
};

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

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

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

let config = Box::leak(Box::new({
let mut config = SenderAccountConfig::from_config(&CONFIG);
config.horizon_enabled = is_horizon_enabled;
config.horizon_enabled = horizon_is_enabled;
config
}));

let domain_separator = tap_core::tap_eip712_domain(
CONFIG.blockchain.chain_id as u64,
CONFIG.blockchain.receipts_verifier_address,
if horizon_is_enabled {
tap_core::TapVersion::V2
} else {
tap_core::TapVersion::V1
},
);

let args = SenderAccountsManagerArgs {
config,
domain_separator: EIP_712_DOMAIN.clone(),
domain_separator,
pgpool,
indexer_allocations,
escrow_accounts_v1: escrow_accounts_v1_final,
Expand Down
9 changes: 0 additions & 9 deletions crates/tap-agent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,10 @@
use std::sync::LazyLock;

use indexer_config::Config;
use tap_core::tap_eip712_domain;
use thegraph_core::alloy::sol_types::Eip712Domain;

/// Static configuration
pub static CONFIG: LazyLock<Config> =
LazyLock::new(|| cli::get_config().expect("Failed to load configuration"));
/// Static EIP_712_DOMAIN used with config values
pub static EIP_712_DOMAIN: LazyLock<Eip712Domain> = LazyLock::new(|| {
tap_eip712_domain(
CONFIG.blockchain.chain_id as u64,
CONFIG.blockchain.receipts_verifier_address,
)
});

pub mod adaptative_concurrency;
pub mod agent;
Expand Down
4 changes: 2 additions & 2 deletions crates/tap-agent/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rand::{distr::Alphanumeric, rng, Rng};
use reqwest::Url;
use sqlx::{types::BigDecimal, PgPool};
use tap_aggregator::server::run_server;
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain};
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain, TapVersion};
use tap_graph::{Receipt, ReceiptAggregateVoucher, SignedRav, SignedReceipt};
use test_assets::{flush_messages, TAP_SENDER as SENDER, TAP_SIGNER as SIGNER};
use thegraph_core::alloy::{
Expand Down Expand Up @@ -56,7 +56,7 @@ use crate::{
pub static SENDER_2: LazyLock<(PrivateKeySigner, Address)> = LazyLock::new(|| wallet(1));
pub static INDEXER: LazyLock<(PrivateKeySigner, Address)> = LazyLock::new(|| wallet(3));
pub static TAP_EIP712_DOMAIN_SEPARATOR: LazyLock<Eip712Domain> =
LazyLock::new(|| tap_eip712_domain(1, Address::from([0x11u8; 20])));
LazyLock::new(|| tap_eip712_domain(1, Address::from([0x11u8; 20]), TapVersion::V1));

pub const TRIGGER_VALUE: u128 = 500;
pub const RECEIPT_LIMIT: u64 = 10000;
Expand Down
2 changes: 1 addition & 1 deletion crates/test-assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ pub static TAP_SIGNER: LazyLock<(PrivateKeySigner, Address)> = LazyLock::new(||
});

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

#[derive(bon::Builder)]
pub struct SignedReceiptRequest {
Expand Down
9 changes: 7 additions & 2 deletions integration-tests/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
//! Constants used in the integration tests for the TAP RAV generation
//! their value is taken from local-network .env variable

pub const INDEXER_URL: &str = "http://localhost:7601";
// Keep for backwards compatibility if needed
// pub const INDEXER_URL: &str = "http://localhost:7601";

pub const GATEWAY_API_KEY: &str = "deadbeefdeadbeefdeadbeefdeadbeef";
pub const GATEWAY_URL: &str = "http://localhost:7700";
Expand All @@ -24,7 +25,11 @@ pub const ACCOUNT0_SECRET: &str =
"ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
pub const CHAIN_ID: u64 = 1337;

pub const SUBGRAPH_ID: &str = "Qmc2CbqucMvaS4GFvt2QUZWvRwSZ3K5ipeGvbC6UUBf616";
// Use the test subgraph ID for TAP receipt generation testing
pub const SUBGRAPH_ID: &str = "QmRcucmbxAXLaAZkkCR8Bdj1X7QGPLjfRmQ5H6tFhGqiHX";

// Network subgraph ID - used by gateway for network information
pub const NETWORK_SUBGRAPH_ID: &str = "Qmc2CbqucMvaS4GFvt2QUZWvRwSZ3K5ipeGvbC6UUBf616";

pub const GRAPH_URL: &str = "http://localhost:8000/subgraphs/name/graph-network";

Expand Down
16 changes: 9 additions & 7 deletions integration-tests/src/load_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use tokio::{sync::Semaphore, task, time::Instant};

use crate::{
constants::{
ACCOUNT0_SECRET, CHAIN_ID, GRAPH_URL, INDEXER_URL, MAX_RECEIPT_VALUE, SUBGRAPH_ID,
TAP_VERIFIER_CONTRACT,
ACCOUNT0_SECRET, CHAIN_ID, GATEWAY_API_KEY, GATEWAY_URL, GRAPH_URL, MAX_RECEIPT_VALUE,
SUBGRAPH_ID, TAP_VERIFIER_CONTRACT,
},
utils::{
create_request, create_tap_receipt, create_tap_receipt_v2, encode_v2_receipt,
create_request_with_api_key, create_tap_receipt, create_tap_receipt_v2, encode_v2_receipt,
find_allocation,
},
};
Expand Down Expand Up @@ -109,13 +109,14 @@ async fn create_and_send_receipts(
)?;

let receipt_json = serde_json::to_string(&receipt).unwrap();
let response = create_request(
let response = create_request_with_api_key(
&http_client,
format!("{INDEXER_URL}/subgraphs/id/{SUBGRAPH_ID}").as_str(),
format!("{GATEWAY_URL}/api/subgraphs/id/{SUBGRAPH_ID}").as_str(),
&receipt_json,
&json!({
"query": "{ _meta { block { number } } }"
}),
GATEWAY_API_KEY,
)
.send()
.await?;
Expand Down Expand Up @@ -225,13 +226,14 @@ async fn create_and_send_receipts_v2(
)?;

let receipt_encoded = encode_v2_receipt(&receipt)?;
let response = create_request(
let response = create_request_with_api_key(
&http_client,
format!("{INDEXER_URL}/subgraphs/id/{SUBGRAPH_ID}").as_str(),
format!("{GATEWAY_URL}/api/subgraphs/id/{SUBGRAPH_ID}").as_str(),
&receipt_encoded,
&json!({
"query": "{ _meta { block { number } } }"
}),
GATEWAY_API_KEY,
)
.send()
.await?;
Expand Down
7 changes: 7 additions & 0 deletions integration-tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ enum Commands {

#[clap(name = "debug")]
Debug,

#[clap(name = "verify")]
VerifyGateway,
}

#[tokio::main]
Expand Down Expand Up @@ -73,6 +76,10 @@ async fn main() -> Result<()> {
Commands::Debug => {
signature_test::test_v2_signature_recovery().await?;
}
// cargo run -- verify
Commands::VerifyGateway => {
utils::verify_gateway_routing().await?;
}
}

Ok(())
Expand Down
Loading
Loading