Skip to content

Commit be58818

Browse files
committed
fix(tap-agent): derive allocation_id from V2 collection_id in AllocationId check
- Accept Horizon (V2) receipts that only provide collection_id by mapping the 32‑byte value to an Address (last 20 bytes, right‑aligned). - Preserve V1 behavior (use allocation_id() when present). - Validate collection_id length and return a clear error when invalid. - Add a small debug log comparing the resolved allocation_id to the expected one.
1 parent 11bd525 commit be58818

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

crates/tap-agent/src/tap/context/checks/allocation_id.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use indexer_monitor::SubgraphClient;
88
use indexer_query::{tap_transactions, TapTransactions};
99
use indexer_watcher::new_watcher;
1010
use tap_core::receipt::checks::{Check, CheckError, CheckResult};
11-
use thegraph_core::alloy::primitives::Address;
11+
use thegraph_core::{alloy::primitives::Address, CollectionId as CollectionIdCore};
1212
use tokio::sync::watch::Receiver;
1313

1414
use crate::tap::{CheckingReceipt, TapReceipt};
@@ -54,13 +54,33 @@ impl Check<TapReceipt> for AllocationId {
5454
_: &tap_core::receipt::Context,
5555
receipt: &CheckingReceipt,
5656
) -> CheckResult {
57-
let allocation_id = receipt
58-
.signed_receipt()
59-
.allocation_id()
60-
.ok_or_else(|| CheckError::Failed(anyhow!("Receipt does not have an allocation_id")))?;
57+
// Support both Legacy (V1) and Horizon (V2) receipts.
58+
// V1 provides allocation_id directly; V2 provides collection_id which we map to an Address.
59+
let allocation_id = if let Some(a) = receipt.signed_receipt().allocation_id() {
60+
a
61+
} else if let Some(cid) = receipt.signed_receipt().collection_id() {
62+
// V2: collection_id is 32 bytes with the 20-byte address right-aligned (left-padded zeros).
63+
let bytes = cid.as_slice();
64+
if bytes.len() != 32 {
65+
return Err(CheckError::Failed(anyhow!(
66+
"Invalid collection_id length: {} (expected 32)",
67+
bytes.len()
68+
)));
69+
}
70+
Address::from_slice(&bytes[12..32])
71+
} else {
72+
return Err(CheckError::Failed(anyhow!(
73+
"Receipt does not have an allocation_id or collection_id"
74+
)));
75+
};
6176
// TODO: Remove the if block below? Each TAP Monitor is specific to an allocation
6277
// ID. So the receipts that are received here should already have been filtered by
6378
// allocation ID.
79+
tracing::debug!(
80+
"Checking allocation_id: {:?} against expected_allocation_id: {}",
81+
allocation_id,
82+
self.allocation_id
83+
);
6484
if allocation_id != self.allocation_id {
6585
return Err(CheckError::Failed(anyhow!("Receipt allocation_id different from expected: allocation_id: {:?}, expected_allocation_id: {}", allocation_id, self.allocation_id)));
6686
};

0 commit comments

Comments
 (0)