Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
hieblmi committed May 3, 2024
1 parent 2a3b3bd commit 04017a4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
7 changes: 6 additions & 1 deletion network/backend/lnd/lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,12 @@ func (l Backend) SubscribeRoutingEvents(ctx context.Context, channelEvents chan
return err
}

channelEvents <- protoToRoutingEvent(event)
routingEvent := protoToRoutingEvent(event)
if !routingEvent.IsEmpty() {
channelEvents <- routingEvent
} else {
l.logger.Debug("receive htlcUpdate", logging.Object("routing_event", routingEvent))
}
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions network/models/routingevent.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package models

import (
"go.uber.org/zap/zapcore"
"time"
)

Expand Down Expand Up @@ -33,6 +34,24 @@ type RoutingEvent struct {
FailureDetail string
}

func (u *RoutingEvent) MarshalLogObject(enc zapcore.ObjectEncoder) error {
enc.AddUint64("incoming_channel_id", u.IncomingChannelId)
enc.AddUint64("outgoing_channel_id", u.OutgoingChannelId)
enc.AddUint64("incoming_htlc_id", u.IncomingHtlcId)
enc.AddUint64("outgoing_htlc_id", u.OutgoingHtlcId)
enc.AddTime("last_update", u.LastUpdate)
enc.AddInt("direction", u.Direction)
enc.AddInt("status", u.Status)
enc.AddUint32("incoming_timelock", u.IncomingTimelock)
enc.AddUint32("outgoing_timelock", u.OutgoingTimelock)
enc.AddUint64("amount_msat", u.AmountMsat)
enc.AddUint64("fee_msat", u.FeeMsat)
enc.AddInt32("failure_code", u.FailureCode)
enc.AddString("failure_detail", u.FailureDetail)

return nil
}

func (u *RoutingEvent) Equals(other *RoutingEvent) bool {
return u.IncomingChannelId == other.IncomingChannelId && u.IncomingHtlcId == other.IncomingHtlcId && u.OutgoingChannelId == other.OutgoingChannelId && u.OutgoingHtlcId == other.OutgoingHtlcId
}
Expand All @@ -43,3 +62,7 @@ func (u *RoutingEvent) Update(newer *RoutingEvent) {
u.FailureCode = newer.FailureCode
u.FailureDetail = newer.FailureDetail
}

func (u *RoutingEvent) IsEmpty() bool {
return u.Equals(&RoutingEvent{})
}
7 changes: 6 additions & 1 deletion pubsub/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ func (p *PubSub) routingUpdates(ctx context.Context, sub chan *events.Event) {
go func() {
for hu := range routingUpdates {
p.logger.Debug("receive htlcUpdate")
sub <- events.NewWithData(events.RoutingEventUpdated, hu)
if !hu.IsEmpty() {
p.logger.Debug("EMPTY BANG BANG")
sub <- events.NewWithData(events.RoutingEventUpdated, hu)
} else {
p.logger.Debug("NOT EMPTY BANG BANG")
}
}
p.wg.Done()
}()
Expand Down

0 comments on commit 04017a4

Please sign in to comment.