diff --git a/lightningd/Makefile b/lightningd/Makefile index 7d8444abd..8606f8865 100644 --- a/lightningd/Makefile +++ b/lightningd/Makefile @@ -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 \ diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 60730c86f..70a8ed9e7 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -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, diff --git a/openingd/Makefile b/openingd/Makefile index 326715aa3..fb787195e 100644 --- a/openingd/Makefile +++ b/openingd/Makefile @@ -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 \ diff --git a/openingd/opening_wire.csv b/openingd/opening_wire.csv index ef1adb13f..8af31da54 100644 --- a/openingd/opening_wire.csv +++ b/openingd/opening_wire.csv @@ -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 # 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, diff --git a/openingd/openingd.c b/openingd/openingd.c index 679df9759..e89bf7258 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -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,