MCPcopy Create free account
hub / github.com/ElementsProject/lightning / store_latest_scb

Function store_latest_scb

plugins/chanbackup.c:827–858  ·  view source on GitHub ↗

Compares the data between the stored scb and latest recvd scb, * stores the most recent one only. */

Source from the content-addressed store, hash-verified

825/* Compares the data between the stored scb and latest recvd scb,
826 * stores the most recent one only. */
827static 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, &timestamp_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
860static struct command_result *handle_your_peer_storage(struct command *cmd,
861 const char *buf,

Callers 1

handle_your_peer_storageFunction · 0.85

Calls 5

tal_bytelenFunction · 0.85
read_static_chan_backupFunction · 0.85
tal_hexFunction · 0.85
plugin_logFunction · 0.70
command_hook_successFunction · 0.70

Tested by

no test coverage detected