@@ -278,16 +278,6 @@ static void chanmap_add(struct lightningd *ld,
278278 tal_add_destructor2 (scc , destroy_scid_to_channel , ld );
279279}
280280
281- static void channel_set_random_local_alias (struct channel * channel )
282- {
283- assert (channel -> alias [LOCAL ] == NULL );
284- channel -> alias [LOCAL ] = tal (channel , struct short_channel_id );
285- * channel -> alias [LOCAL ] = random_scid ();
286- /* We don't check for uniqueness. We would crash on a clash, but your machine is
287- * probably broken beyond repair if it gets two equal 64 bit numbers */
288- chanmap_add (channel -> peer -> ld , channel , * channel -> alias [LOCAL ]);
289- }
290-
291281void channel_set_scid (struct channel * channel , const struct short_channel_id * new_scid )
292282{
293283 struct lightningd * ld = channel -> peer -> ld ;
@@ -365,8 +355,12 @@ struct channel *new_unsaved_channel(struct peer *peer,
365355 = CLOSING_FEE_NEGOTIATION_STEP_UNIT_PERCENTAGE ;
366356 channel -> shutdown_wrong_funding = NULL ;
367357 channel -> closing_feerate_range = NULL ;
368- channel -> alias [REMOTE ] = channel -> alias [LOCAL ] = NULL ;
369- channel_set_random_local_alias (channel );
358+ channel -> alias [REMOTE ] = NULL ;
359+ channel -> alias [LOCAL ] = tal (channel , struct short_channel_id );
360+ * channel -> alias [LOCAL ] = random_scid ();
361+ /* We don't check for uniqueness. We would crash on a clash, but your machine is
362+ * probably broken beyond repair if it gets two equal 64 bit numbers */
363+ chanmap_add (channel -> peer -> ld , channel , * channel -> alias [LOCAL ]);
370364
371365 channel -> shutdown_scriptpubkey [REMOTE ] = NULL ;
372366 channel -> last_was_revoke = false;
@@ -487,9 +481,9 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
487481 struct amount_sat our_funds ,
488482 bool remote_channel_ready ,
489483 /* NULL or stolen */
490- struct short_channel_id * scid ,
484+ struct short_channel_id * scid TAKES ,
491485 struct short_channel_id * old_scids TAKES ,
492- struct short_channel_id * alias_local TAKES ,
486+ struct short_channel_id alias_local ,
493487 struct short_channel_id * alias_remote STEALS ,
494488 struct channel_id * cid ,
495489 struct amount_msat our_msat ,
@@ -615,22 +609,18 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
615609 channel -> push = push ;
616610 channel -> our_funds = our_funds ;
617611 channel -> remote_channel_ready = remote_channel_ready ;
618- channel -> scid = tal_steal (channel , scid );
612+ channel -> scid = tal_dup_or_null (channel , struct short_channel_id , scid );
619613 channel -> old_scids = tal_dup_talarr (channel , struct short_channel_id , old_scids );
620- channel -> alias [LOCAL ] = tal_dup_or_null (channel , struct short_channel_id , alias_local );
614+ channel -> alias [LOCAL ] = tal_dup (channel , struct short_channel_id , & alias_local );
621615 /* All these possible short_channel_id variants go in the lookup table! */
622616 /* Stub channels all have the same scid though, *and* get loaded from db! */
623617 if (channel -> scid && !is_stub_scid (* channel -> scid ))
624618 chanmap_add (peer -> ld , channel , * channel -> scid );
625- if (channel -> alias [LOCAL ])
619+ if (! is_stub_scid ( * channel -> alias [LOCAL ]) )
626620 chanmap_add (peer -> ld , channel , * channel -> alias [LOCAL ]);
627621 for (size_t i = 0 ; i < tal_count (channel -> old_scids ); i ++ )
628622 chanmap_add (peer -> ld , channel , channel -> old_scids [i ]);
629623
630- /* We always make sure this is set (historical channels from db might not) */
631- if (!channel -> alias [LOCAL ])
632- channel_set_random_local_alias (channel );
633-
634624 channel -> alias [REMOTE ] = tal_steal (channel , alias_remote ); /* Haven't gotten one yet. */
635625 channel -> cid = * cid ;
636626 channel -> our_msat = our_msat ;
@@ -737,7 +727,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
737727 }
738728 /* scid is NULL when opening a new channel so we don't
739729 * need to set error in that case as well */
740- if (scid && is_stub_scid (* scid ))
730+ if (channel -> scid && is_stub_scid (* channel -> scid ))
741731 channel -> error = towire_errorfmt (peer -> ld ,
742732 & channel -> cid ,
743733 "We can't be together anymore." );
0 commit comments