@@ -268,16 +268,6 @@ static void chanmap_add(struct lightningd *ld,
268268 tal_add_destructor2 (scc , destroy_scid_to_channel , ld );
269269}
270270
271- static void channel_set_random_local_alias (struct channel * channel )
272- {
273- assert (channel -> alias [LOCAL ] == NULL );
274- channel -> alias [LOCAL ] = tal (channel , struct short_channel_id );
275- * channel -> alias [LOCAL ] = random_scid ();
276- /* We don't check for uniqueness. We would crash on a clash, but your machine is
277- * probably broken beyond repair if it gets two equal 64 bit numbers */
278- chanmap_add (channel -> peer -> ld , channel , * channel -> alias [LOCAL ]);
279- }
280-
281271void channel_set_scid (struct channel * channel , const struct short_channel_id * new_scid )
282272{
283273 struct lightningd * ld = channel -> peer -> ld ;
@@ -355,8 +345,12 @@ struct channel *new_unsaved_channel(struct peer *peer,
355345 = CLOSING_FEE_NEGOTIATION_STEP_UNIT_PERCENTAGE ;
356346 channel -> shutdown_wrong_funding = NULL ;
357347 channel -> closing_feerate_range = NULL ;
358- channel -> alias [REMOTE ] = channel -> alias [LOCAL ] = NULL ;
359- channel_set_random_local_alias (channel );
348+ channel -> alias [REMOTE ] = NULL ;
349+ channel -> alias [LOCAL ] = tal (channel , struct short_channel_id );
350+ * channel -> alias [LOCAL ] = random_scid ();
351+ /* We don't check for uniqueness. We would crash on a clash, but your machine is
352+ * probably broken beyond repair if it gets two equal 64 bit numbers */
353+ chanmap_add (channel -> peer -> ld , channel , * channel -> alias [LOCAL ]);
360354
361355 channel -> shutdown_scriptpubkey [REMOTE ] = NULL ;
362356 channel -> last_was_revoke = false;
@@ -477,9 +471,9 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
477471 struct amount_sat our_funds ,
478472 bool remote_channel_ready ,
479473 /* NULL or stolen */
480- struct short_channel_id * scid ,
474+ struct short_channel_id * scid TAKES ,
481475 struct short_channel_id * old_scids TAKES ,
482- struct short_channel_id * alias_local TAKES ,
476+ struct short_channel_id alias_local ,
483477 struct short_channel_id * alias_remote STEALS ,
484478 struct channel_id * cid ,
485479 struct amount_msat our_msat ,
@@ -605,22 +599,18 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
605599 channel -> push = push ;
606600 channel -> our_funds = our_funds ;
607601 channel -> remote_channel_ready = remote_channel_ready ;
608- channel -> scid = tal_steal (channel , scid );
602+ channel -> scid = tal_dup_or_null (channel , struct short_channel_id , scid );
609603 channel -> old_scids = tal_dup_talarr (channel , struct short_channel_id , old_scids );
610- channel -> alias [LOCAL ] = tal_dup_or_null (channel , struct short_channel_id , alias_local );
604+ channel -> alias [LOCAL ] = tal_dup (channel , struct short_channel_id , & alias_local );
611605 /* All these possible short_channel_id variants go in the lookup table! */
612606 /* Stub channels all have the same scid though, *and* get loaded from db! */
613607 if (channel -> scid && !is_stub_scid (* channel -> scid ))
614608 chanmap_add (peer -> ld , channel , * channel -> scid );
615- if (channel -> alias [LOCAL ])
609+ if (! is_stub_scid ( * channel -> alias [LOCAL ]) )
616610 chanmap_add (peer -> ld , channel , * channel -> alias [LOCAL ]);
617611 for (size_t i = 0 ; i < tal_count (channel -> old_scids ); i ++ )
618612 chanmap_add (peer -> ld , channel , channel -> old_scids [i ]);
619613
620- /* We always make sure this is set (historical channels from db might not) */
621- if (!channel -> alias [LOCAL ])
622- channel_set_random_local_alias (channel );
623-
624614 channel -> alias [REMOTE ] = tal_steal (channel , alias_remote ); /* Haven't gotten one yet. */
625615 channel -> cid = * cid ;
626616 channel -> our_msat = our_msat ;
@@ -727,7 +717,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
727717 }
728718 /* scid is NULL when opening a new channel so we don't
729719 * need to set error in that case as well */
730- if (scid && is_stub_scid (* scid ))
720+ if (channel -> scid && is_stub_scid (* channel -> scid ))
731721 channel -> error = towire_errorfmt (peer -> ld ,
732722 & channel -> cid ,
733723 "We can't be together anymore." );
0 commit comments