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

Restart Push integration tests and corresponding fixes #78

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions channels/channel_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (

// channelState is immutable channel data plus mutable state
type channelState struct {
// peerId of the manager peer
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is an interesting change and probably useful.

I dunno if you saw but there's a method called OtherParty that takes a peer.ID for the party the data transfer is running on.

For symmetry, I'd like to do two things:
I'd like to rename ManagerPeer to ThisParty or SelfParty
and then I'd like to remove the parameter to OtherParty since we now have it in the channel state.
I guess I'd also be fine with SelfPeer and OtherPeer if Party doesn't make sense.

I'm ok with doing this as a seperate cleanup PR btw as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is done.

managerPeer peer.ID
// an identifier for this channel shared by request and responder, set by requester through protocol
transferID datatransfer.TransferID
// base CID for the piece being transferred
Expand Down Expand Up @@ -154,4 +156,8 @@ func (c channelState) OtherParty(thisParty peer.ID) peer.ID {
return c.sender
}

func (c channelState) ManagerPeer() peer.ID {
return c.managerPeer
}

var _ datatransfer.ChannelState = channelState{}
17 changes: 9 additions & 8 deletions channels/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (c *Channels) dispatch(eventName fsm.EventName, channel fsm.StateType) {

// CreateNew creates a new channel id and channel state and saves to channels.
// returns error if the channel exists already.
func (c *Channels) CreateNew(tid datatransfer.TransferID, baseCid cid.Cid, selector ipld.Node, voucher datatransfer.Voucher, initiator, dataSender, dataReceiver peer.ID) (datatransfer.ChannelID, error) {
func (c *Channels) CreateNew(managerPeer peer.ID, tid datatransfer.TransferID, baseCid cid.Cid, selector ipld.Node, voucher datatransfer.Voucher, initiator, dataSender, dataReceiver peer.ID) (datatransfer.ChannelID, error) {
var responder peer.ID
if dataSender == initiator {
responder = dataReceiver
Expand All @@ -107,13 +107,14 @@ func (c *Channels) CreateNew(tid datatransfer.TransferID, baseCid cid.Cid, selec
return datatransfer.ChannelID{}, err
}
err = c.statemachines.Begin(chid, &internalChannelState{
TransferID: tid,
Initiator: initiator,
Responder: responder,
BaseCid: baseCid,
Selector: &cbg.Deferred{Raw: selBytes},
Sender: dataSender,
Recipient: dataReceiver,
ManagerPeer: managerPeer,
TransferID: tid,
Initiator: initiator,
Responder: responder,
BaseCid: baseCid,
Selector: &cbg.Deferred{Raw: selBytes},
Sender: dataSender,
Recipient: dataReceiver,
Vouchers: []encodedVoucher{
{
Type: voucher.Type(),
Expand Down
2 changes: 1 addition & 1 deletion channels/channels_fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var log = logging.Logger("data-transfer")
var ChannelEvents = fsm.Events{
fsm.Event(datatransfer.Open).FromAny().To(datatransfer.Requested),
fsm.Event(datatransfer.Accept).From(datatransfer.Requested).To(datatransfer.Ongoing),
fsm.Event(datatransfer.Restart).FromAny().ToNoChange(),
fsm.Event(datatransfer.Restart).FromAny().To(datatransfer.Ongoing),

fsm.Event(datatransfer.Cancel).FromAny().To(datatransfer.Cancelling),

Expand Down
13 changes: 8 additions & 5 deletions channels/channels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,25 @@ func TestChannels(t *testing.T) {
peers := testutil.GeneratePeers(4)

t.Run("adding channels", func(t *testing.T) {
chid, err := channelList.CreateNew(tid1, cids[0], selector, fv1, peers[0], peers[0], peers[1])
chid, err := channelList.CreateNew(peers[0], tid1, cids[0], selector, fv1, peers[0], peers[0], peers[1])
require.NoError(t, err)
require.Equal(t, peers[0], chid.Initiator)
require.Equal(t, tid1, chid.ID)

// cannot add twice for same channel id
_, err = channelList.CreateNew(tid1, cids[1], selector, fv2, peers[0], peers[1], peers[0])
_, err = channelList.CreateNew(peers[0], tid1, cids[1], selector, fv2, peers[0], peers[1], peers[0])
require.Error(t, err)
state := checkEvent(ctx, t, received, datatransfer.Open)
require.Equal(t, datatransfer.Requested, state.Status())

// can add for different id
chid, err = channelList.CreateNew(tid2, cids[1], selector, fv2, peers[3], peers[2], peers[3])
chid, err = channelList.CreateNew(peers[0], tid2, cids[1], selector, fv2, peers[3], peers[2], peers[3])
require.NoError(t, err)
require.Equal(t, peers[3], chid.Initiator)
require.Equal(t, tid2, chid.ID)
state = checkEvent(ctx, t, received, datatransfer.Open)
require.Equal(t, datatransfer.Requested, state.Status())
require.Equal(t, peers[0], state.ManagerPeer())
})

t.Run("in progress channels", func(t *testing.T) {
Expand Down Expand Up @@ -97,6 +99,7 @@ func TestChannels(t *testing.T) {
state, err = channelList.GetByID(ctx, datatransfer.ChannelID{Initiator: peers[3], Responder: peers[2], ID: tid2})
require.NotEqual(t, nil, state)
require.NoError(t, err)
require.Equal(t, peers[0], state.ManagerPeer())
})

t.Run("accept", func(t *testing.T) {
Expand All @@ -118,7 +121,7 @@ func TestChannels(t *testing.T) {
channelList, err := channels.New(ds, notifier, decoderByType, decoderByType, &fakeEnv{})
require.NoError(t, err)

_, err = channelList.CreateNew(tid1, cids[0], selector, fv1, peers[0], peers[0], peers[1])
_, err = channelList.CreateNew(peers[0], tid1, cids[0], selector, fv1, peers[0], peers[0], peers[1])
require.NoError(t, err)
state := checkEvent(ctx, t, received, datatransfer.Open)
require.Equal(t, datatransfer.Requested, state.Status())
Expand Down Expand Up @@ -247,7 +250,7 @@ func TestChannels(t *testing.T) {
state = checkEvent(ctx, t, received, datatransfer.CleanupComplete)
require.Equal(t, datatransfer.Failed, state.Status())

chid, err := channelList.CreateNew(tid2, cids[1], selector, fv2, peers[2], peers[1], peers[2])
chid, err := channelList.CreateNew(peers[0], tid2, cids[1], selector, fv2, peers[2], peers[1], peers[2])
require.NoError(t, err)
require.Equal(t, peers[2], chid.Initiator)
require.Equal(t, tid2, chid.ID)
Expand Down
3 changes: 3 additions & 0 deletions channels/internalchannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type encodedVoucherResult struct {
}

type internalChannelState struct {
// PeerId of the manager peer
ManagerPeer peer.ID
// an identifier for this channel shared by request and responder, set by requester through protocol
TransferID datatransfer.TransferID
// Initiator is the person who intiated this datatransfer request
Expand Down Expand Up @@ -58,6 +60,7 @@ type internalChannelState struct {

func (c internalChannelState) ToChannelState(voucherDecoder DecoderByTypeFunc, voucherResultDecoder DecoderByTypeFunc) datatransfer.ChannelState {
return channelState{
managerPeer: c.ManagerPeer,
isPull: c.Initiator == c.Recipient,
transferID: c.TransferID,
baseCid: c.BaseCid,
Expand Down
26 changes: 24 additions & 2 deletions channels/internalchannel_cbor_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/ipfs/go-blockservice v0.1.3
github.com/ipfs/go-cid v0.0.7
github.com/ipfs/go-datastore v0.4.4
github.com/ipfs/go-graphsync v0.1.2
github.com/ipfs/go-graphsync v0.1.2-0.20200915122843-4c9b3c863031
github.com/ipfs/go-ipfs-blockstore v1.0.1
github.com/ipfs/go-ipfs-blocksutil v0.0.1
github.com/ipfs/go-ipfs-chunker v0.0.5
Expand All @@ -29,5 +29,6 @@ require (
github.com/libp2p/go-libp2p-core v0.5.0
github.com/stretchr/testify v1.5.1
github.com/whyrusleeping/cbor-gen v0.0.0-20200810223238-211df3b9e24c
go.uber.org/atomic v1.6.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

did you mean to add this? I don't have an objection. I haven't worked with this library before but I'm sure I can figure it out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, it's a simple wrapper over "sync/atomic.

golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ github.com/ipfs/go-ds-badger v0.0.5/go.mod h1:g5AuuCGmr7efyzQhLL8MzwqcauPojGPUaH
github.com/ipfs/go-ds-badger v0.2.1/go.mod h1:Tx7l3aTph3FMFrRS838dcSJh+jjA7cX9DrGVwx/NOwE=
github.com/ipfs/go-ds-leveldb v0.0.1/go.mod h1:feO8V3kubwsEF22n0YRQCffeb79OOYIykR4L04tMOYc=
github.com/ipfs/go-ds-leveldb v0.4.1/go.mod h1:jpbku/YqBSsBc1qgME8BkWS4AxzF2cEu1Ii2r79Hh9s=
github.com/ipfs/go-graphsync v0.1.2 h1:25Ll9kIXCE+DY0dicvfS3KMw+U5sd01b/FJbA7KAbhg=
github.com/ipfs/go-graphsync v0.1.2/go.mod h1:sLXVXm1OxtE2XYPw62MuXCdAuNwkAdsbnfrmos5odbA=
github.com/ipfs/go-graphsync v0.1.2-0.20200915122843-4c9b3c863031 h1:2qWrD0VWo+TXIrgG/Jk/XaW2J1Qmo0jPud9/T1c7OqQ=
github.com/ipfs/go-graphsync v0.1.2-0.20200915122843-4c9b3c863031/go.mod h1:sLXVXm1OxtE2XYPw62MuXCdAuNwkAdsbnfrmos5odbA=
github.com/ipfs/go-ipfs-blockstore v0.0.1/go.mod h1:d3WClOmRQKFnJ0Jz/jj/zmksX0ma1gROTlovZKBmN08=
github.com/ipfs/go-ipfs-blockstore v0.1.0/go.mod h1:5aD0AvHPi7mZc6Ci1WCAhiBQu2IsfTduLl+422H6Rqw=
github.com/ipfs/go-ipfs-blockstore v0.1.4 h1:2SGI6U1B44aODevza8Rde3+dY30Pb+lbcObe1LETxOQ=
Expand Down
9 changes: 8 additions & 1 deletion impl/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ func (m *manager) OnResponseReceived(chid datatransfer.ChannelID, response datat
return m.resumeOther(chid)
}

func (m *manager) OnRequestTimedOut(chid datatransfer.ChannelID) error {
// TODO Start a timer to cleanup state if this dosen't complete in a while
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@hannahhoward Have created issue filecoin-project/lotus#3878 to clean these up from the FSM.

// TODO Should we introduce a new state for this ?
log.Warnf("channel %v has timed out", chid)
return nil
}

func (m *manager) OnChannelCompleted(chid datatransfer.ChannelID, success bool) error {
if success {
if chid.Initiator != m.peerID {
Expand Down Expand Up @@ -269,7 +276,7 @@ func (m *manager) acceptRequest(
dataReceiver = m.peerID
}

chid, err := m.channels.CreateNew(incoming.TransferID(), incoming.BaseCid(), stor, voucher, initiator, dataSender, dataReceiver)
chid, err := m.channels.CreateNew(m.peerID, incoming.TransferID(), incoming.BaseCid(), stor, voucher, initiator, dataSender, dataReceiver)
if err != nil {
return result, err
}
Expand Down
4 changes: 2 additions & 2 deletions impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (m *manager) OpenPushDataChannel(ctx context.Context, requestTo peer.ID, vo
return datatransfer.ChannelID{}, err
}

chid, err := m.channels.CreateNew(req.TransferID(), baseCid, selector, voucher,
chid, err := m.channels.CreateNew(m.peerID, req.TransferID(), baseCid, selector, voucher,
m.peerID, m.peerID, requestTo) // initiator = us, sender = us, receiver = them
if err != nil {
return chid, err
Expand All @@ -166,7 +166,7 @@ func (m *manager) OpenPullDataChannel(ctx context.Context, requestTo peer.ID, vo
return datatransfer.ChannelID{}, err
}
// initiator = us, sender = them, receiver = us
chid, err := m.channels.CreateNew(req.TransferID(), baseCid, selector, voucher,
chid, err := m.channels.CreateNew(m.peerID, req.TransferID(), baseCid, selector, voucher,
m.peerID, requestTo, m.peerID)
if err != nil {
return chid, err
Expand Down
10 changes: 6 additions & 4 deletions impl/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import (
"github.com/filecoin-project/go-data-transfer/transport/graphsync/extension"
)

const loremFile = "lorem.txt"

func TestRoundTrip(t *testing.T) {
ctx := context.Background()
testCases := map[string]struct {
Expand Down Expand Up @@ -149,7 +151,7 @@ func TestRoundTrip(t *testing.T) {
} else {
sourceDagService = gsData.DagService1
}
root, origBytes := testutil.LoadUnixFSFile(ctx, t, sourceDagService)
root, origBytes := testutil.LoadUnixFSFile(ctx, t, sourceDagService, loremFile)
rootCid := root.(cidlink.Link).Cid

var destDagService ipldformat.DAGService
Expand Down Expand Up @@ -273,7 +275,7 @@ func TestMultipleRoundTripMultipleStores(t *testing.T) {
}
sv := testutil.NewStubbedValidator()

root, origBytes := testutil.LoadUnixFSFile(ctx, t, gsData.DagService1)
root, origBytes := testutil.LoadUnixFSFile(ctx, t, gsData.DagService1, loremFile)
rootCid := root.(cidlink.Link).Cid

destDagServices := make([]ipldformat.DAGService, 0, data.requestCount)
Expand Down Expand Up @@ -443,7 +445,7 @@ func TestManyReceiversAtOnce(t *testing.T) {
}
sv := testutil.NewStubbedValidator()

root, origBytes := testutil.LoadUnixFSFile(ctx, t, gsData.DagService1)
root, origBytes := testutil.LoadUnixFSFile(ctx, t, gsData.DagService1, loremFile)
rootCid := root.(cidlink.Link).Cid

if data.isPull {
Expand Down Expand Up @@ -539,7 +541,7 @@ func TestRoundTripCancelledRequest(t *testing.T) {
dt2.SubscribeToEvents(subscriber)
voucher := testutil.FakeDTType{Data: "applesauce"}
sv := testutil.NewStubbedValidator()
root, _ := testutil.LoadUnixFSFile(ctx, t, gsData.DagService1)
root, _ := testutil.LoadUnixFSFile(ctx, t, gsData.DagService1, loremFile)
rootCid := root.(cidlink.Link).Cid

var chid datatransfer.ChannelID
Expand Down
Loading