@@ -22,6 +22,7 @@ import (
22
22
"github.com/lightningnetwork/lnd/htlcswitch"
23
23
"github.com/lightningnetwork/lnd/input"
24
24
"github.com/lightningnetwork/lnd/keychain"
25
+ "github.com/lightningnetwork/lnd/labels"
25
26
"github.com/lightningnetwork/lnd/lnpeer"
26
27
"github.com/lightningnetwork/lnd/lnrpc"
27
28
"github.com/lightningnetwork/lnd/lnwallet"
@@ -243,6 +244,10 @@ type fundingConfig struct {
243
244
// transaction to the network.
244
245
PublishTransaction func (* wire.MsgTx , string ) error
245
246
247
+ // UpdateLabel updates the label that a transaction has in our wallet,
248
+ // overwriting any existing labels.
249
+ UpdateLabel func (chainhash.Hash , string ) error
250
+
246
251
// FeeEstimator calculates appropriate fee rates based on historical
247
252
// transaction information.
248
253
FeeEstimator chainfee.Estimator
@@ -576,8 +581,15 @@ func (f *fundingManager) start() error {
576
581
channel .FundingOutpoint ,
577
582
fundingTxBuf .Bytes ())
578
583
584
+ // Set a nil short channel ID at this stage
585
+ // because we do not know it until our funding
586
+ // tx confirms.
587
+ label := labels .MakeLabel (
588
+ labels .LabelTypeChannelOpen , nil ,
589
+ )
590
+
579
591
err = f .cfg .PublishTransaction (
580
- channel .FundingTxn , "" ,
592
+ channel .FundingTxn , label ,
581
593
)
582
594
if err != nil {
583
595
fndgLog .Errorf ("Unable to rebroadcast " +
@@ -2032,7 +2044,13 @@ func (f *fundingManager) handleFundingSigned(fmsg *fundingSignedMsg) {
2032
2044
fndgLog .Infof ("Broadcasting funding tx for ChannelPoint(%v): %x" ,
2033
2045
completeChan .FundingOutpoint , fundingTxBuf .Bytes ())
2034
2046
2035
- err = f .cfg .PublishTransaction (fundingTx , "" )
2047
+ // Set a nil short channel ID at this stage because we do not
2048
+ // know it until our funding tx confirms.
2049
+ label := labels .MakeLabel (
2050
+ labels .LabelTypeChannelOpen , nil ,
2051
+ )
2052
+
2053
+ err = f .cfg .PublishTransaction (fundingTx , label )
2036
2054
if err != nil {
2037
2055
fndgLog .Errorf ("Unable to broadcast funding tx %x for " +
2038
2056
"ChannelPoint(%v): %v" , fundingTxBuf .Bytes (),
@@ -2372,6 +2390,25 @@ func (f *fundingManager) handleFundingConfirmation(
2372
2390
fndgLog .Errorf ("unable to report short chan id: %v" , err )
2373
2391
}
2374
2392
2393
+ // If we opened the channel, and lnd's wallet published our funding tx
2394
+ // (which is not the case for some channels) then we update our
2395
+ // transaction label with our short channel ID, which is known now that
2396
+ // our funding transaction has confirmed. We do not label transactions
2397
+ // we did not publish, because our wallet has no knowledge of them.
2398
+ if completeChan .IsInitiator && completeChan .ChanType .HasFundingTx () {
2399
+ shortChanID := completeChan .ShortChanID ()
2400
+ label := labels .MakeLabel (
2401
+ labels .LabelTypeChannelOpen , & shortChanID ,
2402
+ )
2403
+
2404
+ err = f .cfg .UpdateLabel (
2405
+ completeChan .FundingOutpoint .Hash , label ,
2406
+ )
2407
+ if err != nil {
2408
+ fndgLog .Errorf ("unable to update label: %v" , err )
2409
+ }
2410
+ }
2411
+
2375
2412
// Close the discoverySignal channel, indicating to a separate
2376
2413
// goroutine that the channel now is marked as open in the database
2377
2414
// and that it is acceptable to process funding locked messages
0 commit comments