Sender Pending Fallback state#1557
Conversation
7cf2e7c to
d3dac67
Compare
Coverage Report for CI Build 26115328632Coverage decreased (-0.09%) to 85.211%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
d3dac67 to
cefae94
Compare
38ef7b3 to
402848a
Compare
|
concept ACK just like #1558 |
402848a to
b6040c7
Compare
| /// Indicates that the fallback transaction has been broadcast and the session is complete. | ||
| pub fn broadcasted( | ||
| &self, | ||
| ) -> MaybeSuccessTransition<SessionEvent, (), std::convert::Infallible> { |
There was a problem hiding this comment.
std::convert::Infallible bc this method can never fail due to a API error.
There was a problem hiding this comment.
TerminalTransition is more appropriate
If application manually cancels the assumption is they will not attempt to resume that session again. The session is marked closed. The cancel type leaves the session open and the session can only be closed once the user confirms they broadcasted the fallback tx -- or took an equivalent action.
Introduce a `cancel` command for v2 sender sessions. The command transitions the session to `PendingFallback`.
`cancel` only records the cancellation event and prints a message directing the user to run `fallback` to broadcast. `fallback` handles the broadcast. The e2e test is updated to exercise both steps in sequence, asserting the fallback is absent from the mempool after `cancel` and present after `fallback`.
b6040c7 to
c57d338
Compare
xstoicunicornx
left a comment
There was a problem hiding this comment.
utACK c57d338
Somewhat strongly held nit: changing from SessionOutcome::Cancel to SessionOutcome::Aborted makes it more confusing/less intuitive. It gives two different terms that refer to the same state transition path. Was there a reason you felt that SessionOutcome::Aborted was better? I do think Cancelled is better than Cancel though.
Other than my nits and the comment that seems like it can be removed, implementation looks good and all tests pass.
|
|
||
| // impl<S> From<payjoin::persist::PersistedError<std::convert::Infallible, S>> for SenderPersistedError | ||
| // where | ||
| // S: std::error::Error + Send + Sync + 'static, | ||
| // { | ||
| // fn from(err: payjoin::persist::PersistedError<std::convert::Infallible, S>) -> Self { | ||
| // if let Some(storage_err) = err.storage_error() { | ||
| // return SenderPersistedError::from(ImplementationError::new(storage_err)); | ||
| // } | ||
| // SenderPersistedError::Unexpected | ||
| // } | ||
| // } |
There was a problem hiding this comment.
| // impl<S> From<payjoin::persist::PersistedError<std::convert::Infallible, S>> for SenderPersistedError | |
| // where | |
| // S: std::error::Error + Send + Sync + 'static, | |
| // { | |
| // fn from(err: payjoin::persist::PersistedError<std::convert::Infallible, S>) -> Self { | |
| // if let Some(storage_err) = err.storage_error() { | |
| // return SenderPersistedError::from(ImplementationError::new(storage_err)); | |
| // } | |
| // SenderPersistedError::Unexpected | |
| // } | |
| // } |
Can this be removed?
| SendSession::PendingFallback(inner) => | ||
| Self::Cancelled { inner: Arc::new(inner.into()) }, |
There was a problem hiding this comment.
| SendSession::PendingFallback(inner) => | |
| Self::Cancelled { inner: Arc::new(inner.into()) }, | |
| SendSession::PendingFallback(inner) => | |
| Self::PendingFallback { inner: Arc::new(inner.into()) }, |
Nit: Why not follow the base code naming conventions rather than creating anti-patterns?
| "State should be Closed after cancel", | ||
| "Cancelled", | ||
| "State should be Cancelled after cancel", | ||
| ); |
There was a problem hiding this comment.
const cancelled = pendingFallback
.broadcasted()
.save(senderPersister);
const result = payjoin.replaySenderEventLog(senderPersister);
const state = result.state();
assert.strictEqual(
state.tag,
"Closed",
"State should be Closed after cancel",
);Nit: Maybe keep Closed as the final state so that it tests broadcasted() and continues to test that send session is closed out? Would apply to rest of unit tests as well.
Implementing @spacebear21 's idea from #1542 (comment)
for just the sender.
Recevier side is implemented here: #1558
Pull Request Checklist
Please confirm the following before requesting review:
AI
in the body of this PR.
Claude made the updates to the payjoin-cli