contractcourt: replace MarkChannelClosed with NotifyChannelResolved

This commit is contained in:
yyforyongyu committed 2025-07-25 17:13:43 +08:00
1 parent d3501197be
commit 10b4ed6c28
3 files changed
+13 -30

No files matched your search

+6 -15
View File
@@ -465,6 +465,9 @@ func newActiveChannelArbitrator(channel *channeldb.OpenChannel,
channel.ShortChanID(), htlc, channel.ShortChanID(), htlc,
) )
}, },
NotifyChannelResolved: func() {
c.notifyChannelResolved(chanPoint)
},
} }
// The final component needed is an arbitrator log that the arbitrator // The final component needed is an arbitrator log that the arbitrator
@@ -480,14 +483,6 @@ func newActiveChannelArbitrator(channel *channeldb.OpenChannel,
return nil, err 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 // Finally, we'll need to construct a series of htlc Sets based on all
// currently known valid commitments. // currently known valid commitments.
htlcSets := make(map[HtlcSetKey]htlcSet) htlcSets := make(map[HtlcSetKey]htlcSet)
@@ -1399,6 +1394,9 @@ func (c *ChainArbitrator) loadPendingCloseChannels() error {
closeChanInfo.ShortChanID, htlc, closeChanInfo.ShortChanID, htlc,
) )
}, },
NotifyChannelResolved: func() {
c.notifyChannelResolved(chanPoint)
},
} }
chanLog, err := newBoltArbitratorLog( chanLog, err := newBoltArbitratorLog(
c.chanSource.Backend, arbCfg, c.cfg.ChainHash, chanPoint, c.chanSource.Backend, arbCfg, c.cfg.ChainHash, chanPoint,
@@ -1406,13 +1404,6 @@ func (c *ChainArbitrator) loadPendingCloseChannels() error {
if err != nil { if err != nil {
return err 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 // We create an empty map of HTLC's here since it's possible
// that the channel is in StateDefault and updateActiveHTLCs is // that the channel is in StateDefault and updateActiveHTLCs is
+4 -11
View File
@@ -153,13 +153,9 @@ type ChannelArbitratorConfig struct {
// true. Otherwise this value is unset. // true. Otherwise this value is unset.
CloseType channeldb.ClosureType CloseType channeldb.ClosureType
// MarkChannelResolved is a function closure that serves to mark a // NotifyChannelResolved is used by the channel arbitrator to signal
// channel as "fully resolved". A channel itself can be considered // that a given channel has been resolved.
// fully resolved once all active contracts have individually been NotifyChannelResolved func()
// fully resolved.
//
// TODO(roasbeef): need RPC's to combine for pendingchannels RPC
MarkChannelResolved func() error
// PutResolverReport records a resolver report for the channel. If the // PutResolverReport records a resolver report for the channel. If the
// transaction provided is nil, the function should write the report // 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 "+ log.Infof("ChannelPoint(%v) has been fully resolved "+
"on-chain at height=%v", c.cfg.ChanPoint, triggerHeight) "on-chain at height=%v", c.cfg.ChanPoint, triggerHeight)
if err := c.cfg.MarkChannelResolved(); err != nil { c.cfg.NotifyChannelResolved()
log.Errorf("unable to mark channel resolved: %v", err)
return StateError, closeTx, err
}
} }
log.Tracef("ChannelArbitrator(%v): next_state=%v", c.cfg.ChanPoint, log.Tracef("ChannelArbitrator(%v): next_state=%v", c.cfg.ChanPoint,
+3 -4
View File
@@ -417,7 +417,7 @@ func createTestChannelArbitrator(t *testing.T, log ArbitratorLog,
} }
// We'll use the resolvedChan to synchronize on call to // We'll use the resolvedChan to synchronize on call to
// MarkChannelResolved. // NotifyChannelResolved.
resolvedChan := make(chan struct{}, 1) resolvedChan := make(chan struct{}, 1)
// Next we'll create the matching configuration struct that contains // Next we'll create the matching configuration struct that contains
@@ -425,9 +425,8 @@ func createTestChannelArbitrator(t *testing.T, log ArbitratorLog,
arbCfg := &ChannelArbitratorConfig{ arbCfg := &ChannelArbitratorConfig{
ChanPoint: chanPoint, ChanPoint: chanPoint,
ShortChanID: shortChanID, ShortChanID: shortChanID,
MarkChannelResolved: func() error { NotifyChannelResolved: func() {
resolvedChan <- struct{}{} resolvedChan <- struct{}{}
return nil
}, },
MarkCommitmentBroadcasted: func(_ *wire.MsgTx, MarkCommitmentBroadcasted: func(_ *wire.MsgTx,
_ lntypes.ChannelParty) error { _ lntypes.ChannelParty) error {
@@ -547,7 +546,7 @@ func TestChannelArbitratorCooperativeClose(t *testing.T) {
} }
// Cooperative close should do trigger a MarkChannelClosed + // Cooperative close should do trigger a MarkChannelClosed +
// MarkChannelResolved. // NotifyChannelResolved.
closeInfo := &CooperativeCloseInfo{ closeInfo := &CooperativeCloseInfo{
&channeldb.ChannelCloseSummary{}, &channeldb.ChannelCloseSummary{},
} }