Skip to content

Commit 58afaef

Browse files
committed
fix: update RAV and receipt structs for horizon to latest version
Signed-off-by: Tomás Migone <[email protected]>
1 parent 8a55a78 commit 58afaef

File tree

7 files changed

+80
-75
lines changed

7 files changed

+80
-75
lines changed

tap_aggregator/proto/v2.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package tap_aggregator.v2;
77
import "uint128.proto";
88

99
message Receipt {
10-
bytes allocation_id = 1;
10+
bytes collection_id = 1;
1111
bytes payer = 2;
1212
bytes data_service = 3;
1313
bytes service_provider = 4;
@@ -22,7 +22,7 @@ message SignedReceipt {
2222
}
2323

2424
message ReceiptAggregateVoucher {
25-
bytes allocation_id = 1;
25+
bytes collection_id = 1;
2626
bytes payer = 2;
2727
bytes data_service = 3;
2828
bytes service_provider = 4;

tap_aggregator/src/aggregator/v2.rs

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rayon::prelude::*;
88
use tap_core::{receipt::WithUniqueId, signed_message::Eip712SignedMessage};
99
use tap_graph::v2::{Receipt, ReceiptAggregateVoucher};
1010
use thegraph_core::alloy::{
11-
dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateKeySigner,
11+
dyn_abi::Eip712Domain, primitives::{Address, FixedBytes}, signers::local::PrivateKeySigner,
1212
sol_types::SolStruct,
1313
};
1414

@@ -39,65 +39,65 @@ pub fn check_and_aggregate_receipts(
3939
check_receipt_timestamps(receipts, previous_rav.as_ref())?;
4040

4141
// Get the allocation id from the first receipt, return error if there are no receipts
42-
let (allocation_id, payer, data_service, service_provider) = match receipts.first() {
42+
let (collection_id, payer, data_service, service_provider) = match receipts.first() {
4343
Some(receipt) => (
44-
receipt.message.allocation_id,
44+
receipt.message.collection_id,
4545
receipt.message.payer,
4646
receipt.message.data_service,
4747
receipt.message.service_provider,
4848
),
4949
None => return Err(tap_core::Error::NoValidReceiptsForRavRequest.into()),
5050
};
5151

52-
// Check that the receipts all have the same allocation id
53-
check_allocation_id(
52+
// Check that the receipts all have the same collection id
53+
check_collection_id(
5454
receipts,
55-
allocation_id,
55+
collection_id,
5656
payer,
5757
data_service,
5858
service_provider,
5959
)?;
6060

6161
// Check that the rav has the correct allocation id
6262
if let Some(previous_rav) = &previous_rav {
63-
let prev_id = previous_rav.message.allocationId;
63+
let prev_id = previous_rav.message.collectionId;
6464
let prev_payer = previous_rav.message.payer;
6565
let prev_data_service = previous_rav.message.dataService;
6666
let prev_service_provider = previous_rav.message.serviceProvider;
67-
if prev_id != allocation_id {
67+
if prev_id != collection_id {
6868
return Err(tap_core::Error::RavAllocationIdMismatch {
6969
prev_id: format!("{prev_id:#X}"),
70-
new_id: format!("{allocation_id:#X}"),
70+
new_id: format!("{collection_id:#X}"),
7171
}
7272
.into());
7373
}
7474
if prev_payer != payer {
7575
return Err(tap_core::Error::RavAllocationIdMismatch {
7676
prev_id: format!("{prev_id:#X}"),
77-
new_id: format!("{allocation_id:#X}"),
77+
new_id: format!("{collection_id:#X}"),
7878
}
7979
.into());
8080
}
8181

8282
if prev_data_service != data_service {
8383
return Err(tap_core::Error::RavAllocationIdMismatch {
8484
prev_id: format!("{prev_id:#X}"),
85-
new_id: format!("{allocation_id:#X}"),
85+
new_id: format!("{collection_id:#X}"),
8686
}
8787
.into());
8888
}
8989
if prev_service_provider != service_provider {
9090
return Err(tap_core::Error::RavAllocationIdMismatch {
9191
prev_id: format!("{prev_id:#X}"),
92-
new_id: format!("{allocation_id:#X}"),
92+
new_id: format!("{collection_id:#X}"),
9393
}
9494
.into());
9595
}
9696
}
9797

9898
// Aggregate the receipts
9999
let rav = ReceiptAggregateVoucher::aggregate_receipts(
100-
allocation_id,
100+
collection_id,
101101
payer,
102102
data_service,
103103
service_provider,
@@ -123,16 +123,16 @@ fn check_signature_is_from_one_of_addresses<M: SolStruct>(
123123
Ok(())
124124
}
125125

126-
fn check_allocation_id(
126+
fn check_collection_id(
127127
receipts: &[Eip712SignedMessage<Receipt>],
128-
allocation_id: Address,
128+
collection_id: FixedBytes<32>,
129129
payer: Address,
130130
data_service: Address,
131131
service_provider: Address,
132132
) -> Result<()> {
133133
for receipt in receipts.iter() {
134134
let receipt = &receipt.message;
135-
if receipt.allocation_id != allocation_id {
135+
if receipt.collection_id != collection_id {
136136
return Err(tap_core::Error::RavAllocationIdNotUniform.into());
137137
}
138138
if receipt.payer != payer {
@@ -190,7 +190,7 @@ mod tests {
190190
use tap_graph::v2::{Receipt, ReceiptAggregateVoucher};
191191
use thegraph_core::alloy::{
192192
dyn_abi::Eip712Domain,
193-
primitives::{address, Address, Bytes},
193+
primitives::{address, fixed_bytes, Address, Bytes, FixedBytes},
194194
signers::local::PrivateKeySigner,
195195
};
196196

@@ -202,8 +202,8 @@ mod tests {
202202
}
203203

204204
#[fixture]
205-
fn allocation_id() -> Address {
206-
address!("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef")
205+
fn collection_id() -> FixedBytes<32> {
206+
fixed_bytes!("deaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddead")
207207
}
208208

209209
#[fixture]
@@ -222,8 +222,8 @@ mod tests {
222222
}
223223

224224
#[fixture]
225-
fn other_address() -> Address {
226-
address!("1234567890abcdef1234567890abcdef12345678")
225+
fn other_collection_id() -> FixedBytes<32> {
226+
fixed_bytes!("1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef")
227227
}
228228
#[fixture]
229229
fn domain_separator() -> Eip712Domain {
@@ -234,7 +234,7 @@ mod tests {
234234
#[test]
235235
fn check_signatures_unique_fail(
236236
keys: (PrivateKeySigner, Address),
237-
allocation_id: Address,
237+
collection_id: FixedBytes<32>,
238238
payer: Address,
239239
data_service: Address,
240240
service_provider: Address,
@@ -244,7 +244,7 @@ mod tests {
244244
let mut receipts = Vec::new();
245245
let receipt = Eip712SignedMessage::new(
246246
&domain_separator,
247-
Receipt::new(allocation_id, payer, data_service, service_provider, 42).unwrap(),
247+
Receipt::new(collection_id, payer, data_service, service_provider, 42).unwrap(),
248248
&keys.0,
249249
)
250250
.unwrap();
@@ -259,7 +259,7 @@ mod tests {
259259
#[test]
260260
fn check_signatures_unique_ok(
261261
keys: (PrivateKeySigner, Address),
262-
allocation_id: Address,
262+
collection_id: FixedBytes<32>,
263263
payer: Address,
264264
data_service: Address,
265265
service_provider: Address,
@@ -269,13 +269,13 @@ mod tests {
269269
let receipts = vec![
270270
Eip712SignedMessage::new(
271271
&domain_separator,
272-
Receipt::new(allocation_id, payer, data_service, service_provider, 42).unwrap(),
272+
Receipt::new(collection_id, payer, data_service, service_provider, 42).unwrap(),
273273
&keys.0,
274274
)
275275
.unwrap(),
276276
Eip712SignedMessage::new(
277277
&domain_separator,
278-
Receipt::new(allocation_id, payer, data_service, service_provider, 42).unwrap(),
278+
Receipt::new(collection_id, payer, data_service, service_provider, 42).unwrap(),
279279
&keys.0,
280280
)
281281
.unwrap(),
@@ -290,7 +290,7 @@ mod tests {
290290
/// Test that a receipt with a timestamp greater than the rav timestamp passes
291291
fn check_receipt_timestamps(
292292
keys: (PrivateKeySigner, Address),
293-
allocation_id: Address,
293+
collection_id: FixedBytes<32>,
294294
payer: Address,
295295
data_service: Address,
296296
service_provider: Address,
@@ -304,7 +304,7 @@ mod tests {
304304
Eip712SignedMessage::new(
305305
&domain_separator,
306306
Receipt {
307-
allocation_id,
307+
collection_id,
308308
payer,
309309
data_service,
310310
service_provider,
@@ -322,7 +322,7 @@ mod tests {
322322
let rav = Eip712SignedMessage::new(
323323
&domain_separator,
324324
ReceiptAggregateVoucher {
325-
allocationId: allocation_id,
325+
collectionId: collection_id,
326326
dataService: data_service,
327327
payer,
328328
serviceProvider: service_provider,
@@ -340,7 +340,7 @@ mod tests {
340340
let rav = Eip712SignedMessage::new(
341341
&domain_separator,
342342
ReceiptAggregateVoucher {
343-
allocationId: allocation_id,
343+
collectionId: collection_id,
344344
dataService: data_service,
345345
payer,
346346
serviceProvider: service_provider,
@@ -358,7 +358,7 @@ mod tests {
358358
let rav = Eip712SignedMessage::new(
359359
&domain_separator,
360360
ReceiptAggregateVoucher {
361-
allocationId: allocation_id,
361+
collectionId: collection_id,
362362
dataService: data_service,
363363
payer,
364364
serviceProvider: service_provider,
@@ -378,37 +378,37 @@ mod tests {
378378
/// and 1 receipt that has the wrong allocation id
379379
fn check_allocation_id_fail(
380380
keys: (PrivateKeySigner, Address),
381-
allocation_id: Address,
381+
collection_id: FixedBytes<32>,
382382
payer: Address,
383383
data_service: Address,
384384
service_provider: Address,
385-
other_address: Address,
385+
other_collection_id: FixedBytes<32>,
386386
domain_separator: Eip712Domain,
387387
) {
388388
let receipts = vec![
389389
Eip712SignedMessage::new(
390390
&domain_separator,
391-
Receipt::new(allocation_id, payer, data_service, service_provider, 42).unwrap(),
391+
Receipt::new(collection_id, payer, data_service, service_provider, 42).unwrap(),
392392
&keys.0,
393393
)
394394
.unwrap(),
395395
Eip712SignedMessage::new(
396396
&domain_separator,
397-
Receipt::new(allocation_id, payer, data_service, service_provider, 43).unwrap(),
397+
Receipt::new(collection_id, payer, data_service, service_provider, 43).unwrap(),
398398
&keys.0,
399399
)
400400
.unwrap(),
401401
Eip712SignedMessage::new(
402402
&domain_separator,
403-
Receipt::new(other_address, payer, data_service, service_provider, 44).unwrap(),
403+
Receipt::new(other_collection_id, payer, data_service, service_provider, 44).unwrap(),
404404
&keys.0,
405405
)
406406
.unwrap(),
407407
];
408408

409-
let res = super::check_allocation_id(
409+
let res = super::check_collection_id(
410410
&receipts,
411-
allocation_id,
411+
collection_id,
412412
payer,
413413
data_service,
414414
service_provider,
@@ -422,7 +422,7 @@ mod tests {
422422
/// Test check_allocation_id with 3 receipts that have the correct allocation id
423423
fn check_allocation_id_ok(
424424
keys: (PrivateKeySigner, Address),
425-
allocation_id: Address,
425+
collection_id: FixedBytes<32>,
426426
payer: Address,
427427
data_service: Address,
428428
service_provider: Address,
@@ -431,27 +431,27 @@ mod tests {
431431
let receipts = vec![
432432
Eip712SignedMessage::new(
433433
&domain_separator,
434-
Receipt::new(allocation_id, payer, data_service, service_provider, 42).unwrap(),
434+
Receipt::new(collection_id, payer, data_service, service_provider, 42).unwrap(),
435435
&keys.0,
436436
)
437437
.unwrap(),
438438
Eip712SignedMessage::new(
439439
&domain_separator,
440-
Receipt::new(allocation_id, payer, data_service, service_provider, 43).unwrap(),
440+
Receipt::new(collection_id, payer, data_service, service_provider, 43).unwrap(),
441441
&keys.0,
442442
)
443443
.unwrap(),
444444
Eip712SignedMessage::new(
445445
&domain_separator,
446-
Receipt::new(allocation_id, payer, data_service, service_provider, 44).unwrap(),
446+
Receipt::new(collection_id, payer, data_service, service_provider, 44).unwrap(),
447447
&keys.0,
448448
)
449449
.unwrap(),
450450
];
451451

452-
let res = super::check_allocation_id(
452+
let res = super::check_collection_id(
453453
&receipts,
454-
allocation_id,
454+
collection_id,
455455
payer,
456456
data_service,
457457
service_provider,

tap_aggregator/src/grpc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ pub mod v2 {
151151
type Error = anyhow::Error;
152152
fn try_from(receipt: self::Receipt) -> Result<Self, Self::Error> {
153153
Ok(Self {
154-
allocation_id: receipt.allocation_id.as_slice().try_into()?,
154+
collection_id: receipt.collection_id.as_slice().try_into()?,
155155
timestamp_ns: receipt.timestamp_ns,
156156
value: receipt.value.ok_or(anyhow!("Missing value"))?.into(),
157157
nonce: receipt.nonce,
@@ -178,7 +178,7 @@ pub mod v2 {
178178
impl From<tap_graph::v2::Receipt> for self::Receipt {
179179
fn from(value: tap_graph::v2::Receipt) -> Self {
180180
Self {
181-
allocation_id: value.allocation_id.as_slice().to_vec(),
181+
collection_id: value.collection_id.as_slice().to_vec(),
182182
timestamp_ns: value.timestamp_ns,
183183
nonce: value.nonce,
184184
value: Some(value.value.into()),
@@ -224,7 +224,7 @@ pub mod v2 {
224224
type Error = anyhow::Error;
225225
fn try_from(voucher: self::ReceiptAggregateVoucher) -> Result<Self, Self::Error> {
226226
Ok(Self {
227-
allocationId: voucher.allocation_id.as_slice().try_into()?,
227+
collectionId: voucher.collection_id.as_slice().try_into()?,
228228
timestampNs: voucher.timestamp_ns,
229229
valueAggregate: voucher
230230
.value_aggregate
@@ -241,7 +241,7 @@ pub mod v2 {
241241
impl From<tap_graph::v2::ReceiptAggregateVoucher> for self::ReceiptAggregateVoucher {
242242
fn from(voucher: tap_graph::v2::ReceiptAggregateVoucher) -> Self {
243243
Self {
244-
allocation_id: voucher.allocationId.to_vec(),
244+
collection_id: voucher.collectionId.to_vec(),
245245
timestamp_ns: voucher.timestampNs,
246246
value_aggregate: Some(voucher.valueAggregate.into()),
247247
payer: voucher.payer.to_vec(),

0 commit comments

Comments
 (0)