Skip to content
Merged
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
10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
[workspace]
resolver = "2"
members = ["tap_core", "tap_aggregator", "tap_integration_tests"]
members = [
"tap_core",
"tap_aggregator",
"tap_integration_tests",
"tap_graph",
"tap_eip712_message",
"tap_receipt",
]

[workspace.package]
version = "0.1.0"
Expand All @@ -18,3 +25,4 @@ rand = "0.8.5"
jsonrpsee = { version = "0.24.7", features = ["macros", "server"] }
insta = { version = "1.42.0", features = ["json"] }
serde_json = { version = "1.0.137", features = ["raw_value"] }
thiserror = "2.0.11"
3 changes: 3 additions & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"draft": false,
"packages": {
"tap_core": {},
"tap_graph": {},
"tap_eip712_message": {},
"tap_receipt": {},
"tap_aggregator": {
"bump-minor-pre-major": true,
"bump-patch-for-minor-pre-major": true,
Expand Down
13 changes: 7 additions & 6 deletions tap_aggregator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ path = "src/main.rs"
alloy.workspace = true
anyhow.workspace = true
axum = { version = "0.7.5", features = [
"http1",
"json",
"matched-path",
"original-uri",
"query",
"tokio",
"http1",
"json",
"matched-path",
"original-uri",
"query",
"tokio",
], default-features = false }
clap = { version = "4.5.15", features = ["derive", "env"] }
futures-util = "0.3.28"
Expand All @@ -39,6 +39,7 @@ tokio.workspace = true
tonic = { version = "0.12.3", features = ["transport", "zstd"] }
tower = { version = "0.5.2", features = ["util", "steer"] }
tracing-subscriber = "0.3.17"
tap_graph = { version = "0.1.0", path = "../tap_graph" }

[build-dependencies]
tonic-build = "0.12.3"
Expand Down
16 changes: 7 additions & 9 deletions tap_aggregator/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ use alloy::{
};
use anyhow::{bail, Ok, Result};
use rayon::prelude::*;
use tap_core::{
rav::ReceiptAggregateVoucher,
receipt::Receipt,
signed_message::{EIP712SignedMessage, SignatureBytes, SignatureBytesExt},
};
use tap_core::signed_message::{EIP712SignedMessage, SignatureBytes, SignatureBytesExt};
use tap_graph::{Receipt, ReceiptAggregateVoucher};

pub fn check_and_aggregate_receipts(
domain_separator: &Eip712Domain,
Expand Down Expand Up @@ -137,7 +134,8 @@ mod tests {

use alloy::{dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateKeySigner};
use rstest::*;
use tap_core::{receipt::Receipt, signed_message::EIP712SignedMessage, tap_eip712_domain};
use tap_core::{signed_message::EIP712SignedMessage, tap_eip712_domain};
use tap_graph::{Receipt, ReceiptAggregateVoucher};

use crate::aggregator;

Expand Down Expand Up @@ -242,7 +240,7 @@ mod tests {
// Create rav with max_timestamp below the receipts timestamps
let rav = EIP712SignedMessage::new(
&domain_separator,
tap_core::rav::ReceiptAggregateVoucher {
ReceiptAggregateVoucher {
allocationId: allocation_ids[0],
timestampNs: receipt_timestamp_range.clone().min().unwrap() - 1,
valueAggregate: 42,
Expand All @@ -256,7 +254,7 @@ mod tests {
// Aggregation should fail
let rav = EIP712SignedMessage::new(
&domain_separator,
tap_core::rav::ReceiptAggregateVoucher {
ReceiptAggregateVoucher {
allocationId: allocation_ids[0],
timestampNs: receipt_timestamp_range.clone().min().unwrap(),
valueAggregate: 42,
Expand All @@ -270,7 +268,7 @@ mod tests {
// Aggregation should fail
let rav = EIP712SignedMessage::new(
&domain_separator,
tap_core::rav::ReceiptAggregateVoucher {
ReceiptAggregateVoucher {
allocationId: allocation_ids[0],
timestampNs: receipt_timestamp_range.clone().max().unwrap() + 1,
valueAggregate: 42,
Expand Down
32 changes: 16 additions & 16 deletions tap_aggregator/src/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tap_core::signed_message::EIP712SignedMessage;

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

impl TryFrom<Receipt> for tap_core::receipt::Receipt {
impl TryFrom<Receipt> for tap_graph::Receipt {
type Error = anyhow::Error;
fn try_from(receipt: Receipt) -> Result<Self, Self::Error> {
Ok(Self {
Expand All @@ -18,7 +18,7 @@ impl TryFrom<Receipt> for tap_core::receipt::Receipt {
}
}

impl TryFrom<SignedReceipt> for tap_core::receipt::SignedReceipt {
impl TryFrom<SignedReceipt> for tap_graph::SignedReceipt {
type Error = anyhow::Error;
fn try_from(receipt: SignedReceipt) -> Result<Self, Self::Error> {
Ok(Self {
Expand All @@ -31,8 +31,8 @@ impl TryFrom<SignedReceipt> for tap_core::receipt::SignedReceipt {
}
}

impl From<tap_core::receipt::Receipt> for Receipt {
fn from(value: tap_core::receipt::Receipt) -> Self {
impl From<tap_graph::Receipt> for Receipt {
fn from(value: tap_graph::Receipt) -> Self {
Self {
allocation_id: value.allocation_id.as_slice().to_vec(),
timestamp_ns: value.timestamp_ns,
Expand All @@ -42,16 +42,16 @@ impl From<tap_core::receipt::Receipt> for Receipt {
}
}

impl From<tap_core::receipt::SignedReceipt> for SignedReceipt {
fn from(value: tap_core::receipt::SignedReceipt) -> Self {
impl From<tap_graph::SignedReceipt> for SignedReceipt {
fn from(value: tap_graph::SignedReceipt) -> Self {
Self {
message: Some(value.message.into()),
signature: value.signature.as_bytes().to_vec(),
}
}
}

impl TryFrom<SignedRav> for EIP712SignedMessage<tap_core::rav::ReceiptAggregateVoucher> {
impl TryFrom<SignedRav> for EIP712SignedMessage<tap_graph::ReceiptAggregateVoucher> {
type Error = anyhow::Error;
fn try_from(voucher: SignedRav) -> Result<Self, Self::Error> {
Ok(Self {
Expand All @@ -64,16 +64,16 @@ impl TryFrom<SignedRav> for EIP712SignedMessage<tap_core::rav::ReceiptAggregateV
}
}

impl From<EIP712SignedMessage<tap_core::rav::ReceiptAggregateVoucher>> for SignedRav {
fn from(voucher: EIP712SignedMessage<tap_core::rav::ReceiptAggregateVoucher>) -> Self {
impl From<EIP712SignedMessage<tap_graph::ReceiptAggregateVoucher>> for SignedRav {
fn from(voucher: EIP712SignedMessage<tap_graph::ReceiptAggregateVoucher>) -> Self {
Self {
signature: voucher.signature.as_bytes().to_vec(),
message: Some(voucher.message.into()),
}
}
}

impl TryFrom<ReceiptAggregateVoucher> for tap_core::rav::ReceiptAggregateVoucher {
impl TryFrom<ReceiptAggregateVoucher> for tap_graph::ReceiptAggregateVoucher {
type Error = anyhow::Error;
fn try_from(voucher: ReceiptAggregateVoucher) -> Result<Self, Self::Error> {
Ok(Self {
Expand All @@ -87,8 +87,8 @@ impl TryFrom<ReceiptAggregateVoucher> for tap_core::rav::ReceiptAggregateVoucher
}
}

impl From<tap_core::rav::ReceiptAggregateVoucher> for ReceiptAggregateVoucher {
fn from(voucher: tap_core::rav::ReceiptAggregateVoucher) -> Self {
impl From<tap_graph::ReceiptAggregateVoucher> for ReceiptAggregateVoucher {
fn from(voucher: tap_graph::ReceiptAggregateVoucher) -> Self {
Self {
allocation_id: voucher.allocationId.to_vec(),
timestamp_ns: voucher.timestampNs,
Expand All @@ -113,8 +113,8 @@ impl From<u128> for Uint128 {

impl RavRequest {
pub fn new(
receipts: Vec<tap_core::receipt::SignedReceipt>,
previous_rav: Option<tap_core::rav::SignedRav>,
receipts: Vec<tap_graph::SignedReceipt>,
previous_rav: Option<tap_graph::SignedRav>,
) -> Self {
Self {
receipts: receipts.into_iter().map(Into::into).collect(),
Expand All @@ -124,8 +124,8 @@ impl RavRequest {
}

impl RavResponse {
pub fn signed_rav(mut self) -> anyhow::Result<tap_core::rav::SignedRav> {
let signed_rav: tap_core::rav::SignedRav = self
pub fn signed_rav(mut self) -> anyhow::Result<tap_graph::SignedRav> {
let signed_rav: tap_graph::SignedRav = self
.rav
.take()
.ok_or(anyhow!("Couldn't find rav"))?
Expand Down
13 changes: 4 additions & 9 deletions tap_aggregator/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ use jsonrpsee::{
use lazy_static::lazy_static;
use log::info;
use prometheus::{register_counter, register_int_counter, Counter, IntCounter};
use tap_core::{
rav::ReceiptAggregateVoucher,
receipt::{Receipt, SignedReceipt},
signed_message::EIP712SignedMessage,
};
use tap_core::signed_message::EIP712SignedMessage;
use tap_graph::{Receipt, ReceiptAggregateVoucher, SignedReceipt};
use tokio::{net::TcpListener, signal, task::JoinHandle};
use tonic::{codec::CompressionEncoding, service::Routes, Request, Response, Status};
use tower::{layer::util::Identity, make::Shared};
Expand Down Expand Up @@ -394,10 +391,8 @@ mod tests {
use jsonrpsee::{core::client::ClientT, http_client::HttpClientBuilder, rpc_params};
use rand::{prelude::*, seq::SliceRandom};
use rstest::*;
use tap_core::{
rav::ReceiptAggregateVoucher, receipt::Receipt, signed_message::EIP712SignedMessage,
tap_eip712_domain,
};
use tap_core::{signed_message::EIP712SignedMessage, tap_eip712_domain};
use tap_graph::{Receipt, ReceiptAggregateVoucher};

use crate::server;

Expand Down
10 changes: 4 additions & 6 deletions tap_aggregator/tests/aggregate_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ use tap_aggregator::{
jsonrpsee_helpers::JsonRpcResponse,
server,
};
use tap_core::{
rav::ReceiptAggregateVoucher, receipt::Receipt, signed_message::EIP712SignedMessage,
tap_eip712_domain,
};
use tap_core::{signed_message::EIP712SignedMessage, tap_eip712_domain};
use tap_graph::{Receipt, ReceiptAggregateVoucher};
use tonic::codec::CompressionEncoding;

#[tokio::test]
Expand Down Expand Up @@ -64,11 +62,11 @@ async fn aggregation_test() {

let rav_request = RavRequest::new(receipts.clone(), None);
let res = client.aggregate_receipts(rav_request).await.unwrap();
let signed_rav: tap_core::rav::SignedRav = res.into_inner().signed_rav().unwrap();
let signed_rav: tap_graph::SignedRav = res.into_inner().signed_rav().unwrap();

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

let previous_rav: Option<tap_core::rav::SignedRav> = None;
let previous_rav: Option<tap_graph::SignedRav> = None;

let response: JsonRpcResponse<EIP712SignedMessage<ReceiptAggregateVoucher>> = sender_aggregator
.request(
Expand Down
8 changes: 5 additions & 3 deletions tap_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ description = "Core Timeline Aggregation Protocol library: a fast, efficient and
[dependencies]
alloy.workspace = true
anyhow.workspace = true
anymap3 = "1.0.1"
async-trait = "0.1.85"
rand.workspace = true
serde.workspace = true
thiserror = "2.0.11"
thiserror.workspace = true
tokio.workspace = true
tap_receipt = { version = "0.1.0", path = "../tap_receipt" }
tap_eip712_message = { version = "0.1.0", path = "../tap_eip712_message" }
tap_graph = { version = "0.1.0", path = "../tap_graph", optional = true }

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

[features]
default = ["in_memory"]
in_memory = []
in_memory = ["dep:tap_graph"]

[[bench]]
name = 'timeline_aggretion_protocol_benchmark'
Expand Down
6 changes: 2 additions & 4 deletions tap_core/benches/timeline_aggretion_protocol_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ use std::str::FromStr;

use alloy::{dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateKeySigner};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use tap_core::{
rav::ReceiptAggregateVoucher, receipt::Receipt, signed_message::EIP712SignedMessage,
tap_eip712_domain,
};
use tap_core::{signed_message::EIP712SignedMessage, tap_eip712_domain};
use tap_graph::{Receipt, ReceiptAggregateVoucher};

pub fn create_and_sign_receipt(
domain_separator: &Eip712Domain,
Expand Down
4 changes: 2 additions & 2 deletions tap_core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use std::result::Result as StdResult;

use alloy::primitives::{Address, SignatureError};
use alloy::primitives::Address;
use thiserror::Error as ThisError;

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

/// `alloy` wallet error
#[error(transparent)]
SignatureError(#[from] SignatureError),
SignatureError(#[from] tap_eip712_message::Eip712Error),

/// Error when signature verification fails
#[error("Expected address {expected} but received {received}")]
Expand Down
10 changes: 4 additions & 6 deletions tap_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use thiserror::Error;

mod error;
pub mod manager;
pub mod rav;
pub mod rav_request;
pub mod receipt;
pub mod signed_message;

Expand Down Expand Up @@ -62,11 +62,9 @@ mod tap_tests {

use alloy::{dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateKeySigner};
use rstest::*;
use tap_graph::{Receipt, ReceiptAggregateVoucher};

use crate::{
rav::ReceiptAggregateVoucher, receipt::Receipt, signed_message::EIP712SignedMessage,
tap_eip712_domain,
};
use crate::{signed_message::EIP712SignedMessage, tap_eip712_domain};

#[fixture]
fn keys() -> (PrivateKeySigner, Address) {
Expand Down Expand Up @@ -187,6 +185,6 @@ mod tap_tests {
&domain_separator,
Address::from_str("0x76f4eeD9fE41262669D0250b2A97db79712aD855").unwrap()
)
.is_err());
.unwrap());
}
}
7 changes: 4 additions & 3 deletions tap_core/src/manager/context/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ use std::{

use alloy::primitives::Address;
use async_trait::async_trait;
use tap_graph::{ReceiptAggregateVoucher, SignedRav, SignedReceipt};

use crate::{
manager::adapters::*,
rav::{ReceiptAggregateVoucher, SignedRav},
receipt::{checks::StatefulTimestampCheck, state::Checking, ReceiptWithState, SignedReceipt},
receipt::{checks::StatefulTimestampCheck, state::Checking, ReceiptWithState},
signed_message::MessageId,
};

Expand Down Expand Up @@ -259,12 +259,13 @@ pub mod checks {
};

use alloy::{dyn_abi::Eip712Domain, primitives::Address};
use tap_graph::SignedReceipt;

use crate::{
receipt::{
checks::{Check, CheckError, CheckResult, ReceiptCheck},
state::Checking,
Context, ReceiptError, ReceiptWithState, SignedReceipt,
Context, ReceiptError, ReceiptWithState,
},
signed_message::MessageId,
};
Expand Down
3 changes: 1 addition & 2 deletions tap_core/src/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
//! ReceiptError,
//! Context
//! },
//! rav::ReceiptAggregateVoucher,
//! manager::{
//! Manager,
//! adapters::ReceiptStore
Expand All @@ -63,7 +62,7 @@
//! # #[tokio::main]
//! # async fn main() {
//! # use alloy::{dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateKeySigner};
//! # use tap_core::receipt::{Receipt, SignedReceipt};
//! # use tap_graph::{Receipt, SignedReceipt, ReceiptAggregateVoucher};
//! # use tap_core::signed_message::EIP712SignedMessage;
//! # let domain_separator = Eip712Domain::default();
//! # let wallet = PrivateKeySigner::random();
Expand Down
Loading