Skip to content

Commit 68ec766

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 6eb746f commit 68ec766

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
@@ -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)
514+
NotifyOpenChannelEvent func(wire.OutPoint, *btcec.PublicKey) error
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,7 +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)
524+
*channeldb.OpenChannel, *btcec.PublicKey) error
525+
526+
// NotifyFundingTimeout informs the ChannelNotifier when a pending-open
527+
// channel times out because the funding transaction hasn't confirmed.
528+
// This is only called for the fundee and only if the channel is
529+
// zero-conf.
530+
NotifyFundingTimeout func(wire.OutPoint, *btcec.PublicKey) error
525531

526532
// EnableUpfrontShutdown specifies whether the upfront shutdown script
527533
// is enabled.
@@ -1313,7 +1319,13 @@ func (f *Manager) advancePendingChannelState(channel *channeldb.OpenChannel,
13131319

13141320
// Inform the ChannelNotifier that the channel has transitioned
13151321
// from pending open to open.
1316-
f.cfg.NotifyOpenChannelEvent(channel.FundingOutpoint)
1322+
if err := f.cfg.NotifyOpenChannelEvent(
1323+
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+
}
13171329

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

26552667
// Inform the ChannelNotifier that the channel has entered
26562668
// pending open state.
2657-
f.cfg.NotifyPendingOpenChannelEvent(fundingOut, completeChan)
2669+
if err := f.cfg.NotifyPendingOpenChannelEvent(
2670+
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+
}
26582675

26592676
// At this point we have sent our last funding message to the
26602677
// initiating peer before the funding transaction will be broadcast.
@@ -2874,7 +2891,14 @@ func (f *Manager) funderProcessFundingSigned(peer lnpeer.Peer,
28742891
case resCtx.updates <- upd:
28752892
// Inform the ChannelNotifier that the channel has entered
28762893
// pending open state.
2877-
f.cfg.NotifyPendingOpenChannelEvent(*fundingPoint, completeChan)
2894+
if err := f.cfg.NotifyPendingOpenChannelEvent(
2895+
*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+
}
2901+
28782902
case <-f.quit:
28792903
return
28802904
}
@@ -2930,6 +2954,13 @@ func (f *Manager) fundingTimeout(c *channeldb.OpenChannel,
29302954
c.FundingOutpoint, err)
29312955
}
29322956

2957+
// 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+
}
2963+
29332964
timeoutErr := fmt.Errorf("timeout waiting for funding tx (%v) to "+
29342965
"confirm", c.FundingOutpoint)
29352966

@@ -3310,7 +3341,13 @@ func (f *Manager) handleFundingConfirmation(
33103341

33113342
// Inform the ChannelNotifier that the channel has transitioned from
33123343
// pending open to open.
3313-
f.cfg.NotifyOpenChannelEvent(completeChan.FundingOutpoint)
3344+
if err := f.cfg.NotifyOpenChannelEvent(
3345+
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+
}
33143351

33153352
// Close the discoverySignal channel, indicating to a separate
33163353
// 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
@@ -1681,9 +1681,10 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
16811681
MaxPendingChannels: cfg.MaxPendingChannels,
16821682
RejectPush: cfg.RejectPush,
16831683
MaxLocalCSVDelay: chainCfg.MaxLocalDelay,
1684-
NotifyOpenChannelEvent: s.channelNotifier.NotifyOpenChannelEvent,
1684+
NotifyOpenChannelEvent: s.notifyOpenChannelPeerEvent,
16851685
OpenChannelPredicate: chanPredicate,
1686-
NotifyPendingOpenChannelEvent: s.channelNotifier.NotifyPendingOpenChannelEvent,
1686+
NotifyPendingOpenChannelEvent: s.notifyPendingOpenChannelPeerEvent,
1687+
NotifyFundingTimeout: s.notifyFundingTimeoutPeerEvent,
16871688
EnableUpfrontShutdown: cfg.EnableUpfrontShutdown,
16881689
MaxAnchorsCommitFeeRate: chainfee.SatPerKVByte(
16891690
s.cfg.MaxCommitFeeRateAnchors * 1000).FeePerKWeight(),

0 commit comments

Comments
 (0)