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

Function handle_your_peer_storage

plugins/chanbackup.c:860–952  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

858}
859
860static struct command_result *handle_your_peer_storage(struct command *cmd,
861 const char *buf,
862 const jsmntok_t *params)
863{
864 struct node_id node_id;
865 u8 *payload, *payload_deserialise;
866 const char *err;
867 struct chanbackup *cb = chanbackup(cmd->plugin);
868
869 err = json_scan(cmd, buf, params,
870 "{payload:%,peer_id:%}",
871 JSON_SCAN_TAL(cmd, json_tok_bin_from_hex, &payload),
872 JSON_SCAN(json_to_node_id, &node_id));
873 if (err) {
874 plugin_err(cmd->plugin,
875 "`your_peer_storage` response did not scan %s: %.*s",
876 err, json_tok_full_len(params),
877 json_tok_full(buf, params));
878 }
879
880 if (fromwire_peer_storage(cmd, payload, &payload_deserialise)) {
881 struct peer_backup *pb;
882
883 if (!cb->handle_their_peer_backup)
884 return command_hook_success(cmd);
885
886 /* BOLT #1:
887 * The receiver of `peer_storage`:
888 * - If it offered `option_provide_storage`:
889 * - if it has an open channel with the sender:
890 * - MUST store the message.
891 * - MAY store the message anyway.
892 */
893 /* We store if we have a datastore slot for it
894 * (otherwise, this fails). We create those once it
895 * has a channel, though the user could also create an
896 * empty one if they wanted to */
897
898 /* BOLT #1:
899 * - If it does store the message:
900 * - MAY delay storage to ratelimit peer to no more than one
901 * update per minute.
902 * - MUST replace the old `blob` with the latest received.
903 */
904 pb = backup_map_get(cb->backups, &node_id);
905 if (!pb)
906 return command_hook_success(cmd);
907
908 tal_free(pb->data);
909 pb->data = tal_steal(pb, payload_deserialise);
910 return commit_peer_backup(cmd, pb);
911 } else if (fromwire_peer_storage_retrieval(cmd, payload, &payload_deserialise)) {
912 crypto_secretstream_xchacha20poly1305_state crypto_state;
913
914 plugin_log(cmd->plugin, LOG_DBG,
915 "Received peer_storage from peer.");
916
917 if (!cb->send_our_peer_backup)

Callers

nothing calls this directly

Calls 12

tal_freeFunction · 0.85
commit_peer_backupFunction · 0.85
tal_bytelenFunction · 0.85
failed_peer_restoreFunction · 0.85
store_latest_scbFunction · 0.85
chanbackupFunction · 0.70
plugin_errFunction · 0.70
command_hook_successFunction · 0.70
plugin_logFunction · 0.70
json_scanFunction · 0.50
json_tok_full_lenFunction · 0.50
json_tok_fullFunction · 0.50

Tested by

no test coverage detected