@@ -3,6 +3,7 @@ package funding
3
3
import (
4
4
"bytes"
5
5
"encoding/binary"
6
+ "encoding/hex"
6
7
"fmt"
7
8
"io"
8
9
"sync"
@@ -510,7 +511,7 @@ type Config struct {
510
511
511
512
// NotifyOpenChannelEvent informs the ChannelNotifier when channels
512
513
// transition from pending open to open.
513
- NotifyOpenChannelEvent func (wire.OutPoint )
514
+ NotifyOpenChannelEvent func (wire.OutPoint , string ) error
514
515
515
516
// OpenChannelPredicate is a predicate on the lnwire.OpenChannel message
516
517
// and on the requesting node's public key that returns a bool which
@@ -520,7 +521,11 @@ type Config struct {
520
521
// NotifyPendingOpenChannelEvent informs the ChannelNotifier when
521
522
// channels enter a pending state.
522
523
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
524
529
525
530
// EnableUpfrontShutdown specifies whether the upfront shutdown script
526
531
// is enabled.
@@ -1312,7 +1317,14 @@ func (f *Manager) advancePendingChannelState(channel *channeldb.OpenChannel,
1312
1317
1313
1318
// Inform the ChannelNotifier that the channel has transitioned
1314
1319
// 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
+ }
1316
1328
1317
1329
// Find and close the discoverySignal for this channel such
1318
1330
// that ChannelReady messages will be processed.
@@ -2653,7 +2665,13 @@ func (f *Manager) fundeeProcessFundingCreated(peer lnpeer.Peer,
2653
2665
2654
2666
// Inform the ChannelNotifier that the channel has entered
2655
2667
// 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
+ }
2657
2675
2658
2676
// At this point we have sent our last funding message to the
2659
2677
// initiating peer before the funding transaction will be broadcast.
@@ -2873,7 +2891,15 @@ func (f *Manager) funderProcessFundingSigned(peer lnpeer.Peer,
2873
2891
case resCtx .updates <- upd :
2874
2892
// Inform the ChannelNotifier that the channel has entered
2875
2893
// 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
+
2877
2903
case <- f .quit :
2878
2904
return
2879
2905
}
@@ -2929,6 +2955,14 @@ func (f *Manager) fundingTimeout(c *channeldb.OpenChannel,
2929
2955
c .FundingOutpoint , err )
2930
2956
}
2931
2957
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
+
2932
2966
timeoutErr := fmt .Errorf ("timeout waiting for funding tx (%v) to " +
2933
2967
"confirm" , c .FundingOutpoint )
2934
2968
@@ -3297,7 +3331,14 @@ func (f *Manager) handleFundingConfirmation(
3297
3331
3298
3332
// Inform the ChannelNotifier that the channel has transitioned from
3299
3333
// 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
+ }
3301
3342
3302
3343
// Close the discoverySignal channel, indicating to a separate
3303
3344
// 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,
5374
5415
}
5375
5416
return peer , nil
5376
5417
}
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
+ }
0 commit comments