Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tap_aggregator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ tonic-build.workspace = true
[dev-dependencies]
rand.workspace = true
rstest.workspace = true
jsonrpsee = { workspace = true, features = ["http-client"] }

[features]
default = ["v2"]
v2 = []
3 changes: 3 additions & 0 deletions tap_aggregator/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::configure().compile_protos(
&[
"proto/uint128.proto",
"proto/uint256.proto",
"proto/tap_aggregator.proto",
"proto/tap_aggregator_u256.proto",
"proto/v2.proto",
"proto/v2_u256.proto",
],
&["proto"],
)?;
Expand Down
43 changes: 43 additions & 0 deletions tap_aggregator/proto/tap_aggregator_u256.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2023-, Semiotic AI, Inc.
// SPDX-License-Identifier: Apache-2.0

syntax = "proto3";
package tap_aggregator.v1_u256;

import "uint256.proto";

message Receipt {
bytes allocation_id = 1;
uint64 timestamp_ns = 2;
uint64 nonce = 3;
grpc.uint256.Uint256 value = 4;
}

message SignedReceipt {
Receipt message = 1;
bytes signature = 2;
}

message ReceiptAggregateVoucher {
bytes allocation_id = 1;
uint64 timestamp_ns = 2;
grpc.uint256.Uint256 value_aggregate = 3;
}

message SignedRav {
ReceiptAggregateVoucher message = 1;
bytes signature = 2;
}

message RavRequest {
repeated SignedReceipt receipts = 1;
optional SignedRav previous_rav = 2;
}

message RavResponse {
SignedRav rav = 1;
}

service TapAggregator {
rpc AggregateReceipts(RavRequest) returns (RavResponse);
}
16 changes: 16 additions & 0 deletions tap_aggregator/proto/uint256.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2023-, Semiotic AI, Inc.
// SPDX-License-Identifier: Apache-2.0

syntax = "proto3";
package grpc.uint256;

message Uint256 {
// Bits 192-255 of a 256 bit number.
uint64 word3 = 1;
// Bits 128-191 of a 256 bit number.
uint64 word2 = 2;
// Bits 64-127 of a 256 bit number.
uint64 word1 = 3;
// Bits 0-63 of a 256 bit number.
uint64 word0 = 4;
}
50 changes: 50 additions & 0 deletions tap_aggregator/proto/v2_u256.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2023-, Semiotic AI, Inc.
// SPDX-License-Identifier: Apache-2.0

syntax = "proto3";
package tap_aggregator.v2_u256;

import "uint256.proto";

message Receipt {
bytes collection_id = 1;
uint64 timestamp_ns = 2;
uint64 nonce = 3;
grpc.uint256.Uint256 value = 4;
bytes payer = 5;
bytes data_service = 6;
bytes service_provider = 7;
}

message SignedReceipt {
Receipt message = 1;
bytes signature = 2;
}

message ReceiptAggregateVoucher {
bytes collection_id = 1;
uint64 timestamp_ns = 2;
grpc.uint256.Uint256 value_aggregate = 3;
bytes payer = 4;
bytes data_service = 5;
bytes service_provider = 6;
bytes metadata = 7;
}

message SignedRav {
ReceiptAggregateVoucher message = 1;
bytes signature = 2;
}

message RavRequest {
repeated SignedReceipt receipts = 1;
optional SignedRav previous_rav = 2;
}

message RavResponse {
SignedRav rav = 1;
}

