Skip to content
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

Merged
merged 11 commits into from Mar 30, 2021

Conversation

nonsense
Copy link
Member

No description provided.

channels/channel_state.go Outdated Show resolved Hide resolved
types.go Outdated Show resolved Hide resolved
types.go Show resolved Hide resolved
@nonsense nonsense marked this pull request as ready for review March 23, 2021 12:02
@@ -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{}
Copy link
Member

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).

Copy link
Member

@raulk raulk Mar 25, 2021

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.

Copy link
Member

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.

@dirkmc dirkmc merged commit b3dcd70 into filecoin-project:master Mar 30, 2021
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.

None yet

3 participants