Skip to content

Commit e21d7d9

Browse files
committed
fix(tap-manager): adds an error when receipt timestamp window is inverted
if the user chooses a timestamp buffer that causes the max timestamp to be less than the min timestamp than an error is thrown. This can be due to a timestamp buffer that is too large. Signed-off-by: Bryan Cole <[email protected]>
1 parent bb869ff commit e21d7d9

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

tap_core/src/error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ pub enum Error {
3939
AdapterError { source_error_message: String },
4040
#[error("Failed to produce rav request, no valid receipts")]
4141
NoValidReceiptsForRAVRequest,
42+
#[error("Timestamp range error: min_timestamp_ns: {min_timestamp_ns}, max_timestamp_ns: {max_timestamp_ns}. Adjust timestamp buffer.")]
43+
TimestampRangeError {
44+
min_timestamp_ns: u64,
45+
max_timestamp_ns: u64,
46+
},
4247
}
4348

4449
pub type Result<T> = StdResult<T, Error>;

tap_core/src/tap_manager/manager.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ impl<
149149
///
150150
/// Returns [`Error::AdapterError`] if unable to fetch previous RAV or if unable to fetch previous receipts
151151
///
152+
/// Returns [`Error::TimestampRangeError`] if the max timestamp of the previous RAV is greater than the min timestamp. Caused by timestamp buffer being too large, or requests coming too soon.
153+
///
152154
pub fn create_rav_request(&mut self, timestamp_buffer_ns: u64) -> Result<RAVRequest, Error> {
153155
let previous_rav = self.get_previous_rav()?;
154156
let min_timestamp_ns = previous_rav
@@ -193,6 +195,13 @@ impl<
193195
min_timestamp_ns: u64,
194196
) -> Result<(Vec<SignedReceipt>, Vec<SignedReceipt>), Error> {
195197
let max_timestamp_ns = crate::get_current_timestamp_u64_ns()? - timestamp_buffer_ns;
198+
199+
if min_timestamp_ns > max_timestamp_ns {
200+
return Err(Error::TimestampRangeError {
201+
min_timestamp_ns,
202+
max_timestamp_ns,
203+
});
204+
}
196205
let received_receipts = self
197206
.receipt_storage_adapter
198207
.retrieve_receipts_in_timestamp_range(min_timestamp_ns..max_timestamp_ns)

0 commit comments

Comments
 (0)