service TapAggregator {
rpc AggregateReceipts(RavRequest) returns (RavResponse);
}
40 changes: 19 additions & 21 deletions tap_aggregator/src/aggregator/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,12 @@ fn check_receipt_timestamps(

#[cfg(test)]
mod tests {
use std::str::FromStr;

use rstest::*;
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain};
use tap_graph::{Receipt, ReceiptAggregateVoucher};
use thegraph_core::alloy::{
dyn_abi::Eip712Domain,
primitives::{Address, U256},
primitives::{address, Address, U256},
signers::{local::PrivateKeySigner, Signature},
};

Expand All @@ -153,10 +151,10 @@ mod tests {
#[fixture]
fn allocation_ids() -> Vec<Address> {
vec![
Address::from_str("0xabababababababababababababababababababab").unwrap(),
Address::from_str("0xdeaddeaddeaddeaddeaddeaddeaddeaddeaddead").unwrap(),
Address::from_str("0xbeefbeefbeefbeefbeefbeefbeefbeefbeefbeef").unwrap(),
Address::from_str("0x1234567890abcdef1234567890abcdef12345678").unwrap(),
address!("0xabababababababababababababababababababab"),
address!("0xdeaddeaddeaddeaddeaddeaddeaddeaddeaddead"),
address!("0xbeefbeefbeefbeefbeefbeefbeefbeefbeefbeef"),
address!("0x1234567890abcdef1234567890abcdef12345678"),
]
}

Expand All @@ -175,7 +173,7 @@ mod tests {
// Create a test receipt
let receipt = Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_ids[0], 42).unwrap(),
Receipt::new(allocation_ids[0], U256::from(42)).unwrap(),
&keys.0,
)
.unwrap();
Expand Down Expand Up @@ -236,7 +234,7 @@ mod tests {
let mut receipts = Vec::new();
let receipt = Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_ids[0], 42).unwrap(),
Receipt::new(allocation_ids[0], U256::from(42)).unwrap(),
&keys.0,
)
.unwrap();
Expand All @@ -258,13 +256,13 @@ mod tests {
let receipts = vec![
Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_ids[0], 42).unwrap(),
Receipt::new(allocation_ids[0], U256::from(42)).unwrap(),
&keys.0,
)
.unwrap(),
Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_ids[0], 43).unwrap(),
Receipt::new(allocation_ids[0], U256::from(43)).unwrap(),
&keys.0,
)
.unwrap(),
Expand Down Expand Up @@ -293,7 +291,7 @@ mod tests {
allocation_id: allocation_ids[0],
timestamp_ns: i,
nonce: 0,
value: 42,
value: U256::from(42),
},
&keys.0,
)
Expand All @@ -307,7 +305,7 @@ mod tests {
ReceiptAggregateVoucher {
allocationId: allocation_ids[0],
timestampNs: receipt_timestamp_range.clone().min().unwrap() - 1,
valueAggregate: 42,
valueAggregate: U256::from(42),
},
&keys.0,
)
Expand All @@ -321,7 +319,7 @@ mod tests {
ReceiptAggregateVoucher {
allocationId: allocation_ids[0],
timestampNs: receipt_timestamp_range.clone().min().unwrap(),
valueAggregate: 42,
valueAggregate: U256::from(42),
},
&keys.0,
)
Expand All @@ -335,7 +333,7 @@ mod tests {
ReceiptAggregateVoucher {
allocationId: allocation_ids[0],
timestampNs: receipt_timestamp_range.clone().max().unwrap() + 1,
valueAggregate: 42,
valueAggregate: U256::from(42),
},
&keys.0,
)
Expand All @@ -355,19 +353,19 @@ mod tests {
let receipts = vec![
Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_ids[0], 42).unwrap(),
Receipt::new(allocation_ids[0], U256::from(42)).unwrap(),
&keys.0,
)
.unwrap(),
Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_ids[0], 43).unwrap(),
Receipt::new(allocation_ids[0], U256::from(43)).unwrap(),
&keys.0,
)
.unwrap(),
Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_ids[1], 44).unwrap(),
Receipt::new(allocation_ids[1], U256::from(44)).unwrap(),
&keys.0,
)
.unwrap(),
Expand All @@ -389,19 +387,19 @@ mod tests {
let receipts = vec![
Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_ids[0], 42).unwrap(),
Receipt::new(allocation_ids[0], U256::from(42)).unwrap(),
&keys.0,
)
.unwrap(),
Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_ids[0], 43).unwrap(),
Receipt::new(allocation_ids[0], U256::from(43)).unwrap(),
&keys.0,
)
.unwrap(),
Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_ids[0], 44).unwrap(),
Receipt::new(allocation_ids[0], U256::from(44)).unwrap(),
&keys.0,
)
.unwrap(),
Expand Down
Loading