Skip to content

Commit

Permalink
funder: handle RBF callback
Browse files Browse the repository at this point in the history
Fund an RBF same as you would an open. We dont' do anything fancy with
our inputs -- we dont' have a copy of the last PSBT that was sent.
  • Loading branch information
niftynei committed Apr 26, 2021
1 parent ef64172 commit fc77f51
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions plugins/funder.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,68 @@ json_openchannel2_call(struct command *cmd,
return send_outreq(cmd->plugin, req);
}

/* Peer has asked us to RBF */
static struct command_result *
json_rbf_channel_call(struct command *cmd,
const char *buf,
const jsmntok_t *params)
{
struct open_info *info = tal(cmd, struct open_info);
u64 feerate_our_max, feerate_our_min;
const char *err;
struct out_req *req;

err = json_scan(tmpctx, buf, params,
"{rbf_channel:"
"{id:%"
",channel_id:%"
",their_funding:%"
",funding_feerate_per_kw:%"
",feerate_our_max:%"
",feerate_our_min:%"
",locktime:%"
",channel_max:%}}",
JSON_SCAN(json_to_node_id, &info->id),
JSON_SCAN(json_to_channel_id, &info->cid),
JSON_SCAN(json_to_sat, &info->their_funding),
JSON_SCAN(json_to_u64, &info->funding_feerate_perkw),
JSON_SCAN(json_to_u64, &feerate_our_max),
JSON_SCAN(json_to_u64, &feerate_our_min),
JSON_SCAN(json_to_u32, &info->locktime),
JSON_SCAN(json_to_sat, &info->channel_max));

if (err)
plugin_err(cmd->plugin,
"`openchannel2` payload did not scan %s: %.*s",
err, json_tok_full_len(params),
json_tok_full(buf, params));

/* We don't fund anything that's above or below our feerate */
if (info->funding_feerate_perkw < feerate_our_min
|| info->funding_feerate_perkw > feerate_our_max) {

plugin_log(cmd->plugin, LOG_DBG,
"their feerate %"PRIu64" is out of"
" our bounds (%"PRIu64"-%"PRIu64")",
info->funding_feerate_perkw,
feerate_our_min,
feerate_our_max);

return command_hook_success(cmd);
}

/* Figure out what our funds are... same flow
* as with openchannel2 callback. We assume that THEY
* will use the same inputs, so we use whatever we want here */
req = jsonrpc_request_start(cmd->plugin, cmd,
"listfunds",
&listfunds_success,
&listfunds_failed,
info);

return send_outreq(cmd->plugin, req);
}

static void json_disconnect(struct command *cmd,
const char *buf,
const jsmntok_t *params)
Expand Down Expand Up @@ -744,6 +806,10 @@ const struct plugin_hook hooks[] = {
"openchannel2_sign",
json_openchannel2_sign_call,
},
{
"rbf_channel",
json_rbf_channel_call,
},
};

const struct plugin_notification notifs[] = {
Expand Down

0 comments on commit fc77f51

Please sign in to comment.