Skip to content

Commit c5f3b67

Browse files
committed
refactor: use network subgraph for v2 escrow accounts
Signed-off-by: Joseph Livesey <[email protected]>
1 parent a830b72 commit c5f3b67

File tree

12 files changed

+630
-218
lines changed

12 files changed

+630
-218
lines changed

contrib/indexer-service/config.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ query_url = "http://graph-node:8000/subgraphs/name/semiotic/tap"
2020
deployment_id = "ESCROW_DEPLOYMENT_PLACEHOLDER"
2121
syncing_interval_secs = 30
2222

23-
[subgraphs.escrow_v2]
24-
query_url = "http://graph-node:8000/subgraphs/name/semiotic/tap-v2"
25-
deployment_id = "ESCROW_V2_DEPLOYMENT_PLACEHOLDER"
26-
syncing_interval_secs = 30
23+
# Note: V2 escrow accounts are in the network subgraph, not a separate TAP v2 subgraph
2724

2825
[blockchain]
2926
chain_id = 1337

contrib/indexer-service/start.sh

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,8 @@ if [ "$ESCROW_DEPLOYMENT" = "null" ] || [ -z "$ESCROW_DEPLOYMENT" ]; then
3939
ESCROW_DEPLOYMENT=""
4040
fi
4141

42-
# Get escrow v2 subgraph deployment ID
43-
stdbuf -oL echo "🔍 DEBUG: Fetching escrow v2 subgraph deployment ID..."
44-
ESCROW_V2_DEPLOYMENT=$(curl -s --max-time 10 "http://graph-node:8000/subgraphs/name/semiotic/tap-v2" \
45-
-H 'content-type: application/json' \
46-
-d '{"query": "{ _meta { deployment } }"}' | jq -r '.data._meta.deployment' 2>/dev/null)
47-
stdbuf -oL echo "🔍 DEBUG: Escrow v2 deployment result: $ESCROW_V2_DEPLOYMENT"
48-
49-
# Handle null deployment IDs for v2
50-
if [ "$ESCROW_V2_DEPLOYMENT" = "null" ] || [ -z "$ESCROW_V2_DEPLOYMENT" ]; then
51-
ESCROW_V2_DEPLOYMENT=""
52-
fi
5342

5443
stdbuf -oL echo "Escrow subgraph deployment ID: $ESCROW_DEPLOYMENT"
55-
stdbuf -oL echo "Escrow v2 subgraph deployment ID: $ESCROW_V2_DEPLOYMENT"
5644
stdbuf -oL echo "Using test Network subgraph deployment ID: $NETWORK_DEPLOYMENT"
5745
stdbuf -oL echo "Using test Verifier address: $VERIFIER_ADDRESS"
5846
stdbuf -oL echo "Using test Indexer address: $RECEIVER_ADDRESS"
@@ -77,12 +65,6 @@ else
7765
sed -i '/deployment_id = "ESCROW_DEPLOYMENT_PLACEHOLDER"/d' /opt/config.toml
7866
fi
7967

80-
if [ -n "$ESCROW_V2_DEPLOYMENT" ]; then
81-
sed -i "s/ESCROW_V2_DEPLOYMENT_PLACEHOLDER/$ESCROW_V2_DEPLOYMENT/g" /opt/config.toml
82-
else
83-
# Remove the escrow_v2 section if deployment not found
84-
sed -i '/\[subgraphs.escrow_v2\]/,/^$/d' /opt/config.toml
85-
fi
8668
sed -i "s/VERIFIER_ADDRESS_PLACEHOLDER/$VERIFIER_ADDRESS/g" /opt/config.toml
8769
sed -i "s/INDEXER_ADDRESS_PLACEHOLDER/$RECEIVER_ADDRESS/g" /opt/config.toml
8870
sed -i "s/INDEXER_MNEMONIC_PLACEHOLDER/$INDEXER_MNEMONIC/g" /opt/config.toml

