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:
3 files changed
+29
-51
No files matched your search
+12
-31
@@ -511,7 +511,7 @@ type Config struct {
|
|||||||
|
|
||||||
// NotifyOpenChannelEvent informs the ChannelNotifier when channels
|
// NotifyOpenChannelEvent informs the ChannelNotifier when channels
|
||||||
// transition from pending open to open.
|
// 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
|
// OpenChannelPredicate is a predicate on the lnwire.OpenChannel message
|
||||||
// and on the requesting node's public key that returns a bool which
|
// 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
|
// NotifyPendingOpenChannelEvent informs the ChannelNotifier when
|
||||||
// channels enter a pending state.
|
// channels enter a pending state.
|
||||||
NotifyPendingOpenChannelEvent func(wire.OutPoint,
|
NotifyPendingOpenChannelEvent func(wire.OutPoint,
|
||||||
*channeldb.OpenChannel, *btcec.PublicKey) error
|
*channeldb.OpenChannel, *btcec.PublicKey)
|
||||||
|
|
||||||
// NotifyFundingTimeout informs the ChannelNotifier when a pending-open
|
// NotifyFundingTimeout informs the ChannelNotifier when a pending-open
|
||||||
// channel times out because the funding transaction hasn't confirmed.
|
// channel times out because the funding transaction hasn't confirmed.
|
||||||
// This is only called for the fundee and only if the channel is
|
// This is only called for the fundee and only if the channel is
|
||||||
// zero-conf.
|
// zero-conf.
|
||||||
NotifyFundingTimeout func(wire.OutPoint, *btcec.PublicKey) error
|
NotifyFundingTimeout func(wire.OutPoint, *btcec.PublicKey)
|
||||||
|
|
||||||
// EnableUpfrontShutdown specifies whether the upfront shutdown script
|
// EnableUpfrontShutdown specifies whether the upfront shutdown script
|
||||||
// is enabled.
|
// is enabled.
|
||||||
@@ -1319,13 +1319,9 @@ func (f *Manager) advancePendingChannelState(channel *channeldb.OpenChannel,
|
|||||||
|
|
||||||
// Inform the ChannelNotifier that the channel has transitioned
|
// Inform the ChannelNotifier that the channel has transitioned
|
||||||
// from pending open to open.
|
// from pending open to open.
|
||||||
if err := f.cfg.NotifyOpenChannelEvent(
|
f.cfg.NotifyOpenChannelEvent(
|
||||||
channel.FundingOutpoint, channel.IdentityPub,
|
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
|
// Find and close the discoverySignal for this channel such
|
||||||
// that ChannelReady messages will be processed.
|
// 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
|
// Inform the ChannelNotifier that the channel has entered
|
||||||
// pending open state.
|
// pending open state.
|
||||||
if err := f.cfg.NotifyPendingOpenChannelEvent(
|
f.cfg.NotifyPendingOpenChannelEvent(
|
||||||
fundingOut, completeChan, completeChan.IdentityPub,
|
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
|
// At this point we have sent our last funding message to the
|
||||||
// initiating peer before the funding transaction will be broadcast.
|
// initiating peer before the funding transaction will be broadcast.
|
||||||
@@ -2891,13 +2884,9 @@ func (f *Manager) funderProcessFundingSigned(peer lnpeer.Peer,
|
|||||||
case resCtx.updates <- upd:
|
case resCtx.updates <- upd:
|
||||||
// Inform the ChannelNotifier that the channel has entered
|
// Inform the ChannelNotifier that the channel has entered
|
||||||
// pending open state.
|
// pending open state.
|
||||||
if err := f.cfg.NotifyPendingOpenChannelEvent(
|
f.cfg.NotifyPendingOpenChannelEvent(
|
||||||
*fundingPoint, completeChan, completeChan.IdentityPub,
|
*fundingPoint, completeChan, completeChan.IdentityPub,
|
||||||
); err != nil {
|
)
|
||||||
log.Errorf("Unable to send pending-open channel "+
|
|
||||||
"event for ChannelPoint(%v) %v", fundingPoint,
|
|
||||||
err)
|
|
||||||
}
|
|
||||||
|
|
||||||
case <-f.quit:
|
case <-f.quit:
|
||||||
return
|
return
|
||||||
@@ -2955,11 +2944,7 @@ func (f *Manager) fundingTimeout(c *channeldb.OpenChannel,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Notify other subsystems about the funding timeout.
|
// Notify other subsystems about the funding timeout.
|
||||||
err := f.cfg.NotifyFundingTimeout(c.FundingOutpoint, c.IdentityPub)
|
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
timeoutErr := fmt.Errorf("timeout waiting for funding tx (%v) to "+
|
timeoutErr := fmt.Errorf("timeout waiting for funding tx (%v) to "+
|
||||||
"confirm", c.FundingOutpoint)
|
"confirm", c.FundingOutpoint)
|
||||||
@@ -3341,13 +3326,9 @@ func (f *Manager) handleFundingConfirmation(
|
|||||||
|
|
||||||
// Inform the ChannelNotifier that the channel has transitioned from
|
// Inform the ChannelNotifier that the channel has transitioned from
|
||||||
// pending open to open.
|
// pending open to open.
|
||||||
if err := f.cfg.NotifyOpenChannelEvent(
|
f.cfg.NotifyOpenChannelEvent(
|
||||||
completeChan.FundingOutpoint, completeChan.IdentityPub,
|
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
|
// Close the discoverySignal channel, indicating to a separate
|
||||||
// goroutine that the channel now is marked as open in the database
|
// goroutine that the channel now is marked as open in the database
|
||||||
|
|||||||
@@ -232,29 +232,23 @@ type mockChanEvent struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockChanEvent) NotifyOpenChannelEvent(outpoint wire.OutPoint,
|
func (m *mockChanEvent) NotifyOpenChannelEvent(outpoint wire.OutPoint,
|
||||||
remotePub *btcec.PublicKey) error {
|
remotePub *btcec.PublicKey) {
|
||||||
|
|
||||||
m.openEvent <- outpoint
|
m.openEvent <- outpoint
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockChanEvent) NotifyPendingOpenChannelEvent(outpoint wire.OutPoint,
|
func (m *mockChanEvent) NotifyPendingOpenChannelEvent(outpoint wire.OutPoint,
|
||||||
pendingChannel *channeldb.OpenChannel,
|
pendingChannel *channeldb.OpenChannel,
|
||||||
remotePub *btcec.PublicKey) error {
|
remotePub *btcec.PublicKey) {
|
||||||
|
|
||||||
m.pendingOpenEvent <- channelnotifier.PendingOpenChannelEvent{
|
m.pendingOpenEvent <- channelnotifier.PendingOpenChannelEvent{
|
||||||
ChannelPoint: &outpoint,
|
ChannelPoint: &outpoint,
|
||||||
PendingChannel: pendingChannel,
|
PendingChannel: pendingChannel,
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockChanEvent) NotifyFundingTimeout(outpoint wire.OutPoint,
|
func (m *mockChanEvent) NotifyFundingTimeout(outpoint wire.OutPoint,
|
||||||
remotePub *btcec.PublicKey) error {
|
remotePub *btcec.PublicKey) {
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// mockZeroConfAcceptor always accepts the channel open request for zero-conf
|
// mockZeroConfAcceptor always accepts the channel open request for zero-conf
|
||||||
|
|||||||
@@ -4279,43 +4279,48 @@ func (s *server) SubscribeCustomMessages() (*subscribe.Client, error) {
|
|||||||
// notifyOpenChannelPeerEvent updates the access manager's maps and then calls
|
// notifyOpenChannelPeerEvent updates the access manager's maps and then calls
|
||||||
// the channelNotifier's NotifyOpenChannelEvent.
|
// the channelNotifier's NotifyOpenChannelEvent.
|
||||||
func (s *server) notifyOpenChannelPeerEvent(op wire.OutPoint,
|
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.
|
// Call newOpenChan to update the access manager's maps for this peer.
|
||||||
if err := s.peerAccessMan.newOpenChan(remotePub); err != nil {
|
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.
|
// Notify subscribers about this open channel event.
|
||||||
s.channelNotifier.NotifyOpenChannelEvent(op)
|
s.channelNotifier.NotifyOpenChannelEvent(op)
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// notifyPendingOpenChannelPeerEvent updates the access manager's maps and then
|
// notifyPendingOpenChannelPeerEvent updates the access manager's maps and then
|
||||||
// calls the channelNotifier's NotifyPendingOpenChannelEvent.
|
// calls the channelNotifier's NotifyPendingOpenChannelEvent.
|
||||||
func (s *server) notifyPendingOpenChannelPeerEvent(op wire.OutPoint,
|
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
|
// Call newPendingOpenChan to update the access manager's maps for this
|
||||||
// peer.
|
// peer.
|
||||||
if err := s.peerAccessMan.newPendingOpenChan(remotePub); err != nil {
|
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.
|
// Notify subscribers about this event.
|
||||||
s.channelNotifier.NotifyPendingOpenChannelEvent(op, pendingChan)
|
s.channelNotifier.NotifyPendingOpenChannelEvent(op, pendingChan)
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// notifyFundingTimeoutPeerEvent updates the access manager's maps and then
|
// notifyFundingTimeoutPeerEvent updates the access manager's maps and then
|
||||||
// calls the channelNotifier's NotifyFundingTimeout.
|
// calls the channelNotifier's NotifyFundingTimeout.
|
||||||
func (s *server) notifyFundingTimeoutPeerEvent(op wire.OutPoint,
|
func (s *server) notifyFundingTimeoutPeerEvent(op wire.OutPoint,
|
||||||
remotePub *btcec.PublicKey) error {
|
remotePub *btcec.PublicKey) {
|
||||||
|
|
||||||
// Call newPendingCloseChan to potentially demote the peer.
|
// Call newPendingCloseChan to potentially demote the peer.
|
||||||
err := s.peerAccessMan.newPendingCloseChan(remotePub)
|
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 errors.Is(err, ErrNoMoreRestrictedAccessSlots) {
|
||||||
// If we encounter an error while attempting to disconnect the
|
// If we encounter an error while attempting to disconnect the
|
||||||
// peer, log the error.
|
// peer, log the error.
|
||||||
@@ -4326,8 +4331,6 @@ func (s *server) notifyFundingTimeoutPeerEvent(op wire.OutPoint,
|
|||||||
|
|
||||||
// Notify subscribers about this event.
|
// Notify subscribers about this event.
|
||||||
s.channelNotifier.NotifyFundingTimeout(op)
|
s.channelNotifier.NotifyFundingTimeout(op)
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// peerConnected is a function that handles initialization a newly connected
|
// peerConnected is a function that handles initialization a newly connected
|
||||||
|
|||||||
Reference in new issue
Block a user