Compares the data between the stored scb and latest recvd scb, * stores the most recent one only. */
| 825 | /* Compares the data between the stored scb and latest recvd scb, |
| 826 | * stores the most recent one only. */ |
| 827 | static struct command_result *store_latest_scb(struct command *cmd, |
| 828 | struct chanbackup *cb, |
| 829 | const u8 *received_scb) |
| 830 | { |
| 831 | size_t recvd_scb_len = tal_bytelen(received_scb); |
| 832 | u64 version; |
| 833 | struct modern_scb_chan **scb_tlvs; |
| 834 | u32 timestamp_new; |
| 835 | bool is_converted; |
| 836 | |
| 837 | if (!read_static_chan_backup(cmd, received_scb, &version, ×tamp_new, &scb_tlvs, &is_converted)) { |
| 838 | plugin_log(cmd->plugin, LOG_BROKEN, "Ignoring invalid peer storage: %s", |
| 839 | tal_hex(tmpctx, received_scb)); |
| 840 | return command_hook_success(cmd); |
| 841 | } |
| 842 | |
| 843 | if (timestamp_new < cb->latest_timestamp) { |
| 844 | plugin_log(cmd->plugin, LOG_DBG, "Ignoring old Peer Storage"); |
| 845 | return command_hook_success(cmd); |
| 846 | } |
| 847 | |
| 848 | cb->latest_timestamp = timestamp_new; |
| 849 | |
| 850 | return jsonrpc_set_datastore_binary(cmd, |
| 851 | mkdatastorekey(tmpctx, "chanbackup", "latestscb"), |
| 852 | received_scb, recvd_scb_len, |
| 853 | "create-or-replace", |
| 854 | datastore_success, |
| 855 | datastore_failed, |
| 856 | "Saving latestscb"); |
| 857 | |
| 858 | } |
| 859 | |
| 860 | static struct command_result *handle_your_peer_storage(struct command *cmd, |
| 861 | const char *buf, |
no test coverage detected