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

Refactor transport part 1 #324

Merged
merged 8 commits into from
Jun 16, 2022

Conversation

hannahhoward
Copy link
Collaborator

Goals

Well, I got to passing integration tests with the messaging layer underneath the transport. I'm not feeling done at all yet, truthfully. The question now is whether to try to get all tests passing and merge the changeset, or push for something closer to what I think makes sense before we go forward.

The biggest issue at the moment is that the "dtChannel" struct, which grew sort of like a frankenstein to begin with, is even more of a frankenstein now. I think I need to dig into refactoring this. The whole of the transport code is very messy. While I can certainly finish off the unit tests, I don't know what value we get from unit testing some very rough code.

@hannahhoward hannahhoward changed the base branch from master to v2 May 19, 2022 22:27
@hannahhoward
Copy link
Collaborator Author

Proposed path forward: get unit tests outside the transport passing, comment out transport tests for now, fix transport code in a subsequent PR.

@hannahhoward
Copy link
Collaborator Author

So: I'm asking @rvagg and maybe @dirkmc or @willscott to look at the code outside the transport layer with an unfortunate promise for the moment that the code "just works" by way of the integration tests, understanding the merge is to V2, not to master, and there will be subsequence prs before release. (though to be fair there will be additional changes made to the transport boundary for the events handlers.

@hannahhoward
Copy link
Collaborator Author

Things I am most interested in review on:

  1. The current transport interface
  2. The "WithTransport" method
  3. Code changes in the impl directory (as opposed to the transport dir)

decoder, _ := c.voucherDecoder(encoded.Type)
encodable, _ := decoder.DecodeFromCbor(encoded.Voucher.Raw)
vouchers = append(vouchers, encodable.(datatransfer.Voucher))
voucher := encodable.(datatransfer.Voucher)
c.decodedVouchers[0] = &voucher
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
c.decodedVouchers[0] = &voucher
c.decodedVouchers[i] = &voucher

looks like a copypasta bug?

log.Infof("sending open channel to %s to restart channel %s", requestTo, chid)
if err := m.transport.OpenChannel(ctx, requestTo, chid, cidlink.Link{Cid: baseCid}, selector, channel, req); err != nil {
monitoredChan := m.channelMonitor.AddChannel(chid, channel.IsPull())
log.Infof("sending push restart channel to %s for channel %s", requestTo, chid)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
log.Infof("sending push restart channel to %s for channel %s", requestTo, chid)
log.Infof("sending restart channel to %s for channel %s", requestTo, chid)

@rvagg
Copy link
Member

rvagg commented May 20, 2022

OK, so we're going with the slightly odd WithChannel() actions callback API because different transports may have different "capabilities", so the actions object you get may have different methods on it depending on the transport. I suppose that's reasonable, but some questions to further clarify whether this is really needed:

  1. If you can query transport.Capabilities() prior to even touching WithChannel(), couldn't we just have a single actions object that can be constructed without the need for the actions callback, then pass that in and have it error if you requested actions that the transport doesn't have the capabilities for? i.e. is the actions callback really needed and couldn't it just be done with a declarative config object passed in to WithChannel().
  2. What variations in capabilities are you designing for here? I imagine this is mostly about thinking ahead to the features that bitswap doesn't support that Graphsync does, but maybe you're also thinking broader to other protocols?

@hannahhoward hannahhoward force-pushed the feat/refactor-transport-part-1 branch from 27daa3b to ab05cba Compare May 31, 2022 04:28
@hannahhoward hannahhoward marked this pull request as ready for review May 31, 2022 04:30
@hannahhoward
Copy link
Collaborator Author

@rvagg OK I've modified my interfaces significantly, based on your feedback. I still have a kind of "multi-command" in the form of UpdateChannel, but all the individual methods are also here.

Would love your feedback. Also, the transport code should be generally easier to comprehend now.

@codecov-commenter
Copy link

codecov-commenter commented May 31, 2022

Codecov Report

❗ No coverage uploaded for pull request base (v2@681bfed). Click here to learn what that means.
The diff coverage is n/a.

❗ Current head 6b581f2 differs from pull request most recent head 7fa9bb2. Consider uploading reports for the commit 7fa9bb2 to get more accurate results

Impacted file tree graph

@@          Coverage Diff          @@
##             v2     #324   +/-   ##
=====================================
  Coverage      ?   54.77%           
=====================================
  Files         ?       26           
  Lines         ?     2817           
  Branches      ?        0           
=====================================
  Hits          ?     1543           
  Misses        ?     1095           
  Partials      ?      179           

// we aren't able to send the message to the peer because the channel
// is already in an error state, which is probably because of connection
// issues, so if we cant send the message just log a warning.
// Close transfport and try to send a cancel message to the remote peer.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Close transfport and try to send a cancel message to the remote peer.
// Close transport and try to send a cancel message to the remote peer.

@@ -74,22 +129,11 @@ func (ft *FakeTransport) SetEventHandler(events datatransfer.EventsHandler) erro
return ft.SetEventHandlerErr
}

