df-rbf: add method to fail an RBF

this is a bit different than straight up failing a channel. we want to
signal that the RBF attempt failed, only
This commit is contained in:
niftynei 2021-01-12 13:07:10 -06:00 committed by Rusty Russell
parent 54d5cdb938
commit 067f1f2eb7
5 changed files with 74 additions and 2 deletions

View File

@ -1987,6 +1987,10 @@ static unsigned int dual_opend_msg(struct subd *dualopend,
case WIRE_DUALOPEND_FAILED:
open_failed(dualopend, msg);
return 0;
case WIRE_DUALOPEND_RBF_FAILED:
// FIXME: handle this
abort();
return 0;
case WIRE_DUALOPEND_DEV_MEMLEAK_REPLY:
/* Messages we send */

View File

@ -332,6 +332,38 @@ static void negotiation_failed(struct state *state,
open_error(state, "You gave bad parameters: %s", errmsg);
}
/* FIXME: remove this once used */
void rbf_failed(struct state *state, const char *fmt, ...);
void rbf_failed(struct state *state,
const char *fmt, ...)
{
va_list ap;
const char *errmsg;
u8 *msg;
va_start(ap, fmt);
errmsg = tal_vfmt(tmpctx, fmt, ap);
va_end(ap);
msg = towire_fail_rbf(NULL, &state->channel_id,
(u8 *)tal_dup_arr(errmsg, char, errmsg,
strlen(errmsg), 0));
sync_crypto_write(state->pps, take(msg));
status_debug("aborted rbf negotiation: %s", errmsg);
/*~ The "billboard" (exposed as "status" in the JSON listpeers RPC
* call) is a transient per-channel area which indicates important
* information about what is happening. It has a "permanent" area for
* each state, which can be used to indicate what went wrong in that
* state (such as here), and a single transient area for current
* status. */
peer_billboard(true, errmsg);
/* Tell master that RBF failed. */
msg = towire_dualopend_rbf_failed(NULL, errmsg);
wire_sync_write(REQ_FD, take(msg));
}
static void billboard_update(struct state *state)
{
const char *update = billboard_message(tmpctx, state->funding_locked,
@ -2678,6 +2710,7 @@ static u8 *handle_master_in(struct state *state)
case WIRE_DUALOPEND_SHUTDOWN_COMPLETE:
case WIRE_DUALOPEND_FAIL_FALLEN_BEHIND:
case WIRE_DUALOPEND_FAILED:
case WIRE_DUALOPEND_RBF_FAILED:
break;
}

View File

@ -143,6 +143,10 @@ msgdata,dualopend_fail,reason,wirestring,
msgtype,dualopend_failed,7004
msgdata,dualopend_failed,reason,wirestring,
# dualopend->master: we failed to negotate RBF
msgtype,dualopend_rbf_failed,7015
msgdata,dualopend_rbf_failed,reason,wirestring,
# master->dualopend: hello, I'd like to start a channel open
msgtype,dualopend_opener_init,7200
msgdata,dualopend_opener_init,psbt,wally_psbt,

Can't render this file because it has a wrong number of fields in line 13.

View File

@ -29,6 +29,7 @@ const char *dualopend_wire_name(int e)
case WIRE_DUALOPEND_PSBT_UPDATED: return "WIRE_DUALOPEND_PSBT_UPDATED";
case WIRE_DUALOPEND_FAIL: return "WIRE_DUALOPEND_FAIL";
case WIRE_DUALOPEND_FAILED: return "WIRE_DUALOPEND_FAILED";
case WIRE_DUALOPEND_RBF_FAILED: return "WIRE_DUALOPEND_RBF_FAILED";
case WIRE_DUALOPEND_OPENER_INIT: return "WIRE_DUALOPEND_OPENER_INIT";
case WIRE_DUALOPEND_FUNDING_SIGS: return "WIRE_DUALOPEND_FUNDING_SIGS";
case WIRE_DUALOPEND_SEND_TX_SIGS: return "WIRE_DUALOPEND_SEND_TX_SIGS";
@ -60,6 +61,7 @@ bool dualopend_wire_is_defined(u16 type)
case WIRE_DUALOPEND_PSBT_UPDATED:;
case WIRE_DUALOPEND_FAIL:;
case WIRE_DUALOPEND_FAILED:;
case WIRE_DUALOPEND_RBF_FAILED:;
case WIRE_DUALOPEND_OPENER_INIT:;
case WIRE_DUALOPEND_FUNDING_SIGS:;
case WIRE_DUALOPEND_SEND_TX_SIGS:;
@ -529,6 +531,28 @@ bool fromwire_dualopend_failed(const tal_t *ctx, const void *p, wirestring **rea
return cursor != NULL;
}
/* WIRE: DUALOPEND_RBF_FAILED */
/* dualopend->master: we failed to negotate RBF */
u8 *towire_dualopend_rbf_failed(const tal_t *ctx, const wirestring *reason)
{
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_DUALOPEND_RBF_FAILED);
towire_wirestring(&p, reason);
return memcheck(p, tal_count(p));
}
bool fromwire_dualopend_rbf_failed(const tal_t *ctx, const void *p, wirestring **reason)
{
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_DUALOPEND_RBF_FAILED)
return false;
*reason = fromwire_wirestring(ctx, &cursor, &plen);
return cursor != NULL;
}
/* WIRE: DUALOPEND_OPENER_INIT */
/* master->dualopend: hello */
u8 *towire_dualopend_opener_init(const tal_t *ctx, const struct wally_psbt *psbt, struct amount_sat funding_amount, const u8 *local_shutdown_scriptpubkey, u32 feerate_per_kw, u32 feerate_per_kw_funding, u8 channel_flags)
@ -838,4 +862,4 @@ bool fromwire_dualopend_dev_memleak_reply(const void *p, bool *leak)
*leak = fromwire_bool(&cursor, &plen);
return cursor != NULL;
}
// SHA256STAMP:466b562a93af757c8bea696934d22420f3626b43f1476012e44f7946d51b06ba
// SHA256STAMP:6e149f437eae7fde2f891bbb7f36903fa105179d9a97cd1b765d34641c0839ce

