Skip to content

Commit 3b5aace

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 3df87fe commit 3b5aace

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

tapchannel/aux_traffic_shaper.go

Lines changed: 40 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,11 +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(*commitment, htlcView)
184+
computedLocal, decodedView, err := ComputeLocalBalance(
185+
*commitment, htlcView,
186+
)
184187
if err != nil {
185188
return 0, err
186189
}
187190

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+
188199
// If the HTLC carries asset units (keysend, forwarding), then there's
189200
// no need to do any RFQ related math. We can directly compare the asset
190201
// units of the HTLC with those in our local balance.
@@ -437,3 +448,31 @@ func (s *AuxTrafficShaper) ProduceHtlcExtraData(totalAmount lnwire.MilliSatoshi,
437448

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

0 commit comments

Comments
 (0)