Skip to content

Commit 8958945

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 32a94ee commit 8958945

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

tapchannel/aux_traffic_shaper.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
cmsg "github.com/lightninglabs/taproot-assets/tapchannelmsg"
1616
lfn "github.com/lightningnetwork/lnd/fn/v2"
1717
"github.com/lightningnetwork/lnd/lntypes"
18+
"github.com/lightningnetwork/lnd/lnutils"
1819
"github.com/lightningnetwork/lnd/lnwallet"
1920
"github.com/lightningnetwork/lnd/lnwire"
2021
"github.com/lightningnetwork/lnd/tlv"
@@ -180,13 +181,21 @@ func (s *AuxTrafficShaper) PaymentBandwidth(htlcBlob,
180181
// never be settled. Other HTLCs that may also call into this method are
181182
// not yet registered to the commitment, so we need to account for them
182183
// manually.
183-
computedLocal, _, err := ComputeLocalBalance(
184+
computedLocal, decodedView, err := ComputeLocalBalance(
184185
commitment, htlcView,
185186
)
186187
if err != nil {
187188
return 0, err
188189
}
189190

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

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

0 commit comments

Comments
 (0)