@@ -296,14 +296,6 @@ type ChannelLinkConfig struct {
296
296
HtlcNotifier htlcNotifier
297
297
}
298
298
299
- // localUpdateAddMsg contains a locally initiated htlc and a channel that will
300
- // receive the outcome of the link processing. This channel must be buffered to
301
- // prevent the link from blocking.
302
- type localUpdateAddMsg struct {
303
- pkt * htlcPacket
304
- err chan error
305
- }
306
-
307
299
// shutdownReq contains an error channel that will be used by the channelLink
308
300
// to send an error if shutdown failed. If shutdown succeeded, the channel will
309
301
// be closed.
@@ -371,10 +363,6 @@ type channelLink struct {
371
363
// by the HTLC switch.
372
364
downstream chan * htlcPacket
373
365
374
- // localUpdateAdd is a channel to which locally initiated HTLCs are
375
- // sent across.
376
- localUpdateAdd chan * localUpdateAddMsg
377
-
378
366
// shutdownRequest is a channel that the channelLink will listen on to
379
367
// service shutdown requests from ShutdownIfChannelClean calls.
380
368
shutdownRequest chan * shutdownReq
@@ -428,7 +416,6 @@ func NewChannelLink(cfg ChannelLinkConfig,
428
416
hodlQueue : queue .NewConcurrentQueue (10 ),
429
417
log : build .NewPrefixLog (logPrefix , log ),
430
418
quit : make (chan struct {}),
431
- localUpdateAdd : make (chan * localUpdateAddMsg ),
432
419
}
433
420
}
434
421
@@ -1057,7 +1044,21 @@ func (l *channelLink) htlcManager() {
1057
1044
// the channel is not pending, otherwise we should have no htlcs to
1058
1045
// reforward.
1059
1046
if l .ShortChanID () != hop .Source {
1060
- if err := l .resolveFwdPkgs (); err != nil {
1047
+ err := l .resolveFwdPkgs ()
1048
+ switch err {
1049
+ // No error was encountered, success.
1050
+ case nil :
1051
+
1052
+ // If the duplicate keystone error was encountered, we'll fail
1053
+ // without sending an Error message to the peer.
1054
+ case ErrDuplicateKeystone :
1055
+ l .fail (LinkFailureError {code : ErrCircuitError },
1056
+ "temporary circuit error: %v" , err )
1057
+ return
1058
+
1059
+ // A non-nil error was encountered, send an Error message to
1060
+ // the peer.
1061
+ default :
1061
1062
l .fail (LinkFailureError {code : ErrInternalError },
1062
1063
"unable to resolve fwd pkgs: %v" , err )
1063
1064
return
@@ -1180,10 +1181,6 @@ func (l *channelLink) htlcManager() {
1180
1181
case pkt := <- l .downstream :
1181
1182
l .handleDownstreamPkt (pkt )
1182
1183
1183
- // A message containing a locally initiated add was received.
1184
- case msg := <- l .localUpdateAdd :
1185
- msg .err <- l .handleDownstreamUpdateAdd (msg .pkt )
1186
-
1187
1184
// A message from the connected peer was just received. This
1188
1185
// indicates that we have a new incoming HTLC, either directly
1189
1186
// for us, or part of a multi-hop HTLC circuit.
@@ -1195,12 +1192,27 @@ func (l *channelLink) htlcManager() {
1195
1192
case hodlItem := <- l .hodlQueue .ChanOut ():
1196
1193
htlcResolution := hodlItem .(invoices.HtlcResolution )
1197
1194
err := l .processHodlQueue (htlcResolution )
1198
- if err != nil {
1195
+ switch err {
1196
+ // No error, success.
1197
+ case nil :
1198
+
1199
+ // If the duplicate keystone error was encountered,
1200
+ // fail back gracefully.
1201
+ case ErrDuplicateKeystone :
1202
+ l .fail (LinkFailureError {code : ErrCircuitError },
1203
+ fmt .Sprintf ("process hodl queue: " +
1204
+ "temporary circuit error: %v" ,
1205
+ err ,
1206
+ ),
1207
+ )
1208
+
1209
+ // Send an Error message to the peer.
1210
+ default :
1199
1211
l .fail (LinkFailureError {code : ErrInternalError },
1200
- fmt .Sprintf ("process hodl queue: %v" ,
1201
- err .Error ()),
1212
+ fmt .Sprintf ("process hodl queue: " +
1213
+ "unable to update commitment:" +
1214
+ " %v" , err ),
1202
1215
)
1203
- return
1204
1216
}
1205
1217
1206
1218
case req := <- l .shutdownRequest :
@@ -1259,7 +1271,7 @@ loop:
1259
1271
1260
1272
// Update the commitment tx.
1261
1273
if err := l .updateCommitTx (); err != nil {
1262
- return fmt . Errorf ( "unable to update commitment: %v" , err )
1274
+ return err
1263
1275
}
1264
1276
1265
1277
return nil
@@ -2081,7 +2093,21 @@ func (l *channelLink) ackDownStreamPackets() error {
2081
2093
// updateCommitTxOrFail updates the commitment tx and if that fails, it fails
2082
2094
// the link.
2083
2095
func (l * channelLink ) updateCommitTxOrFail () bool {
2084
- if err := l .updateCommitTx (); err != nil {
2096
+ err := l .updateCommitTx ()
2097
+ switch err {
2098
+ // No error encountered, success.
2099
+ case nil :
2100
+
2101
+ // A duplicate keystone error should be resolved and is not fatal, so
2102
+ // we won't send an Error message to the peer.
2103
+ case ErrDuplicateKeystone :
2104
+ l .fail (LinkFailureError {code : ErrCircuitError },
2105
+ "temporary circuit error: %v" , err )
2106
+ return false
2107
+
2108
+ // Any other error is treated results in an Error message being sent to
2109
+ // the peer.
2110
+ default :
2085
2111
l .fail (LinkFailureError {code : ErrInternalError },
2086
2112
"unable to update commitment: %v" , err )
2087
2113
return false
@@ -2099,6 +2125,8 @@ func (l *channelLink) updateCommitTx() error {
2099
2125
// sign a commitment state.
2100
2126
err := l .cfg .Circuits .OpenCircuits (l .keystoneBatch ... )
2101
2127
if err != nil {
2128
+ // If ErrDuplicateKeystone is returned, the caller will catch
2129
+ // it.
2102
2130
return err
2103
2131
}
2104
2132
@@ -2568,33 +2596,6 @@ func (l *channelLink) handleSwitchPacket(pkt *htlcPacket) error {
2568
2596
return l .mailBox .AddPacket (pkt )
2569
2597
}
2570
2598
2571
- // handleLocalAddPacket handles a locally-initiated UpdateAddHTLC packet. It
2572
- // will be processed synchronously.
2573
- //
2574
- // NOTE: Part of the packetHandler interface.
2575
- func (l * channelLink ) handleLocalAddPacket (pkt * htlcPacket ) error {
2576
- l .log .Tracef ("received switch packet outkey=%v" , pkt .outKey ())
2577
-
2578
- // Create a buffered result channel to prevent the link from blocking.
2579
- errChan := make (chan error , 1 )
2580
-
2581
- select {
2582
- case l .localUpdateAdd <- & localUpdateAddMsg {
2583
- pkt : pkt ,
2584
- err : errChan ,
2585
- }:
2586
- case <- l .quit :
2587
- return ErrLinkShuttingDown
2588
- }
2589
-
2590
- select {
2591
- case err := <- errChan :
2592
- return err
2593
- case <- l .quit :
2594
- return ErrLinkShuttingDown
2595
- }
2596
- }
2597
-
2598
2599
// HandleChannelUpdate handles the htlc requests as settle/add/fail which sent
2599
2600
// to us from remote peer we have a channel with.
2600
2601
//
0 commit comments