From fd772d45b85ed56fa67bf3ef09dbb55e9c18d173 Mon Sep 17 00:00:00 2001 From: George Tsagkarelis Date: Mon, 13 Oct 2025 15:10:41 +0200 Subject: [PATCH] contractcourt: add aux chan closer to chain watcher --- contractcourt/chain_arbitrator.go | 6 ++++++ contractcourt/chain_watcher.go | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/contractcourt/chain_arbitrator.go b/contractcourt/chain_arbitrator.go index 05eb46a68..2e5f54258 100644 --- a/contractcourt/chain_arbitrator.go +++ b/contractcourt/chain_arbitrator.go @@ -230,6 +230,10 @@ type ChainArbitratorConfig struct { // AuxResolver is an optional interface that can be used to modify the // way contracts are resolved. AuxResolver fn.Option[lnwallet.AuxContractResolver] + + // AuxCloser is an optional interface that can be used to finalize + // cooperative channel closes. + AuxCloser fn.Option[AuxChanCloser] } // ChainArbitrator is a sub-system that oversees the on-chain resolution of all @@ -1138,6 +1142,7 @@ func (c *ChainArbitrator) WatchNewChannel(newChan *channeldb.OpenChannel) error extractStateNumHint: lnwallet.GetStateNumHint, auxLeafStore: c.cfg.AuxLeafStore, auxResolver: c.cfg.AuxResolver, + auxCloser: c.cfg.AuxCloser, }, ) if err != nil { @@ -1315,6 +1320,7 @@ func (c *ChainArbitrator) loadOpenChannels() error { extractStateNumHint: lnwallet.GetStateNumHint, auxLeafStore: c.cfg.AuxLeafStore, auxResolver: c.cfg.AuxResolver, + auxCloser: c.cfg.AuxCloser, }, ) if err != nil { diff --git a/contractcourt/chain_watcher.go b/contractcourt/chain_watcher.go index 082b47228..6f33c0fb6 100644 --- a/contractcourt/chain_watcher.go +++ b/contractcourt/chain_watcher.go @@ -24,6 +24,7 @@ import ( "github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lnutils" "github.com/lightningnetwork/lnd/lnwallet" + "github.com/lightningnetwork/lnd/lnwallet/types" "github.com/lightningnetwork/lnd/lnwire" ) @@ -37,6 +38,14 @@ const ( maxCommitPointPollTimeout = 10 * time.Minute ) +// AuxChanCloser is used to allow an external caller to finalize a cooperative +// channel close. +type AuxChanCloser interface { + // FinalizeClose is called after the close transaction has been agreed + // upon and confirmed. + FinalizeClose(desc types.AuxCloseDesc, closeTx *wire.MsgTx) error +} + // LocalUnilateralCloseInfo encapsulates all the information we need to act on // a local force close that gets confirmed. type LocalUnilateralCloseInfo struct { @@ -229,6 +238,9 @@ type chainWatcherConfig struct { // auxResolver is used to supplement contract resolution. auxResolver fn.Option[lnwallet.AuxContractResolver] + + // auxCloser is used to finalize cooperative closes. + auxCloser fn.Option[AuxChanCloser] } // chainWatcher is a system that's assigned to every active channel. The duty