Skip to content

Commit 796c4bd

Browse files
committed
refactor: configure system for transition mode
Signed-off-by: Joseph Livesey <[email protected]>
1 parent 8c06699 commit 796c4bd

File tree

9 files changed

+146
-63
lines changed

9 files changed

+146
-63
lines changed

contrib/indexer-service/config.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,8 @@ trigger_value_divisor = 500_000
4646
"ACCOUNT0_ADDRESS_PLACEHOLDER" = "http://tap-aggregator:7610"
4747

4848
[horizon]
49-
enabled = true
49+
# Horizon migration mode: legacy | transition | full
50+
# - legacy: Only v1 TAP receipts supported (pre-migration)
51+
# - transition: Both v1 and v2 TAP receipts supported (during migration)
52+
# - full: Only v2 TAP receipts supported (post-migration)
53+
mode = "transition"

contrib/tap-agent/config.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,8 @@ trigger_value_divisor = 500_000
4646
"ACCOUNT0_ADDRESS_PLACEHOLDER" = "http://tap-aggregator:7610"
4747

4848
[horizon]
49-
enabled = true
49+
# Horizon migration mode: legacy | transition | full
50+
# - legacy: Only v1 TAP receipts supported (pre-migration)
51+
# - transition: Both v1 and v2 TAP receipts supported (during migration)
52+
# - full: Only v2 TAP receipts supported (post-migration)
53+
mode = "transition"

crates/config/maximal-config-example.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,4 @@ hardhat = "100"
170170
"eip155:1337" = "hardhat"
171171

172172
[horizon]
173-
enabled = false
173+
mode = "legacy"

crates/config/minimal-config-example.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,6 @@ receipts_verifier_address = "0x2222222222222222222222222222222222222222"
6363
# Key-Value of all senders and their aggregator endpoints
6464
0xDDE4cfFd3D9052A9cb618fC05a1Cd02be1f2F467 = "https://tap-aggregator.network.thegraph.com"
6565
0xDD6a6f76eb36B873C1C184e8b9b9e762FE216490 = "https://tap-aggregator-arbitrum-one.graphops.xyz"
66+
67+
[horizon]
68+
mode = "legacy"

crates/config/src/config.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,26 @@ pub struct RavRequestConfig {
446446
pub max_receipts_per_request: u64,
447447
}
448448

449+
/// Horizon upgrade mode configuration
450+
#[derive(Debug, Clone, Deserialize, PartialEq, Default)]
451+
#[serde(rename_all = "lowercase")]
452+
pub enum HorizonMode {
453+
/// Legacy mode: Only v1 TAP receipts supported
454+
#[default]
455+
Legacy,
456+
/// Transition mode: Both v1 and v2 TAP receipts supported (for migration)
457+
Transition,
458+
/// Full mode: Only v2 TAP receipts supported (post-migration)
459+
Full,
460+
}
461+
449462
/// Configuration for the horizon
450463
/// standard
451464
#[derive(Debug, Default, Deserialize)]
452465
#[cfg_attr(test, derive(PartialEq))]
453466
pub struct HorizonConfig {
454-
/// Whether the horizon is enabled or not
455-
pub enabled: bool,
467+
/// Horizon upgrade mode
468+
pub mode: HorizonMode,
456469
}
457470

458471
#[cfg(test)]

crates/service/src/service.rs

