htlcswitch: add handler handleHtlcResolution
This commit is contained in:
1 file changed
+46
-23
+46
-23
@@ -1511,29 +1511,10 @@ func (l *channelLink) htlcManager(ctx context.Context) {
|
|||||||
// A htlc resolution is received. This means that we now have a
|
// A htlc resolution is received. This means that we now have a
|
||||||
// resolution for a previously accepted htlc.
|
// resolution for a previously accepted htlc.
|
||||||
case hodlItem := <-l.hodlQueue.ChanOut():
|
case hodlItem := <-l.hodlQueue.ChanOut():
|
||||||
htlcResolution := hodlItem.(invoices.HtlcResolution)
|
err := l.handleHtlcResolution(ctx, hodlItem)
|
||||||
err := l.processHodlQueue(ctx, htlcResolution)
|
if err != nil {
|
||||||
switch err {
|
l.log.Errorf("failed to handle htlc "+
|
||||||
// No error, success.
|
"resolution: %v", err)
|
||||||
case nil:
|
|
||||||
|
|
||||||
// If the duplicate keystone error was encountered,
|
|
||||||
// fail back gracefully.
|
|
||||||
case ErrDuplicateKeystone:
|
|
||||||
l.failf(LinkFailureError{
|
|
||||||
code: ErrCircuitError,
|
|
||||||
}, "process hodl queue: "+
|
|
||||||
"temporary circuit error: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
|
|
||||||
// Send an Error message to the peer.
|
|
||||||
default:
|
|
||||||
l.failf(LinkFailureError{
|
|
||||||
code: ErrInternalError,
|
|
||||||
}, "process hodl queue: unable to update "+
|
|
||||||
"commitment: %v", err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case qReq := <-l.quiescenceReqs:
|
case qReq := <-l.quiescenceReqs:
|
||||||
@@ -4582,3 +4563,45 @@ func (l *channelLink) CommitmentCustomBlob() fn.Option[tlv.Blob] {
|
|||||||
|
|
||||||
return l.channel.LocalCommitmentBlob()
|
return l.channel.LocalCommitmentBlob()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handleHtlcResolution takes an HTLC resolution and processes it by draining
|
||||||
|
// the hodlQueue. Once processed, a commit_sig is sent to the remote to update
|
||||||
|
// their commitment.
|
||||||
|
func (l *channelLink) handleHtlcResolution(ctx context.Context,
|
||||||
|
hodlItem any) error {
|
||||||
|
|
||||||
|
htlcResolution, ok := hodlItem.(invoices.HtlcResolution)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("expect HtlcResolution, got %T", hodlItem)
|
||||||
|
}
|
||||||
|
|
||||||
|
err := l.processHodlQueue(ctx, htlcResolution)
|
||||||
|
// No error, success.
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
|
switch err {
|
||||||
|
// If the duplicate keystone error was encountered, fail back
|
||||||
|
// gracefully.
|
||||||
|
case ErrDuplicateKeystone:
|
||||||
|
l.failf(
|
||||||
|
LinkFailureError{
|
||||||
|
code: ErrCircuitError,
|
||||||
|
},
|
||||||
|
"process hodl queue: temporary circuit error: %v", err,
|
||||||
|
)
|
||||||
|
|
||||||
|
// Send an Error message to the peer.
|
||||||
|
default:
|
||||||
|
l.failf(
|
||||||
|
LinkFailureError{
|
||||||
|
code: ErrInternalError,
|
||||||
|
},
|
||||||
|
"process hodl queue: unable to update commitment: %v",
|
||||||
|
err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
Reference in new issue
Block a user