@@ -570,7 +570,7 @@ func (s *SQLStore) AddChannelEdge(ctx context.Context,
570
570
alreadyExists = false
571
571
},
572
572
Do : func (tx SQLQueries ) error {
573
- err := insertChannel (ctx , tx , edge )
573
+ _ , err := insertChannel (ctx , tx , edge )
574
574
575
575
// Silence ErrEdgeAlreadyExist so that the batch can
576
576
// succeed, but propagate the error via local state.
@@ -3759,9 +3759,17 @@ func marshalExtraOpaqueData(data []byte) (map[uint64][]byte, error) {
3759
3759
return records , nil
3760
3760
}
3761
3761
3762
+ // dbChanInfo holds the DB level IDs of a channel and the nodes involved in the
3763
+ // channel.
3764
+ type dbChanInfo struct {
3765
+ channelID int64
3766
+ node1ID int64
3767
+ node2ID int64
3768
+ }
3769
+
3762
3770
// insertChannel inserts a new channel record into the database.
3763
3771
func insertChannel (ctx context.Context , db SQLQueries ,
3764
- edge * models.ChannelEdgeInfo ) error {
3772
+ edge * models.ChannelEdgeInfo ) ( * dbChanInfo , error ) {
3765
3773
3766
3774
chanIDB := channelIDToBytes (edge .ChannelID )
3767
3775
@@ -3776,21 +3784,21 @@ func insertChannel(ctx context.Context, db SQLQueries,
3776
3784
},
3777
3785
)
3778
3786
if err == nil {
3779
- return ErrEdgeAlreadyExist
3787
+ return nil , ErrEdgeAlreadyExist
3780
3788
} else if ! errors .Is (err , sql .ErrNoRows ) {
3781
- return fmt .Errorf ("unable to fetch channel: %w" , err )
3789
+ return nil , fmt .Errorf ("unable to fetch channel: %w" , err )
3782
3790
}
3783
3791
3784
3792
// Make sure that at least a "shell" entry for each node is present in
3785
3793
// the nodes table.
3786
3794
node1DBID , err := maybeCreateShellNode (ctx , db , edge .NodeKey1Bytes )
3787
3795
if err != nil {
3788
- return fmt .Errorf ("unable to create shell node: %w" , err )
3796
+ return nil , fmt .Errorf ("unable to create shell node: %w" , err )
3789
3797
}
3790
3798
3791
3799
node2DBID , err := maybeCreateShellNode (ctx , db , edge .NodeKey2Bytes )
3792
3800
if err != nil {
3793
- return fmt .Errorf ("unable to create shell node: %w" , err )
3801
+ return nil , fmt .Errorf ("unable to create shell node: %w" , err )
3794
3802
}
3795
3803
3796
3804
var capacity sql.NullInt64
@@ -3821,15 +3829,15 @@ func insertChannel(ctx context.Context, db SQLQueries,
3821
3829
// Insert the new channel record.
3822
3830
dbChanID , err := db .CreateChannel (ctx , createParams )
3823
3831
if err != nil {
3824
- return err
3832
+ return nil , err
3825
3833
}
3826
3834
3827
3835
// Insert any channel features.
3828
3836
if len (edge .Features ) != 0 {
3829
3837
chanFeatures := lnwire .NewRawFeatureVector ()
3830
3838
err := chanFeatures .Decode (bytes .NewReader (edge .Features ))
3831
3839
if err != nil {
3832
- return err
3840
+ return nil , err
3833
3841
}
3834
3842
3835
3843
fv := lnwire .NewFeatureVector (chanFeatures , lnwire .Features )
@@ -3841,7 +3849,7 @@ func insertChannel(ctx context.Context, db SQLQueries,
3841
3849
},
3842
3850
)
3843
3851
if err != nil {
3844
- return fmt .Errorf ("unable to insert " +
3852
+ return nil , fmt .Errorf ("unable to insert " +
3845
3853
"channel(%d) feature(%v): %w" , dbChanID ,
3846
3854
feature , err )
3847
3855
}
@@ -3851,8 +3859,8 @@ func insertChannel(ctx context.Context, db SQLQueries,
3851
3859
// Finally, insert any extra TLV fields in the channel announcement.
3852
3860
extra , err := marshalExtraOpaqueData (edge .ExtraOpaqueData )
3853
3861
if err != nil {
3854
- return fmt .Errorf ("unable to marshal extra opaque data: %w" ,
3855
- err )
3862
+ return nil , fmt .Errorf ("unable to marshal extra opaque " +
3863
+ "data: %w" , err )
3856
3864
}
3857
3865
3858
3866
for tlvType , value := range extra {
@@ -3864,13 +3872,17 @@ func insertChannel(ctx context.Context, db SQLQueries,
3864
3872
},
3865
3873
)
3866
3874
if err != nil {
3867
- return fmt .Errorf ("unable to upsert channel(%d) extra " +
3868
- "signed field(%v): %w" , edge . ChannelID ,
3869
- tlvType , err )
3875
+ return nil , fmt .Errorf ("unable to upsert " +
3876
+ "channel(%d) extra signed field(%v): %w" ,
3877
+ edge . ChannelID , tlvType , err )
3870
3878
}
3871
3879
}
3872
3880
3873
- return nil
3881
+ return & dbChanInfo {
3882
+ channelID : dbChanID ,
3883
+ node1ID : node1DBID ,
3884
+ node2ID : node2DBID ,
3885
+ }, nil
3874
3886
}
3875
3887
3876
3888
// maybeCreateShellNode checks if a shell node entry exists for the
0 commit comments