Skip to content

Commit 9f8d951

Browse files
committed
feat(tap-agent): integrate V2 domain separator throughout agent
Add V2 domain separator support to sender account management, allocation handling, and receipt processing. Maintains single allocation type invariant while enabling version-appropriate domain usage.
1 parent 13a8f2d commit 9f8d951

File tree

4 files changed

+41
-34
lines changed

4 files changed

+41
-34
lines changed

crates/tap-agent/src/agent.rs

Lines changed: 2 additions & 1 deletion
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, EIP_712_DOMAIN, EIP_712_DOMAIN_V2,
5353
};
5454

5555
/// Actor, Arguments, State, Messages and implementation for [crate::agent::sender_account::SenderAccount]
@@ -244,6 +244,7 @@ pub async fn start_agent() -> (ActorRef<SenderAccountsManagerMessage>, JoinHandl
244244
let args = SenderAccountsManagerArgs {
245245
config,
246246
domain_separator: EIP_712_DOMAIN.clone(),
247+
domain_separator_v2: EIP_712_DOMAIN_V2.clone(),
247248
pgpool,
248249
indexer_allocations,
249250
escrow_accounts_v1: escrow_accounts_v1_final,

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ pub struct SenderAccountArgs {
272272
pub network_subgraph: &'static SubgraphClient,
273273
/// Domain separator used for tap
274274
pub domain_separator: Eip712Domain,
275+
// TODO: check if we need this
276+
/// Domain separator used for horizon
277+
pub domain_separator_v2: Eip712Domain,
275278
/// Endpoint URL for aggregator server
276279
pub sender_aggregator_endpoint: Url,
277280
/// List of allocation ids that must created at startup
@@ -349,6 +352,8 @@ pub struct State {
349352

350353
/// Domain separator used for tap
351354
domain_separator: Eip712Domain,
355+
/// Domain separator used for horizon
356+
domain_separator_v2: Eip712Domain,
352357
/// Database connection
353358
pgpool: PgPool,
354359
/// Aggregator client for V1
@@ -483,7 +488,7 @@ impl State {
483488
.sender(self.sender)
484489
.escrow_accounts(self.escrow_accounts.clone())
485490
.escrow_subgraph(self.escrow_subgraph)
486-
.domain_separator(self.domain_separator.clone())
491+
.domain_separator(self.domain_separator_v2.clone())
487492
.sender_account_ref(sender_account_ref.clone())
488493
.sender_aggregator(self.aggregator_v2.clone())
489494
.config(AllocationConfig::from_sender_config(self.config))
@@ -783,6 +788,7 @@ impl Actor for SenderAccount {
783788
escrow_subgraph,
784789
network_subgraph,
785790
domain_separator,
791+
domain_separator_v2,
786792
sender_aggregator_endpoint,
787793
allocation_ids,
788794
prefix,
@@ -797,7 +803,7 @@ impl Actor for SenderAccount {
797803
myself_clone
798804
.cast(SenderAccountMessage::UpdateAllocationIds(allocation_ids))
799805
.unwrap_or_else(|e| {
800-
tracing::error!("Error while updating allocation_ids: {:?}", e);
806+
tracing::error!(error=?e, "Error while updating allocation_ids");
801807
});
802808
async {}
803809
});
@@ -1093,6 +1099,7 @@ impl Actor for SenderAccount {
10931099
escrow_subgraph,
10941100
network_subgraph,
10951101
domain_separator,
1102+
domain_separator_v2,
10961103
pgpool,
10971104
aggregator_v1,
10981105
aggregator_v2,

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

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ static RECEIPTS_CREATED: LazyLock<CounterVec> = LazyLock::new(|| {
3939
.unwrap()
4040
});
4141

42+
const RETRY_INTERVAL: Duration = Duration::from_secs(30);
43+
4244
/// Notification received by pgnotify for V1 (legacy) receipts
4345
///
4446
/// This contains a list of properties that are sent by postgres when a V1 receipt is inserted
@@ -231,6 +233,9 @@ pub struct SenderAccountsManagerArgs {
231233
/// Domain separator used for tap
232234
pub domain_separator: Eip712Domain,
233235

236+
/// Domain separator used for tap v2 (Horizon)
237+
pub domain_separator_v2: Eip712Domain,
238+
234239
/// Database connection
235240
pub pgpool: PgPool,
236241
/// Watcher that returns a map of open and recently closed allocation ids
@@ -262,6 +267,7 @@ pub struct State {
262267

263268
config: &'static SenderAccountConfig,
264269
domain_separator: Eip712Domain,
270+
domain_separator_v2: Eip712Domain,
265271
pgpool: PgPool,
266272
indexer_allocations: Receiver<HashSet<AllocationId>>,
267273
/// Watcher containing the escrow accounts for v1
@@ -289,6 +295,7 @@ impl Actor for SenderAccountsManager {
289295
SenderAccountsManagerArgs {
290296
config,
291297
domain_separator,
298+
domain_separator_v2,
292299
indexer_allocations,
293300
pgpool,
294301
escrow_accounts_v1,
@@ -299,32 +306,15 @@ impl Actor for SenderAccountsManager {
299306
prefix,
300307
}: Self::Arguments,
301308
) -> Result<Self::State, ActorProcessingErr> {
302-
let is_horizon_active = if config.horizon_enabled {
303-
match indexer_monitor::is_horizon_active(network_subgraph).await {
304-
Ok(active) => {
305-
if active {
306-
tracing::info!(
307-
"Horizon contracts detected - allocations will use Horizon type"
308-
);
309-
} else {
310-
tracing::info!(
311-
"Horizon contracts not active - allocations will use Legacy type"
312-
);
313-
}
314-
active
315-
}
316-
Err(e) => {
317-
tracing::warn!(
318-
"Failed to detect Horizon contracts: {}. Using Legacy type",
319-
e
320-
);
321-
false
322-
}
323-
}
309+
// we can use config.horizon_enabled directly
310+
// because agent_start method does the horizon smart contract/subgraph validation
311+
// and updates the passed in config accordingly
312+
let is_horizon_active = config.horizon_enabled;
313+
if is_horizon_active {
314+
tracing::info!("Horizon enabled in config - allocations will use Horizon type");
324315
} else {
325316
tracing::info!("Horizon disabled in config - allocations will use Legacy type");
326-
false
327-
};
317+
}
328318

329319
let indexer_allocations = map_watcher(indexer_allocations, move |allocation_id| {
330320
let allocations: HashSet<_> = allocation_id
@@ -403,6 +393,7 @@ impl Actor for SenderAccountsManager {
403393
let mut state = State {
404394
config,
405395
domain_separator,
396+
domain_separator_v2,
406397
sender_ids_v1: HashSet::new(),
407398
sender_ids_v2: HashSet::new(),
408399
new_receipts_watcher_handle_v1: None,
@@ -998,18 +989,21 @@ impl State {
998989
allocation_ids: HashSet<AllocationId>,
999990
sender_type: SenderType,
1000991
) -> anyhow::Result<SenderAccountArgs> {
992+
let escrow_accounts = match sender_type {
993+
SenderType::Legacy => self.escrow_accounts_v1.clone(),
994+
SenderType::Horizon => self.escrow_accounts_v2.clone(),
995+
};
996+
1001997
Ok(SenderAccountArgs {
1002998
config: self.config,
1003999
pgpool: self.pgpool.clone(),
10041000
sender_id: *sender_id,
1005-
escrow_accounts: match sender_type {
1006-
SenderType::Legacy => self.escrow_accounts_v1.clone(),
1007-
SenderType::Horizon => self.escrow_accounts_v2.clone(),
1008-
},
1001+
escrow_accounts,
10091002
indexer_allocations: self.indexer_allocations.clone(),
10101003
escrow_subgraph: self.escrow_subgraph,
10111004
network_subgraph: self.network_subgraph,
10121005
domain_separator: self.domain_separator.clone(),
1006+
domain_separator_v2: self.domain_separator_v2.clone(),
10131007
sender_aggregator_endpoint: self
10141008
.sender_aggregator_endpoints
10151009
.get(sender_id)
@@ -1020,7 +1014,7 @@ impl State {
10201014
.clone(),
10211015
allocation_ids,
10221016
prefix: self.prefix.clone(),
1023-
retry_interval: Duration::from_secs(30),
1017+
retry_interval: RETRY_INTERVAL,
10241018
sender_type,
10251019
})
10261020
}
@@ -1356,7 +1350,7 @@ mod tests {
13561350
create_rav, create_received_receipt, create_sender_accounts_manager,
13571351
generate_random_prefix, get_grpc_url, get_sender_account_config, store_rav,
13581352
store_receipt, ALLOCATION_ID_0, ALLOCATION_ID_1, INDEXER, SENDER_2,
1359-
TAP_EIP712_DOMAIN_SEPARATOR,
1353+
TAP_EIP712_DOMAIN_SEPARATOR, TAP_EIP712_DOMAIN_SEPARATOR_V2,
13601354
},
13611355
};
13621356
const DUMMY_URL: &str = "http://localhost:1234";
@@ -1412,6 +1406,7 @@ mod tests {
14121406
State {
14131407
config,
14141408
domain_separator: TAP_EIP712_DOMAIN_SEPARATOR.clone(),
1409+
domain_separator_v2: TAP_EIP712_DOMAIN_SEPARATOR_V2.clone(),
14151410
sender_ids_v1: HashSet::new(),
14161411
sender_ids_v2: HashSet::new(),
14171412
new_receipts_watcher_handle_v1: None,

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ pub struct SenderAllocationState<T: NetworkVersion> {
148148

149149
/// Watcher containing the escrow accounts
150150
escrow_accounts: Receiver<EscrowAccounts>,
151-
/// Domain separator used for tap
151+
/// Domain separator used for tap/horizon
152+
/// depending if SenderAllocationState<Legacy> or SenderAllocationState<Horizon>??
153+
/// TODO: Double check if we actually need to add an additional domain_sepparator_v2 field
154+
/// at first glance it seems like each sender allocation will deal only with one allocation
155+
/// type. not both
152156
domain_separator: Eip712Domain,
153157
/// Reference to [super::sender_account::SenderAccount] actor
154158
///

0 commit comments

Comments
 (0)