contrib/tap-agent/config.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ query_url = "http://graph-node:8000/subgraphs/name/semiotic/tap"
2020
deployment_id = "ESCROW_DEPLOYMENT_PLACEHOLDER"
2121
syncing_interval_secs = 30
2222

23-
[subgraphs.escrow_v2]
24-
query_url = "http://graph-node:8000/subgraphs/name/semiotic/tap-v2"
25-
deployment_id = "ESCROW_V2_DEPLOYMENT_PLACEHOLDER"
26-
syncing_interval_secs = 30
23+
# Note: V2 escrow accounts are in the network subgraph, not a separate TAP v2 subgraph
2724

2825
[blockchain]
2926
chain_id = 1337

contrib/tap-agent/start.sh

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -105,43 +105,13 @@ fi
105105

106106
echo "Escrow subgraph deployment ID: $ESCROW_DEPLOYMENT"
107107

108-
# Get escrow v2 subgraph deployment ID with retries
109-
echo "Getting escrow v2 subgraph deployment ID..."
110-
MAX_ATTEMPTS=30
111-
ATTEMPT=0
112-
ESCROW_V2_DEPLOYMENT=""
113-
114-
while [ -z "$ESCROW_V2_DEPLOYMENT" ] || [ "$ESCROW_V2_DEPLOYMENT" = "null" ] && [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
115-
ESCROW_V2_DEPLOYMENT=$(curl -s "http://graph-node:8000/subgraphs/name/semiotic/tap-v2" \
116-
-H 'content-type: application/json' \
117-
-d '{"query": "{ _meta { deployment } }"}' | jq -r '.data._meta.deployment' 2>/dev/null)
118-
119-
if [ -z "$ESCROW_V2_DEPLOYMENT" ] || [ "$ESCROW_V2_DEPLOYMENT" = "null" ]; then
120-
ATTEMPT=$((ATTEMPT + 1))
121-
echo "Waiting for escrow v2 subgraph to be deployed... Attempt $ATTEMPT/$MAX_ATTEMPTS"
122-
sleep 5
123-
fi
124-
done
125-
126-
if [ -z "$ESCROW_V2_DEPLOYMENT" ] || [ "$ESCROW_V2_DEPLOYMENT" = "null" ]; then
127-
echo "WARNING: Failed to get escrow v2 subgraph deployment ID after $MAX_ATTEMPTS attempts"
128-
# Continue without v2 for backward compatibility
129-
else
130-
echo "Escrow v2 subgraph deployment ID: $ESCROW_V2_DEPLOYMENT"
131-
fi
132108

133109
# Copy the config template
134110
cp /opt/config/config.toml /opt/config.toml
135111

136112
# Replace the placeholders with actual values
137113
sed -i "s/NETWORK_DEPLOYMENT_PLACEHOLDER/$NETWORK_DEPLOYMENT/g" /opt/config.toml
138114
sed -i "s/ESCROW_DEPLOYMENT_PLACEHOLDER/$ESCROW_DEPLOYMENT/g" /opt/config.toml
139-
if [ ! -z "$ESCROW_V2_DEPLOYMENT" ] && [ "$ESCROW_V2_DEPLOYMENT" != "null" ]; then
140-
sed -i "s/ESCROW_V2_DEPLOYMENT_PLACEHOLDER/$ESCROW_V2_DEPLOYMENT/g" /opt/config.toml
141-
else
142-
# Remove the escrow_v2 section if deployment not found
143-
sed -i '/\[subgraphs.escrow_v2\]/,/^$/d' /opt/config.toml
144-
fi
145115
sed -i "s/VERIFIER_ADDRESS_PLACEHOLDER/$VERIFIER_ADDRESS/g" /opt/config.toml
146116
sed -i "s/INDEXER_ADDRESS_PLACEHOLDER/$RECEIVER_ADDRESS/g" /opt/config.toml
147117
sed -i "s/INDEXER_MNEMONIC_PLACEHOLDER/$INDEXER_MNEMONIC/g" /opt/config.toml

crates/config/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl MetricsConfig {
303303
pub struct SubgraphsConfig {
304304
pub network: NetworkSubgraphConfig,
305305
pub escrow: EscrowSubgraphConfig,
306-
pub escrow_v2: Option<EscrowSubgraphConfig>,
306+
// Note: V2 escrow accounts are in the network subgraph, not a separate escrow_v2 subgraph
307307
}
308308

309309
#[serde_as]

crates/monitor/src/escrow_accounts.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ use std::{
99

1010
use anyhow::anyhow;
1111
use indexer_query::escrow_account::{self, EscrowAccountQuery};
12-
use indexer_query::escrow_account_v2::{
13-
self as escrow_account_v2, EscrowAccountQuery as EscrowAccountQueryV2,
14-
};
1512
use thegraph_core::alloy::primitives::{Address, U256};
1613
use thiserror::Error;
1714
use tokio::sync::watch::Receiver;
@@ -120,22 +117,16 @@ async fn get_escrow_accounts_v2(
120117
indexer_address: Address,
121118
reject_thawing_signers: bool,
122119
) -> anyhow::Result<EscrowAccounts> {
123-
// V2 TAP receipts use different field names (payer/service_provider) but the underlying
124-
// escrow account model is identical to V1. Both V1 and V2 receipts reference the same
125-
// sender addresses and the same escrow relationships.
126-
//
127-
// The separation of V1/V2 escrow account watchers allows for potential future differences
128-
// in escrow models, but currently both query the same subgraph data with identical logic.
129-
//
130-
// V2 receipt flow:
131-
// 1. V2 receipt contains payer address (equivalent to V1 sender)
132-
// 2. Receipt is signed by a signer authorized by the payer
133-
// 3. Escrow accounts map: signer -> payer (sender) -> balance
134-
// 4. Service provider (indexer) receives payments from payer's escrow
120+
// Query V2 escrow accounts from the network subgraph which tracks PaymentsEscrow
121+
// and GraphTallyCollector contract events.
122+
123+
use indexer_query::network_escrow_account_v2::{
124+
self as network_escrow_account_v2, NetworkEscrowAccountQueryV2,
125+
};
135126

136127
let response = escrow_subgraph
137-
.query::<EscrowAccountQueryV2, _>(escrow_account_v2::Variables {
138-
indexer: format!("{:x?}", indexer_address),
128+
.query::<NetworkEscrowAccountQueryV2, _>(network_escrow_account_v2::Variables {
129+
receiver: format!("{:x?}", indexer_address),
139130
thaw_end_timestamp: if reject_thawing_signers {
140131
U256::ZERO.to_string()
141132
} else {
@@ -146,7 +137,20 @@ async fn get_escrow_accounts_v2(
146137

147138
let response = response?;
148139

149-
tracing::trace!("V2 Escrow accounts response: {:?}", response);
140+
tracing::trace!("Network V2 Escrow accounts response: {:?}", response);
141+
142+
// V2 TAP receipts use different field names (payer/service_provider) but the underlying
143+
// escrow account model is identical to V1. Both V1 and V2 receipts reference the same
144+
// sender addresses and the same escrow relationships.
145+
//
146+
// V1 queries the TAP subgraph while V2 queries the network subgraph, but both return
147+
// the same escrow account structure for processing.
148+
//
149+
// V2 receipt flow:
150+
// 1. V2 receipt contains payer address (equivalent to V1 sender)
151+
// 2. Receipt is signed by a signer authorized by the payer
152+
// 3. Escrow accounts map: signer -> payer (sender) -> balance
153+
// 4. Service provider (indexer) receives payments from payer's escrow
150154

151155
let senders_balances: HashMap<Address, U256> = response
152156
.escrow_accounts

0 commit comments

Comments
 (0)