View File

@ -38,6 +38,8 @@ enum dualopend_wire {
WIRE_DUALOPEND_FAIL = 7003,
/* dualopend->master: we failed to negotiate channel */
WIRE_DUALOPEND_FAILED = 7004,
/* dualopend->master: we failed to negotate RBF */
WIRE_DUALOPEND_RBF_FAILED = 7015,
/* master->dualopend: hello */
WIRE_DUALOPEND_OPENER_INIT = 7200,
/* dualopend->master received tx_sigs from peer */
@ -122,6 +124,11 @@ bool fromwire_dualopend_fail(const tal_t *ctx, const void *p, wirestring **reaso
u8 *towire_dualopend_failed(const tal_t *ctx, const wirestring *reason);
bool fromwire_dualopend_failed(const tal_t *ctx, const void *p, wirestring **reason);
/* WIRE: DUALOPEND_RBF_FAILED */
/* dualopend->master: we failed to negotate RBF */
u8 *towire_dualopend_rbf_failed(const tal_t *ctx, const wirestring *reason);
bool fromwire_dualopend_rbf_failed(const tal_t *ctx, const void *p, wirestring **reason);
/* WIRE: DUALOPEND_OPENER_INIT */
/* master->dualopend: hello */
u8 *towire_dualopend_opener_init(const tal_t *ctx, const struct wally_psbt *psbt, struct amount_sat funding_amount, const u8 *local_shutdown_scriptpubkey, u32 feerate_per_kw, u32 feerate_per_kw_funding, u8 channel_flags);
@ -188,4 +195,4 @@ bool fromwire_dualopend_dev_memleak_reply(const void *p, bool *leak);
#endif /* LIGHTNING_OPENINGD_DUALOPEND_WIREGEN_H */
// SHA256STAMP:466b562a93af757c8bea696934d22420f3626b43f1476012e44f7946d51b06ba
// SHA256STAMP:6e149f437eae7fde2f891bbb7f36903fa105179d9a97cd1b765d34641c0839ce