// Shutdownc loses a this transport
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Shutdownc loses a this transport
// Shutdown loses a this transport

@rvagg
Copy link
Member

rvagg commented May 31, 2022

Nice. I haven't quite gone thoroughly through the graphsync bits yet, lots of detail there. But the API is nicer and much more direct.

Two questions:

  1. Could we get rid of PauseChannel(), CloseChannel() and SendMessage() entirely and end up with a simplified API, where you need to go through UpdateChannel() for all of those operations? It might also encourage usage that batches operations if you don't offer the atomic forms.
  2. Is there a case for making ChannelUpdate#SendUpdate a slice instead of a single Message so you could send multiple messages? Or are we not dealing with communication channels that have a case for multiple messages without response?

@hannahhoward hannahhoward force-pushed the feat/refactor-transport-part-1 branch from b7c9d9e to 1076301 Compare June 1, 2022 01:40
@@ -399,7 +399,10 @@ func (m *manager) CloseDataTransferChannel(ctx context.Context, chid datatransfe
))
defer span.End()
// Close the channel on the local transport
err = m.transport.CloseChannel(ctx, chid)
err = m.transport.UpdateChannel(ctx, chid, datatransfer.ChannelUpdate{
Paused: chst.Status().IsResponderPaused(),
Copy link
Member

Choose a reason for hiding this comment

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

yeah, this is slightly awkward isn't it? as long as we have access to the channel status this then it's probably not the worst thing

you could make it an enum with 3 values: pause, unpause (resume?), continue - where the latter is "just keep on doing what you were doing".

@hannahhoward hannahhoward force-pushed the feat/refactor-transport-part-1 branch from 1076301 to 7fa9bb2 Compare June 3, 2022 01:19
@hannahhoward hannahhoward force-pushed the feat/refactor-transport-part-1 branch from 6b581f2 to 7fa9bb2 Compare June 16, 2022 02:59
@hannahhoward hannahhoward changed the base branch from v2 to feat/refactor-transport June 16, 2022 03:20
@hannahhoward hannahhoward merged commit 51da526 into feat/refactor-transport Jun 16, 2022
hannahhoward added a commit that referenced this pull request Jun 16, 2022
* refactor(transport): move libp2p message layer into transport

* refactor(graphsync): cleanup channel state tracking

* refactor(dtchannel): extract dtchannel to package

* test(impl): get remaining tests passing

* refactor(transport): much simpler interface

* style(lint): fix imports

* refactor(transport): remote unneccesary methods

* fix(rebase): fix errors after rebase
hannahhoward added a commit that referenced this pull request Jun 25, 2022
* refactor(transport): move libp2p message layer into transport

* refactor(graphsync): cleanup channel state tracking

* refactor(dtchannel): extract dtchannel to package

* test(impl): get remaining tests passing

* refactor(transport): much simpler interface

* style(lint): fix imports

* refactor(transport): remote unneccesary methods

* fix(rebase): fix errors after rebase
hannahhoward added a commit that referenced this pull request Jul 21, 2022
* refactor(transport): move libp2p message layer into transport

* refactor(graphsync): cleanup channel state tracking

* refactor(dtchannel): extract dtchannel to package

* test(impl): get remaining tests passing

* refactor(transport): much simpler interface

* style(lint): fix imports

* refactor(transport): remote unneccesary methods

* fix(rebase): fix errors after rebase
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.

3 participants