Skip to content

Commit 15e16ae

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 321685a commit 15e16ae

File tree

3 files changed

+71
-10
lines changed

3 files changed

+71
-10
lines changed

funding/manager.go

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package funding
33
import (
44
"bytes"
55
"encoding/binary"
6+
"encoding/hex"
67
"fmt"
78
"io"
89
"sync"
@@ -510,7 +511,7 @@ type Config struct {
510511

511512
// NotifyOpenChannelEvent informs the ChannelNotifier when channels
512513
// transition from pending open to open.
513-
NotifyOpenChannelEvent func(wire.OutPoint)
514+
NotifyOpenChannelEvent func(wire.OutPoint, string) error
514515

515516
// OpenChannelPredicate is a predicate on the lnwire.OpenChannel message
516517
// and on the requesting node's public key that returns a bool which
@@ -520,7 +521,11 @@ type Config struct {
520521
// NotifyPendingOpenChannelEvent informs the ChannelNotifier when
521522
// channels enter a pending state.
522523
NotifyPendingOpenChannelEvent func(wire.OutPoint,
523-
*channeldb.OpenChannel)
524+
*channeldb.OpenChannel, string) error
525+
526+
// NotifyFundingTimeout informs the ChannelNotifier when a pending-open
527+
// channel times out because the funding transaction hasn't confirmed.
528+
NotifyFundingTimeout func(wire.OutPoint, string) error
524529

525530
// EnableUpfrontShutdown specifies whether the upfront shutdown script
526531
// is enabled.
@@ -1312,7 +1317,14 @@ func (f *Manager) advancePendingChannelState(channel *channeldb.OpenChannel,
13121317

13131318
// Inform the ChannelNotifier that the channel has transitioned
13141319
// from pending open to open.
1315-
f.cfg.NotifyOpenChannelEvent(channel.FundingOutpoint)
1320+
remoteHex := remotePubHex(channel.IdentityPub)
1321+
if err := f.cfg.NotifyOpenChannelEvent(
1322+
channel.FundingOutpoint, remoteHex,
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,13 @@ 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+
remoteHex := remotePubHex(completeChan.IdentityPub)
2669+
if err := f.cfg.NotifyPendingOpenChannelEvent(
2670+
fundingOut, completeChan, remoteHex,
2671+
); err != nil {
2672+
log.Errorf("Unable to send pending-open channel event for "+
2673+
"ChannelPoint(%v) %v", fundingOut, err)
2674+
}
26572675

26582676
// At this point we have sent our last funding message to the
26592677
// initiating peer before the funding transaction will be broadcast.
@@ -2873,7 +2891,15 @@ func (f *Manager) funderProcessFundingSigned(peer lnpeer.Peer,
28732891
case resCtx.updates <- upd:
28742892
// Inform the ChannelNotifier that the channel has entered
28752893
// pending open state.
2876-
f.cfg.NotifyPendingOpenChannelEvent(*fundingPoint, completeChan)
2894+
remoteHex := remotePubHex(completeChan.IdentityPub)
2895+
if err := f.cfg.NotifyPendingOpenChannelEvent(
2896+
*fundingPoint, completeChan, remoteHex,
2897+
); err != nil {
2898+
log.Errorf("Unable to send pending-open channel "+
2899+
"event for ChannelPoint(%v) %v", fundingPoint,
2900+
err)
2901+
}
2902+
28772903
case <-f.quit:
28782904
return
28792905
}
@@ -2929,6 +2955,14 @@ func (f *Manager) fundingTimeout(c *channeldb.OpenChannel,
29292955
c.FundingOutpoint, err)
29302956
}
29312957

2958+
// Notify other subsystems about the funding timeout.
2959+
remoteHex := remotePubHex(c.IdentityPub)
2960+
err := f.cfg.NotifyFundingTimeout(c.FundingOutpoint, remoteHex)
2961+
if err != nil {
2962+
log.Errorf("failed to notify of funding timeout for "+
2963+
"ChanPoint(%v): %v", c.FundingOutpoint, err)
2964+
}
2965+
29322966
timeoutErr := fmt.Errorf("timeout waiting for funding tx (%v) to "+
29332967
"confirm", c.FundingOutpoint)
29342968

@@ -3297,7 +3331,14 @@ func (f *Manager) handleFundingConfirmation(
32973331

32983332
// Inform the ChannelNotifier that the channel has transitioned from
32993333
// pending open to open.
3300-
f.cfg.NotifyOpenChannelEvent(completeChan.FundingOutpoint)
3334+
remoteHex := remotePubHex(completeChan.IdentityPub)
3335+
if err := f.cfg.NotifyOpenChannelEvent(
3336+
completeChan.FundingOutpoint, remoteHex,
3337+
); err != nil {
3338+
log.Errorf("Unable to notify open channel event for "+
3339+
"ChannelPoint(%v): %v", completeChan.FundingOutpoint,
3340+
err)
3341+
}
33013342

33023343
// Close the discoverySignal channel, indicating to a separate
33033344
// goroutine that the channel now is marked as open in the database
@@ -5374,3 +5415,9 @@ func (f *Manager) waitForPeerOnline(peerPubkey *btcec.PublicKey) (lnpeer.Peer,
53745415
}
53755416
return peer, nil
53765417
}
5418+
5419+
// remotePubHex takes a *btcec.PublicKey and converts it to a hex-encoded
5420+
// string.
5421+
func remotePubHex(remotePub *btcec.PublicKey) string {
5422+
return hex.EncodeToString(remotePub.SerializeCompressed())
5423+
}

funding/manager_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,29 @@ 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+
remoteHex string) 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, remoteHex string) error {
240244

241245
m.pendingOpenEvent <- channelnotifier.PendingOpenChannelEvent{
242246
ChannelPoint: &outpoint,
243247
PendingChannel: pendingChannel,
244248
}
249+
250+
return nil
251+
}
252+
253+
func (m *mockChanEvent) NotifyFundingTimeout(outpoint wire.OutPoint,
254+
remoteHex string) error {
255+
256+
return nil
245257
}
246258

247259
// mockZeroConfAcceptor always accepts the channel open request for zero-conf
@@ -550,6 +562,7 @@ func createTestFundingManager(t *testing.T, privKey *btcec.PrivateKey,
550562
NotifyOpenChannelEvent: evt.NotifyOpenChannelEvent,
551563
OpenChannelPredicate: chainedAcceptor,
552564
NotifyPendingOpenChannelEvent: evt.NotifyPendingOpenChannelEvent,
565+
NotifyFundingTimeout: evt.NotifyFundingTimeout,
553566
DeleteAliasEdge: func(scid lnwire.ShortChannelID) (
554567
*models.ChannelEdgePolicy, error) {
555568

server.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,9 +1704,10 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
17041704
MaxPendingChannels: cfg.MaxPendingChannels,
17051705
RejectPush: cfg.RejectPush,
17061706
MaxLocalCSVDelay: chainCfg.MaxLocalDelay,
1707-
NotifyOpenChannelEvent: s.channelNotifier.NotifyOpenChannelEvent,
1707+
NotifyOpenChannelEvent: s.notifyOpenChannelPeerEvent,
17081708
OpenChannelPredicate: chanPredicate,
1709-
NotifyPendingOpenChannelEvent: s.channelNotifier.NotifyPendingOpenChannelEvent,
1709+
NotifyPendingOpenChannelEvent: s.notifyPendingOpenChannelPeerEvent,
1710+
NotifyFundingTimeout: s.notifyFundingTimeoutPeerEvent,
17101711
EnableUpfrontShutdown: cfg.EnableUpfrontShutdown,
17111712
MaxAnchorsCommitFeeRate: chainfee.SatPerKVByte(
17121713
s.cfg.MaxCommitFeeRateAnchors * 1000).FeePerKWeight(),

0 commit comments

Comments
 (0)