-
Notifications
You must be signed in to change notification settings - Fork 97
Fix resume succeding prematurely #1573
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
Open
zealsham
wants to merge
2
commits into
payjoin:master
Choose a base branch
from
zealsham:premature-resume
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -299,7 +299,6 @@ impl AppTrait for App { | |||||
| Ok(()) | ||||||
| } | ||||||
|
|
||||||
| #[allow(clippy::incompatible_msrv)] | ||||||
| async fn resume_payjoins(&self) -> Result<()> { | ||||||
| let recv_session_ids = self.db.get_recv_session_ids()?; | ||||||
| let send_session_ids = self.db.get_send_session_ids()?; | ||||||
|
|
@@ -309,20 +308,26 @@ impl AppTrait for App { | |||||
| return Ok(()); | ||||||
| } | ||||||
|
|
||||||
| let mut tasks = Vec::new(); | ||||||
| let mut tasks: Vec<(String, tokio::task::JoinHandle<Result<()>>)> = Vec::new(); | ||||||
|
|
||||||
| // Process receiver sessions | ||||||
| for session_id in recv_session_ids { | ||||||
| let self_clone = self.clone(); | ||||||
| let recv_persister = ReceiverPersister::from_id(self.db.clone(), session_id.clone()); | ||||||
| match replay_receiver_event_log(&recv_persister) { | ||||||
| Ok((receiver_state, _)) => { | ||||||
| tasks.push(tokio::spawn(async move { | ||||||
| self_clone.process_receiver_session(receiver_state, &recv_persister).await | ||||||
| })); | ||||||
| tasks.push(( | ||||||
| session_id.to_string(), | ||||||
| tokio::spawn(async move { | ||||||
| self_clone | ||||||
| .process_receiver_session(receiver_state, &recv_persister) | ||||||
| .await | ||||||
| }), | ||||||
| )); | ||||||
| } | ||||||
| Err(e) => { | ||||||
| tracing::error!("An error {:?} occurred while replaying receiver session", e); | ||||||
| println!("Session {session_id} receiver failed to replay - {e}"); | ||||||
| Self::close_failed_session(&recv_persister, &session_id, "receiver"); | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -334,12 +339,16 @@ impl AppTrait for App { | |||||
| match replay_sender_event_log(&sender_persister) { | ||||||
| Ok((sender_state, _)) => { | ||||||
| let self_clone = self.clone(); | ||||||
| tasks.push(tokio::spawn(async move { | ||||||
| self_clone.process_sender_session(sender_state, &sender_persister).await | ||||||
| })); | ||||||
| tasks.push(( | ||||||
| session_id.clone().to_string(), | ||||||
| tokio::spawn(async move { | ||||||
| self_clone.process_sender_session(sender_state, &sender_persister).await | ||||||
| }), | ||||||
| )); | ||||||
| } | ||||||
| Err(e) => { | ||||||
| tracing::error!("An error {:?} occurred while replaying Sender session", e); | ||||||
| println!("Session {session_id} sender failed to replay - {e}"); | ||||||
| Self::close_failed_session(&sender_persister, &session_id, "sender"); | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -348,12 +357,21 @@ impl AppTrait for App { | |||||
| let mut interrupt = self.interrupt.clone(); | ||||||
| tokio::select! { | ||||||
| _ = async { | ||||||
| for task in tasks { | ||||||
| let _ = task.await; | ||||||
|
|
||||||
| for (session_id, task) in tasks { | ||||||
| match task.await { | ||||||
| Ok(Ok(())) => { | ||||||
| println!("Session {session_id} completed."); | ||||||
| } | ||||||
| Ok(Err(e)) => { | ||||||
| println!("Session {session_id} error: {e:#}"); | ||||||
| } | ||||||
| Err(e) => { | ||||||
| println!("Session {session_id} panicked or was cancelled: {e:?}"); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } => { | ||||||
| println!("All resumed sessions completed."); | ||||||
| } | ||||||
| } => {} | ||||||
| _ = interrupt.changed() => { | ||||||
| println!("Resumed sessions were interrupted."); | ||||||
| } | ||||||
|
|
@@ -571,9 +589,8 @@ impl App { | |||||
| sender: Sender<WithReplyKey>, | ||||||
| persister: &SenderPersister, | ||||||
| ) -> Result<()> { | ||||||
| let (req, ctx) = sender.create_v2_post_request( | ||||||
| self.unwrap_relay_or_else_fetch(Some(&sender.endpoint())).await?.as_str(), | ||||||
| )?; | ||||||
| let relay = self.unwrap_relay_or_else_fetch(Some(&sender.endpoint())).await?; | ||||||
| let (req, ctx) = sender.create_v2_post_request(relay.as_str())?; | ||||||
| let response = self.post_request(req).await?; | ||||||
| let sender = sender.process_response(&response.bytes().await?, ctx).save(persister)?; | ||||||
| println!("Posted Original PSBT..."); | ||||||
|
|
@@ -859,15 +876,12 @@ impl App { | |||||
| .save(persister); | ||||||
|
|
||||||
| match check_result { | ||||||
| Ok(_) => { | ||||||
| Ok(OptionalTransitionOutcome::Progress(())) => { | ||||||
| println!("Payjoin transaction detected in the mempool!"); | ||||||
| return Ok(()); | ||||||
| } | ||||||
| Err(_) => { | ||||||
| // keep polling | ||||||
|
|
||||||
| continue; | ||||||
| } | ||||||
| Ok(OptionalTransitionOutcome::Stasis(_)) => continue, | ||||||
| Err(_) => continue, | ||||||
| } | ||||||
| } | ||||||
| }) | ||||||
|
|
@@ -876,8 +890,7 @@ impl App { | |||||
| match result { | ||||||
| Ok(ok) => ok, | ||||||
| Err(_) => Err(anyhow!( | ||||||
| "Timeout waiting for payment confirmation after {:?}", | ||||||
| timeout_duration | ||||||
| "No payjoin transaction detected in mempool within {timeout_duration:?} seconds, stopping." | ||||||
|
Collaborator
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
I was wrong about adding the "seconds", its already included as part of the |
||||||
| )), | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
This file contains hidden or 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.
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.
This is really the meat of the fix (we were previously returning on Stasis). Would be nice to see some test coverage like https://github.com/payjoin/rust-payjoin/pull/1575/changes#diff-162f6469a0779bd5b6f735aa260e95f854b0e8c0d7cc9da278a2c2f51d394c15R316
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.
@xstoicunicornx since your branch already has the needed test coverage, i can borrow that heavily and then credit you as co-author in the commit
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.
Of course!