-
Notifications
You must be signed in to change notification settings - Fork 7
feat: allow manager to interact with different rav and receipt #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6885d9c
e74bc2c
81446e0
44f0afa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,19 +10,19 @@ use alloy::{ | |
| use anyhow::{bail, Ok, Result}; | ||
| use rayon::prelude::*; | ||
| use tap_core::{ | ||
| rav::ReceiptAggregateVoucher, | ||
| rav::{Aggregate, ReceiptAggregateVoucher}, | ||
| receipt::Receipt, | ||
| signed_message::{EIP712SignedMessage, SignatureBytes, SignatureBytesExt}, | ||
| }; | ||
|
|
||
| pub fn check_and_aggregate_receipts( | ||
| domain_separator: &Eip712Domain, | ||
| receipts: &[EIP712SignedMessage<Receipt>], | ||
| receipts: Vec<EIP712SignedMessage<Receipt>>, | ||
| previous_rav: Option<EIP712SignedMessage<ReceiptAggregateVoucher>>, | ||
| wallet: &PrivateKeySigner, | ||
| accepted_addresses: &HashSet<Address>, | ||
| ) -> Result<EIP712SignedMessage<ReceiptAggregateVoucher>> { | ||
| check_signatures_unique(receipts)?; | ||
| check_signatures_unique(&receipts)?; | ||
|
|
||
| // Check that the receipts are signed by an accepted signer address | ||
| receipts.par_iter().try_for_each(|receipt| { | ||
|
|
@@ -39,7 +39,7 @@ pub fn check_and_aggregate_receipts( | |
| } | ||
|
|
||
| // Check that the receipts timestamp is greater than the previous rav | ||
| check_receipt_timestamps(receipts, previous_rav.as_ref())?; | ||
| check_receipt_timestamps(&receipts, previous_rav.as_ref())?; | ||
|
|
||
| // Get the allocation id from the first receipt, return error if there are no receipts | ||
| let allocation_id = match receipts.first() { | ||
|
|
@@ -48,7 +48,7 @@ pub fn check_and_aggregate_receipts( | |
| }; | ||
|
|
||
| // Check that the receipts all have the same allocation id | ||
| check_allocation_id(receipts, allocation_id)?; | ||
| check_allocation_id(&receipts, allocation_id)?; | ||
|
|
||
| // Check that the rav has the correct allocation id | ||
| if let Some(previous_rav) = &previous_rav { | ||
|
|
@@ -62,8 +62,10 @@ pub fn check_and_aggregate_receipts( | |
| } | ||
| } | ||
|
|
||
| let receipts = receipts.into_iter().map(Into::into).collect::<Vec<_>>(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No big deal but here is one place I'd like to see what type it's being coerced to 😄 |
||
|
|
||
| // Aggregate the receipts | ||
| let rav = ReceiptAggregateVoucher::aggregate_receipts(allocation_id, receipts, previous_rav)?; | ||
| let rav = ReceiptAggregateVoucher::aggregate_receipts(&receipts, previous_rav)?; | ||
|
|
||
| // Sign the rav and return | ||
| Ok(EIP712SignedMessage::new(domain_separator, rav, wallet)?) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,9 @@ 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, | ||
| rav::{Aggregate, ReceiptAggregateVoucher}, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these benchmarks used? |
||
| receipt::Receipt, | ||
| signed_message::EIP712SignedMessage, | ||
| tap_eip712_domain, | ||
| }; | ||
|
|
||
|
|
@@ -66,15 +68,16 @@ pub fn criterion_benchmark(c: &mut Criterion) { | |
|
|
||
| for log_number_of_receipts in 10..30 { | ||
| let receipts = (0..2 ^ log_number_of_receipts) | ||
| .map(|_| create_and_sign_receipt(&domain_seperator, allocation_id, value, &wallet)) | ||
| .map(|_| { | ||
| create_and_sign_receipt(&domain_seperator, allocation_id, value, &wallet).into() | ||
| }) | ||
| .collect::<Vec<_>>(); | ||
|
|
||
| rav_group.bench_function( | ||
| format!("Create RAV w/ 2^{} receipt's", log_number_of_receipts), | ||
| |b| { | ||
| b.iter(|| { | ||
| ReceiptAggregateVoucher::aggregate_receipts( | ||
| black_box(allocation_id), | ||
| black_box(&receipts), | ||
| black_box(None), | ||
| ) | ||
|
|
@@ -84,7 +87,7 @@ pub fn criterion_benchmark(c: &mut Criterion) { | |
|
|
||
| let signed_rav = EIP712SignedMessage::new( | ||
| &domain_seperator, | ||
| ReceiptAggregateVoucher::aggregate_receipts(allocation_id, &receipts, None).unwrap(), | ||
| ReceiptAggregateVoucher::aggregate_receipts(&receipts, None).unwrap(), | ||
| &wallet, | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -9,7 +9,7 @@ use std::result::Result as StdResult; | |||||
| use alloy::primitives::{Address, SignatureError}; | ||||||
| use thiserror::Error as ThisError; | ||||||
|
|
||||||
| use crate::{rav::ReceiptAggregateVoucher, receipt::ReceiptError}; | ||||||
| use crate::receipt::ReceiptError; | ||||||
|
|
||||||
| /// Error type for the TAP protocol | ||||||
| #[derive(ThisError, Debug)] | ||||||
|
|
@@ -38,8 +38,8 @@ pub enum Error { | |||||
| /// Error when the received RAV does not match the expected RAV | ||||||
| #[error("Received RAV does not match expexted RAV")] | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| InvalidReceivedRAV { | ||||||
| received_rav: ReceiptAggregateVoucher, | ||||||
| expected_rav: ReceiptAggregateVoucher, | ||||||
| received_rav: String, | ||||||
| expected_rav: String, | ||||||
|
Comment on lines
-41
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems strange! This is to allow for basically any generic message? Why not use a newtype? |
||||||
| }, | ||||||
| /// Generic error from the adapter | ||||||
| #[error("Error from adapter.\n Caused by: {source_error}")] | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really liking this feature here in tap_aggregator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah... Why is it required?