Skip to content

Commit 9500e22

Browse files
committed
tapchannel: add trace logs for payment bandwidth computed view
We add a trace log which includes a pretty print of the HTLCs that are part of our local update log.
1 parent 61a14e0 commit 9500e22

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

tapchannel/aux_traffic_shaper.go

+36-1
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,20 @@ func (s *AuxTrafficShaper) PaymentBandwidth(htlcBlob,
180180
// never be settled. Other HTLCs that may also call into this method are
181181
// not yet registered to the commitment, so we need to account for them
182182
// manually.
183-
computedLocal, _, err := ComputeLocalBalance(
183+
computedLocal, decodedView, err := ComputeLocalBalance(
184184
commitment, htlcView,
185185
)
186186
if err != nil {
187187
return 0, err
188188
}
189189

190+
log.Tracef("Computed asset HTLC View: commitmentLocal=%v, "+
191+
"computedLocal=%v, nextHeight=%v, thisHtlc=%v, newView=%v",
192+
cmsg.OutputSum(commitment.LocalOutputs()), computedLocal,
193+
htlcView.NextHeight, htlc.Amounts.Val.Sum(), func() string {
194+
return prettyPrintLocalView(*decodedView)
195+
}())
196+
190197
// If the HTLC carries asset units (keysend, forwarding), then there's
191198
// no need to do any RFQ related math. We can directly compare the asset
192199
// units of the HTLC with those in our local balance.
@@ -438,3 +445,31 @@ func (s *AuxTrafficShaper) ProduceHtlcExtraData(totalAmount lnwire.MilliSatoshi,
438445

439446
return htlcAmountMSat, updatedRecords, nil
440447
}
448+
449+
// prettyPrintLocalView returns a string that pretty-prints the local update log
450+
// of an HTLC view.
451+
func prettyPrintLocalView(view DecodedView) string {
452+
var res string
453+
res = "\nHtlcView Local Updates:\n"
454+
for _, v := range view.OurUpdates {
455+
assetAmt := uint64(0)
456+
if rfqmsg.HasAssetHTLCCustomRecords(v.CustomRecords) {
457+
assetHtlc, err := rfqmsg.HtlcFromCustomRecords(
458+
v.CustomRecords,
459+
)
460+
if err != nil {
461+
res = fmt.Sprintf("%s\terror: could not "+
462+
"decode htlc custom records\n", res)
463+
continue
464+
}
465+
466+
assetAmt = rfqmsg.Sum(assetHtlc.Balances())
467+
}
468+
469+
res = fmt.Sprintf("%s\thtlcIndex=%v: amt=%v, assets=%v, "+
470+
"addHeight=%v\n", res, v.HtlcIndex, v.Amount, assetAmt,
471+
v.AddHeight(lntypes.Local))
472+
}
473+
474+
return res
475+
}

0 commit comments

Comments
 (0)