Lines changed: 91 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -105,57 +105,97 @@ pub async fn run() -> anyhow::Result<()> {
105105
let indexer_address = config.indexer.indexer_address;
106106
let ipfs_url = config.service.ipfs_url.clone();
107107

108-
// Configure router with escrow watchers based on Horizon setting
109-
let router = if config.horizon.enabled {
110-
tracing::info!("Horizon support enabled - using escrow accounts v2");
111-
// Only create v2 watcher when Horizon is enabled
112-
let v2_watcher = indexer_monitor::escrow_accounts_v2(
113-
escrow_subgraph,
114-
indexer_address,
115-
config.subgraphs.escrow.config.syncing_interval_secs,
116-
true, // Reject thawing signers eagerly
117-
)
118-
.await
119-
.expect("Error creating escrow_accounts_v2 channel");
120-
121-
ServiceRouter::builder()
122-
.database(database.clone())
123-
.domain_separator(domain_separator.clone())
124-
.graph_node(config.graph_node)
125-
.http_client(http_client)
126-
.release(release)
127-
.indexer(config.indexer)
128-
.service(config.service)
129-
.blockchain(config.blockchain)
130-
.timestamp_buffer_secs(config.tap.rav_request.timestamp_buffer_secs)
131-
.network_subgraph(network_subgraph, config.subgraphs.network)
132-
.escrow_accounts_v2(v2_watcher)
133-
.build()
134-
} else {
135-
tracing::info!("Horizon support disabled - using escrow accounts v1");
136-
// Only create v1 watcher when Horizon is disabled
137-
let v1_watcher = indexer_monitor::escrow_accounts_v1(
138-
escrow_subgraph,
139-
indexer_address,
140-
config.subgraphs.escrow.config.syncing_interval_secs,
141-
true, // Reject thawing signers eagerly
142-
)
143-
.await
144-
.expect("Error creating escrow_accounts_v1 channel");
145-
146-
ServiceRouter::builder()
147-
.database(database.clone())
148-
.domain_separator(domain_separator.clone())
149-
.graph_node(config.graph_node)
150-
.http_client(http_client)
151-
.release(release)
152-
.indexer(config.indexer)
153-
.service(config.service)
154-
.blockchain(config.blockchain)
155-
.timestamp_buffer_secs(config.tap.rav_request.timestamp_buffer_secs)
156-
.network_subgraph(network_subgraph, config.subgraphs.network)
157-
.escrow_accounts_v1(v1_watcher)
158-
.build()
108+
// Configure router with escrow watchers based on Horizon mode
109+
use indexer_config::HorizonMode;
110+
let router = match config.horizon.mode {
111+
HorizonMode::Legacy => {
112+
tracing::info!("Horizon mode: Legacy - using escrow accounts v1 only");
113+
// Only create v1 watcher for legacy mode
114+
let v1_watcher = indexer_monitor::escrow_accounts_v1(
115+
escrow_subgraph,
116+
indexer_address,
117+
config.subgraphs.escrow.config.syncing_interval_secs,
118+
true, // Reject thawing signers eagerly
119+
)
120+
.await
121+
.expect("Error creating escrow_accounts_v1 channel");
122+
123+
ServiceRouter::builder()
124+
.database(database.clone())
125+
.domain_separator(domain_separator.clone())
126+
.graph_node(config.graph_node)
127+
.http_client(http_client)
128+
.release(release)
129+
.indexer(config.indexer)
130+
.service(config.service)
131+
.blockchain(config.blockchain)
132+
.timestamp_buffer_secs(config.tap.rav_request.timestamp_buffer_secs)
133+
.network_subgraph(network_subgraph, config.subgraphs.network)
134+
.escrow_accounts_v1(v1_watcher)
135+
.build()
136+
}
137+
HorizonMode::Transition => {
138+
tracing::info!("Horizon mode: Transition - using both escrow accounts v1 and v2");
139+
// Create both watchers for transition mode
140+
let v1_watcher = indexer_monitor::escrow_accounts_v1(
141+
escrow_subgraph,
142+
indexer_address,
143+
config.subgraphs.escrow.config.syncing_interval_secs,
144+
true, // Reject thawing signers eagerly
145+
)
146+
.await
147+
.expect("Error creating escrow_accounts_v1 channel");
148+
149+
let v2_watcher = indexer_monitor::escrow_accounts_v2(
150+
escrow_subgraph,
151+
indexer_address,
152+
config.subgraphs.escrow.config.syncing_interval_secs,
153+
true, // Reject thawing signers eagerly
154+
)
155+
.await
156+
.expect("Error creating escrow_accounts_v2 channel");
157+
158+
ServiceRouter::builder()
159+
.database(database.clone())
160+
.domain_separator(domain_separator.clone())
161+
.graph_node(config.graph_node)
162+
.http_client(http_client)
163+
.release(release)
164+
.indexer(config.indexer)
165+
.service(config.service)
166+
.blockchain(config.blockchain)
167+
.timestamp_buffer_secs(config.tap.rav_request.timestamp_buffer_secs)
168+
.network_subgraph(network_subgraph, config.subgraphs.network)
169+
.escrow_accounts_v1(v1_watcher)
170+
.escrow_accounts_v2(v2_watcher)
171+
.build()
172+
}
173+
HorizonMode::Full => {
174+
tracing::info!("Horizon mode: Full - using escrow accounts v2 only");
175+
// Only create v2 watcher for full Horizon mode
176+
let v2_watcher = indexer_monitor::escrow_accounts_v2(
177+
escrow_subgraph,
178+
indexer_address,
179+
config.subgraphs.escrow.config.syncing_interval_secs,
180+
true, // Reject thawing signers eagerly
181+
)
182+
.await
183+
.expect("Error creating escrow_accounts_v2 channel");
184+
185+
ServiceRouter::builder()
186+
.database(database.clone())
187+
.domain_separator(domain_separator.clone())
188+
.graph_node(config.graph_node)
189+
.http_client(http_client)
190+
.release(release)
191+
.indexer(config.indexer)
192+
.service(config.service)
193+
.blockchain(config.blockchain)
194+
.timestamp_buffer_secs(config.tap.rav_request.timestamp_buffer_secs)
195+
.network_subgraph(network_subgraph, config.subgraphs.network)
196+
.escrow_accounts_v2(v2_watcher)
197+
.build()
198+
}
159199
};
160200

161201
serve_metrics(config.metrics.get_socket_addr());

crates/tap-agent/src/agent.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,20 @@ pub async fn start_agent() -> (ActorRef<SenderAccountsManagerMessage>, JoinHandl
177177
let config = Box::leak(Box::new({
178178
let mut config = SenderAccountConfig::from_config(&CONFIG);
179179
// Use the configuration setting for Horizon support
180-
config.horizon_enabled = CONFIG.horizon.enabled;
181-
if CONFIG.horizon.enabled {
182-
tracing::info!("Horizon support is enabled");
183-
} else {
184-
tracing::info!("Horizon support is disabled");
180+
use indexer_config::HorizonMode;
181+
match CONFIG.horizon.mode {
182+
HorizonMode::Legacy => {
183+
tracing::info!("Horizon mode: Legacy - v1 receipts only");
184+
config.horizon_enabled = false;
185+
}
186+
HorizonMode::Transition => {
187+
tracing::info!("Horizon mode: Transition - both v1 and v2 receipts supported");
188+
config.horizon_enabled = true;
189+
}
190+
HorizonMode::Full => {
191+
tracing::info!("Horizon mode: Full - v2 receipts only");
192+
config.horizon_enabled = true;
193+
}
185194
}
186195
config
187196
}));

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,11 @@ impl SenderAccountConfig {
422422
rav_request_timeout: config.tap.rav_request.request_timeout_secs,
423423
tap_sender_timeout: config.tap.sender_timeout_secs,
424424
trusted_senders: config.tap.trusted_senders.clone(),
425-
horizon_enabled: config.horizon.enabled,
425+
horizon_enabled: match config.horizon.mode {
426+
indexer_config::HorizonMode::Legacy => false,
427+
indexer_config::HorizonMode::Transition => true,
428+
indexer_config::HorizonMode::Full => true,
429+
},
426430
}
427431
}
428432
}

crates/test-assets/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,14 @@ pub fn pgpool() -> Pin<Box<dyn Future<Output = PgPool>>> {
461461
ConnectOptions, Connection,
462462
};
463463
Box::pin(async {
464+
let timestamp = SystemTime::now()
465+
.duration_since(UNIX_EPOCH)
466+
.unwrap()
467+
.as_nanos();
468+
let test_path =
469+
Box::leak(format!("{}_{}", stdext::function_name!(), timestamp).into_boxed_str());
464470
let args = TestArgs {
465-
test_path: stdext::function_name!(),
471+
test_path,
466472
migrator: Some(&migrate!("../../migrations")),
467473
fixtures: &[],
468474
};

0 commit comments

Comments
 (0)