-
Notifications
You must be signed in to change notification settings - Fork 78
Name audit for 0.24 release #803
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
Conversation
Pull Request Test Coverage Report for Build 15893586163Details
💛 - Coveralls |
|
Since pub enum SenderTypeState {
Uninitialized(),
WithReplyKey(Sender<WithReplyKey>),
V2GetContext(Sender<V2GetContext>), // ProposalPending? PollingProposal?
ProposalReceived(Psbt),
TerminalState,
} |
|
I have a big problem with both of the sumtypes. I don't think they're properly sumtypes as-is. I think they should be pub enum AnySender {
Uninitialized(Sender<Uninitialized>), // (or Sender(Uninitielized)
WithReplyKey(Sender<WithReplyKey>),
V2GetContext(Sender<V2GetContext>), // ProposalPending? PollingProposal?
ProposalReceived(Sender<ProposalReceived>), // struct ProposalReceived(Psbt);
TerminalState(Sender<TerminalError>)
}Then they could even be reduced to pub enum AnySender {
Uninitialized(Uninitialized), // (or Sender(Uninitielized)
WithReplyKey(WithReplyKey),
V2GetContext(V2GetContext), // ProposalPending? PollingProposal?
ProposalReceived(ProposalReceived), // struct ProposalReceived(Psbt);
TerminalState(TerminalError)
}
impl AnySender {
fn into_sender(self) -> Sender<State> {
// ...
}
}And yes I think there is a more descriptive name of V2GetContext to PollingForProposal or similar I think I remember Armin saying this can't work but I want to document why not if that is indeed the case. |
I think it could work but I can't think of any case where we need the state struct but not the typestate. Take a look at how the sumtype is used in payjoin cli after resume. The state structs being the template for the data are useful for the multiparty constructions that impl their own typestates. And we don't really need a union / sumtype for that |
|
This is a sort of first-round name audit. There are some more things I'd like to change but wish to progress on these things that can be independently considered. |
|
rebased |
This is one of my biggest bugbears with the existing design. The It seems possible for that Investigating. |
spacebear21
left a comment
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.
concept ACK.
I feel like Initialized could be more descriptive (what was initialized? ohttp keys? a directory mailbox? a db entry?) but don't have an immediate name suggestion.
|
Sender typestate goes |
|
I'm following up with a Receiver that takes sessioncontext out of the state (because it remains for all states) where Uninitialized has no Receiver / state at all #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Receiver<State: ReceiverState> {
pub(crate) state: State,
pub(crate) context: Arc<SessionContext>,
}In that context this will make more sense. |
There is nothing preventing a loop. In fact that is how it was implemented at onepoint IIRC. I simply find it more straightfoward have methods both do the state transition and continute progressing the state machine until you get to the desired state and then return (). Otherwise you have to return a sumtype and match again. But this point seems unrelated to the the first comment (?) . You still need a typestate to access the state transition methods |
|
Please bear with me as I audit what we merged in these PRs with a finer-toothed comb. The bugbear (if that's what "first comment" was referring to) is indeed unrelated to the first comment, but a direct response to your quote. I'm erring toward overcommunication here so that we can index our discussions. When I said
I think I was just wrong. "Proper" there was just a preference and not related to a specific definition of sumtype or best practice. I was trying to find out why the heck the pattern is the way it is. After more digging, the concrete reason we need the I think it might be able to be addressed with a trait transition for each of the pub trait ProcessEvent: Sized {
/// Attempts to transition from the current state to the next by processing the relevant event.
fn process_event(self, event: SessionEvent) -> Result<ReceiverTypeState, ReplayError>;
}where the which makes the logic in the match more less verbose (just calls to receiver.transition(event) for most arms) keeping the logic in the actual Receiver impl, which is close to what we have with the |
shared SessionContext can be moved to Receiver and out of state field.
arminsabouri
left a comment
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.
Ack ba6f515
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
| pub struct WithContext { | ||
| pub struct Initialized { |
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.
Nit the commit says
shared SessionContext can be moved to Receiver and out of state field.
Is this justiification for the rename or something that should be done in this 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.
Another PR that is coming imminently since it does affect the Serialization
arminsabouri
left a comment
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.
Meant to approve
No description provided.