mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-26 20:30:59 +01:00
openingd: Return the penalty base after funding completes
This commit is contained in:
parent
eb8eabcc3c
commit
30e4443eae
5 changed files with 51 additions and 22 deletions
|
@ -53,6 +53,7 @@ LIGHTNINGD_COMMON_OBJS := \
|
|||
common/onion.o \
|
||||
common/onionreply.o \
|
||||
common/param.o \
|
||||
common/penalty_base.o \
|
||||
common/per_peer_state.o \
|
||||
common/permute_tx.o \
|
||||
common/pseudorand.o \
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <common/jsonrpc_errors.h>
|
||||
#include <common/key_derive.h>
|
||||
#include <common/param.h>
|
||||
#include <common/penalty_base.h>
|
||||
#include <common/per_peer_state.h>
|
||||
#include <common/utils.h>
|
||||
#include <common/wallet_tx.h>
|
||||
|
@ -374,6 +375,7 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
|
|||
struct lightningd *ld = openingd->ld;
|
||||
u8 *remote_upfront_shutdown_script;
|
||||
struct per_peer_state *pps;
|
||||
struct penalty_base *pbase;
|
||||
|
||||
/* This is a new channel_info.their_config so set its ID to 0 */
|
||||
channel_info.their_config.id = 0;
|
||||
|
@ -381,6 +383,7 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
|
|||
if (!fromwire_opening_funder_reply(resp, resp,
|
||||
&channel_info.their_config,
|
||||
&remote_commit,
|
||||
&pbase,
|
||||
&remote_commit_sig,
|
||||
&pps,
|
||||
&channel_info.theirbase.revocation,
|
||||
|
@ -464,6 +467,7 @@ static void opening_fundee_finished(struct subd *openingd,
|
|||
struct channel *channel;
|
||||
u8 *remote_upfront_shutdown_script, *local_upfront_shutdown_script;
|
||||
struct per_peer_state *pps;
|
||||
struct penalty_base *pbase;
|
||||
|
||||
log_debug(uc->log, "Got opening_fundee_finish_response");
|
||||
|
||||
|
@ -471,26 +475,27 @@ static void opening_fundee_finished(struct subd *openingd,
|
|||
channel_info.their_config.id = 0;
|
||||
|
||||
if (!fromwire_opening_fundee(tmpctx, reply,
|
||||
&channel_info.their_config,
|
||||
&remote_commit,
|
||||
&remote_commit_sig,
|
||||
&pps,
|
||||
&channel_info.theirbase.revocation,
|
||||
&channel_info.theirbase.payment,
|
||||
&channel_info.theirbase.htlc,
|
||||
&channel_info.theirbase.delayed_payment,
|
||||
&channel_info.remote_per_commit,
|
||||
&channel_info.remote_fundingkey,
|
||||
&funding_txid,
|
||||
&funding_outnum,
|
||||
&funding,
|
||||
&push,
|
||||
&channel_flags,
|
||||
&feerate,
|
||||
&funding_signed,
|
||||
&uc->our_config.channel_reserve,
|
||||
&local_upfront_shutdown_script,
|
||||
&remote_upfront_shutdown_script)) {
|
||||
&channel_info.their_config,
|
||||
&remote_commit,
|
||||
&pbase,
|
||||
&remote_commit_sig,
|
||||
&pps,
|
||||
&channel_info.theirbase.revocation,
|
||||
&channel_info.theirbase.payment,
|
||||
&channel_info.theirbase.htlc,
|
||||
&channel_info.theirbase.delayed_payment,
|
||||
&channel_info.remote_per_commit,
|
||||
&channel_info.remote_fundingkey,
|
||||
&funding_txid,
|
||||
&funding_outnum,
|
||||
&funding,
|
||||
&push,
|
||||
&channel_flags,
|
||||
&feerate,
|
||||
&funding_signed,
|
||||
&uc->our_config.channel_reserve,
|
||||
&local_upfront_shutdown_script,
|
||||
&remote_upfront_shutdown_script)) {
|
||||
log_broken(uc->log, "bad OPENING_FUNDEE_REPLY %s",
|
||||
tal_hex(reply, reply));
|
||||
uncommitted_channel_disconnect(uc, LOG_BROKEN,
|
||||
|
|
|
@ -63,6 +63,7 @@ OPENINGD_COMMON_OBJS := \
|
|||
common/memleak.o \
|
||||
common/msg_queue.o \
|
||||
common/onionreply.o \
|
||||
common/penalty_base.o \
|
||||
common/per_peer_state.o \
|
||||
common/peer_billboard.o \
|
||||
common/peer_failed.o \
|
||||
|
|
|
@ -49,11 +49,13 @@ msgdata,opening_got_offer_reply,rejection,?wirestring,
|
|||
msgdata,opening_got_offer_reply,shutdown_len,u16,
|
||||
msgdata,opening_got_offer_reply,our_shutdown_scriptpubkey,?u8,shutdown_len
|
||||
|
||||
#include <common/penalty_base.h>
|
||||
# Openingd->master: we've successfully offered channel.
|
||||
# This gives their sig, means we can broadcast tx: we're done.
|
||||
msgtype,opening_funder_reply,6101
|
||||
msgdata,opening_funder_reply,their_config,channel_config,
|
||||
msgdata,opening_funder_reply,first_commit,bitcoin_tx,
|
||||
msgdata,opening_funder_reply,pbase,?penalty_base,
|
||||
msgdata,opening_funder_reply,first_commit_sig,bitcoin_signature,
|
||||
msgdata,opening_funder_reply,pps,per_peer_state,
|
||||
msgdata,opening_funder_reply,revocation_basepoint,pubkey,
|
||||
|
@ -104,6 +106,7 @@ msgdata,opening_funder_failed,reason,wirestring,
|
|||
msgtype,opening_fundee,6003
|
||||
msgdata,opening_fundee,their_config,channel_config,
|
||||
msgdata,opening_fundee,first_commit,bitcoin_tx,
|
||||
msgdata,opening_fundee,pbase,?penalty_base,
|
||||
msgdata,opening_fundee,first_commit_sig,bitcoin_signature,
|
||||
msgdata,opening_fundee,pps,per_peer_state,
|
||||
msgdata,opening_fundee,revocation_basepoint,pubkey,
|
||||
|
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <common/overflows.h>
|
||||
#include <common/peer_billboard.h>
|
||||
#include <common/peer_failed.h>
|
||||
#include <common/penalty_base.h>
|
||||
#include <common/pseudorand.h>
|
||||
#include <common/read_peer_msg.h>
|
||||
#include <common/status.h>
|
||||
|
@ -659,7 +660,8 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags)
|
|||
static bool funder_finalize_channel_setup(struct state *state,
|
||||
struct amount_msat local_msat,
|
||||
struct bitcoin_signature *sig,
|
||||
struct bitcoin_tx **tx)
|
||||
struct bitcoin_tx **tx,
|
||||
struct penalty_base **pbase)
|
||||
{
|
||||
u8 *msg;
|
||||
struct channel_id id_in;
|
||||
|
@ -720,6 +722,11 @@ static bool funder_finalize_channel_setup(struct state *state,
|
|||
goto fail;
|
||||
}
|
||||
|
||||
if (direct_outputs[LOCAL])
|
||||
*pbase = penalty_base_new(state, 0, *tx, direct_outputs[LOCAL]);
|
||||
else
|
||||
*pbase = NULL;
|
||||
|
||||
/* We ask the HSM to sign their commitment transaction for us: it knows
|
||||
* our funding key, it just needs the remote funding key to create the
|
||||
* witness script. It also needs the amount of the funding output,
|
||||
|
@ -850,9 +857,11 @@ fail:
|
|||
|
||||
static u8 *funder_channel_complete(struct state *state)
|
||||
{
|
||||
/* Remote commitment tx */
|
||||
struct bitcoin_tx *tx;
|
||||
struct bitcoin_signature sig;
|
||||
struct amount_msat local_msat;
|
||||
struct penalty_base *pbase;
|
||||
|
||||
/* Update the billboard about what we're doing*/
|
||||
peer_billboard(false,
|
||||
|
@ -869,12 +878,14 @@ static u8 *funder_channel_complete(struct state *state)
|
|||
type_to_string(tmpctx, struct amount_sat,
|
||||
&state->funding));
|
||||
|
||||
if (!funder_finalize_channel_setup(state, local_msat, &sig, &tx))
|
||||
if (!funder_finalize_channel_setup(state, local_msat, &sig, &tx,
|
||||
&pbase))
|
||||
return NULL;
|
||||
|
||||
return towire_opening_funder_reply(state,
|
||||
&state->remoteconf,
|
||||
tx,
|
||||
pbase,
|
||||
&sig,
|
||||
state->pps,
|
||||
&state->their_points.revocation,
|
||||
|
@ -905,6 +916,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
|
|||
u8 channel_flags;
|
||||
char* err_reason;
|
||||
struct wally_tx_output *direct_outputs[NUM_SIDES];
|
||||
struct penalty_base *pbase;
|
||||
|
||||
/* BOLT #2:
|
||||
*
|
||||
|
@ -1274,9 +1286,16 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
|
|||
assert(sig.sighash_type == SIGHASH_ALL);
|
||||
msg = towire_funding_signed(state, &state->channel_id, &sig.s);
|
||||
|
||||
if (direct_outputs[LOCAL] != NULL)
|
||||
pbase = penalty_base_new(tmpctx, 0, remote_commit,
|
||||
direct_outputs[LOCAL]);
|
||||
else
|
||||
pbase = NULL;
|
||||
|
||||
return towire_opening_fundee(state,
|
||||
&state->remoteconf,
|
||||
local_commit,
|
||||
pbase,
|
||||
&theirsig,
|
||||
state->pps,
|
||||
&theirs.revocation,
|
||||
|
|
Loading…
Add table
Reference in a new issue