From 10b4ed6c2814765af15f288fec4a6c70c02a2585 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Wed, 23 Jul 2025 01:03:59 +0800 Subject: [PATCH] contractcourt: replace `MarkChannelClosed` with `NotifyChannelResolved` --- contractcourt/chain_arbitrator.go | 21 ++++++--------------- contractcourt/channel_arbitrator.go | 15 ++++----------- contractcourt/channel_arbitrator_test.go | 7 +++---- 3 files changed, 13 insertions(+), 30 deletions(-) diff --git a/contractcourt/chain_arbitrator.go b/contractcourt/chain_arbitrator.go index 02e28cb26..05eb46a68 100644 --- a/contractcourt/chain_arbitrator.go +++ b/contractcourt/chain_arbitrator.go @@ -465,6 +465,9 @@ func newActiveChannelArbitrator(channel *channeldb.OpenChannel, channel.ShortChanID(), htlc, ) }, + NotifyChannelResolved: func() { + c.notifyChannelResolved(chanPoint) + }, } // The final component needed is an arbitrator log that the arbitrator @@ -480,14 +483,6 @@ func newActiveChannelArbitrator(channel *channeldb.OpenChannel, return nil, err } - arbCfg.MarkChannelResolved = func() error { - if c.cfg.NotifyFullyResolvedChannel != nil { - c.cfg.NotifyFullyResolvedChannel(chanPoint) - } - - return c.ResolveContract(chanPoint) - } - // Finally, we'll need to construct a series of htlc Sets based on all // currently known valid commitments. htlcSets := make(map[HtlcSetKey]htlcSet) @@ -1399,6 +1394,9 @@ func (c *ChainArbitrator) loadPendingCloseChannels() error { closeChanInfo.ShortChanID, htlc, ) }, + NotifyChannelResolved: func() { + c.notifyChannelResolved(chanPoint) + }, } chanLog, err := newBoltArbitratorLog( c.chanSource.Backend, arbCfg, c.cfg.ChainHash, chanPoint, @@ -1406,13 +1404,6 @@ func (c *ChainArbitrator) loadPendingCloseChannels() error { if err != nil { return err } - arbCfg.MarkChannelResolved = func() error { - if c.cfg.NotifyFullyResolvedChannel != nil { - c.cfg.NotifyFullyResolvedChannel(chanPoint) - } - - return c.ResolveContract(chanPoint) - } // We create an empty map of HTLC's here since it's possible // that the channel is in StateDefault and updateActiveHTLCs is diff --git a/contractcourt/channel_arbitrator.go b/contractcourt/channel_arbitrator.go index feb4bf35f..ae2ffc8ab 100644 --- a/contractcourt/channel_arbitrator.go +++ b/contractcourt/channel_arbitrator.go @@ -153,13 +153,9 @@ type ChannelArbitratorConfig struct { // true. Otherwise this value is unset. CloseType channeldb.ClosureType - // MarkChannelResolved is a function closure that serves to mark a - // channel as "fully resolved". A channel itself can be considered - // fully resolved once all active contracts have individually been - // fully resolved. - // - // TODO(roasbeef): need RPC's to combine for pendingchannels RPC - MarkChannelResolved func() error + // NotifyChannelResolved is used by the channel arbitrator to signal + // that a given channel has been resolved. + NotifyChannelResolved func() // PutResolverReport records a resolver report for the channel. If the // transaction provided is nil, the function should write the report @@ -1397,10 +1393,7 @@ func (c *ChannelArbitrator) stateStep( log.Infof("ChannelPoint(%v) has been fully resolved "+ "on-chain at height=%v", c.cfg.ChanPoint, triggerHeight) - if err := c.cfg.MarkChannelResolved(); err != nil { - log.Errorf("unable to mark channel resolved: %v", err) - return StateError, closeTx, err - } + c.cfg.NotifyChannelResolved() } log.Tracef("ChannelArbitrator(%v): next_state=%v", c.cfg.ChanPoint, diff --git a/contractcourt/channel_arbitrator_test.go b/contractcourt/channel_arbitrator_test.go index 67a9a42e8..8f695c531 100644 --- a/contractcourt/channel_arbitrator_test.go +++ b/contractcourt/channel_arbitrator_test.go @@ -417,7 +417,7 @@ func createTestChannelArbitrator(t *testing.T, log ArbitratorLog, } // We'll use the resolvedChan to synchronize on call to - // MarkChannelResolved. + // NotifyChannelResolved. resolvedChan := make(chan struct{}, 1) // Next we'll create the matching configuration struct that contains @@ -425,9 +425,8 @@ func createTestChannelArbitrator(t *testing.T, log ArbitratorLog, arbCfg := &ChannelArbitratorConfig{ ChanPoint: chanPoint, ShortChanID: shortChanID, - MarkChannelResolved: func() error { + NotifyChannelResolved: func() { resolvedChan <- struct{}{} - return nil }, MarkCommitmentBroadcasted: func(_ *wire.MsgTx, _ lntypes.ChannelParty) error { @@ -547,7 +546,7 @@ func TestChannelArbitratorCooperativeClose(t *testing.T) { } // Cooperative close should do trigger a MarkChannelClosed + - // MarkChannelResolved. + // NotifyChannelResolved. closeInfo := &CooperativeCloseInfo{ &channeldb.ChannelCloseSummary{}, }