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
Add ChannelStages to keep track of history of lifecycle of a DataTransfer #163
Conversation
8abaf40
to
bda3a51
Compare
@@ -171,6 +173,14 @@ func (c channelState) OtherPeer() peer.ID { | |||
return c.sender | |||
} | |||
|
|||
func (c channelState) Stages() *datatransfer.ChannelStages { | |||
if c.stages == nil { | |||
return &datatransfer.ChannelStages{} |
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.
This behaviour a bit footgunny. This method returns a mutable ChannelStages
object, either from the state (which means that changes will be persisted), or an entirely new instance without setting it in the internal state (which means that mutations will be discarded).
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.
It looks like we did it this way to save nil-checks on the user side, concretely for transfers that were already in progress before this code got deployed. I'll come up with a different way.
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.
I ended up adding a note to the godocs that mutating the return value is unsafe. There's only so much you can do with Go. Even if we returned a value instead of a pointer, the inner slices can be mutated.
No description provided.