Skip to content

Commit 3d35cac

Browse files
authored
refactor!: create tap_eip712_message, tap_receipts and tap_graph (#268)
* refactor!: new crates Signed-off-by: Gustavo Inacio <[email protected]> * docs: fix typo Signed-off-by: Gustavo Inacio <[email protected]> * ci: update release-please publish packages Signed-off-by: Gustavo Inacio <[email protected]> * refactor!: return bool in Eip712SignedMessage::verify Signed-off-by: Gustavo Inacio <[email protected]> --------- Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 1fc51a3 commit 3d35cac

37 files changed

+398
-282
lines changed

Cargo.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
[workspace]
22
resolver = "2"
3-
members = ["tap_core", "tap_aggregator", "tap_integration_tests"]
3+
members = [
4+
"tap_core",
5+
"tap_aggregator",
6+
"tap_integration_tests",
7+
"tap_graph",
8+
"tap_eip712_message",
9+
"tap_receipt",
10+
]
411

512
[workspace.package]
613
version = "0.1.0"
@@ -18,3 +25,4 @@ rand = "0.8.5"
1825
jsonrpsee = { version = "0.24.7", features = ["macros", "server"] }
1926
insta = { version = "1.42.0", features = ["json"] }
2027
serde_json = { version = "1.0.137", features = ["raw_value"] }
28+
thiserror = "2.0.11"

release-please-config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"draft": false,
55
"packages": {
66
"tap_core": {},
7+
"tap_graph": {},
8+
"tap_eip712_message": {},
9+
"tap_receipt": {},
710
"tap_aggregator": {
811
"bump-minor-pre-major": true,
912
"bump-patch-for-minor-pre-major": true,

tap_aggregator/Cargo.toml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ path = "src/main.rs"
1515
alloy.workspace = true
1616
anyhow.workspace = true
1717
axum = { version = "0.7.5", features = [
18-
"http1",
19-
"json",
20-
"matched-path",
21-
"original-uri",
22-
"query",
23-
"tokio",
18+
"http1",
19+
"json",
20+
"matched-path",
21+
"original-uri",
22+
"query",
23+
"tokio",
2424
], default-features = false }
2525
clap = { version = "4.5.15", features = ["derive", "env"] }
2626
futures-util = "0.3.28"
@@ -39,6 +39,7 @@ tokio.workspace = true
3939
tonic = { version = "0.12.3", features = ["transport", "zstd"] }
4040
tower = { version = "0.5.2", features = ["util", "steer"] }
4141
tracing-subscriber = "0.3.17"
42+
tap_graph = { version = "0.1.0", path = "../tap_graph" }
4243

4344
[build-dependencies]
4445
tonic-build = "0.12.3"

tap_aggregator/src/aggregator.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ use alloy::{
99
};
1010
use anyhow::{bail, Ok, Result};
1111
use rayon::prelude::*;
12-
use tap_core::{
13-
rav::ReceiptAggregateVoucher,
14-
receipt::Receipt,
15-
signed_message::{EIP712SignedMessage, SignatureBytes, SignatureBytesExt},
16-
};
12+
use tap_core::signed_message::{EIP712SignedMessage, SignatureBytes, SignatureBytesExt};
13+
use tap_graph::{Receipt, ReceiptAggregateVoucher};
1714

1815
pub fn check_and_aggregate_receipts(
1916
domain_separator: &Eip712Domain,
@@ -137,7 +134,8 @@ mod tests {
137134

138135
use alloy::{dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateKeySigner};
139136
use rstest::*;
140-
use tap_core::{receipt::Receipt, signed_message::EIP712SignedMessage, tap_eip712_domain};
137+
use tap_core::{signed_message::EIP712SignedMessage, tap_eip712_domain};
138+
use tap_graph::{Receipt, ReceiptAggregateVoucher};
141139

142140
use crate::aggregator;
143141

@@ -242,7 +240,7 @@ mod tests {
242240
// Create rav with max_timestamp below the receipts timestamps
243241
let rav = EIP712SignedMessage::new(
244242
&domain_separator,
245-
tap_core::rav::ReceiptAggregateVoucher {
243+
ReceiptAggregateVoucher {
246244
allocationId: allocation_ids[0],
247245
timestampNs: receipt_timestamp_range.clone().min().unwrap() - 1,
248246
valueAggregate: 42,
@@ -256,7 +254,7 @@ mod tests {
256254
// Aggregation should fail
257255
let rav = EIP712SignedMessage::new(
258256
&domain_separator,
259-
tap_core::rav::ReceiptAggregateVoucher {
257+
ReceiptAggregateVoucher {
260258
allocationId: allocation_ids[0],
261259
timestampNs: receipt_timestamp_range.clone().min().unwrap(),
262260
valueAggregate: 42,
@@ -270,7 +268,7 @@ mod tests {
270268
// Aggregation should fail
271269
let rav = EIP712SignedMessage::new(
272270
&domain_separator,
273-
tap_core::rav::ReceiptAggregateVoucher {
271+
ReceiptAggregateVoucher {
274272
allocationId: allocation_ids[0],
275273
timestampNs: receipt_timestamp_range.clone().max().unwrap() + 1,
276274
valueAggregate: 42,

tap_aggregator/src/grpc.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use tap_core::signed_message::EIP712SignedMessage;
66

77
tonic::include_proto!("tap_aggregator.v1");
88

9-
impl TryFrom<Receipt> for tap_core::receipt::Receipt {
9+
impl TryFrom<Receipt> for tap_graph::Receipt {
1010
type Error = anyhow::Error;
1111
fn try_from(receipt: Receipt) -> Result<Self, Self::Error> {
1212
Ok(Self {
@@ -18,7 +18,7 @@ impl TryFrom<Receipt> for tap_core::receipt::Receipt {
1818
}
1919
}
2020

21-
impl TryFrom<SignedReceipt> for tap_core::receipt::SignedReceipt {
21+
impl TryFrom<SignedReceipt> for tap_graph::SignedReceipt {
2222
type Error = anyhow::Error;
2323
fn try_from(receipt: SignedReceipt) -> Result<Self, Self::Error> {
2424
Ok(Self {
@@ -31,8 +31,8 @@ impl TryFrom<SignedReceipt> for tap_core::receipt::SignedReceipt {
3131
}
3232
}
3333

34-
impl From<tap_core::receipt::Receipt> for Receipt {
35-
fn from(value: tap_core::receipt::Receipt) -> Self {
34+
impl From<tap_graph::Receipt> for Receipt {
35+
fn from(value: tap_graph::Receipt) -> Self {
3636
Self {
3737
allocation_id: value.allocation_id.as_slice().to_vec(),
3838
timestamp_ns: value.timestamp_ns,
@@ -42,16 +42,16 @@ impl From<tap_core::receipt::Receipt> for Receipt {
4242
}
4343
}
4444

45-
impl From<tap_core::receipt::SignedReceipt> for SignedReceipt {
46-
fn from(value: tap_core::receipt::SignedReceipt) -> Self {
45+
impl From<tap_graph::SignedReceipt> for SignedReceipt {
46+
fn from(value: tap_graph::SignedReceipt) -> Self {
4747
Self {
4848
message: Some(value.message.into()),
4949
signature: value.signature.as_bytes().to_vec(),
5050
}
5151
}
5252
}
5353

54-
impl TryFrom<SignedRav> for EIP712SignedMessage<tap_core::rav::ReceiptAggregateVoucher> {
54+
impl TryFrom<SignedRav> for EIP712SignedMessage<tap_graph::ReceiptAggregateVoucher> {
5555
type Error = anyhow::Error;
5656
fn try_from(voucher: SignedRav) -> Result<Self, Self::Error> {
5757
Ok(Self {
@@ -64,16 +64,16 @@ impl TryFrom<SignedRav> for EIP712SignedMessage<tap_core::rav::ReceiptAggregateV
6464
}
6565
}
6666

67-
impl From<EIP712SignedMessage<tap_core::rav::ReceiptAggregateVoucher>> for SignedRav {
68-
fn from(voucher: EIP712SignedMessage<tap_core::rav::ReceiptAggregateVoucher>) -> Self {
67+
impl From<EIP712SignedMessage<tap_graph::ReceiptAggregateVoucher>> for SignedRav {
68+
fn from(voucher: EIP712SignedMessage<tap_graph::ReceiptAggregateVoucher>) -> Self {
6969
Self {
7070
signature: voucher.signature.as_bytes().to_vec(),
7171
message: Some(voucher.message.into()),
7272
}
7373
}
7474
}
7575

76-
impl TryFrom<ReceiptAggregateVoucher> for tap_core::rav::ReceiptAggregateVoucher {
76+
impl TryFrom<ReceiptAggregateVoucher> for tap_graph::ReceiptAggregateVoucher {
7777
type Error = anyhow::Error;
7878
fn try_from(voucher: ReceiptAggregateVoucher) -> Result<Self, Self::Error> {
7979
Ok(Self {
@@ -87,8 +87,8 @@ impl TryFrom<ReceiptAggregateVoucher> for tap_core::rav::ReceiptAggregateVoucher
8787
}
8888
}
8989

90-
impl From<tap_core::rav::ReceiptAggregateVoucher> for ReceiptAggregateVoucher {
91-
fn from(voucher: tap_core::rav::ReceiptAggregateVoucher) -> Self {
90+
impl From<tap_graph::ReceiptAggregateVoucher> for ReceiptAggregateVoucher {
91+
fn from(voucher: tap_graph::ReceiptAggregateVoucher) -> Self {
9292
Self {
9393
allocation_id: voucher.allocationId.to_vec(),
9494
timestamp_ns: voucher.timestampNs,
@@ -113,8 +113,8 @@ impl From<u128> for Uint128 {
113113

114114
impl RavRequest {
115115
pub fn new(
116-
receipts: Vec<tap_core::receipt::SignedReceipt>,
117-
previous_rav: Option<tap_core::rav::SignedRav>,
116+
receipts: Vec<tap_graph::SignedReceipt>,
117+
previous_rav: Option<tap_graph::SignedRav>,
118118
) -> Self {
119119
Self {
120120
receipts: receipts.into_iter().map(Into::into).collect(),
@@ -124,8 +124,8 @@ impl RavRequest {
124124
}
125125

126126
impl RavResponse {
127-
pub fn signed_rav(mut self) -> anyhow::Result<tap_core::rav::SignedRav> {
128-
let signed_rav: tap_core::rav::SignedRav = self
127+
pub fn signed_rav(mut self) -> anyhow::Result<tap_graph::SignedRav> {
128+
let signed_rav: tap_graph::SignedRav = self
129129
.rav
130130
.take()
131131
.ok_or(anyhow!("Couldn't find rav"))?

tap_aggregator/src/server.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ use jsonrpsee::{
1414
use lazy_static::lazy_static;
1515
use log::info;
1616
use prometheus::{register_counter, register_int_counter, Counter, IntCounter};
17-
use tap_core::{
18-
rav::ReceiptAggregateVoucher,
19-
receipt::{Receipt, SignedReceipt},
20-
signed_message::EIP712SignedMessage,
21-
};
17+
use tap_core::signed_message::EIP712SignedMessage;
18+
use tap_graph::{Receipt, ReceiptAggregateVoucher, SignedReceipt};
2219
use tokio::{net::TcpListener, signal, task::JoinHandle};
2320
use tonic::{codec::CompressionEncoding, service::Routes, Request, Response, Status};
2421
use tower::{layer::util::Identity, make::Shared};
@@ -394,10 +391,8 @@ mod tests {
394391
use jsonrpsee::{core::client::ClientT, http_client::HttpClientBuilder, rpc_params};
395392
use rand::{prelude::*, seq::SliceRandom};
396393
use rstest::*;
397-
use tap_core::{
398-
rav::ReceiptAggregateVoucher, receipt::Receipt, signed_message::EIP712SignedMessage,
399-
tap_eip712_domain,
400-
};
394+
use tap_core::{signed_message::EIP712SignedMessage, tap_eip712_domain};
395+
use tap_graph::{Receipt, ReceiptAggregateVoucher};
401396

402397
use crate::server;
403398

tap_aggregator/tests/aggregate_test.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ use tap_aggregator::{
1010
jsonrpsee_helpers::JsonRpcResponse,
1111
server,
1212
};
13-
use tap_core::{
14-
rav::ReceiptAggregateVoucher, receipt::Receipt, signed_message::EIP712SignedMessage,
15-
tap_eip712_domain,
16-
};
13+
use tap_core::{signed_message::EIP712SignedMessage, tap_eip712_domain};
14+
use tap_graph::{Receipt, ReceiptAggregateVoucher};
1715
use tonic::codec::CompressionEncoding;
1816

1917
#[tokio::test]
@@ -64,11 +62,11 @@ async fn aggregation_test() {
6462

6563
let rav_request = RavRequest::new(receipts.clone(), None);
6664
let res = client.aggregate_receipts(rav_request).await.unwrap();
67-
let signed_rav: tap_core::rav::SignedRav = res.into_inner().signed_rav().unwrap();
65+
let signed_rav: tap_graph::SignedRav = res.into_inner().signed_rav().unwrap();
6866

6967
let sender_aggregator = HttpClientBuilder::default().build(&endpoint).unwrap();
7068

71-
let previous_rav: Option<tap_core::rav::SignedRav> = None;
69+
let previous_rav: Option<tap_graph::SignedRav> = None;
7270

7371
let response: JsonRpcResponse<EIP712SignedMessage<ReceiptAggregateVoucher>> = sender_aggregator
7472
.request(

tap_core/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ description = "Core Timeline Aggregation Protocol library: a fast, efficient and
1010
[dependencies]
1111
alloy.workspace = true
1212
anyhow.workspace = true
13-
anymap3 = "1.0.1"
1413
async-trait = "0.1.85"
1514
rand.workspace = true
1615
serde.workspace = true
17-
thiserror = "2.0.11"
16+
thiserror.workspace = true
1817
tokio.workspace = true
18+
tap_receipt = { version = "0.1.0", path = "../tap_receipt" }
19+
tap_eip712_message = { version = "0.1.0", path = "../tap_eip712_message" }
20+
tap_graph = { version = "0.1.0", path = "../tap_graph", optional = true }
1921

2022
[dev-dependencies]
2123
criterion = { version = "0.5.1", features = ["async_std"] }
@@ -25,7 +27,7 @@ serde_json.workspace = true
2527

2628
[features]
2729
default = ["in_memory"]
28-
in_memory = []
30+
in_memory = ["dep:tap_graph"]
2931

3032
[[bench]]
3133
name = 'timeline_aggretion_protocol_benchmark'

tap_core/benches/timeline_aggretion_protocol_benchmark.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ use std::str::FromStr;
1212

1313
use alloy::{dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateKeySigner};
1414
use criterion::{black_box, criterion_group, criterion_main, Criterion};
15-
use tap_core::{
16-
rav::ReceiptAggregateVoucher, receipt::Receipt, signed_message::EIP712SignedMessage,
17-
tap_eip712_domain,
18-
};
15+
use tap_core::{signed_message::EIP712SignedMessage, tap_eip712_domain};
16+
use tap_graph::{Receipt, ReceiptAggregateVoucher};
1917

2018
pub fn create_and_sign_receipt(
2119
domain_separator: &Eip712Domain,

tap_core/src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
use std::result::Result as StdResult;
88

9-
use alloy::primitives::{Address, SignatureError};
9+
use alloy::primitives::Address;
1010
use thiserror::Error as ThisError;
1111

1212
use crate::receipt::ReceiptError;
@@ -26,7 +26,7 @@ pub enum Error {
2626

2727
/// `alloy` wallet error
2828
#[error(transparent)]
29-
SignatureError(#[from] SignatureError),
29+
SignatureError(#[from] tap_eip712_message::Eip712Error),
3030

3131
/// Error when signature verification fails
3232
#[error("Expected address {expected} but received {received}")]

0 commit comments

Comments
 (0)