mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
hsmd: Add hsmd_ready_channel
This commit is contained in:
committed by
Rusty Russell
parent
bb574be839
commit
335ef3fb69
@@ -641,6 +641,7 @@ static struct io_plan *handle_client(struct io_conn *conn, struct client *c)
|
||||
#endif /* DEVELOPER */
|
||||
|
||||
case WIRE_HSMD_NEW_CHANNEL:
|
||||
case WIRE_HSMD_READY_CHANNEL:
|
||||
case WIRE_HSMD_SIGN_COMMITMENT_TX:
|
||||
case WIRE_HSMD_VALIDATE_REVOCATION:
|
||||
case WIRE_HSMD_SIGN_PENALTY_TO_US:
|
||||
@@ -673,6 +674,7 @@ static struct io_plan *handle_client(struct io_conn *conn, struct client *c)
|
||||
case WIRE_HSMD_CUPDATE_SIG_REPLY:
|
||||
case WIRE_HSMD_CLIENT_HSMFD_REPLY:
|
||||
case WIRE_HSMD_NEW_CHANNEL_REPLY:
|
||||
case WIRE_HSMD_READY_CHANNEL_REPLY:
|
||||
case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY:
|
||||
case WIRE_HSMD_SIGN_WITHDRAWAL_REPLY:
|
||||
case WIRE_HSMD_SIGN_INVOICE_REPLY:
|
||||
|
||||
@@ -52,6 +52,28 @@ msgtype,hsmd_get_channel_basepoints_reply,110
|
||||
msgdata,hsmd_get_channel_basepoints_reply,basepoints,basepoints,
|
||||
msgdata,hsmd_get_channel_basepoints_reply,funding_pubkey,pubkey,
|
||||
|
||||
#include <common/channel_type.h>
|
||||
# Provide channel parameters.
|
||||
msgtype,hsmd_ready_channel,31
|
||||
msgdata,hsmd_ready_channel,is_outbound,bool,
|
||||
msgdata,hsmd_ready_channel,channel_value,amount_sat,
|
||||
msgdata,hsmd_ready_channel,push_value,amount_msat,
|
||||
msgdata,hsmd_ready_channel,funding_txid,bitcoin_txid,
|
||||
msgdata,hsmd_ready_channel,funding_txout,u16,
|
||||
msgdata,hsmd_ready_channel,local_to_self_delay,u16,
|
||||
msgdata,hsmd_ready_channel,local_shutdown_script_len,u16,
|
||||
msgdata,hsmd_ready_channel,local_shutdown_script,u8,local_shutdown_script_len
|
||||
msgdata,hsmd_ready_channel,local_shutdown_wallet_index,?u32,
|
||||
msgdata,hsmd_ready_channel,remote_basepoints,basepoints,
|
||||
msgdata,hsmd_ready_channel,remote_funding_pubkey,pubkey,
|
||||
msgdata,hsmd_ready_channel,remote_to_self_delay,u16,
|
||||
msgdata,hsmd_ready_channel,remote_shutdown_script_len,u16,
|
||||
msgdata,hsmd_ready_channel,remote_shutdown_script,u8,remote_shutdown_script_len
|
||||
msgdata,hsmd_ready_channel,channel_type,channel_type,
|
||||
|
||||
# No value returned.
|
||||
msgtype,hsmd_ready_channel_reply,131
|
||||
|
||||
# Return signature for a funding tx.
|
||||
#include <common/utxo.h>
|
||||
|
||||
|
||||
|
@@ -91,6 +91,7 @@ bool hsmd_check_client_capabilities(struct hsmd_client *client,
|
||||
|
||||
case WIRE_HSMD_GET_PER_COMMITMENT_POINT:
|
||||
case WIRE_HSMD_CHECK_FUTURE_SECRET:
|
||||
case WIRE_HSMD_READY_CHANNEL:
|
||||
return (client->capabilities & HSM_CAP_COMMITMENT_POINT) != 0;
|
||||
|
||||
case WIRE_HSMD_SIGN_REMOTE_COMMITMENT_TX:
|
||||
@@ -125,6 +126,7 @@ bool hsmd_check_client_capabilities(struct hsmd_client *client,
|
||||
case WIRE_HSMD_CUPDATE_SIG_REPLY:
|
||||
case WIRE_HSMD_CLIENT_HSMFD_REPLY:
|
||||
case WIRE_HSMD_NEW_CHANNEL_REPLY:
|
||||
case WIRE_HSMD_READY_CHANNEL_REPLY:
|
||||
case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY:
|
||||
case WIRE_HSMD_SIGN_WITHDRAWAL_REPLY:
|
||||
case WIRE_HSMD_SIGN_INVOICE_REPLY:
|
||||
@@ -296,6 +298,59 @@ static u8 *handle_new_channel(struct hsmd_client *c, const u8 *msg_in)
|
||||
return towire_hsmd_new_channel_reply(NULL);
|
||||
}
|
||||
|
||||
static bool mem_is_zero(const void *mem, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < len; ++i)
|
||||
if (((const unsigned char *)mem)[i])
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ~This stub implementation is overriden by fully validating signers
|
||||
* that need the unchanging channel parameters. */
|
||||
static u8 *handle_ready_channel(struct hsmd_client *c, const u8 *msg_in)
|
||||
{
|
||||
bool is_outbound;
|
||||
struct amount_sat channel_value;
|
||||
struct amount_msat push_value;
|
||||
struct bitcoin_txid funding_txid;
|
||||
u16 funding_txout;
|
||||
u16 local_to_self_delay;
|
||||
u8 *local_shutdown_script;
|
||||
u32 *local_shutdown_wallet_index;
|
||||
struct basepoints remote_basepoints;
|
||||
struct pubkey remote_funding_pubkey;
|
||||
u16 remote_to_self_delay;
|
||||
u8 *remote_shutdown_script;
|
||||
struct amount_msat value_msat;
|
||||
struct channel_type *channel_type;
|
||||
|
||||
if (!fromwire_hsmd_ready_channel(tmpctx, msg_in, &is_outbound,
|
||||
&channel_value, &push_value, &funding_txid,
|
||||
&funding_txout, &local_to_self_delay,
|
||||
&local_shutdown_script,
|
||||
&local_shutdown_wallet_index,
|
||||
&remote_basepoints,
|
||||
&remote_funding_pubkey,
|
||||
&remote_to_self_delay,
|
||||
&remote_shutdown_script,
|
||||
&channel_type))
|
||||
return hsmd_status_malformed_request(c, msg_in);
|
||||
|
||||
/* Stub implementation */
|
||||
|
||||
/* Fail fast if any values are uninitialized or obviously wrong. */
|
||||
assert(amount_sat_greater(channel_value, AMOUNT_SAT(0)));
|
||||
assert(amount_sat_to_msat(&value_msat, channel_value));
|
||||
assert(amount_msat_less_eq(push_value, value_msat));
|
||||
assert(!mem_is_zero(&funding_txid, sizeof(funding_txid)));
|
||||
assert(local_to_self_delay > 0);
|
||||
assert(remote_to_self_delay > 0);
|
||||
|
||||
return towire_hsmd_ready_channel_reply(NULL);
|
||||
}
|
||||
|
||||
/*~ For almost every wallet tx we use the BIP32 seed, but not for onchain
|
||||
* unilateral closes from a peer: they (may) have an output to us using a
|
||||
* public key based on the channel basepoints. It's a bit spammy to spend
|
||||
@@ -1431,6 +1486,8 @@ u8 *hsmd_handle_client_message(const tal_t *ctx, struct hsmd_client *client,
|
||||
|
||||
case WIRE_HSMD_NEW_CHANNEL:
|
||||
return handle_new_channel(client, msg);
|
||||
case WIRE_HSMD_READY_CHANNEL:
|
||||
return handle_ready_channel(client, msg);
|
||||
case WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY:
|
||||
return handle_get_output_scriptpubkey(client, msg);
|
||||
case WIRE_HSMD_CHECK_FUTURE_SECRET:
|
||||
@@ -1482,6 +1539,7 @@ u8 *hsmd_handle_client_message(const tal_t *ctx, struct hsmd_client *client,
|
||||
case WIRE_HSMD_CUPDATE_SIG_REPLY:
|
||||
case WIRE_HSMD_CLIENT_HSMFD_REPLY:
|
||||
case WIRE_HSMD_NEW_CHANNEL_REPLY:
|
||||
case WIRE_HSMD_READY_CHANNEL_REPLY:
|
||||
case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY:
|
||||
case WIRE_HSMD_SIGN_WITHDRAWAL_REPLY:
|
||||
case WIRE_HSMD_SIGN_INVOICE_REPLY:
|
||||
|
||||
@@ -616,6 +616,7 @@ openchannel2_hook_cb(struct openchannel2_payload *payload STEALS)
|
||||
{
|
||||
struct subd *dualopend = payload->dualopend;
|
||||
struct channel *channel = payload->channel;
|
||||
u32 *our_shutdown_script_wallet_index;
|
||||
u8 *msg;
|
||||
|
||||
/* Our daemon died! */
|
||||
@@ -646,6 +647,19 @@ openchannel2_hook_cb(struct openchannel2_payload *payload STEALS)
|
||||
return subd_send_msg(dualopend, take(msg));
|
||||
}
|
||||
|
||||
/* Determine the wallet index for our_shutdown_scriptpubkey,
|
||||
* NULL if not found. */
|
||||
u32 found_wallet_index;
|
||||
bool is_p2sh;
|
||||
if (wallet_can_spend(dualopend->ld->wallet,
|
||||
payload->our_shutdown_scriptpubkey,
|
||||
&found_wallet_index,
|
||||
&is_p2sh)) {
|
||||
our_shutdown_script_wallet_index = tal(tmpctx, u32);
|
||||
*our_shutdown_script_wallet_index = found_wallet_index;
|
||||
} else
|
||||
our_shutdown_script_wallet_index = NULL;
|
||||
|
||||
channel->cid = payload->channel_id;
|
||||
channel->opener = REMOTE;
|
||||
channel->open_attempt = new_channel_open_attempt(channel);
|
||||
@@ -653,6 +667,7 @@ openchannel2_hook_cb(struct openchannel2_payload *payload STEALS)
|
||||
payload->accepter_funding,
|
||||
payload->psbt,
|
||||
payload->our_shutdown_scriptpubkey,
|
||||
our_shutdown_script_wallet_index,
|
||||
payload->rates);
|
||||
|
||||
subd_send_msg(dualopend, take(msg));
|
||||
@@ -2468,6 +2483,7 @@ static struct command_result *json_openchannel_init(struct command *cmd,
|
||||
struct amount_sat *amount, psbt_val, *request_amt;
|
||||
struct wally_psbt *psbt;
|
||||
const u8 *our_upfront_shutdown_script;
|
||||
u32 *our_upfront_shutdown_script_wallet_index;
|
||||
struct open_attempt *oa;
|
||||
struct lease_rates *rates;
|
||||
struct command_result *res;
|
||||
@@ -2603,9 +2619,23 @@ static struct command_result *json_openchannel_init(struct command *cmd,
|
||||
oa->our_upfront_shutdown_script
|
||||
= tal_steal(oa, our_upfront_shutdown_script);
|
||||
|
||||
/* Determine the wallet index for our_upfront_shutdown_script,
|
||||
* NULL if not found. */
|
||||
u32 found_wallet_index;
|
||||
bool is_p2sh;
|
||||
if (wallet_can_spend(cmd->ld->wallet,
|
||||
oa->our_upfront_shutdown_script,
|
||||
&found_wallet_index,
|
||||
&is_p2sh)) {
|
||||
our_upfront_shutdown_script_wallet_index = tal(tmpctx, u32);
|
||||
*our_upfront_shutdown_script_wallet_index = found_wallet_index;
|
||||
} else
|
||||
our_upfront_shutdown_script_wallet_index = NULL;
|
||||
|
||||
msg = towire_dualopend_opener_init(NULL,
|
||||
psbt, *amount,
|
||||
oa->our_upfront_shutdown_script,
|
||||
our_upfront_shutdown_script_wallet_index,
|
||||
*feerate_per_kw,
|
||||
*feerate_per_kw_funding,
|
||||
channel->channel_flags,
|
||||
@@ -2989,6 +3019,7 @@ static struct command_result *json_queryrates(struct command *cmd,
|
||||
struct amount_sat *amount, *request_amt;
|
||||
struct wally_psbt *psbt;
|
||||
struct open_attempt *oa;
|
||||
u32 *our_upfront_shutdown_script_wallet_index;
|
||||
u8 *msg;
|
||||
struct command_result *res;
|
||||
|
||||
@@ -3060,9 +3091,23 @@ static struct command_result *json_queryrates(struct command *cmd,
|
||||
/* empty psbt to start */
|
||||
psbt = create_psbt(tmpctx, 0, 0, 0);
|
||||
|
||||
/* Determine the wallet index for our_upfront_shutdown_script,
|
||||
* NULL if not found. */
|
||||
u32 found_wallet_index;
|
||||
bool is_p2sh;
|
||||
if (wallet_can_spend(cmd->ld->wallet,
|
||||
oa->our_upfront_shutdown_script,
|
||||
&found_wallet_index,
|
||||
&is_p2sh)) {
|
||||
our_upfront_shutdown_script_wallet_index = tal(tmpctx, u32);
|
||||
*our_upfront_shutdown_script_wallet_index = found_wallet_index;
|
||||
} else
|
||||
our_upfront_shutdown_script_wallet_index = NULL;
|
||||
|
||||
msg = towire_dualopend_opener_init(NULL,
|
||||
psbt, *amount,
|
||||
oa->our_upfront_shutdown_script,
|
||||
our_upfront_shutdown_script_wallet_index,
|
||||
*feerate_per_kw,
|
||||
*feerate_per_kw_funding,
|
||||
channel->channel_flags,
|
||||
@@ -3201,6 +3246,7 @@ void peer_restart_dualopend(struct peer *peer,
|
||||
struct channel_config unused_config;
|
||||
struct channel_inflight *inflight;
|
||||
int hsmfd;
|
||||
u32 *local_shutdown_script_wallet_index;
|
||||
u8 *msg;
|
||||
|
||||
if (channel_unsaved(channel)) {
|
||||
@@ -3243,6 +3289,19 @@ void peer_restart_dualopend(struct peer *peer,
|
||||
blockheight = get_blockheight(channel->blockheight_states,
|
||||
channel->opener, LOCAL);
|
||||
|
||||
/* Determine the wallet index for the LOCAL shutdown_scriptpubkey,
|
||||
* NULL if not found. */
|
||||
u32 found_wallet_index;
|
||||
bool is_p2sh;
|
||||
if (wallet_can_spend(peer->ld->wallet,
|
||||
channel->shutdown_scriptpubkey[LOCAL],
|
||||
&found_wallet_index,
|
||||
&is_p2sh)) {
|
||||
local_shutdown_script_wallet_index = tal(tmpctx, u32);
|
||||
*local_shutdown_script_wallet_index = found_wallet_index;
|
||||
} else
|
||||
local_shutdown_script_wallet_index = NULL;
|
||||
|
||||
msg = towire_dualopend_reinit(NULL,
|
||||
chainparams,
|
||||
peer->ld->our_features,
|
||||
@@ -3271,6 +3330,7 @@ void peer_restart_dualopend(struct peer *peer,
|
||||
channel->shutdown_scriptpubkey[REMOTE] != NULL,
|
||||
channel->shutdown_scriptpubkey[LOCAL],
|
||||
channel->remote_upfront_shutdown_script,
|
||||
local_shutdown_script_wallet_index,
|
||||
inflight->remote_tx_sigs,
|
||||
channel->fee_states,
|
||||
channel->channel_flags,
|
||||
|
||||
@@ -649,6 +649,7 @@ openchannel_hook_final(struct openchannel_hook_payload *payload STEALS)
|
||||
const u8 *our_upfront_shutdown_script = payload->our_upfront_shutdown_script;
|
||||
const char *errmsg = payload->errmsg;
|
||||
struct uncommitted_channel* uc = payload->uc;
|
||||
u32 *upfront_shutdown_script_wallet_index;
|
||||
|
||||
/* We want to free this, whatever happens. */
|
||||
tal_steal(tmpctx, payload);
|
||||
@@ -669,9 +670,24 @@ openchannel_hook_final(struct openchannel_hook_payload *payload STEALS)
|
||||
uc->got_offer = true;
|
||||
}
|
||||
|
||||
/* Determine the wallet index for our_upfront_shutdown_script,
|
||||
* NULL if not found. */
|
||||
u32 found_wallet_index;
|
||||
bool is_p2sh;
|
||||
if (wallet_can_spend(payload->openingd->ld->wallet,
|
||||
our_upfront_shutdown_script,
|
||||
&found_wallet_index,
|
||||
&is_p2sh)) {
|
||||
upfront_shutdown_script_wallet_index = tal(tmpctx, u32);
|
||||
*upfront_shutdown_script_wallet_index = found_wallet_index;
|
||||
} else
|
||||
upfront_shutdown_script_wallet_index = NULL;
|
||||
|
||||
|
||||
subd_send_msg(openingd,
|
||||
take(towire_openingd_got_offer_reply(NULL, errmsg,
|
||||
our_upfront_shutdown_script)));
|
||||
our_upfront_shutdown_script,
|
||||
upfront_shutdown_script_wallet_index)));
|
||||
}
|
||||
|
||||
static bool
|
||||
@@ -760,8 +776,8 @@ static void opening_got_offer(struct subd *openingd,
|
||||
/* Tell them they can't open, if we already have open channel. */
|
||||
if (peer_active_channel(uc->peer)) {
|
||||
subd_send_msg(openingd,
|
||||
take(towire_openingd_got_offer_reply(NULL,
|
||||
"Already have active channel", NULL)));
|
||||
take(towire_openingd_got_offer_reply(
|
||||
NULL, "Already have active channel", NULL, NULL)));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1110,6 +1126,7 @@ static struct command_result *json_fundchannel_start(struct command *cmd,
|
||||
u8 *msg = NULL;
|
||||
struct amount_sat *amount;
|
||||
struct amount_msat *push_msat;
|
||||
u32 *upfront_shutdown_script_wallet_index;
|
||||
|
||||
fc->cmd = cmd;
|
||||
fc->cancels = tal_arr(fc, struct command *, 0);
|
||||
@@ -1220,10 +1237,24 @@ static struct command_result *json_fundchannel_start(struct command *cmd,
|
||||
fc->our_upfront_shutdown_script
|
||||
= tal_steal(fc, fc->our_upfront_shutdown_script);
|
||||
|
||||
/* Determine the wallet index for our_upfront_shutdown_script,
|
||||
* NULL if not found. */
|
||||
u32 found_wallet_index;
|
||||
bool is_p2sh;
|
||||
if (wallet_can_spend(fc->cmd->ld->wallet,
|
||||
fc->our_upfront_shutdown_script,
|
||||
&found_wallet_index,
|
||||
&is_p2sh)) {
|
||||
upfront_shutdown_script_wallet_index = tal(tmpctx, u32);
|
||||
*upfront_shutdown_script_wallet_index = found_wallet_index;
|
||||
} else
|
||||
upfront_shutdown_script_wallet_index = NULL;
|
||||
|
||||
msg = towire_openingd_funder_start(NULL,
|
||||
*amount,
|
||||
fc->push,
|
||||
fc->our_upfront_shutdown_script,
|
||||
upfront_shutdown_script_wallet_index,
|
||||
*feerate_per_kw,
|
||||
fc->channel_flags);
|
||||
|
||||
|
||||
@@ -181,6 +181,9 @@ struct state {
|
||||
/* If non-NULL, this is the scriptpubkey we/they *must* close with */
|
||||
u8 *upfront_shutdown_script[NUM_SIDES];
|
||||
|
||||
/* If non-NULL, the wallet index for the LOCAL script */
|
||||
u32 *local_upfront_shutdown_wallet_index;
|
||||
|
||||
/* The channel structure, as defined in common/initial_channel.h. While
|
||||
* the structure has room for HTLCs, those routines are
|
||||
* channeld-specific as initial channels never have HTLCs. */
|
||||
@@ -1799,6 +1802,28 @@ static u8 *accepter_commits(struct state *state,
|
||||
|
||||
type = default_channel_type(NULL,
|
||||
state->our_features, state->their_features);
|
||||
|
||||
/*~ Report the channel parameters to the signer. */
|
||||
msg = towire_hsmd_ready_channel(NULL,
|
||||
false, /* is_outbound */
|
||||
total,
|
||||
our_msats,
|
||||
&tx_state->funding.txid,
|
||||
tx_state->funding.n,
|
||||
tx_state->localconf.to_self_delay,
|
||||
state->upfront_shutdown_script[LOCAL],
|
||||
state->local_upfront_shutdown_wallet_index,
|
||||
&state->their_points,
|
||||
&state->their_funding_pubkey,
|
||||
tx_state->remoteconf.to_self_delay,
|
||||
state->upfront_shutdown_script[REMOTE],
|
||||
type);
|
||||
wire_sync_write(HSM_FD, take(msg));
|
||||
msg = wire_sync_read(tmpctx, HSM_FD);
|
||||
if (!fromwire_hsmd_ready_channel_reply(msg))
|
||||
status_failed(STATUS_FAIL_HSM_IO, "Bad ready_channel_reply %s",
|
||||
tal_hex(tmpctx, msg));
|
||||
|
||||
state->channel = new_initial_channel(state,
|
||||
&state->channel_id,
|
||||
&tx_state->funding,
|
||||
@@ -2139,6 +2164,7 @@ static void accepter_start(struct state *state, const u8 *oc2_msg)
|
||||
&tx_state->accepter_funding,
|
||||
&tx_state->psbt,
|
||||
&state->upfront_shutdown_script[LOCAL],
|
||||
&state->local_upfront_shutdown_wallet_index,
|
||||
&tx_state->rates))
|
||||
master_badmsg(WIRE_DUALOPEND_GOT_OFFER_REPLY, msg);
|
||||
|
||||
@@ -2367,6 +2393,7 @@ static u8 *opener_commits(struct state *state,
|
||||
const u8 *wscript;
|
||||
u8 *msg;
|
||||
char *error;
|
||||
struct amount_msat their_msats;
|
||||
const struct channel_type *type;
|
||||
|
||||
wscript = bitcoin_redeem_2of2(tmpctx, &state->our_funding_pubkey,
|
||||
@@ -2409,9 +2436,40 @@ static u8 *opener_commits(struct state *state,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!amount_sat_to_msat(&their_msats, tx_state->accepter_funding)) {
|
||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||
"Overflow error, can't convert accepter_funding %s"
|
||||
" to msats",
|
||||
type_to_string(tmpctx, struct amount_sat,
|
||||
&tx_state->accepter_funding));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Ok, we're mostly good now? Let's do this */
|
||||
type = default_channel_type(NULL,
|
||||
state->our_features, state->their_features);
|
||||
|
||||
/*~ Report the channel parameters to the signer. */
|
||||
msg = towire_hsmd_ready_channel(NULL,
|
||||
true, /* is_outbound */
|
||||
total,
|
||||
their_msats,
|
||||
&tx_state->funding.txid,
|
||||
tx_state->funding.n,
|
||||
tx_state->localconf.to_self_delay,
|
||||
state->upfront_shutdown_script[LOCAL],
|
||||
state->local_upfront_shutdown_wallet_index,
|
||||
&state->their_points,
|
||||
&state->their_funding_pubkey,
|
||||
tx_state->remoteconf.to_self_delay,
|
||||
state->upfront_shutdown_script[REMOTE],
|
||||
type);
|
||||
wire_sync_write(HSM_FD, take(msg));
|
||||
msg = wire_sync_read(tmpctx, HSM_FD);
|
||||
if (!fromwire_hsmd_ready_channel_reply(msg))
|
||||
status_failed(STATUS_FAIL_HSM_IO, "Bad ready_channel_reply %s",
|
||||
tal_hex(tmpctx, msg));
|
||||
|
||||
state->channel = new_initial_channel(state,
|
||||
&cid,
|
||||
&tx_state->funding,
|
||||
@@ -2612,6 +2670,7 @@ static void opener_start(struct state *state, u8 *msg)
|
||||
&tx_state->psbt,
|
||||
&tx_state->opener_funding,
|
||||
&state->upfront_shutdown_script[LOCAL],
|
||||
&state->local_upfront_shutdown_wallet_index,
|
||||
&state->feerate_per_kw_commitment,
|
||||
&tx_state->feerate_per_kw_funding,
|
||||
&state->channel_flags,
|
||||
@@ -3826,6 +3885,7 @@ int main(int argc, char *argv[])
|
||||
&state->shutdown_sent[REMOTE],
|
||||
&state->upfront_shutdown_script[LOCAL],
|
||||
&state->upfront_shutdown_script[REMOTE],
|
||||
&state->local_upfront_shutdown_wallet_index,
|
||||
&state->tx_state->remote_funding_sigs_rcvd,
|
||||
&fee_states,
|
||||
&state->channel_flags,
|
||||
|
||||
@@ -61,6 +61,7 @@ msgdata,dualopend_reinit,local_shutdown_len,u16,
|
||||
msgdata,dualopend_reinit,local_shutdown_scriptpubkey,u8,local_shutdown_len
|
||||
msgdata,dualopend_reinit,remote_shutdown_len,u16,
|
||||
msgdata,dualopend_reinit,remote_shutdown_scriptpubkey,u8,remote_shutdown_len
|
||||
msgdata,dualopend_reinit,local_shutdown_wallet_index,?u32,
|
||||
msgdata,dualopend_reinit,remote_funding_sigs_received,bool,
|
||||
msgdata,dualopend_reinit,fee_states,fee_states,
|
||||
msgdata,dualopend_reinit,channel_flags,u8,
|
||||
@@ -94,6 +95,7 @@ msgdata,dualopend_got_offer_reply,accepter_funding,amount_sat,
|
||||
msgdata,dualopend_got_offer_reply,psbt,wally_psbt,
|
||||
msgdata,dualopend_got_offer_reply,shutdown_len,u16,
|
||||
msgdata,dualopend_got_offer_reply,our_shutdown_scriptpubkey,?u8,shutdown_len
|
||||
msgdata,dualopend_got_offer_reply,our_shutdown_wallet_index,?u32,
|
||||
# must go last because of embedded tu32
|
||||
msgdata,dualopend_got_offer_reply,lease_rates,?lease_rates,
|
||||
|
||||
@@ -172,6 +174,7 @@ msgdata,dualopend_opener_init,psbt,wally_psbt,
|
||||
msgdata,dualopend_opener_init,funding_amount,amount_sat,
|
||||
msgdata,dualopend_opener_init,local_shutdown_len,u16,
|
||||
msgdata,dualopend_opener_init,local_shutdown_scriptpubkey,u8,local_shutdown_len
|
||||
msgdata,dualopend_opener_init,local_shutdown_wallet_index,?u32,
|
||||
msgdata,dualopend_opener_init,feerate_per_kw,u32,
|
||||
msgdata,dualopend_opener_init,feerate_per_kw_funding,u32,
|
||||
msgdata,dualopend_opener_init,channel_flags,u8,
|
||||
|
||||
|
Can't render this file because it has a wrong number of fields in line 15.
|
@@ -84,6 +84,9 @@ struct state {
|
||||
/* If non-NULL, this is the scriptpubkey we/they *must* close with */
|
||||
u8 *upfront_shutdown_script[NUM_SIDES];
|
||||
|
||||
/* If non-NULL, the wallet index for the LOCAL script */
|
||||
u32 *local_upfront_shutdown_wallet_index;
|
||||
|
||||
/* This is a cluster of fields in open_channel and accept_channel which
|
||||
* indicate the restrictions each side places on the channel. */
|
||||
struct channel_config localconf, remoteconf;
|
||||
@@ -519,6 +522,27 @@ static bool funder_finalize_channel_setup(struct state *state,
|
||||
char *err_reason;
|
||||
struct wally_tx_output *direct_outputs[NUM_SIDES];
|
||||
|
||||
/*~ Channel is ready; Report the channel parameters to the signer. */
|
||||
msg = towire_hsmd_ready_channel(NULL,
|
||||
true, /* is_outbound */
|
||||
state->funding_sats,
|
||||
state->push_msat,
|
||||
&state->funding.txid,
|
||||
state->funding.n,
|
||||
state->localconf.to_self_delay,
|
||||
state->upfront_shutdown_script[LOCAL],
|
||||
state->local_upfront_shutdown_wallet_index,
|
||||
&state->their_points,
|
||||
&state->their_funding_pubkey,
|
||||
state->remoteconf.to_self_delay,
|
||||
state->upfront_shutdown_script[REMOTE],
|
||||
state->channel_type);
|
||||
wire_sync_write(HSM_FD, take(msg));
|
||||
msg = wire_sync_read(tmpctx, HSM_FD);
|
||||
if (!fromwire_hsmd_ready_channel_reply(msg))
|
||||
status_failed(STATUS_FAIL_HSM_IO, "Bad ready_channel_reply %s",
|
||||
tal_hex(tmpctx, msg));
|
||||
|
||||
/*~ Now we can initialize the `struct channel`. This represents
|
||||
* the current channel state and is how we can generate the current
|
||||
* commitment transaction.
|
||||
@@ -979,7 +1003,8 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
|
||||
/* We don't allocate off tmpctx, because that's freed inside
|
||||
* opening_negotiate_msg */
|
||||
if (!fromwire_openingd_got_offer_reply(state, msg, &err_reason,
|
||||
&state->upfront_shutdown_script[LOCAL]))
|
||||
&state->upfront_shutdown_script[LOCAL],
|
||||
&state->local_upfront_shutdown_wallet_index))
|
||||
master_badmsg(WIRE_OPENINGD_GOT_OFFER_REPLY, msg);
|
||||
|
||||
/* If they give us a reason to reject, do so. */
|
||||
@@ -1055,6 +1080,27 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
|
||||
&state->channel_id),
|
||||
type_to_string(msg, struct channel_id, &id_in));
|
||||
|
||||
/*~ Channel is ready; Report the channel parameters to the signer. */
|
||||
msg = towire_hsmd_ready_channel(NULL,
|
||||
false, /* is_outbound */
|
||||
state->funding_sats,
|
||||
state->push_msat,
|
||||
&state->funding.txid,
|
||||
state->funding.n,
|
||||
state->localconf.to_self_delay,
|
||||
state->upfront_shutdown_script[LOCAL],
|
||||
state->local_upfront_shutdown_wallet_index,
|
||||
&theirs,
|
||||
&their_funding_pubkey,
|
||||
state->remoteconf.to_self_delay,
|
||||
state->upfront_shutdown_script[REMOTE],
|
||||
state->channel_type);
|
||||
wire_sync_write(HSM_FD, take(msg));
|
||||
msg = wire_sync_read(tmpctx, HSM_FD);
|
||||
if (!fromwire_hsmd_ready_channel_reply(msg))
|
||||
status_failed(STATUS_FAIL_HSM_IO, "Bad ready_channel_reply %s",
|
||||
tal_hex(tmpctx, msg));
|
||||
|
||||
/* Now we can create the channel structure. */
|
||||
state->channel = new_initial_channel(state,
|
||||
&state->channel_id,
|
||||
@@ -1318,6 +1364,7 @@ static u8 *handle_master_in(struct state *state)
|
||||
&state->funding_sats,
|
||||
&state->push_msat,
|
||||
&state->upfront_shutdown_script[LOCAL],
|
||||
&state->local_upfront_shutdown_wallet_index,
|
||||
&state->feerate_per_kw,
|
||||
&channel_flags))
|
||||
master_badmsg(WIRE_OPENINGD_FUNDER_START, msg);
|
||||
|
||||
@@ -55,6 +55,7 @@ msgtype,openingd_got_offer_reply,6105
|
||||
msgdata,openingd_got_offer_reply,rejection,?wirestring,
|
||||
msgdata,openingd_got_offer_reply,shutdown_len,u16,
|
||||
msgdata,openingd_got_offer_reply,our_shutdown_scriptpubkey,?u8,shutdown_len
|
||||
msgdata,openingd_got_offer_reply,our_shutdown_wallet_index,?u32,
|
||||
|
||||
#include <common/penalty_base.h>
|
||||
# Openingd->master: we've successfully offered channel.
|
||||
@@ -85,6 +86,7 @@ msgdata,openingd_funder_start,funding_satoshis,amount_sat,
|
||||
msgdata,openingd_funder_start,push_msat,amount_msat,
|
||||
msgdata,openingd_funder_start,len_upfront,u16,
|
||||
msgdata,openingd_funder_start,upfront_shutdown_script,u8,len_upfront
|
||||
msgdata,openingd_funder_start,upfront_shutdown_wallet_index,?u32,
|
||||
msgdata,openingd_funder_start,feerate_per_kw,u32,
|
||||
msgdata,openingd_funder_start,channel_flags,u8,
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user