@@ -280,16 +280,6 @@ static void chanmap_add(struct lightningd *ld,
280280 tal_add_destructor2 (scc , destroy_scid_to_channel , ld );
281281}
282282
283- static void channel_set_random_local_alias (struct channel * channel )
284- {
285- assert (channel -> alias [LOCAL ] == NULL );
286- channel -> alias [LOCAL ] = tal (channel , struct short_channel_id );
287- * channel -> alias [LOCAL ] = random_scid ();
288- /* We don't check for uniqueness. We would crash on a clash, but your machine is
289- * probably broken beyond repair if it gets two equal 64 bit numbers */
290- chanmap_add (channel -> peer -> ld , channel , * channel -> alias [LOCAL ]);
291- }
292-
293283void channel_set_scid (struct channel * channel , const struct short_channel_id * new_scid )
294284{
295285 struct lightningd * ld = channel -> peer -> ld ;
@@ -367,8 +357,12 @@ struct channel *new_unsaved_channel(struct peer *peer,
367357 = CLOSING_FEE_NEGOTIATION_STEP_UNIT_PERCENTAGE ;
368358 channel -> shutdown_wrong_funding = NULL ;
369359 channel -> closing_feerate_range = NULL ;
370- channel -> alias [REMOTE ] = channel -> alias [LOCAL ] = NULL ;
371- channel_set_random_local_alias (channel );
360+ channel -> alias [REMOTE ] = NULL ;
361+ channel -> alias [LOCAL ] = tal (channel , struct short_channel_id );
362+ * channel -> alias [LOCAL ] = random_scid ();
363+ /* We don't check for uniqueness. We would crash on a clash, but your machine is
364+ * probably broken beyond repair if it gets two equal 64 bit numbers */
365+ chanmap_add (channel -> peer -> ld , channel , * channel -> alias [LOCAL ]);
372366
373367 channel -> shutdown_scriptpubkey [REMOTE ] = NULL ;
374368 channel -> last_was_revoke = false;
@@ -489,9 +483,9 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
489483 struct amount_sat our_funds ,
490484 bool remote_channel_ready ,
491485 /* NULL or stolen */
492- struct short_channel_id * scid ,
486+ struct short_channel_id * scid TAKES ,
493487 struct short_channel_id * old_scids TAKES ,
494- struct short_channel_id * alias_local TAKES ,
488+ struct short_channel_id alias_local ,
495489 struct short_channel_id * alias_remote STEALS ,
496490 struct channel_id * cid ,
497491 struct amount_msat our_msat ,
@@ -617,22 +611,18 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
617611 channel -> push = push ;
618612 channel -> our_funds = our_funds ;
619613 channel -> remote_channel_ready = remote_channel_ready ;
620- channel -> scid = tal_steal (channel , scid );
614+ channel -> scid = tal_dup_or_null (channel , struct short_channel_id , scid );
621615 channel -> old_scids = tal_dup_talarr (channel , struct short_channel_id , old_scids );
622- channel -> alias [LOCAL ] = tal_dup_or_null (channel , struct short_channel_id , alias_local );
616+ channel -> alias [LOCAL ] = tal_dup (channel , struct short_channel_id , & alias_local );
623617 /* All these possible short_channel_id variants go in the lookup table! */
624618 /* Stub channels all have the same scid though, *and* get loaded from db! */
625619 if (channel -> scid && !is_stub_scid (* channel -> scid ))
626620 chanmap_add (peer -> ld , channel , * channel -> scid );
627- if (channel -> alias [LOCAL ])
621+ if (! is_stub_scid ( * channel -> alias [LOCAL ]) )
628622 chanmap_add (peer -> ld , channel , * channel -> alias [LOCAL ]);
629623 for (size_t i = 0 ; i < tal_count (channel -> old_scids ); i ++ )
630624 chanmap_add (peer -> ld , channel , channel -> old_scids [i ]);
631625
632- /* We always make sure this is set (historical channels from db might not) */
633- if (!channel -> alias [LOCAL ])
634- channel_set_random_local_alias (channel );
635-
636626 channel -> alias [REMOTE ] = tal_steal (channel , alias_remote ); /* Haven't gotten one yet. */
637627 channel -> cid = * cid ;
638628 channel -> our_msat = our_msat ;
@@ -739,7 +729,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
739729 }
740730 /* scid is NULL when opening a new channel so we don't
741731 * need to set error in that case as well */
742- if (scid && is_stub_scid (* scid ))
732+ if (channel -> scid && is_stub_scid (* channel -> scid ))
743733 channel -> error = towire_errorfmt (peer -> ld ,
744734 & channel -> cid ,
745735 "We can't be together anymore." );
0 commit comments