@@ -175,16 +175,17 @@ static fp16_t *get_capacities(const tal_t *ctx,
175175 * but we won't. */
176176/* FIXME: We could cache this until gossmap/layer changes... */
177177static struct layer * source_free_layer (const tal_t * ctx ,
178- struct gossmap * gossmap ,
178+ struct askrene * askrene ,
179179 const struct node_id * source ,
180180 struct gossmap_localmods * localmods )
181181{
182182 /* We apply existing localmods so we see *all* channels */
183+ struct gossmap * gossmap = askrene -> gossmap ;
183184 const struct gossmap_node * srcnode ;
184185 const struct amount_msat zero_base_fee = AMOUNT_MSAT (0 );
185186 const u16 zero_delay = 0 ;
186187 const u32 zero_prop_fee = 0 ;
187- struct layer * layer = new_temp_layer (ctx , "auto.sourcefree" );
188+ struct layer * layer = new_temp_layer (ctx , askrene , "auto.sourcefree" );
188189
189190 /* We apply this so we see any created channels */
190191 gossmap_apply_localmods (gossmap , localmods );
@@ -363,7 +364,7 @@ static const char *get_routes(const tal_t *ctx,
363364 /* Handled below, after other layers */
364365 assert (streq (layers [i ], "auto.sourcefree" ));
365366 plugin_log (rq -> plugin , LOG_DBG , "Adding auto.sourcefree" );
366- l = source_free_layer (layers , askrene -> gossmap , source , localmods );
367+ l = source_free_layer (layers , askrene , source , localmods );
367368 }
368369 }
369370
@@ -732,11 +733,12 @@ listpeerchannels_done(struct command *cmd,
732733 const jsmntok_t * toks ,
733734 struct getroutes_info * info )
734735{
736+ struct askrene * askrene = get_askrene (cmd -> plugin );
735737 struct gossmap_localmods * localmods ;
736738
737- info -> local_layer = new_temp_layer (info , "auto.localchans" );
739+ info -> local_layer = new_temp_layer (info , askrene , "auto.localchans" );
738740 localmods = gossmods_from_listpeerchannels (cmd ,
739- & get_askrene ( cmd -> plugin ) -> my_id ,
741+ & askrene -> my_id ,
740742 buffer , toks ,
741743 false,
742744 add_localchan ,
@@ -1066,24 +1068,33 @@ static struct command_result *json_askrene_create_layer(struct command *cmd,
10661068 struct layer * layer ;
10671069 const char * layername ;
10681070 struct json_stream * response ;
1071+ bool * persistent ;
10691072
10701073 if (!param_check (cmd , buffer , params ,
10711074 p_req ("layer" , param_string , & layername ),
1075+ p_opt_def ("persistent" , param_bool , & persistent , false),
10721076 NULL ))
10731077 return command_param_failed ();
10741078
1075- if (find_layer (askrene , layername ))
1076- return command_fail (cmd , JSONRPC2_INVALID_PARAMS ,
1077- "Layer already exists" );
1078-
10791079 if (strstarts (layername , "auto." ))
10801080 return command_fail (cmd , JSONRPC2_INVALID_PARAMS ,
10811081 "Cannot create auto layer" );
10821082
1083+ /* If it's persistent, creation is a noop if it already exists */
1084+ layer = find_layer (askrene , layername );
1085+ if (layer && !* persistent ) {
1086+ return command_fail (cmd , JSONRPC2_INVALID_PARAMS ,
1087+ "Layer already exists" );
1088+ }
1089+
10831090 if (command_check_only (cmd ))
10841091 return command_check_done (cmd );
10851092
1086- layer = new_layer (askrene , layername );
1093+ if (!layer ) {
1094+ layer = new_layer (askrene , layername , * persistent );
1095+ if (* persistent )
1096+ save_new_layer (layer );
1097+ }
10871098
10881099 response = jsonrpc_stream_success (cmd );
10891100 json_add_layers (response , askrene , "layers" , layer );
@@ -1102,7 +1113,7 @@ static struct command_result *json_askrene_remove_layer(struct command *cmd,
11021113 NULL ))
11031114 return command_param_failed ();
11041115
1105- tal_free (layer );
1116+ remove_layer (layer );
11061117
11071118 response = jsonrpc_stream_success (cmd );
11081119 return command_finished (cmd , response );
@@ -1230,6 +1241,10 @@ static const char *init(struct command *init_cmd,
12301241
12311242 plugin_set_data (plugin , askrene );
12321243 plugin_set_memleak_handler (plugin , askrene_markmem );
1244+
1245+ /* Layer needs its own command to access datastore */
1246+ askrene -> layer_cmd = aux_command (init_cmd );
1247+ load_layers (askrene );
12331248 return NULL ;
12341249}
12351250
0 commit comments