Fix resume succeding prematurely#1573
Conversation
2303b41 to
56c9bb2
Compare
Coverage Report for CI Build 26514540156Coverage increased (+0.05%) to 85.19%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
xstoicunicornx
left a comment
There was a problem hiding this comment.
I like how you are breaking out session level information but I think this solution is a bit over engineered and it seems unnecessary to introduce additional state.
My comments below are a bit general but feel free to take more concrete direction from my branch https://github.com/xstoicunicornx/rust-payjoin/tree/pr1573-alt
0809f0c to
0e3690a
Compare
xstoicunicornx
left a comment
There was a problem hiding this comment.
A bit more feedback.
| } => { | ||
| println!("All resumed sessions completed."); | ||
| let closed = results.iter().filter(|r| matches!(r, Ok(Ok(())))).count(); | ||
| let total = spawned_recv_ids.len() + spawned_send_ids.len(); |
There was a problem hiding this comment.
| let total = spawned_recv_ids.len() + spawned_send_ids.len(); | |
| let total = results.len(); |
Why not just this? Then the spawned_recv_ids and spawned_send_ids aren't needed anymore.
| wait_for_stdout_match(&mut stdout, |line| { | ||
| line.contains("All resumed sessions completed.") | ||
| }), | ||
| wait_for_stdout_match(&mut stdout, |line| line.contains("Resume done:")), |
There was a problem hiding this comment.
| wait_for_stdout_match(&mut stdout, |line| line.contains("Resume done:")), | |
| wait_for_stdout_match(&mut stdout, |line| line.contains("1/1 session(s) closed.")), |
This is supposed to assert that the resumed session was completed, checking for "Resume done:" only asserts that summary was printed not that the session was actually closed.
| Err(_) => { | ||
| let id = persister.session_id(); | ||
| println!( | ||
| "No payjoin transaction seen yet (waited {timeout_duration:?}). Session {id} \ |
There was a problem hiding this comment.
| "No payjoin transaction seen yet (waited {timeout_duration:?}). Session {id} \ | |
| "No payjoin transaction seen yet, stopping (waited {timeout_duration:?} sec). Session {id} \ |
| let id = persister.session_id(); | ||
| println!( | ||
| "No payjoin transaction seen yet (waited {timeout_duration:?}). Session {id} \ | ||
| remains open; run `payjoin-cli resume` to keep watching." |
There was a problem hiding this comment.
| remains open; run `payjoin-cli resume` to keep watching." | |
| remains open. Run `payjoin-cli resume` to keep watching." |
nit: semicolon isn't used anywhere else
There was a problem hiding this comment.
thanks for catching that
| } | ||
| } | ||
| println!( | ||
| "Resume done: {closed}/{total} session(s) closed. \ |
There was a problem hiding this comment.
I don't think printing the completed/total sessions count is useful or worth the complexity. It seems sufficient to print per-session results (session XYZ either completed, is still polling, or had an error).
| Err(_) => { | ||
| let id = persister.session_id(); | ||
| println!( | ||
| "No payjoin transaction seen yet (waited {timeout_duration:?}). Session {id} \ | ||
| remains open; run `payjoin-cli resume` to keep watching." | ||
| ); | ||
| Err(anyhow!( | ||
| "No payjoin transaction detected in mempool within {timeout_duration:?}" | ||
| )) | ||
| } |
There was a problem hiding this comment.
this change seems unrelated to the resume fix, if really necessary it should be a separate commit.
There was a problem hiding this comment.
Yes , it's not related to resume fix , more like a helpful ux . i'll extract to diff commit or drop it entirely
| Ok(OptionalTransitionOutcome::Progress(())) => { | ||
| println!("Payjoin transaction detected in the mempool!"); | ||
| return Ok(()); | ||
| } | ||
| Err(_) => { | ||
| // keep polling | ||
|
|
||
| continue; | ||
| } | ||
| Ok(OptionalTransitionOutcome::Stasis(_)) => continue, | ||
| Err(_) => continue, |
There was a problem hiding this comment.
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.
@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
This addresses payjoin#1545, upon resuming a session where the sender posted the original proposal but went ofline, the cli succeds prematurely and outputs "payjoin transaction detected in mempool" because the cli treats any Ok(_) as scucess. This also addresses a subtle issue where after a certain period without tx detected in the mempool the the monitor_proposal function returned Err("Timeout waiting for payment confirmation after 5s"). That looked like a failure even though the session should stay open in Monitor. And finally the missleading "All resumed sessions completed" message. Co-authored-by: xstoicunicornx <xstoicunicornx@users.noreply.github.com>
0e3690a to
0ed9646
Compare
0ed9646 to
7779c42
Compare
This addresses #1545, upon resuming a session where the sender posted the original proposal but went ofline, the cli succeds prematurely and outputs "payjoin transaction detected in mempool" because the cli treats any Ok(_) as sucess.
This also addresses a subtle issue where after a certain period without tx detected in the mempool the the monitor_proposal function returned
Err("Timeout waiting for payment confirmation after 5s").
That looked like a failure even though the session should stay open in Monitor. And finally the missleading "All resumed sessions completed" message.
my initial analysis of the issue in #1545 was wrong, as the intended solution witht that did not fix it. i had LLM (gemini) help with some of the root cause analysis
Pull Request Checklist
Please confirm the following before requesting review:
AI
in the body of this PR.