Skip to content

Commit 39810f7

Browse files
committed
refactor: configure system for transition mode
1 parent 8c06699 commit 39810f7

File tree

5 files changed

+135
-60
lines changed

5 files changed

+135
-60
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/src/config.rs

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

449+
/// Horizon upgrade mode configuration
450+
#[derive(Debug, Clone, Deserialize, PartialEq)]
451+
#[serde(rename_all = "lowercase")]
452+
pub enum HorizonMode {
453+
/// Legacy mode: Only v1 TAP receipts supported
454+
Legacy,
455+
/// Transition mode: Both v1 and v2 TAP receipts supported (for migration)
456+
Transition,
457+
/// Full mode: Only v2 TAP receipts supported (post-migration)
458+
Full,
459+
}
460+
461+
impl Default for HorizonMode {
462+
fn default() -> Self {
463+
HorizonMode::Legacy
464+
}
465+
}
466+
449467
/// Configuration for the horizon
450468
/// standard
451469
#[derive(Debug, Default, Deserialize)]
452470
#[cfg_attr(test, derive(PartialEq))]
453471
pub struct HorizonConfig {
454-
/// Whether the horizon is enabled or not
455-
pub enabled: bool,
472+
/// Horizon upgrade mode
473+
pub mode: HorizonMode,
456474
}
457475

458476
#[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
}));

0 commit comments

Comments
 (0)