funding+lnd: make sure accessman won't interrupt funding flow

If there's an error occured when updating the peer's status after the
channel status is changed, we now make sure we log the error instead of
letting it interrupt the channel open/close flow.
This commit is contained in:
yyforyongyu
2025-06-17 22:46:37 +08:00
committed by Olaoluwa Osuntokun
parent 107b74d81d
commit a8d1985fd6
3 changed files with 29 additions and 51 deletions

View File

@@ -511,7 +511,7 @@ type Config struct {
// NotifyOpenChannelEvent informs the ChannelNotifier when channels
// transition from pending open to open.
NotifyOpenChannelEvent func(wire.OutPoint, *btcec.PublicKey) error
NotifyOpenChannelEvent func(wire.OutPoint, *btcec.PublicKey)
// OpenChannelPredicate is a predicate on the lnwire.OpenChannel message
// and on the requesting node's public key that returns a bool which
@@ -521,13 +521,13 @@ type Config struct {
// NotifyPendingOpenChannelEvent informs the ChannelNotifier when
// channels enter a pending state.
NotifyPendingOpenChannelEvent func(wire.OutPoint,
*channeldb.OpenChannel, *btcec.PublicKey) error
*channeldb.OpenChannel, *btcec.PublicKey)
// NotifyFundingTimeout informs the ChannelNotifier when a pending-open
// channel times out because the funding transaction hasn't confirmed.
// This is only called for the fundee and only if the channel is
// zero-conf.
NotifyFundingTimeout func(wire.OutPoint, *btcec.PublicKey) error
NotifyFundingTimeout func(wire.OutPoint, *btcec.PublicKey)
// EnableUpfrontShutdown specifies whether the upfront shutdown script
// is enabled.
@@ -1319,13 +1319,9 @@ func (f *Manager) advancePendingChannelState(channel *channeldb.OpenChannel,
// Inform the ChannelNotifier that the channel has transitioned
// from pending open to open.
if err := f.cfg.NotifyOpenChannelEvent(
f.cfg.NotifyOpenChannelEvent(
channel.FundingOutpoint, channel.IdentityPub,
); err != nil {
log.Errorf("Unable to notify open channel event for "+
"ChannelPoint(%v): %v",
channel.FundingOutpoint, err)
}
)
// Find and close the discoverySignal for this channel such
// that ChannelReady messages will be processed.
@@ -2666,12 +2662,9 @@ func (f *Manager) fundeeProcessFundingCreated(peer lnpeer.Peer,
// Inform the ChannelNotifier that the channel has entered
// pending open state.
if err := f.cfg.NotifyPendingOpenChannelEvent(
f.cfg.NotifyPendingOpenChannelEvent(
fundingOut, completeChan, completeChan.IdentityPub,
); err != nil {
log.Errorf("Unable to send pending-open channel event for "+
"ChannelPoint(%v) %v", fundingOut, err)
}
)
// At this point we have sent our last funding message to the
// initiating peer before the funding transaction will be broadcast.
@@ -2891,13 +2884,9 @@ func (f *Manager) funderProcessFundingSigned(peer lnpeer.Peer,
case resCtx.updates <- upd:
// Inform the ChannelNotifier that the channel has entered
// pending open state.
if err := f.cfg.NotifyPendingOpenChannelEvent(
f.cfg.NotifyPendingOpenChannelEvent(
*fundingPoint, completeChan, completeChan.IdentityPub,
); err != nil {
log.Errorf("Unable to send pending-open channel "+
"event for ChannelPoint(%v) %v", fundingPoint,
err)
}
)
case <-f.quit:
return
@@ -2955,11 +2944,7 @@ func (f *Manager) fundingTimeout(c *channeldb.OpenChannel,
}
// Notify other subsystems about the funding timeout.
err := f.cfg.NotifyFundingTimeout(c.FundingOutpoint, c.IdentityPub)
if err != nil {
log.Errorf("failed to notify of funding timeout for "+
"ChanPoint(%v): %v", c.FundingOutpoint, err)
}
f.cfg.NotifyFundingTimeout(c.FundingOutpoint, c.IdentityPub)
timeoutErr := fmt.Errorf("timeout waiting for funding tx (%v) to "+
"confirm", c.FundingOutpoint)
@@ -3341,13 +3326,9 @@ func (f *Manager) handleFundingConfirmation(
// Inform the ChannelNotifier that the channel has transitioned from
// pending open to open.
if err := f.cfg.NotifyOpenChannelEvent(
f.cfg.NotifyOpenChannelEvent(
completeChan.FundingOutpoint, completeChan.IdentityPub,
); err != nil {
log.Errorf("Unable to notify open channel event for "+
"ChannelPoint(%v): %v", completeChan.FundingOutpoint,
err)
}
)
// Close the discoverySignal channel, indicating to a separate
// goroutine that the channel now is marked as open in the database

View File

@@ -232,29 +232,23 @@ type mockChanEvent struct {
}
func (m *mockChanEvent) NotifyOpenChannelEvent(outpoint wire.OutPoint,
remotePub *btcec.PublicKey) error {
remotePub *btcec.PublicKey) {
m.openEvent <- outpoint
return nil
}
func (m *mockChanEvent) NotifyPendingOpenChannelEvent(outpoint wire.OutPoint,
pendingChannel *channeldb.OpenChannel,
remotePub *btcec.PublicKey) error {
remotePub *btcec.PublicKey) {
m.pendingOpenEvent <- channelnotifier.PendingOpenChannelEvent{
ChannelPoint: &outpoint,
PendingChannel: pendingChannel,
}
return nil
}
func (m *mockChanEvent) NotifyFundingTimeout(outpoint wire.OutPoint,
remotePub *btcec.PublicKey) error {
return nil
remotePub *btcec.PublicKey) {
}
// mockZeroConfAcceptor always accepts the channel open request for zero-conf

View File

@@ -4271,43 +4271,48 @@ func (s *server) SubscribeCustomMessages() (*subscribe.Client, error) {
// notifyOpenChannelPeerEvent updates the access manager's maps and then calls
// the channelNotifier's NotifyOpenChannelEvent.
func (s *server) notifyOpenChannelPeerEvent(op wire.OutPoint,
remotePub *btcec.PublicKey) error {
remotePub *btcec.PublicKey) {
// Call newOpenChan to update the access manager's maps for this peer.
if err := s.peerAccessMan.newOpenChan(remotePub); err != nil {
return err
srvrLog.Errorf("Failed to update peer[%x] access status after "+
"channel[%v] open", remotePub.SerializeCompressed(), op)
}
// Notify subscribers about this open channel event.
s.channelNotifier.NotifyOpenChannelEvent(op)
return nil
}
// notifyPendingOpenChannelPeerEvent updates the access manager's maps and then
// calls the channelNotifier's NotifyPendingOpenChannelEvent.
func (s *server) notifyPendingOpenChannelPeerEvent(op wire.OutPoint,
pendingChan *channeldb.OpenChannel, remotePub *btcec.PublicKey) error {
pendingChan *channeldb.OpenChannel, remotePub *btcec.PublicKey) {
// Call newPendingOpenChan to update the access manager's maps for this
// peer.
if err := s.peerAccessMan.newPendingOpenChan(remotePub); err != nil {
return err
srvrLog.Errorf("Failed to update peer[%x] access status after "+
"channel[%v] pending open",
remotePub.SerializeCompressed(), op)
}
// Notify subscribers about this event.
s.channelNotifier.NotifyPendingOpenChannelEvent(op, pendingChan)
return nil
}
// notifyFundingTimeoutPeerEvent updates the access manager's maps and then
// calls the channelNotifier's NotifyFundingTimeout.
func (s *server) notifyFundingTimeoutPeerEvent(op wire.OutPoint,
remotePub *btcec.PublicKey) error {
remotePub *btcec.PublicKey) {
// Call newPendingCloseChan to potentially demote the peer.
err := s.peerAccessMan.newPendingCloseChan(remotePub)
if err != nil {
srvrLog.Errorf("Failed to update peer[%x] access status after "+
"channel[%v] pending close",
remotePub.SerializeCompressed(), op)
}
if errors.Is(err, ErrNoMoreRestrictedAccessSlots) {
// If we encounter an error while attempting to disconnect the
// peer, log the error.
@@ -4318,8 +4323,6 @@ func (s *server) notifyFundingTimeoutPeerEvent(op wire.OutPoint,
// Notify subscribers about this event.
s.channelNotifier.NotifyFundingTimeout(op)
return nil
}
// peerConnected is a function that handles initialization a newly connected