Skip to content

Commit 03de0f9

Browse files
committed
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.
1 parent 0dc10ba commit 03de0f9

File tree

3 files changed

+29
-51
lines changed

3 files changed

+29
-51
lines changed

funding/manager.go

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ type Config struct {
511511

512512
// NotifyOpenChannelEvent informs the ChannelNotifier when channels
513513
// transition from pending open to open.
514-
NotifyOpenChannelEvent func(wire.OutPoint, *btcec.PublicKey) error
514+
NotifyOpenChannelEvent func(wire.OutPoint, *btcec.PublicKey)
515515

516516
// OpenChannelPredicate is a predicate on the lnwire.OpenChannel message
517517
// and on the requesting node's public key that returns a bool which
@@ -521,13 +521,13 @@ type Config struct {
521521
// NotifyPendingOpenChannelEvent informs the ChannelNotifier when
522522
// channels enter a pending state.
523523
NotifyPendingOpenChannelEvent func(wire.OutPoint,
524-
*channeldb.OpenChannel, *btcec.PublicKey) error
524+
*channeldb.OpenChannel, *btcec.PublicKey)
525525

526526
// NotifyFundingTimeout informs the ChannelNotifier when a pending-open
527527
// channel times out because the funding transaction hasn't confirmed.
528528
// This is only called for the fundee and only if the channel is
529529
// zero-conf.
530-
NotifyFundingTimeout func(wire.OutPoint, *btcec.PublicKey) error
530+
NotifyFundingTimeout func(wire.OutPoint, *btcec.PublicKey)
531531

532532
// EnableUpfrontShutdown specifies whether the upfront shutdown script
533533
// is enabled.
@@ -1319,13 +1319,9 @@ func (f *Manager) advancePendingChannelState(channel *channeldb.OpenChannel,
13191319

13201320
// Inform the ChannelNotifier that the channel has transitioned
13211321
// from pending open to open.
1322-
if err := f.cfg.NotifyOpenChannelEvent(
1322+
f.cfg.NotifyOpenChannelEvent(
13231323
channel.FundingOutpoint, channel.IdentityPub,
1324-
); err != nil {
1325-
log.Errorf("Unable to notify open channel event for "+
1326-
"ChannelPoint(%v): %v",
1327-
channel.FundingOutpoint, err)
1328-
}
1324+
)
13291325

13301326
// Find and close the discoverySignal for this channel such
13311327
// that ChannelReady messages will be processed.
@@ -2666,12 +2662,9 @@ func (f *Manager) fundeeProcessFundingCreated(peer lnpeer.Peer,
26662662

26672663
// Inform the ChannelNotifier that the channel has entered
26682664
// pending open state.
2669-
if err := f.cfg.NotifyPendingOpenChannelEvent(
2665+
f.cfg.NotifyPendingOpenChannelEvent(
26702666
fundingOut, completeChan, completeChan.IdentityPub,
2671-
); err != nil {
2672-
log.Errorf("Unable to send pending-open channel event for "+
2673-
"ChannelPoint(%v) %v", fundingOut, err)
2674-
}
2667+
)
26752668

26762669
// At this point we have sent our last funding message to the
26772670
// initiating peer before the funding transaction will be broadcast.
@@ -2891,13 +2884,9 @@ func (f *Manager) funderProcessFundingSigned(peer lnpeer.Peer,
28912884
case resCtx.updates <- upd:
28922885
// Inform the ChannelNotifier that the channel has entered
28932886
// pending open state.
2894-
if err := f.cfg.NotifyPendingOpenChannelEvent(
2887+
f.cfg.NotifyPendingOpenChannelEvent(
28952888
*fundingPoint, completeChan, completeChan.IdentityPub,
2896-
); err != nil {
2897-
log.Errorf("Unable to send pending-open channel "+
2898-
"event for ChannelPoint(%v) %v", fundingPoint,
2899-
err)
2900-
}
2889+
)
29012890

29022891
case <-f.quit:
29032892
return
@@ -2955,11 +2944,7 @@ func (f *Manager) fundingTimeout(c *channeldb.OpenChannel,
29552944
}
29562945

29572946
// Notify other subsystems about the funding timeout.
2958-
err := f.cfg.NotifyFundingTimeout(c.FundingOutpoint, c.IdentityPub)
2959-
if err != nil {
2960-
log.Errorf("failed to notify of funding timeout for "+
2961-
"ChanPoint(%v): %v", c.FundingOutpoint, err)
2962-
}
2947+
f.cfg.NotifyFundingTimeout(c.FundingOutpoint, c.IdentityPub)
29632948

29642949
timeoutErr := fmt.Errorf("timeout waiting for funding tx (%v) to "+
29652950
"confirm", c.FundingOutpoint)
@@ -3341,13 +3326,9 @@ func (f *Manager) handleFundingConfirmation(
33413326

33423327
// Inform the ChannelNotifier that the channel has transitioned from
33433328
// pending open to open.
3344-
if err := f.cfg.NotifyOpenChannelEvent(
3329+
f.cfg.NotifyOpenChannelEvent(
33453330
completeChan.FundingOutpoint, completeChan.IdentityPub,
3346-
); err != nil {
3347-
log.Errorf("Unable to notify open channel event for "+
3348-
"ChannelPoint(%v): %v", completeChan.FundingOutpoint,
3349-
err)
3350-
}
3331+
)
33513332

33523333
// Close the discoverySignal channel, indicating to a separate
33533334
// goroutine that the channel now is marked as open in the database

funding/manager_test.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,29 +232,23 @@ type mockChanEvent struct {
232232
}
233233

234234
func (m *mockChanEvent) NotifyOpenChannelEvent(outpoint wire.OutPoint,
235-
remotePub *btcec.PublicKey) error {
235+
remotePub *btcec.PublicKey) {
236236

237237
m.openEvent <- outpoint
238-
239-
return nil
240238
}
241239

242240
func (m *mockChanEvent) NotifyPendingOpenChannelEvent(outpoint wire.OutPoint,
243241
pendingChannel *channeldb.OpenChannel,
244-
remotePub *btcec.PublicKey) error {
242+
remotePub *btcec.PublicKey) {
245243

246244
m.pendingOpenEvent <- channelnotifier.PendingOpenChannelEvent{
247245
ChannelPoint: &outpoint,
248246
PendingChannel: pendingChannel,
249247
}
250-
251-
return nil
252248
}
253249

254250
func (m *mockChanEvent) NotifyFundingTimeout(outpoint wire.OutPoint,
255-
remotePub *btcec.PublicKey) error {
256-
257-
return nil
251+
remotePub *btcec.PublicKey) {
258252
}
259253

260254
// mockZeroConfAcceptor always accepts the channel open request for zero-conf

server.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4279,43 +4279,48 @@ func (s *server) SubscribeCustomMessages() (*subscribe.Client, error) {
42794279
// notifyOpenChannelPeerEvent updates the access manager's maps and then calls
42804280
// the channelNotifier's NotifyOpenChannelEvent.
42814281
func (s *server) notifyOpenChannelPeerEvent(op wire.OutPoint,
4282-
remotePub *btcec.PublicKey) error {
4282+
remotePub *btcec.PublicKey) {
42834283

42844284
// Call newOpenChan to update the access manager's maps for this peer.
42854285
if err := s.peerAccessMan.newOpenChan(remotePub); err != nil {
4286-
return err
4286+
srvrLog.Errorf("Failed to update peer[%x] access status after "+
4287+
"channel[%v] open", remotePub.SerializeCompressed(), op)
42874288
}
42884289

42894290
// Notify subscribers about this open channel event.
42904291
s.channelNotifier.NotifyOpenChannelEvent(op)
4291-
4292-
return nil
42934292
}
42944293

42954294
// notifyPendingOpenChannelPeerEvent updates the access manager's maps and then
42964295
// calls the channelNotifier's NotifyPendingOpenChannelEvent.
42974296
func (s *server) notifyPendingOpenChannelPeerEvent(op wire.OutPoint,
4298-
pendingChan *channeldb.OpenChannel, remotePub *btcec.PublicKey) error {
4297+
pendingChan *channeldb.OpenChannel, remotePub *btcec.PublicKey) {
42994298

43004299
// Call newPendingOpenChan to update the access manager's maps for this
43014300
// peer.
43024301
if err := s.peerAccessMan.newPendingOpenChan(remotePub); err != nil {
4303-
return err
4302+
srvrLog.Errorf("Failed to update peer[%x] access status after "+
4303+
"channel[%v] pending open",
4304+
remotePub.SerializeCompressed(), op)
43044305
}
43054306

43064307
// Notify subscribers about this event.
43074308
s.channelNotifier.NotifyPendingOpenChannelEvent(op, pendingChan)
4308-
4309-
return nil
43104309
}
43114310

43124311
// notifyFundingTimeoutPeerEvent updates the access manager's maps and then
43134312
// calls the channelNotifier's NotifyFundingTimeout.
43144313
func (s *server) notifyFundingTimeoutPeerEvent(op wire.OutPoint,
4315-
remotePub *btcec.PublicKey) error {
4314+
remotePub *btcec.PublicKey) {
43164315

43174316
// Call newPendingCloseChan to potentially demote the peer.
43184317
err := s.peerAccessMan.newPendingCloseChan(remotePub)
4318+
if err != nil {
4319+
srvrLog.Errorf("Failed to update peer[%x] access status after "+
4320+
"channel[%v] pending close",
4321+
remotePub.SerializeCompressed(), op)
4322+
}
4323+
43194324
if errors.Is(err, ErrNoMoreRestrictedAccessSlots) {
43204325
// If we encounter an error while attempting to disconnect the
43214326
// peer, log the error.
@@ -4326,8 +4331,6 @@ func (s *server) notifyFundingTimeoutPeerEvent(op wire.OutPoint,
43264331

43274332
// Notify subscribers about this event.
43284333
s.channelNotifier.NotifyFundingTimeout(op)
4329-
4330-
return nil
43314334
}
43324335

43334336
// peerConnected is a function that handles initialization a newly connected

0 commit comments

Comments
 (0)