@@ -859,7 +859,7 @@ type failCb func(update *lnwire.ChannelUpdate1) lnwire.FailureMessage
859
859
// outgoing HTLC. It may return a FailureMessage that references a channel's
860
860
// alias. If the channel does not have an alias, then the regular channel
861
861
// update from disk will be returned.
862
- func (l * channelLink ) createFailureWithUpdate (incoming bool ,
862
+ func (l * channelLink ) createFailureWithUpdate (_ context. Context , incoming bool ,
863
863
outgoingScid lnwire.ShortChannelID , cb failCb ) lnwire.FailureMessage {
864
864
865
865
// Determine which SCID to use in case we need to use aliases in the
@@ -1043,7 +1043,7 @@ func (l *channelLink) resolveFwdPkgs(ctx context.Context) error {
1043
1043
l .log .Debugf ("loaded %d fwd pks" , len (fwdPkgs ))
1044
1044
1045
1045
for _ , fwdPkg := range fwdPkgs {
1046
- if err := l .resolveFwdPkg (fwdPkg ); err != nil {
1046
+ if err := l .resolveFwdPkg (ctx , fwdPkg ); err != nil {
1047
1047
return err
1048
1048
}
1049
1049
}
@@ -1060,7 +1060,9 @@ func (l *channelLink) resolveFwdPkgs(ctx context.Context) error {
1060
1060
// resolveFwdPkg interprets the FwdState of the provided package, either
1061
1061
// reprocesses any outstanding htlcs in the package, or performs garbage
1062
1062
// collection on the package.
1063
- func (l * channelLink ) resolveFwdPkg (fwdPkg * channeldb.FwdPkg ) error {
1063
+ func (l * channelLink ) resolveFwdPkg (ctx context.Context ,
1064
+ fwdPkg * channeldb.FwdPkg ) error {
1065
+
1064
1066
// Remove any completed packages to clear up space.
1065
1067
if fwdPkg .State == channeldb .FwdStateCompleted {
1066
1068
l .log .Debugf ("removing completed fwd pkg for height=%d" ,
@@ -1091,7 +1093,7 @@ func (l *channelLink) resolveFwdPkg(fwdPkg *channeldb.FwdPkg) error {
1091
1093
// shove the entire, original set of adds down the pipeline so that the
1092
1094
// batch of adds presented to the sphinx router does not ever change.
1093
1095
if ! fwdPkg .AckFilter .IsFull () {
1094
- l .processRemoteAdds (fwdPkg )
1096
+ l .processRemoteAdds (ctx , fwdPkg )
1095
1097
1096
1098
// If the link failed during processing the adds, we must
1097
1099
// return to ensure we won't attempted to update the state
@@ -2539,10 +2541,10 @@ func (l *channelLink) handleUpstreamMsg(ctx context.Context,
2539
2541
// check since processing those can't result in further updates
2540
2542
// to this channel link.
2541
2543
if l .quiescer .CanSendUpdates () {
2542
- l .processRemoteAdds (fwdPkg )
2544
+ l .processRemoteAdds (ctx , fwdPkg )
2543
2545
} else {
2544
2546
l .quiescer .OnResume (func () {
2545
- l .processRemoteAdds (fwdPkg )
2547
+ l .processRemoteAdds (ctx , fwdPkg )
2546
2548
})
2547
2549
}
2548
2550
l .processRemoteSettleFails (fwdPkg )
@@ -3257,8 +3259,8 @@ func (l *channelLink) UpdateForwardingPolicy(
3257
3259
// issue.
3258
3260
//
3259
3261
// NOTE: Part of the ChannelLink interface.
3260
- func (l * channelLink ) CheckHtlcForward (payHash [32 ]byte , incomingHtlcAmt ,
3261
- amtToForward lnwire.MilliSatoshi , incomingTimeout ,
3262
+ func (l * channelLink ) CheckHtlcForward (ctx context. Context , payHash [32 ]byte ,
3263
+ incomingHtlcAmt , amtToForward lnwire.MilliSatoshi , incomingTimeout ,
3262
3264
outgoingTimeout uint32 , inboundFee models.InboundFee ,
3263
3265
heightNow uint32 , originalScid lnwire.ShortChannelID ,
3264
3266
customRecords lnwire.CustomRecords ) * LinkError {
@@ -3303,13 +3305,15 @@ func (l *channelLink) CheckHtlcForward(payHash [32]byte, incomingHtlcAmt,
3303
3305
cb := func (upd * lnwire.ChannelUpdate1 ) lnwire.FailureMessage {
3304
3306
return lnwire .NewFeeInsufficient (amtToForward , * upd )
3305
3307
}
3306
- failure := l .createFailureWithUpdate (false , originalScid , cb )
3308
+ failure := l .createFailureWithUpdate (
3309
+ ctx , false , originalScid , cb ,
3310
+ )
3307
3311
return NewLinkError (failure )
3308
3312
}
3309
3313
3310
3314
// Check whether the outgoing htlc satisfies the channel policy.
3311
3315
err := l .canSendHtlc (
3312
- policy , payHash , amtToForward , outgoingTimeout , heightNow ,
3316
+ ctx , policy , payHash , amtToForward , outgoingTimeout , heightNow ,
3313
3317
originalScid , customRecords ,
3314
3318
)
3315
3319
if err != nil {
@@ -3333,7 +3337,10 @@ func (l *channelLink) CheckHtlcForward(payHash [32]byte, incomingHtlcAmt,
3333
3337
incomingTimeout , * upd ,
3334
3338
)
3335
3339
}
3336
- failure := l .createFailureWithUpdate (false , originalScid , cb )
3340
+ failure := l .createFailureWithUpdate (
3341
+ ctx , false , originalScid , cb ,
3342
+ )
3343
+
3337
3344
return NewLinkError (failure )
3338
3345
}
3339
3346
@@ -3345,7 +3352,7 @@ func (l *channelLink) CheckHtlcForward(payHash [32]byte, incomingHtlcAmt,
3345
3352
// valid protocol failure message should be returned in order to signal
3346
3353
// the violation. This call is intended to be used for locally initiated
3347
3354
// payments for which there is no corresponding incoming htlc.
3348
- func (l * channelLink ) CheckHtlcTransit (payHash [32 ]byte ,
3355
+ func (l * channelLink ) CheckHtlcTransit (ctx context. Context , payHash [32 ]byte ,
3349
3356
amt lnwire.MilliSatoshi , timeout uint32 , heightNow uint32 ,
3350
3357
customRecords lnwire.CustomRecords ) * LinkError {
3351
3358
@@ -3357,15 +3364,16 @@ func (l *channelLink) CheckHtlcTransit(payHash [32]byte,
3357
3364
// trying to send over a local link. This causes the fallback mechanism
3358
3365
// to occur.
3359
3366
return l .canSendHtlc (
3360
- policy , payHash , amt , timeout , heightNow , hop .Source ,
3367
+ ctx , policy , payHash , amt , timeout , heightNow , hop .Source ,
3361
3368
customRecords ,
3362
3369
)
3363
3370
}
3364
3371
3365
3372
// canSendHtlc checks whether the given htlc parameters satisfy
3366
3373
// the channel's amount and time lock constraints.
3367
- func (l * channelLink ) canSendHtlc (policy models.ForwardingPolicy ,
3368
- payHash [32 ]byte , amt lnwire.MilliSatoshi , timeout uint32 ,
3374
+ func (l * channelLink ) canSendHtlc (ctx context.Context ,
3375
+ policy models.ForwardingPolicy , payHash [32 ]byte ,
3376
+ amt lnwire.MilliSatoshi , timeout uint32 ,
3369
3377
heightNow uint32 , originalScid lnwire.ShortChannelID ,
3370
3378
customRecords lnwire.CustomRecords ) * LinkError {
3371
3379
@@ -3382,7 +3390,10 @@ func (l *channelLink) canSendHtlc(policy models.ForwardingPolicy,
3382
3390
cb := func (upd * lnwire.ChannelUpdate1 ) lnwire.FailureMessage {
3383
3391
return lnwire .NewAmountBelowMinimum (amt , * upd )
3384
3392
}
3385
- failure := l .createFailureWithUpdate (false , originalScid , cb )
3393
+ failure := l .createFailureWithUpdate (
3394
+ ctx , false , originalScid , cb ,
3395
+ )
3396
+
3386
3397
return NewLinkError (failure )
3387
3398
}
3388
3399
@@ -3397,8 +3408,13 @@ func (l *channelLink) canSendHtlc(policy models.ForwardingPolicy,
3397
3408
cb := func (upd * lnwire.ChannelUpdate1 ) lnwire.FailureMessage {
3398
3409
return lnwire .NewTemporaryChannelFailure (upd )
3399
3410
}
3400
- failure := l .createFailureWithUpdate (false , originalScid , cb )
3401
- return NewDetailedLinkError (failure , OutgoingFailureHTLCExceedsMax )
3411
+ failure := l .createFailureWithUpdate (
3412
+ ctx , false , originalScid , cb ,
3413
+ )
3414
+
3415
+ return NewDetailedLinkError (
3416
+ failure , OutgoingFailureHTLCExceedsMax ,
3417
+ )
3402
3418
}
3403
3419
3404
3420
// We want to avoid offering an HTLC which will expire in the near
@@ -3412,7 +3428,10 @@ func (l *channelLink) canSendHtlc(policy models.ForwardingPolicy,
3412
3428
cb := func (upd * lnwire.ChannelUpdate1 ) lnwire.FailureMessage {
3413
3429
return lnwire .NewExpiryTooSoon (* upd )
3414
3430
}
3415
- failure := l .createFailureWithUpdate (false , originalScid , cb )
3431
+ failure := l .createFailureWithUpdate (
3432
+ ctx , false , originalScid , cb ,
3433
+ )
3434
+
3416
3435
return NewLinkError (failure )
3417
3436
}
3418
3437
@@ -3466,7 +3485,10 @@ func (l *channelLink) canSendHtlc(policy models.ForwardingPolicy,
3466
3485
cb := func (upd * lnwire.ChannelUpdate1 ) lnwire.FailureMessage {
3467
3486
return lnwire .NewTemporaryChannelFailure (upd )
3468
3487
}
3469
- failure := l .createFailureWithUpdate (false , originalScid , cb )
3488
+ failure := l .createFailureWithUpdate (
3489
+ ctx , false , originalScid , cb ,
3490
+ )
3491
+
3470
3492
return NewDetailedLinkError (
3471
3493
failure , OutgoingFailureInsufficientBalance ,
3472
3494
)
@@ -3726,7 +3748,9 @@ func (l *channelLink) processRemoteSettleFails(fwdPkg *channeldb.FwdPkg) {
3726
3748
// have already been acknowledged in the forwarding package will be ignored.
3727
3749
//
3728
3750
//nolint:funlen
3729
- func (l * channelLink ) processRemoteAdds (fwdPkg * channeldb.FwdPkg ) {
3751
+ func (l * channelLink ) processRemoteAdds (ctx context.Context ,
3752
+ fwdPkg * channeldb.FwdPkg ) {
3753
+
3730
3754
l .log .Tracef ("processing %d remote adds for height %d" ,
3731
3755
len (fwdPkg .Adds ), fwdPkg .Height )
3732
3756
@@ -4049,7 +4073,7 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg) {
4049
4073
}
4050
4074
4051
4075
failure := l .createFailureWithUpdate (
4052
- true , hop .Source , cb ,
4076
+ ctx , true , hop .Source , cb ,
4053
4077
)
4054
4078
4055
4079
l .sendHTLCError (
0 commit comments