@@ -194,6 +194,11 @@ const (
194
194
Outgoing LinkDirection = true
195
195
)
196
196
197
+ // OptionalBandwidth is a type alias for the result of a bandwidth query that
198
+ // may return a bandwidth value or fn.None if the bandwidth is not available or
199
+ // not applicable.
200
+ type OptionalBandwidth = fn.Option [lnwire.MilliSatoshi ]
201
+
197
202
// ChannelLink is an interface which represents the subsystem for managing the
198
203
// incoming htlc requests, applying the changes to the channel, and also
199
204
// propagating/forwarding it to htlc switch.
@@ -255,25 +260,26 @@ type ChannelLink interface {
255
260
// in order to signal to the source of the HTLC, the policy consistency
256
261
// issue.
257
262
CheckHtlcForward (payHash [32 ]byte , incomingAmt lnwire.MilliSatoshi ,
258
- amtToForward lnwire.MilliSatoshi ,
259
- incomingTimeout , outgoingTimeout uint32 ,
260
- inboundFee models. InboundFee ,
261
- heightNow uint32 , scid lnwire.ShortChannelID ) * LinkError
263
+ amtToForward lnwire.MilliSatoshi , incomingTimeout ,
264
+ outgoingTimeout uint32 , inboundFee models. InboundFee ,
265
+ heightNow uint32 , scid lnwire. ShortChannelID ,
266
+ customRecords lnwire.CustomRecords ) * LinkError
262
267
263
268
// CheckHtlcTransit should return a nil error if the passed HTLC details
264
269
// satisfy the current channel policy. Otherwise, a LinkError with a
265
270
// valid protocol failure message should be returned in order to signal
266
271
// the violation. This call is intended to be used for locally initiated
267
272
// payments for which there is no corresponding incoming htlc.
268
273
CheckHtlcTransit (payHash [32 ]byte , amt lnwire.MilliSatoshi ,
269
- timeout uint32 , heightNow uint32 ) * LinkError
274
+ timeout uint32 , heightNow uint32 ,
275
+ customRecords lnwire.CustomRecords ) * LinkError
270
276
271
277
// Stats return the statistics of channel link. Number of updates,
272
278
// total sent/received milli-satoshis.
273
279
Stats () (uint64 , lnwire.MilliSatoshi , lnwire.MilliSatoshi )
274
280
275
- // Peer returns the serialized public key of remote peer with which we
276
- // have the channel link opened.
281
+ // PeerPubKey returns the serialized public key of remote peer with
282
+ // which we have the channel link opened.
277
283
PeerPubKey () [33 ]byte
278
284
279
285
// AttachMailBox delivers an active MailBox to the link. The MailBox may
@@ -290,9 +296,18 @@ type ChannelLink interface {
290
296
// commitment of the channel that this link is associated with.
291
297
CommitmentCustomBlob () fn.Option [tlv.Blob ]
292
298
293
- // Start/Stop are used to initiate the start/stop of the channel link
294
- // functioning.
299
+ // AuxBandwidth returns the bandwidth that can be used for a channel,
300
+ // expressed in milli-satoshi. This might be different from the regular
301
+ // BTC bandwidth for custom channels. This will always return fn.None()
302
+ // for a regular (non-custom) channel.
303
+ AuxBandwidth (amount lnwire.MilliSatoshi , cid lnwire.ShortChannelID ,
304
+ htlcBlob fn.Option [tlv.Blob ],
305
+ ts AuxTrafficShaper ) fn.Result [OptionalBandwidth ]
306
+
307
+ // Start starts the channel link.
295
308
Start () error
309
+
310
+ // Stop requests the channel link to be shut down.
296
311
Stop ()
297
312
}
298
313
@@ -428,7 +443,7 @@ type htlcNotifier interface {
428
443
NotifyForwardingEvent (key HtlcKey , info HtlcInfo ,
429
444
eventType HtlcEventType )
430
445
431
- // NotifyIncomingLinkFailEvent notifies that a htlc has failed on our
446
+ // NotifyLinkFailEvent notifies that a htlc has failed on our
432
447
// incoming link. It takes an isReceive bool to differentiate between
433
448
// our node's receives and forwards.
434
449
NotifyLinkFailEvent (key HtlcKey , info HtlcInfo ,
@@ -449,3 +464,36 @@ type htlcNotifier interface {
449
464
NotifyFinalHtlcEvent (key models.CircuitKey ,
450
465
info channeldb.FinalHtlcInfo )
451
466
}
467
+
468
+ // AuxHtlcModifier is an interface that allows the sender to modify the outgoing
469
+ // HTLC of a payment by changing the amount or the wire message tlv records.
470
+ type AuxHtlcModifier interface {
471
+ // ProduceHtlcExtraData is a function that, based on the previous extra
472
+ // data blob of an HTLC, may produce a different blob or modify the
473
+ // amount of bitcoin this htlc should carry.
474
+ ProduceHtlcExtraData (totalAmount lnwire.MilliSatoshi ,
475
+ htlcCustomRecords lnwire.CustomRecords ) (lnwire.MilliSatoshi ,
476
+ lnwire.CustomRecords , error )
477
+ }
478
+
479
+ // AuxTrafficShaper is an interface that allows the sender to determine if a
480
+ // payment should be carried by a channel based on the TLV records that may be
481
+ // present in the `update_add_htlc` message or the channel commitment itself.
482
+ type AuxTrafficShaper interface {
483
+ AuxHtlcModifier
484
+
485
+ // ShouldHandleTraffic is called in order to check if the channel
486
+ // identified by the provided channel ID may have external mechanisms
487
+ // that would allow it to carry out the payment.
488
+ ShouldHandleTraffic (cid lnwire.ShortChannelID ,
489
+ fundingBlob fn.Option [tlv.Blob ]) (bool , error )
490
+
491
+ // PaymentBandwidth returns the available bandwidth for a custom channel
492
+ // decided by the given channel aux blob and HTLC blob. A return value
493
+ // of 0 means there is no bandwidth available. To find out if a channel
494
+ // is a custom channel that should be handled by the traffic shaper, the
495
+ // ShouldHandleTraffic method should be called first.
496
+ PaymentBandwidth (htlcBlob , commitmentBlob fn.Option [tlv.Blob ],
497
+ linkBandwidth ,
498
+ htlcAmt lnwire.MilliSatoshi ) (lnwire.MilliSatoshi , error )
499
+ }
0 commit comments