| 695 | } |
| 696 | |
| 697 | static void save_complete_layer(struct layer *layer) |
| 698 | { |
| 699 | struct local_channel_hash_iter lcit; |
| 700 | const struct local_channel *lc; |
| 701 | const struct local_update *lu; |
| 702 | struct local_update_hash_iter luit; |
| 703 | struct constraint_hash_iter conit; |
| 704 | const struct constraint *c; |
| 705 | struct bias_hash_iter biasit; |
| 706 | const struct bias *b; |
| 707 | struct node_bias_hash_iter nbiasit; |
| 708 | const struct node_bias *nb; |
| 709 | struct out_req *req; |
| 710 | u8 *data; |
| 711 | |
| 712 | if (!layer->persistent) |
| 713 | return; |
| 714 | |
| 715 | data = tal_arr(tmpctx, u8, 0); |
| 716 | for (size_t i = 0; i < tal_count(layer->disabled_nodes); i++) |
| 717 | towire_dstore_disabled_node(&data, &layer->disabled_nodes[i]); |
| 718 | |
| 719 | for (lc = local_channel_hash_first(layer->local_channels, &lcit); |
| 720 | lc; |
| 721 | lc = local_channel_hash_next(layer->local_channels, &lcit)) { |
| 722 | towire_save_channel(&data, lc); |
| 723 | } |
| 724 | for (lu = local_update_hash_first(layer->local_updates, &luit); |
| 725 | lu; |
| 726 | lu = local_update_hash_next(layer->local_updates, &luit)) { |
| 727 | towire_save_channel_update(&data, lu); |
| 728 | } |
| 729 | for (c = constraint_hash_first(layer->constraints, &conit); |
| 730 | c; |
| 731 | c = constraint_hash_next(layer->constraints, &conit)) { |
| 732 | /* Don't save ones we generated internally */ |
| 733 | if (c->timestamp == UINT64_MAX) |
| 734 | continue; |
| 735 | towire_save_channel_constraint(&data, c); |
| 736 | } |
| 737 | for (b = bias_hash_first(layer->biases, &biasit); |
| 738 | b; |
| 739 | b = bias_hash_next(layer->biases, &biasit)) { |
| 740 | towire_save_channel_bias(&data, b); |
| 741 | } |
| 742 | for (nb = node_bias_hash_first(layer->node_biases, &nbiasit); nb; |
| 743 | nb = node_bias_hash_next(layer->node_biases, &nbiasit)) { |
| 744 | towire_save_node_bias(&data, nb); |
| 745 | } |
| 746 | |
| 747 | /* Wholesale replacement */ |
| 748 | req = jsonrpc_request_start(layer->askrene->layer_cmd, |
| 749 | "datastore", |
| 750 | ignore_result, |
| 751 | plugin_broken_cb, |
| 752 | NULL); |
| 753 | json_add_layer_key(req->js, "key", layer); |
| 754 | json_add_hex_talarr(req->js, "hex", data); |
no test coverage detected