htlcswitch: add handler handleHtlcResolution

This commit is contained in:
yyforyongyu
2025-06-30 20:41:46 +08:00
parent 8a03414190
commit 30f9257a6b

View File

@@ -1511,29 +1511,10 @@ func (l *channelLink) htlcManager(ctx context.Context) {
// A htlc resolution is received. This means that we now have a
// resolution for a previously accepted htlc.
case hodlItem := <-l.hodlQueue.ChanOut():
htlcResolution := hodlItem.(invoices.HtlcResolution)
err := l.processHodlQueue(ctx, htlcResolution)
switch err {
// No error, success.
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,
)
err := l.handleHtlcResolution(ctx, hodlItem)
if err != nil {
l.log.Errorf("failed to handle htlc "+
"resolution: %v", err)
}
case qReq := <-l.quiescenceReqs:
@@ -4582,3 +4563,45 @@ func (l *channelLink) CommitmentCustomBlob() fn.Option[tlv.Blob] {
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
}