Merge pull request #8024 from Roasbeef/htlc-resolver-c-queue

contractcourt: modify the incoming contest resolver to use concurrent…
This commit is contained in:
Oliver Gugger 2023-09-26 16:03:10 +00:00 committed by GitHub
commit 3821baa0c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View file

@ -16,6 +16,7 @@ import (
"github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/queue"
) )
// htlcIncomingContestResolver is a ContractResolver that's able to resolve an // htlcIncomingContestResolver is a ContractResolver that's able to resolve an
@ -283,12 +284,15 @@ func (h *htlcIncomingContestResolver) Resolve() (ContractResolver, error) {
} }
var ( var (
hodlChan chan interface{} hodlChan <-chan interface{}
witnessUpdates <-chan lntypes.Preimage witnessUpdates <-chan lntypes.Preimage
) )
if payload.FwdInfo.NextHop == hop.Exit { if payload.FwdInfo.NextHop == hop.Exit {
// Create a buffered hodl chan to prevent deadlock. // Create a buffered hodl chan to prevent deadlock.
hodlChan = make(chan interface{}, 1) hodlQueue := queue.NewConcurrentQueue(10)
hodlQueue.Start()
hodlChan = hodlQueue.ChanOut()
// Notify registry that we are potentially resolving as an exit // Notify registry that we are potentially resolving as an exit
// hop on-chain. If this HTLC indeed pays to an existing // hop on-chain. If this HTLC indeed pays to an existing
@ -301,13 +305,17 @@ func (h *htlcIncomingContestResolver) Resolve() (ContractResolver, error) {
resolution, err := h.Registry.NotifyExitHopHtlc( resolution, err := h.Registry.NotifyExitHopHtlc(
h.htlc.RHash, h.htlc.Amt, h.htlcExpiry, currentHeight, h.htlc.RHash, h.htlc.Amt, h.htlcExpiry, currentHeight,
circuitKey, hodlChan, payload, circuitKey, hodlQueue.ChanIn(), payload,
) )
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer h.Registry.HodlUnsubscribeAll(hodlChan) defer func() {
h.Registry.HodlUnsubscribeAll(hodlQueue.ChanIn())
hodlQueue.Stop()
}()
// Take action based on the resolution we received. If the htlc // Take action based on the resolution we received. If the htlc
// was settled, or a htlc for a known invoice failed we can // was settled, or a htlc for a known invoice failed we can

View file

@ -79,6 +79,11 @@ fails](https://github.com/lightningnetwork/lnd/pull/7876).
* `lnd` [now properly handles a case where an erroneous force close attempt * `lnd` [now properly handles a case where an erroneous force close attempt
would impeded start up](https://github.com/lightningnetwork/lnd/pull/7985). would impeded start up](https://github.com/lightningnetwork/lnd/pull/7985).
* A bug that could cause the invoice related sub-system to lock up (potentially
the entire daemon) related to [incoming HTLCs going on chain related to a
hodl invoice has been
fixed](https://github.com/lightningnetwork/lnd/pull/8024).
# New Features # New Features
## Functional Enhancements ## Functional Enhancements