-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Fixing the issue with duplicate transaction synchronization processes #2324
Merged
Merged
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d1240ca
Release v0.38.0
xgreenx a5493c0
Add more detailed changelog
AurelienFT 0a934f8
format
AurelienFT 4d40e88
Tab to the right
xgreenx 056395b
Fixing the issue with duplicate transaction synchronization processes
xgreenx 3b9b86a
Forgot to commit cargo toml
xgreenx 0e55abe
Rename back
xgreenx 69bf5fb
Updated CHANGELOG.md
xgreenx 24d75df
Merge branch 'master' into hotfix/duplicate-tx-syncing
xgreenx 78a3750
Applied suggestion from PR
xgreenx 87fb619
Updated CHANGELOG.md
xgreenx 8baec3f
Merge branch 'master' into hotfix/duplicate-tx-syncing
AurelienFT c762aa1
Fix changelog
AurelienFT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use crate::futures::{ | ||
future_tracker::FutureTracker, | ||
FuturesMetrics, | ||
}; | ||
use std::{ | ||
future::Future, | ||
pin::Pin, | ||
task::{ | ||
Context, | ||
Poll, | ||
}, | ||
}; | ||
|
||
pin_project_lite::pin_project! { | ||
/// Future that tracks its execution with [`FutureTracker`] and reports it back when done | ||
/// to [`FuturesMetrics`]. | ||
#[derive(Debug, Clone)] | ||
#[must_use = "futures do nothing unless you `.await` or poll them"] | ||
pub struct MeteredFuture<F> { | ||
#[pin] | ||
future: FutureTracker<F>, | ||
metrics: FuturesMetrics, | ||
} | ||
} | ||
|
||
impl<F> MeteredFuture<F> { | ||
/// Create a new `MeteredFuture` with the given future and metrics. | ||
pub fn new(future: F, metrics: FuturesMetrics) -> Self { | ||
Self { | ||
future: FutureTracker::new(future), | ||
metrics, | ||
} | ||
} | ||
} | ||
|
||
impl<F> Future for MeteredFuture<F> | ||
where | ||
F: Future, | ||
{ | ||
type Output = F::Output; | ||
|
||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
let this = self.project(); | ||
|
||
match this.future.poll(cx) { | ||
Poll::Ready(output) => { | ||
let output = output.extract(this.metrics); | ||
Poll::Ready(output) | ||
} | ||
Poll::Pending => Poll::Pending, | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use std::time::Duration; | ||
|
||
#[tokio::test] | ||
async fn hybrid_time_correct() { | ||
let future = async { | ||
tokio::time::sleep(Duration::from_secs(2)).await; | ||
std::thread::sleep(Duration::from_secs(1)); | ||
}; | ||
let metrics = FuturesMetrics::obtain_futures_metrics("test"); | ||
let wrapper_future = MeteredFuture::new(future, metrics.clone()); | ||
let _ = wrapper_future.await; | ||
let busy = Duration::from_nanos(metrics.busy.get()); | ||
let idle = Duration::from_nanos(metrics.idle.get()); | ||
assert_eq!(idle.as_secs(), 2); | ||
assert_eq!(busy.as_secs(), 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: we shoould probably have an issue for this
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.
Also it might be wise to use something like https://docs.rs/portable-atomic for now