3030#include <lightningd/peer_fd.h>
3131#include <lightningd/plugin_hook.h>
3232#include <openingd/dualopend_wiregen.h>
33+ #include <stdio.h>
3334#include <unistd.h>
3435
3536struct commit_rcvd {
@@ -4087,6 +4088,35 @@ static void dualopen_errmsg(struct channel *channel,
40874088 err_for_them ? "sent" : "received" , desc );
40884089}
40894090
4091+ /* This is a hack for CLN_DEV_ENTROPY_SEED. We cannot actually use
4092+ * the same seed for each dualopend, or they choose the same ids, and we
4093+ * clash when combining the PSBTs (this is phenomenally unlikey normally).
4094+ * So we set it (for the child) to an incrementing value. */
4095+ static const char * dev_setup_dualopend_seed (const tal_t * ctx , struct lightningd * ld )
4096+ {
4097+ static u64 seed_incr = 0 ;
4098+ char seedstr [STR_MAX_CHARS (u64 )];
4099+ const char * old_seed ;
4100+
4101+ if (!ld -> developer )
4102+ return NULL ;
4103+
4104+ old_seed = getenv ("CLN_DEV_ENTROPY_SEED" );
4105+ if (!old_seed )
4106+ return NULL ;
4107+
4108+ old_seed = tal_strdup (tmpctx , old_seed );
4109+ seed_incr ++ ;
4110+ snprintf (seedstr , sizeof (seedstr ), "%" PRIu64 , atol (old_seed ) + seed_incr );
4111+ setenv ("CLN_DEV_ENTROPY_SEED" , seedstr , 1 );
4112+ return old_seed ;
4113+ }
4114+
4115+ static void dev_restore_seed (const char * old_seed )
4116+ {
4117+ if (old_seed )
4118+ setenv ("CLN_DEV_ENTROPY_SEED" , old_seed , 1 );
4119+ }
40904120
40914121bool peer_start_dualopend (struct peer * peer ,
40924122 struct peer_fd * peer_fd ,
@@ -4096,6 +4126,7 @@ bool peer_start_dualopend(struct peer *peer,
40964126 u32 max_to_self_delay ;
40974127 struct amount_msat min_effective_htlc_capacity ;
40984128 const u8 * msg ;
4129+ const char * dev_old_seed ;
40994130
41004131 hsmfd = hsm_get_client_fd (peer -> ld , & peer -> id , channel -> unsaved_dbid ,
41014132 HSM_PERM_COMMITMENT_POINT
@@ -4109,6 +4140,7 @@ bool peer_start_dualopend(struct peer *peer,
41094140 return false;
41104141 }
41114142
4143+ dev_old_seed = dev_setup_dualopend_seed (tmpctx , peer -> ld );
41124144 channel -> owner = new_channel_subd (channel ,
41134145 peer -> ld ,
41144146 "lightning_dualopend" ,
@@ -4121,6 +4153,7 @@ bool peer_start_dualopend(struct peer *peer,
41214153 channel_set_billboard ,
41224154 take (& peer_fd -> fd ),
41234155 take (& hsmfd ), NULL );
4156+ dev_restore_seed (dev_old_seed );
41244157
41254158 if (!channel -> owner ) {
41264159 channel_internal_error (channel ,
@@ -4174,6 +4207,7 @@ bool peer_restart_dualopend(struct peer *peer,
41744207 int hsmfd ;
41754208 u32 * local_shutdown_script_wallet_index ;
41764209 u8 * msg ;
4210+ const char * dev_old_seed ;
41774211
41784212 if (channel_state_uncommitted (channel -> state ))
41794213 return peer_start_dualopend (peer , peer_fd , channel );
@@ -4193,6 +4227,7 @@ bool peer_restart_dualopend(struct peer *peer,
41934227 return false;
41944228 }
41954229
4230+ dev_old_seed = dev_setup_dualopend_seed (tmpctx , peer -> ld );
41964231 channel_set_owner (channel ,
41974232 new_channel_subd (channel , peer -> ld ,
41984233 "lightning_dualopend" ,
@@ -4205,6 +4240,8 @@ bool peer_restart_dualopend(struct peer *peer,
42054240 channel_set_billboard ,
42064241 take (& peer_fd -> fd ),
42074242 take (& hsmfd ), NULL ));
4243+ dev_restore_seed (dev_old_seed );
4244+
42084245 if (!channel -> owner ) {
42094246 log_broken (channel -> log , "Could not subdaemon channel: %s" ,
42104247 strerror (errno ));
0 commit comments