Skip to content

Commit bda52c3

Browse files
committed
chanbackup: use the cache instead of calling listdatastore every time.
Now actually use our cache. Signed-off-by: Rusty Russell <[email protected]>
1 parent dc2c366 commit bda52c3

File tree

1 file changed

+14
-37
lines changed

1 file changed

+14
-37
lines changed

plugins/chanbackup.c

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -423,31 +423,25 @@ static struct command_result
423423
return command_hook_success(cmd);
424424
}
425425

426-
static struct command_result *peer_after_listdatastore(struct command *cmd,
427-
const u8 *hexdata,
428-
struct node_id *nodeid)
426+
static struct command_result *peer_after_send_scb(struct command *cmd,
427+
const char *method,
428+
const char *buf,
429+
const jsmntok_t *params,
430+
struct node_id *nodeid)
429431
{
432+
const struct chanbackup *cb = chanbackup(cmd->plugin);
433+
struct peer_backup *pb;
430434
struct out_req *req;
435+
const u8 *msg;
431436

432-
/* We use an empty record to indicate we *would* store data
433-
* for this peer, until we actually get data from them */
434-
if (tal_bytelen(hexdata) == 0)
435-
return command_hook_success(cmd);
437+
plugin_log(cmd->plugin, LOG_DBG, "Peer storage sent!");
436438

437-
if (!chanbackup(cmd->plugin)->peer_backup)
439+
/* Now send their backup, if any. */
440+
pb = backup_map_get(cb->backups, nodeid);
441+
if (!pb || tal_bytelen(pb->data) == 0)
438442
return command_hook_success(cmd);
439443

440-
/* BOLT #1:
441-
* - If it does store the message:
442-
*...
443-
* - MUST send `peer_storage_retrieval` again after
444-
* reconnection, after exchanging `init` messages.
445-
*/
446-
/* BOLT #1:
447-
* The sender of `peer_storage_retrieval`:
448-
* - MUST include the last `blob` it stored for that peer.
449-
*/
450-
u8 *payload = towire_peer_storage_retrieval(cmd, hexdata);
444+
msg = towire_peer_storage_retrieval(cmd, pb->data);
451445

452446
plugin_log(cmd->plugin, LOG_DBG,
453447
"sending their backup from our datastore");
@@ -459,28 +453,11 @@ static struct command_result *peer_after_listdatastore(struct command *cmd,
459453
NULL);
460454

461455
json_add_node_id(req->js, "node_id", nodeid);
462-
json_add_hex_talarr(req->js, "msg", payload);
456+
json_add_hex_talarr(req->js, "msg", msg);
463457

464458
return send_outreq(req);
465459
}
466460

467-
static struct command_result *peer_after_send_scb(struct command *cmd,
468-
const char *method,
469-
const char *buf,
470-
const jsmntok_t *params,
471-
struct node_id *nodeid)
472-
{
473-
plugin_log(cmd->plugin, LOG_DBG, "Peer storage sent!");
474-
475-
return jsonrpc_get_datastore_binary(cmd,
476-
tal_fmt(cmd,
477-
"chanbackup/peers/%s",
478-
fmt_node_id(tmpctx,
479-
nodeid)),
480-
peer_after_listdatastore,
481-
nodeid);
482-
}
483-
484461
static struct command_result *peer_after_send_scb_failed(struct command *cmd,
485462
const char *method,
486463
const char *buf,

0 commit comments

Comments
 (0)