-
Notifications
You must be signed in to change notification settings - Fork 17
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
fix: stop infinite process of presignature message missing triples #560
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
use crate::types::PublicKey; | ||
use chrono::{DateTime, LocalResult, TimeZone, Utc}; | ||
use k256::elliptic_curve::scalar::FromUintUnchecked; | ||
use k256::elliptic_curve::sec1::{FromEncodedPoint, ToEncodedPoint}; | ||
use k256::{AffinePoint, EncodedPoint, Scalar, U256}; | ||
|
@@ -83,3 +84,16 @@ pub fn get_triple_timeout() -> Duration { | |
.unwrap_or_default() | ||
.unwrap_or(crate::types::PROTOCOL_TRIPLE_TIMEOUT) | ||
} | ||
|
||
pub fn is_elapsed_longer_than_timeout(timestamp_sec: u64, timeout: Duration) -> bool { | ||
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. We've used simpler pattern before: if timestamp.elapsed() < DEFAULT_TIMEOUT {... 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. that elapsed works with Instant, which records the relative timestamp in the system, not the absolute timestamp. Since we are sending the timestamp as a field in the messages, it needs to be comprehensible in all nodes' system, thus using u64 timestamp to represent the time. |
||
if let LocalResult::Single(msg_timestamp) = Utc.timestamp_opt(timestamp_sec as i64, 0) { | ||
let now_datetime: DateTime<Utc> = Utc::now(); | ||
// Calculate the difference in seconds | ||
let elapsed_duration = now_datetime.signed_duration_since(msg_timestamp); | ||
let timeout = chrono::Duration::seconds(timeout.as_secs() as i64) | ||
+ chrono::Duration::nanoseconds(timeout.subsec_nanos() as i64); | ||
elapsed_duration > timeout | ||
} else { | ||
false | ||
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. If we return false in case of failure, such message will never be deleted from the queue. 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. Seems like the case where it's not
So we should be fine for the most part since our timestamp should never be out of range since we created it with |
||
} | ||
} |
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.
Let's add this field to all message types. Let's make it a standard. We want to delete all types of messages from the queue when they expire. Message trait may be a good idea here.