Skip to content

Commit b455dd6

Browse files
committed
feat: allocation id to collection id for horizon
1 parent dcea15d commit b455dd6

File tree

19 files changed

+377
-229
lines changed

19 files changed

+377
-229
lines changed

crates/indexer-receipt/src/lib.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ use tap_core::{
99
},
1010
signed_message::SignatureBytes,
1111
};
12-
use thegraph_core::alloy::{dyn_abi::Eip712Domain, primitives::Address, signers::Signature};
12+
use thegraph_core::alloy::{
13+
dyn_abi::Eip712Domain,
14+
primitives::{Address, FixedBytes},
15+
signers::Signature,
16+
};
1317

1418
#[derive(Debug, Clone, PartialEq, Eq)]
1519
pub enum TapReceipt {
@@ -70,13 +74,13 @@ impl Aggregate<TapReceipt> for tap_graph::v2::ReceiptAggregateVoucher {
7074
})
7175
.collect::<Result<_, _>>()
7276
.map_err(AggregationError::Other)?;
73-
let allocation_id = receipts[0].message.allocation_id;
77+
let collection_id = receipts[0].message.collection_id;
7478
let payer = receipts[0].message.payer;
7579
let data_service = receipts[0].message.data_service;
7680
let service_provider = receipts[0].message.service_provider;
7781

7882
tap_graph::v2::ReceiptAggregateVoucher::aggregate_receipts(
79-
allocation_id,
83+
collection_id,
8084
payer,
8185
data_service,
8286
service_provider,
@@ -115,10 +119,17 @@ impl TapReceipt {
115119
}
116120
}
117121

118-
pub fn allocation_id(&self) -> Address {
122+
pub fn allocation_id(&self) -> Option<Address> {
119123
match self {
120-
TapReceipt::V1(receipt) => receipt.message.allocation_id,
121-
TapReceipt::V2(receipt) => receipt.message.allocation_id,
124+
TapReceipt::V1(receipt) => Some(receipt.message.allocation_id),
125+
_ => None,
126+
}
127+
}
128+
129+
pub fn collection_id(&self) -> Option<FixedBytes<32>> {
130+
match self {
131+
TapReceipt::V2(receipt) => Some(receipt.message.collection_id),
132+
_ => None,
122133
}
123134
}
124135

crates/profiler/src/lib.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use std::fs::{self, File};
5-
use std::io::Write;
6-
use std::path::{Path, PathBuf};
7-
use std::sync::atomic::{AtomicU64, Ordering};
8-
use std::sync::Arc;
9-
use std::thread;
10-
use std::time::{Duration, SystemTime};
4+
use std::{
5+
fs::{self, File},
6+
io::Write,
7+
path::{Path, PathBuf},
8+
sync::{
9+
atomic::{AtomicU64, Ordering},
10+
Arc,
11+
},
12+
thread,
13+
time::{Duration, SystemTime},
14+
};
1115

1216
use chrono::{DateTime, Utc};
1317
use pprof::protos::Message;

crates/service/src/tap/checks/allocation_eligible.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::collections::HashMap;
66
use anyhow::anyhow;
77
use indexer_allocation::Allocation;
88
use tap_core::receipt::checks::{Check, CheckError, CheckResult};
9-
use thegraph_core::alloy::primitives::Address;
9+
use thegraph_core::{alloy::primitives::Address, CollectionId};
1010
use tokio::sync::watch::Receiver;
1111

1212
use crate::tap::{CheckingReceipt, TapReceipt};
@@ -29,7 +29,12 @@ impl Check<TapReceipt> for AllocationEligible {
2929
_: &tap_core::receipt::Context,
3030
receipt: &CheckingReceipt,
3131
) -> CheckResult {
32-
let allocation_id = receipt.signed_receipt().allocation_id();
32+
let allocation_id = match receipt.signed_receipt() {
33+
TapReceipt::V1(receipt) => receipt.message.allocation_id,
34+
TapReceipt::V2(receipt) => {
35+
CollectionId::from(receipt.message.collection_id).as_address()
36+
}
37+
};
3338
if !self
3439
.indexer_allocations
3540
.borrow()

crates/service/src/tap/receipt_store.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use itertools::{Either, Itertools};
77
use sqlx::{types::BigDecimal, PgPool};
88
use tap_core::{manager::adapters::ReceiptStore, receipt::WithValueAndTimestamp};
99
use thegraph_core::alloy::{hex::ToHexExt, sol_types::Eip712Domain};
10-
use tokio::{sync::mpsc::Receiver, sync::oneshot::Sender as OneShotSender, task::JoinHandle};
10+
use tokio::{
11+
sync::{mpsc::Receiver, oneshot::Sender as OneShotSender},
12+
task::JoinHandle,
13+
};
1114
use tokio_util::sync::CancellationToken;
1215

1316
use super::{AdapterError, CheckingReceipt, IndexerTapContext, TapReceipt};
@@ -164,7 +167,7 @@ impl InnerContext {
164167
let receipts_len = receipts.len();
165168
let mut signers = Vec::with_capacity(receipts_len);
166169
let mut signatures = Vec::with_capacity(receipts_len);
167-
let mut allocation_ids = Vec::with_capacity(receipts_len);
170+
let mut collection_ids = Vec::with_capacity(receipts_len);
168171
let mut payers = Vec::with_capacity(receipts_len);
169172
let mut data_services = Vec::with_capacity(receipts_len);
170173
let mut service_providers = Vec::with_capacity(receipts_len);
@@ -175,7 +178,7 @@ impl InnerContext {
175178
for receipt in receipts {
176179
signers.push(receipt.signer_address);
177180
signatures.push(receipt.signature);
178-
allocation_ids.push(receipt.allocation_id);
181+
collection_ids.push(receipt.collection_id);
179182
payers.push(receipt.payer);
180183
data_services.push(receipt.data_service);
181184
service_providers.push(receipt.service_provider);
@@ -187,7 +190,7 @@ impl InnerContext {
187190
r#"INSERT INTO tap_horizon_receipts (
188191
signer_address,
189192
signature,
190-
allocation_id,
193+
collection_id,
191194
payer,
192195
data_service,
193196
service_provider,
@@ -207,7 +210,7 @@ impl InnerContext {
207210
)"#,
208211
&signers,
209212
&signatures,
210-
&allocation_ids,
213+
&collection_ids,
211214
&payers,
212215
&data_services,
213216
&service_providers,
@@ -328,7 +331,7 @@ impl DbReceiptV1 {
328331
pub struct DbReceiptV2 {
329332
signer_address: String,
330333
signature: Vec<u8>,
331-
allocation_id: String,
334+
collection_id: String,
332335
payer: String,
333336
data_service: String,
334337
service_provider: String,
@@ -342,7 +345,7 @@ impl DbReceiptV2 {
342345
receipt: &tap_graph::v2::SignedReceipt,
343346
separator: &Eip712Domain,
344347
) -> anyhow::Result<Self> {
345-
let allocation_id = receipt.message.allocation_id.encode_hex();
348+
let collection_id = receipt.message.collection_id.encode_hex();
346349
let payer = receipt.message.payer.encode_hex();
347350
let data_service = receipt.message.data_service.encode_hex();
348351
let service_provider = receipt.message.service_provider.encode_hex();
@@ -360,7 +363,7 @@ impl DbReceiptV2 {
360363
let nonce = BigDecimal::from(receipt.message.nonce);
361364
let value = BigDecimal::from(BigInt::from(receipt.value()));
362365
Ok(Self {
363-
allocation_id,
366+
collection_id,
364367
payer,
365368
data_service,
366369
service_provider,

0 commit comments

Comments
 (0)