@@ -4063,3 +4063,83 @@ func TestClosedScid(t *testing.T) {
4063
4063
require .Nil (t , err )
4064
4064
require .True (t , exists )
4065
4065
}
4066
+
4067
+ // TestUpdateAliasChannel tests that the underlying graph channel information
4068
+ // for an alias channel is deleted and readded under a different short channel
4069
+ // id.
4070
+ func TestUpdateAliasChannel (t * testing.T ) {
4071
+ t .Parallel ()
4072
+
4073
+ graph , err := MakeTestGraph (t )
4074
+ require .NoError (t , err , "unable to make test database" )
4075
+
4076
+ // Create first node and add it to the graph.
4077
+ node1 , err := createTestVertex (graph .db )
4078
+ require .NoError (t , err , "unable to create test node" )
4079
+ err = graph .AddLightningNode (node1 )
4080
+ require .NoError (t , err )
4081
+
4082
+ // Create second node and add it to the graph.
4083
+ node2 , err := createTestVertex (graph .db )
4084
+ require .NoError (t , err , "unable to create test node" )
4085
+ err = graph .AddLightningNode (node2 )
4086
+ require .NoError (t , err )
4087
+
4088
+ // Adding a new channel edge to the graph.
4089
+ edgeInfo , edge1 , edge2 := createChannelEdge (
4090
+ graph .db , node1 , node2 ,
4091
+ )
4092
+ if err := graph .AddChannelEdge (edgeInfo ); err != nil {
4093
+ t .Fatalf ("unable to create channel edge: %v" , err )
4094
+ }
4095
+
4096
+ // Add both edge policies.
4097
+ err = graph .UpdateEdgePolicy (edge1 )
4098
+ require .NoError (t , err )
4099
+
4100
+ err = graph .UpdateEdgePolicy (edge2 )
4101
+ require .NoError (t , err )
4102
+
4103
+ oldSCID := edgeInfo .ChannelID
4104
+
4105
+ // Define the new channel id (under real conditions this is the new
4106
+ // confirmed channel id).
4107
+ newChanSCID := rand .Uint64 ()
4108
+
4109
+ // Readd the channel edgeInfo under a different scid.
4110
+ newEdgeInfo := new (models.ChannelEdgeInfo )
4111
+ * newEdgeInfo = * edgeInfo
4112
+ newEdgeInfo .ChannelID = newChanSCID
4113
+
4114
+ // Create a new edge policy with the new channel id.
4115
+ newEdge1 := new (models.ChannelEdgePolicy )
4116
+ * newEdge1 = * edge1
4117
+ newEdge1 .ChannelID = newChanSCID
4118
+
4119
+ // Re-add the channel edge to the graph which deletes the old data and
4120
+ // inserts the new edge data (edge info and edge policy).
4121
+ err = graph .ReAddChannelEdge (oldSCID , newEdgeInfo , newEdge1 )
4122
+ require .NoError (t , err )
4123
+
4124
+ // The old channel data should not exist anymore.
4125
+ _ , _ , _ , err = graph .FetchChannelEdgesByID (oldSCID )
4126
+ require .Error (t , err , "channel should not exist" )
4127
+
4128
+ // Fetch the new channel data.
4129
+ newEdgeInfo , newEdge1 , newEdge2 , err := graph .FetchChannelEdgesByID (
4130
+ newChanSCID ,
4131
+ )
4132
+ require .NoError (t , err , "unable to fetch channel by ID" )
4133
+
4134
+ // Edge 1 should be different and should have another channel id.
4135
+ err = compareEdgePolicies (newEdge1 , edge1 )
4136
+ require .Error (t , err )
4137
+
4138
+ // Edge 2 should be nil, because we deleted the former peer data.
4139
+ require .Nil (t , newEdge2 )
4140
+
4141
+ // Because we did not change the signatures the edge info should be
4142
+ // the same as soon as we swap in the old channel id.
4143
+ newEdgeInfo .ChannelID = oldSCID
4144
+ assertEdgeInfoEqual (t , newEdgeInfo , edgeInfo )
4145
+ }
0 commit comments