Skip to content

Commit f61b4a1

Browse files
committed
funding+server.go: modify notifications to pass through server
This modifies the various channelnotifier notification functions to instead hit the server and then call the notification routine. This allows us to accurately modify the server's maps.
1 parent 4e70a5d commit f61b4a1

File tree

3 files changed

+62
-10
lines changed

3 files changed

+62
-10
lines changed

funding/manager.go

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ type Config struct {
510510

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

515515
// OpenChannelPredicate is a predicate on the lnwire.OpenChannel message
516516
// and on the requesting node's public key that returns a bool which
@@ -520,7 +520,13 @@ type Config struct {
520520
// NotifyPendingOpenChannelEvent informs the ChannelNotifier when
521521
// channels enter a pending state.
522522
NotifyPendingOpenChannelEvent func(wire.OutPoint,
523-
*channeldb.OpenChannel)
523+
*channeldb.OpenChannel, *btcec.PublicKey) error
524+
525+
// NotifyFundingTimeout informs the ChannelNotifier when a pending-open
526+
// channel times out because the funding transaction hasn't confirmed.
527+
// This is only called for the fundee and only if the channel is
528+
// zero-conf.
529+
NotifyFundingTimeout func(wire.OutPoint, *btcec.PublicKey) error
524530

525531
// EnableUpfrontShutdown specifies whether the upfront shutdown script
526532
// is enabled.
@@ -1312,7 +1318,13 @@ func (f *Manager) advancePendingChannelState(channel *channeldb.OpenChannel,
13121318

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

13171329
// Find and close the discoverySignal for this channel such
13181330
// that ChannelReady messages will be processed.
@@ -2653,7 +2665,12 @@ func (f *Manager) fundeeProcessFundingCreated(peer lnpeer.Peer,
26532665

26542666
// Inform the ChannelNotifier that the channel has entered
26552667
// pending open state.
2656-
f.cfg.NotifyPendingOpenChannelEvent(fundingOut, completeChan)
2668+
if err := f.cfg.NotifyPendingOpenChannelEvent(
2669+
fundingOut, completeChan, completeChan.IdentityPub,
2670+
); err != nil {
2671+
log.Errorf("Unable to send pending-open channel event for "+
2672+
"ChannelPoint(%v) %v", fundingOut, err)
2673+
}
26572674

26582675
// At this point we have sent our last funding message to the
26592676
// initiating peer before the funding transaction will be broadcast.
@@ -2873,7 +2890,14 @@ func (f *Manager) funderProcessFundingSigned(peer lnpeer.Peer,
28732890
case resCtx.updates <- upd:
28742891
// Inform the ChannelNotifier that the channel has entered
28752892
// pending open state.
2876-
f.cfg.NotifyPendingOpenChannelEvent(*fundingPoint, completeChan)
2893+
if err := f.cfg.NotifyPendingOpenChannelEvent(
2894+
*fundingPoint, completeChan, completeChan.IdentityPub,
2895+
); err != nil {
2896+
log.Errorf("Unable to send pending-open channel "+
2897+
"event for ChannelPoint(%v) %v", fundingPoint,
2898+
err)
2899+
}
2900+
28772901
case <-f.quit:
28782902
return
28792903
}
@@ -2929,6 +2953,13 @@ func (f *Manager) fundingTimeout(c *channeldb.OpenChannel,
29292953
c.FundingOutpoint, err)
29302954
}
29312955

2956+
// Notify other subsystems about the funding timeout.
2957+
err := f.cfg.NotifyFundingTimeout(c.FundingOutpoint, c.IdentityPub)
2958+
if err != nil {
2959+
log.Errorf("failed to notify of funding timeout for "+
2960+
"ChanPoint(%v): %v", c.FundingOutpoint, err)
2961+
}
2962+
29322963
timeoutErr := fmt.Errorf("timeout waiting for funding tx (%v) to "+
29332964
"confirm", c.FundingOutpoint)
29342965

@@ -3297,7 +3328,13 @@ func (f *Manager) handleFundingConfirmation(
32973328

32983329
// Inform the ChannelNotifier that the channel has transitioned from
32993330
// pending open to open.
3300-
f.cfg.NotifyOpenChannelEvent(completeChan.FundingOutpoint)
3331+
if err := f.cfg.NotifyOpenChannelEvent(
3332+
completeChan.FundingOutpoint, completeChan.IdentityPub,
3333+
); err != nil {
3334+
log.Errorf("Unable to notify open channel event for "+
3335+
"ChannelPoint(%v): %v", completeChan.FundingOutpoint,
3336+
err)
3337+
}
33013338

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

funding/manager_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,30 @@ type mockChanEvent struct {
231231
pendingOpenEvent chan channelnotifier.PendingOpenChannelEvent
232232
}
233233

234-
func (m *mockChanEvent) NotifyOpenChannelEvent(outpoint wire.OutPoint) {
234+
func (m *mockChanEvent) NotifyOpenChannelEvent(outpoint wire.OutPoint,
235+
remotePub *btcec.PublicKey) error {
236+
235237
m.openEvent <- outpoint
238+
239+
return nil
236240
}
237241

238242
func (m *mockChanEvent) NotifyPendingOpenChannelEvent(outpoint wire.OutPoint,
239-
pendingChannel *channeldb.OpenChannel) {
243+
pendingChannel *channeldb.OpenChannel,
244+
remotePub *btcec.PublicKey) error {
240245

241246
m.pendingOpenEvent <- channelnotifier.PendingOpenChannelEvent{
242247
ChannelPoint: &outpoint,
243248
PendingChannel: pendingChannel,
244249
}
250+
251+
return nil
252+
}
253+
254+
func (m *mockChanEvent) NotifyFundingTimeout(outpoint wire.OutPoint,
255+
remotePub *btcec.PublicKey) error {
256+
257+
return nil
245258
}
246259

247260
// mockZeroConfAcceptor always accepts the channel open request for zero-conf
@@ -550,6 +563,7 @@ func createTestFundingManager(t *testing.T, privKey *btcec.PrivateKey,
550563
NotifyOpenChannelEvent: evt.NotifyOpenChannelEvent,
551564
OpenChannelPredicate: chainedAcceptor,
552565
NotifyPendingOpenChannelEvent: evt.NotifyPendingOpenChannelEvent,
566+
NotifyFundingTimeout: evt.NotifyFundingTimeout,
553567
DeleteAliasEdge: func(scid lnwire.ShortChannelID) (
554568
*models.ChannelEdgePolicy, error) {
555569

server.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,9 +1679,10 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
16791679
MaxPendingChannels: cfg.MaxPendingChannels,
16801680
RejectPush: cfg.RejectPush,
16811681
MaxLocalCSVDelay: chainCfg.MaxLocalDelay,
1682-
NotifyOpenChannelEvent: s.channelNotifier.NotifyOpenChannelEvent,
1682+
NotifyOpenChannelEvent: s.notifyOpenChannelPeerEvent,
16831683
OpenChannelPredicate: chanPredicate,
1684-
NotifyPendingOpenChannelEvent: s.channelNotifier.NotifyPendingOpenChannelEvent,
1684+
NotifyPendingOpenChannelEvent: s.notifyPendingOpenChannelPeerEvent,
1685+
NotifyFundingTimeout: s.notifyFundingTimeoutPeerEvent,
16851686
EnableUpfrontShutdown: cfg.EnableUpfrontShutdown,
16861687
MaxAnchorsCommitFeeRate: chainfee.SatPerKVByte(
16871688
s.cfg.MaxCommitFeeRateAnchors * 1000).FeePerKWeight(),

0 commit comments

Comments
 (0)