Skip to content

Remove optional return types from session history methods#1055

Merged
arminsabouri merged 1 commit intopayjoin:masterfrom
0xZaddyy:remove-optional
Sep 11, 2025
Merged

Remove optional return types from session history methods#1055
arminsabouri merged 1 commit intopayjoin:masterfrom
0xZaddyy:remove-optional

Conversation

@0xZaddyy
Copy link
Contributor

@0xZaddyy 0xZaddyy commented Sep 9, 2025

After PR #1014 removes the Uninitialized variant and enforces that every SEL must contain at least one event, session history methods no longer need to return Option<T> since it guarantee's data availability

Changes

  • Sender methods: fallback_tx() and pj_param() now return non-optional types
  • Receiver methods: pj_uri() and session_context() now return non-optional types
  • FFI layer: Updated method signatures to match

Closes #1046

Pull Request Checklist

Please confirm the following before requesting review:

@0xZaddyy 0xZaddyy force-pushed the remove-optional branch 4 times, most recently from 04bdd8b to 5a023db Compare September 9, 2025 14:43
@coveralls
Copy link
Collaborator

coveralls commented Sep 9, 2025

Pull Request Test Coverage Report for Build 17649247435

Details

  • 14 of 14 (100.0%) changed or added relevant lines in 3 files are covered.
  • 4 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.02%) to 86.041%

Files with Coverage Reduction New Missed Lines %
payjoin/src/core/receive/v2/session.rs 2 97.59%
payjoin/src/core/send/v2/session.rs 2 95.65%
Totals Coverage Status
Change from base Build 17593913920: 0.02%
Covered Lines: 8235
Relevant Lines: 9571

💛 - Coveralls

Copy link
Collaborator

@arminsabouri arminsabouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for creating a clean diff! This was easy to review. I have one issue with a comment that was changed.

Besides that we should remove default impl from SessionHistory and replace it with a pub(crate) new method which accepts a non-empty iter of session events. Otherwise we could have a builder pattern but that may be overkill. Lmk what you think.

Point being the application should not have the visibility to create an instance of SessionHistory. It can only be obtained by replaying events -- which guarantees that we have at least one event.

@0xZaddyy 0xZaddyy force-pushed the remove-optional branch 2 times, most recently from 48c096a to 2a1875d Compare September 10, 2025 19:28
@0xZaddyy
Copy link
Contributor Author

Besides that we should remove default impl from SessionHistory and replace it with a pub(crate) new method which accepts a non-empty iter of session events. Otherwise we could have a builder pattern but that may be overkill. Lmk what you think.

looks good to me as this prevents a scenerio where SessionHistory could exist without events.

Copy link
Collaborator

@arminsabouri arminsabouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code ACK
Just one more case of the same rustdoc being modified

pub fn fallback_tx(&self) -> Option<Arc<crate::Transaction>> {
self.0.fallback_tx().map(|tx| Arc::new(tx.into()))
}
/// Fallback transaction from the session
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another case of the same comment being modified. Must have missed this in my first review.

Suggested change
/// Fallback transaction from the session
/// Fallback transaction from the session if present

- Update sender methods & receiver methods to return non-optional types
- Add `expect()` calls with descriptive messages for safety

fix: update expect messages to use session event log

refactor: move Some() wrapping into unwrap_relay_or_else_fetch

revert: restore original comment to fit logic

update comment back to previous state
@0xZaddyy
Copy link
Contributor Author

Code ACK Just one more case of the same rustdoc being modified

thank you @arminsabouri
i've fixed the doc change

Copy link
Collaborator

@arminsabouri arminsabouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACk

@DanGould
Copy link
Contributor

I'm somewhat skeptical of these methods on SessionHistory at all. It seems like fallback_tx is not used (maybe just because our payjoin-cli reference is incomplete?) and pj_url is used for an error handling hack (below) that I think we're gonna be able to internalize. Auditing the use of this is gonna have to be done.

                let pj_uri = session_history.pj_uri().extras.endpoint().clone();
                let ohttp_relay = self.unwrap_relay_or_else_fetch(Some(pj_uri)).await?;
                self.handle_recoverable_error(&ohttp_relay, &session_history).await?;

@DanGould
Copy link
Contributor

My comment is not blocking merge tho

@arminsabouri
Copy link
Collaborator

I'm somewhat skeptical of these methods on SessionHistory at all. It seems like fallback_tx is not used (maybe just because our payjoin-cli reference is incomplete?) and pj_url is used for an error handling hack (below) that I think we're gonna be able to internalize. Auditing the use of this is gonna have to be done.

                let pj_uri = session_history.pj_uri().extras.endpoint().clone();
                let ohttp_relay = self.unwrap_relay_or_else_fetch(Some(pj_uri)).await?;
                self.handle_recoverable_error(&ohttp_relay, &session_history).await?;

OH1H The fact that its not used is indicative that the refrence is incomplete and once we complete it we may find that we dont need exact method of SessionHistory. OTOH I think there is always going to be a need to fallback based on user preference -- this could also be part of the reference.

@arminsabouri arminsabouri merged commit bab2d88 into payjoin:master Sep 11, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SessionHistory should always have one element

4 participants