Fix replayEventLog report closed session as expired.#1672
Conversation
Coverage Report for CI Build 28111040213Coverage increased (+0.2%) to 85.332%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
| pub fn status(&self) -> SessionStatus { | ||
| if self.session_context().expiration.elapsed() { | ||
| return SessionStatus::Expired; | ||
| } | ||
| match self.events.last() { | ||
| Some(SessionEvent::Closed(outcome)) => match outcome { | ||
| SessionOutcome::Success(_) | SessionOutcome::PayjoinProposalSent => | ||
| SessionStatus::Completed, | ||
| SessionOutcome::Aborted => SessionStatus::Failed, | ||
| SessionOutcome::FallbackBroadcasted => SessionStatus::FallbackBroadcasted, | ||
| }, | ||
| Some(SessionEvent::Cancelled | SessionEvent::ProtocolFailed) => | ||
| SessionStatus::PendingFallback, | ||
| _ => SessionStatus::Active, | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
The same problem occurs here we need a simple ordering of the match to fix this though
pub fn status(&self) -> SessionStatus {
match self.events.last() {
Some(SessionEvent::Closed(outcome)) => match outcome {
SessionOutcome::Success(_) | SessionOutcome::PayjoinProposalSent =>
SessionStatus::Completed,
SessionOutcome::Aborted => SessionStatus::Failed,
SessionOutcome::FallbackBroadcasted => SessionStatus::FallbackBroadcasted,
},
Some(SessionEvent::Cancelled | SessionEvent::ProtocolFailed) =>
SessionStatus::PendingFallback,
_ if self.session_context().expiration.elapsed() => SessionStatus::Expired,
_ => SessionStatus::Active,
}
}There was a problem hiding this comment.
Thanks for the review as well as catching this
| Some(SessionEvent::Closed(outcome)) => match outcome { | ||
| SessionOutcome::Success(_) => SessionStatus::Completed, | ||
| SessionOutcome::Aborted => SessionStatus::Failed, | ||
| }, |
There was a problem hiding this comment.
Same here we need to move the expiration SessionStatus to follow only the other non-final outcomes and drop the if statement
_ if self.pj_param().expiration().elapsed() => SessionStatus::Expired,
This addresses payjoin#1651. During replaying of the session event log a completed session is being reported as expired if the expiration time has elapsed when the event is replayed. The fix skips expiration check when the replay state is Closed
d42b5f5 to
95b9bc8
Compare
| Some(SessionEvent::Closed(outcome)) => | ||
| return match outcome { | ||
| SessionOutcome::Success(_) | SessionOutcome::PayjoinProposalSent => | ||
| SessionStatus::Completed, | ||
| SessionOutcome::Aborted => SessionStatus::Failed, | ||
| SessionOutcome::FallbackBroadcasted => SessionStatus::FallbackBroadcasted, | ||
| }, | ||
| Some(SessionEvent::Cancelled | SessionEvent::ProtocolFailed) => | ||
| SessionStatus::PendingFallback, | ||
| _ => SessionStatus::Active, | ||
| return SessionStatus::PendingFallback, | ||
| _ => {} | ||
| } | ||
| if self.session_context().expiration.elapsed() { | ||
| return SessionStatus::Expired; | ||
| } | ||
| SessionStatus::Active |
There was a problem hiding this comment.
nit: the guard-arm form @benalleng suggested (_ if expiration.elapsed() => Expired) avoids the _ => {} + trailing if here. wdyt?
a37f197 to
e2eccf1
Compare
e2eccf1 to
3df5eea
Compare
|
I think we may want to take a step back and consider whether |
|
@benalleng made a good point for keeping this shape. However I tried it with my local payjoin-cli receiver and still see some odd behavior with the history command. Some of the sessions still have a "Completed at" timestamp but also a "Session expired" message with a different timestamp. I think there is still a bug somewhere (maybe cli?). FWIW, this is still an improvement over master, in which all historical sessions are displaying as expired. |
So all the sessions that share Perhaps sessions that don't reach a |
spacebear21
left a comment
There was a problem hiding this comment.
tACK 3df5eea
I confirmed the above by resuming and validating that session 25 is now expired with a completed_at timestamp. I'm not convinced that this is the right behavior from payjoin-cli (at the very least "Completed At" is misleading for expired sessions), but this is unrelated to the fix in this PR.


This addresses #1651. During replaying of the session event log a completed session is being reported as expired if the expiration time has elapsed when the event is replayed. The fix skips expiration check when the replay state is Closed
Pull Request Checklist
Please confirm the following before requesting review:
AI
in the body of this PR.