From ce5c0625bc0fc4274e5505c36b1a3f3dd43d040c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=ADghearn=C3=A1n=20Carroll?= Date: Thu, 24 Mar 2022 13:48:23 +0000 Subject: [PATCH] fix subscription bug for third party peer channels --- peerchannels.go | 2 ++ peerchannels_notify.go | 2 ++ service/pay.go | 2 +- service/peerchannels.go | 4 ++-- service/peerchannels_notify.go | 9 +++++++++ service/proofs.go | 2 +- 6 files changed, 17 insertions(+), 4 deletions(-) diff --git a/peerchannels.go b/peerchannels.go index 4983c481..26aeb974 100644 --- a/peerchannels.go +++ b/peerchannels.go @@ -77,5 +77,7 @@ type PeerChannelAPITokenStoreArgs struct { // PeerChannelMessageArgs for quering a peer channel message. type PeerChannelMessageArgs struct { ChannelID string + Host string + Path string Token string } diff --git a/peerchannels_notify.go b/peerchannels_notify.go index 9f65961a..b37d3039 100644 --- a/peerchannels_notify.go +++ b/peerchannels_notify.go @@ -28,6 +28,8 @@ type PeerChannelsMessageHandler interface { // PeerChannelSubscription for subscribing to channel notifications. type PeerChannelSubscription struct { + Host string + Path string ChannelID string Token string ChannelType PeerChannelHandlerType diff --git a/service/pay.go b/service/pay.go index 65d1fd13..f1354e5e 100644 --- a/service/pay.go +++ b/service/pay.go @@ -151,7 +151,7 @@ func (p *pay) Pay(ctx context.Context, req payd.PayRequest) (*dpp.PaymentACK, er Path: ack.PeerChannel.Path, Type: payd.PeerChannelHandlerTypeProof, }); err != nil { - log.Err(err) + log.Error().Err(err) } if err := p.storeTx.Commit(ctx); err != nil { return nil, errors.Wrap(err, "failed to commit tx") diff --git a/service/peerchannels.go b/service/peerchannels.go index 0dff8bd8..fdcdf25a 100644 --- a/service/peerchannels.go +++ b/service/peerchannels.go @@ -96,8 +96,8 @@ func (p *peerChannelsSvc) PeerChannelsMessage(ctx context.Context, args *payd.Pe spvchannels.WithToken(args.Token), spvchannels.WithChannelID(args.ChannelID), spvchannels.WithVersion("v1"), - spvchannels.WithBaseURL(p.cfg.Host), - spvchannels.WithPath(p.cfg.Path), + spvchannels.WithBaseURL(args.Host), + spvchannels.WithPath(args.Path), spvchannels.WithNoTLS(), ) msgs, err := c.Messages(ctx, spvchannels.MessagesRequest{ diff --git a/service/peerchannels_notify.go b/service/peerchannels_notify.go index e516fe62..f3f4eb8f 100644 --- a/service/peerchannels_notify.go +++ b/service/peerchannels_notify.go @@ -47,6 +47,8 @@ func (p *peerChannelsNotifySvc) Subscribe(ctx context.Context, channel *payd.Pee channel.CreatedAt = time.Now() } + log.Debug().Msgf("subscribing to channel %s with token %s at %s%s", channel.ID, channel.Token, channel.Host, channel.Path) + u := url.URL{ Scheme: "ws", Host: channel.Host, @@ -76,6 +78,8 @@ func (p *peerChannelsNotifySvc) Subscribe(ctx context.Context, channel *payd.Pee }() sub := payd.PeerChannelSubscription{ + Host: channel.Host, + Path: channel.Path, ChannelID: channel.ID, ChannelType: channel.Type, Token: channel.Token, @@ -107,6 +111,7 @@ func (p *peerChannelsNotifySvc) listen(ctx context.Context, sub *payd.PeerChanne log.Error().Err(errors.WithStack(err)) } + log.Debug().Msgf("message received on channel %s", sub.ChannelID) in <- true }() @@ -124,6 +129,8 @@ func (p *peerChannelsNotifySvc) listen(ctx context.Context, sub *payd.PeerChanne func (p *peerChannelsNotifySvc) handleNotification(ctx context.Context, sub *payd.PeerChannelSubscription, cancel context.CancelFunc) error { msgs, err := p.pcSvc.PeerChannelsMessage(ctx, &payd.PeerChannelMessageArgs{ ChannelID: sub.ChannelID, + Host: sub.Host, + Path: sub.Path, Token: sub.Token, }) if err != nil { @@ -131,6 +138,8 @@ func (p *peerChannelsNotifySvc) handleNotification(ctx context.Context, sub *pay return err } + log.Debug().Msgf("channel %s fetched messages: %#v", sub.ChannelID, msgs) + hdlr := p.handlers[sub.ChannelType] finished, err := hdlr.HandlePeerChannelsMessage(ctx, msgs) if err != nil { diff --git a/service/proofs.go b/service/proofs.go index 010462eb..c4ea2ece 100644 --- a/service/proofs.go +++ b/service/proofs.go @@ -67,7 +67,7 @@ func (p *proofs) HandlePeerChannelsMessage(ctx context.Context, msgs spvchannels } if mm["callbackReason"].(string) != "merkleProof" { - log.Info().Msg("skipping msg") + log.Debug().Msgf("skipping msg %#v", msg) continue }