@@ -114,8 +114,8 @@ func (c *GraphCache) AddNodeFeatures(node route.Vertex,
114114// and policy 2 does not matter, the directionality is extracted from the info
115115// and policy flags automatically. The policy will be set as the outgoing policy
116116// on one node and the incoming policy on the peer's side.
117- func (c * GraphCache ) AddChannel (info * models.ChannelEdgeInfo ,
118- policy1 * models. ChannelEdgePolicy , policy2 * models.ChannelEdgePolicy ) {
117+ func (c * GraphCache ) AddChannel (info * models.CachedEdgeInfo ,
118+ policy1 , policy2 * models.CachedEdgePolicy ) {
119119
120120 if info == nil {
121121 return
@@ -147,19 +147,17 @@ func (c *GraphCache) AddChannel(info *models.ChannelEdgeInfo,
147147 // of node 2 then we have the policy 1 as seen from node 1.
148148 if policy1 != nil {
149149 fromNode , toNode := info .NodeKey1Bytes , info .NodeKey2Bytes
150- if policy1 .ToNode != info . NodeKey2Bytes {
150+ if ! policy1 .IsNode1 () {
151151 fromNode , toNode = toNode , fromNode
152152 }
153- isEdge1 := policy1 .ChannelFlags & lnwire .ChanUpdateDirection == 0
154- c .UpdatePolicy (policy1 , fromNode , toNode , isEdge1 )
153+ c .UpdatePolicy (policy1 , fromNode , toNode )
155154 }
156155 if policy2 != nil {
157156 fromNode , toNode := info .NodeKey2Bytes , info .NodeKey1Bytes
158- if policy2 .ToNode != info . NodeKey1Bytes {
157+ if policy2 .IsNode1 () {
159158 fromNode , toNode = toNode , fromNode
160159 }
161- isEdge1 := policy2 .ChannelFlags & lnwire .ChanUpdateDirection == 0
162- c .UpdatePolicy (policy2 , fromNode , toNode , isEdge1 )
160+ c .UpdatePolicy (policy2 , fromNode , toNode )
163161 }
164162}
165163
@@ -177,8 +175,8 @@ func (c *GraphCache) updateOrAddEdge(node route.Vertex, edge *DirectedChannel) {
177175// of the from and to node is not strictly important. But we assume that a
178176// channel edge was added beforehand so that the directed channel struct already
179177// exists in the cache.
180- func (c * GraphCache ) UpdatePolicy (policy * models.ChannelEdgePolicy , fromNode ,
181- toNode route.Vertex , edge1 bool ) {
178+ func (c * GraphCache ) UpdatePolicy (policy * models.CachedEdgePolicy , fromNode ,
179+ toNode route.Vertex ) {
182180
183181 c .mtx .Lock ()
184182 defer c .mtx .Unlock ()
@@ -203,15 +201,15 @@ func (c *GraphCache) UpdatePolicy(policy *models.ChannelEdgePolicy, fromNode,
203201 switch {
204202 // This is node 1, and it is edge 1, so this is the outgoing
205203 // policy for node 1.
206- case channel .IsNode1 && edge1 :
204+ case channel .IsNode1 && policy . IsNode1 () :
207205 channel .OutPolicySet = true
208206 policy .InboundFee .WhenSome (func (fee lnwire.Fee ) {
209207 channel .InboundFee = fee
210208 })
211209
212210 // This is node 2, and it is edge 2, so this is the outgoing
213211 // policy for node 2.
214- case ! channel .IsNode1 && ! edge1 :
212+ case ! channel .IsNode1 && ! policy . IsNode1 () :
215213 channel .OutPolicySet = true
216214 policy .InboundFee .WhenSome (func (fee lnwire.Fee ) {
217215 channel .InboundFee = fee
@@ -220,7 +218,7 @@ func (c *GraphCache) UpdatePolicy(policy *models.ChannelEdgePolicy, fromNode,
220218 // The other two cases left mean it's the inbound policy for the
221219 // node.
222220 default :
223- channel .InPolicy = models . NewCachedPolicy ( policy )
221+ channel .InPolicy = policy
224222 }
225223 }
226224
@@ -264,34 +262,6 @@ func (c *GraphCache) removeChannelIfFound(node route.Vertex, chanID uint64) {
264262 delete (c .nodeChannels [node ], chanID )
265263}
266264
267- // UpdateChannel updates the channel edge information for a specific edge. We
268- // expect the edge to already exist and be known. If it does not yet exist, this
269- // call is a no-op.
270- func (c * GraphCache ) UpdateChannel (info * models.ChannelEdgeInfo ) {
271- c .mtx .Lock ()
272- defer c .mtx .Unlock ()
273-
274- if len (c .nodeChannels [info .NodeKey1Bytes ]) == 0 ||
275- len (c .nodeChannels [info .NodeKey2Bytes ]) == 0 {
276-
277- return
278- }
279-
280- channel , ok := c.nodeChannels [info.NodeKey1Bytes ][info.ChannelID ]
281- if ok {
282- // We only expect to be called when the channel is already
283- // known.
284- channel .Capacity = info .Capacity
285- channel .OtherNode = info .NodeKey2Bytes
286- }
287-
288- channel , ok = c.nodeChannels [info.NodeKey2Bytes ][info.ChannelID ]
289- if ok {
290- channel .Capacity = info .Capacity
291- channel .OtherNode = info .NodeKey1Bytes
292- }
293- }
294-
295265// getChannels returns a copy of the passed node's channels or nil if there
296266// isn't any.
297267func (c * GraphCache ) getChannels (node route.Vertex ) []* DirectedChannel {
0 commit comments