mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
df: move tx_sigs from channeld to dualopend
Non-functional yet, but this gets all the pieces in the right places, rips the signature signing functionality out of channeld.
This commit is contained in:
parent
af46a4f57d
commit
260bd04adb
@ -92,10 +92,6 @@ CHANNELD_COMMON_OBJS := \
|
||||
wire/fromwire.o \
|
||||
wire/towire.o
|
||||
|
||||
ifeq ($(EXPERIMENTAL_FEATURES),1)
|
||||
CHANNELD_COMMON_OBJS += common/psbt_internal.o
|
||||
endif
|
||||
|
||||
channeld/full_channel_error_names_gen.h: channeld/full_channel_error.h ccan/ccan/cdump/tools/cdump-enumstr
|
||||
ccan/ccan/cdump/tools/cdump-enumstr channeld/full_channel_error.h > $@
|
||||
|
||||
|
@ -48,7 +48,6 @@
|
||||
#include <common/peer_failed.h>
|
||||
#include <common/ping.h>
|
||||
#include <common/private_channel_announcement.h>
|
||||
#include <common/psbt_internal.h>
|
||||
#include <common/psbt_open.h>
|
||||
#include <common/read_peer_msg.h>
|
||||
#include <common/status.h>
|
||||
@ -261,34 +260,6 @@ static const u8 *hsm_req(const tal_t *ctx, const u8 *req TAKES)
|
||||
return msg;
|
||||
}
|
||||
|
||||
static enum tx_role their_tx_role(const struct peer *peer)
|
||||
{
|
||||
return peer->channel->opener == LOCAL ?
|
||||
TX_ACCEPTER : TX_INITIATOR;
|
||||
}
|
||||
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
static enum tx_role our_tx_role(const struct peer *peer)
|
||||
{
|
||||
return peer->channel->opener == LOCAL ?
|
||||
TX_INITIATOR : TX_ACCEPTER;
|
||||
}
|
||||
|
||||
static const u8 *psbt_to_tx_sigs_msg(const tal_t *ctx,
|
||||
const struct peer *peer,
|
||||
const struct wally_psbt *psbt)
|
||||
{
|
||||
const struct witness_stack **ws;
|
||||
|
||||
ws = psbt_to_witness_stacks(tmpctx, psbt,
|
||||
our_tx_role(peer));
|
||||
|
||||
return towire_tx_signatures(ctx, &peer->channel->cid,
|
||||
&peer->channel->funding_txid,
|
||||
ws);
|
||||
}
|
||||
#endif /* EXPERIMENTAL_FEATURES */
|
||||
|
||||
/*
|
||||
* The maximum msat that this node will accept for an htlc.
|
||||
* It's flagged as an optional field in `channel_update`.
|
||||
@ -613,13 +584,6 @@ static void handle_peer_funding_locked(struct peer *peer, const u8 *msg)
|
||||
if (peer->shutdown_sent[LOCAL])
|
||||
return;
|
||||
|
||||
if (peer->psbt && !psbt_side_finalized(peer->psbt,
|
||||
their_tx_role(peer)))
|
||||
peer_failed(peer->pps,
|
||||
&peer->channel_id,
|
||||
"Rcvd `funding_locked` from peer but "
|
||||
"have not received `tx_signatures`");
|
||||
|
||||
peer->old_remote_per_commit = peer->remote_per_commit;
|
||||
if (!fromwire_funding_locked(msg, &chanid,
|
||||
&peer->remote_per_commit))
|
||||
@ -1802,126 +1766,6 @@ static bool channeld_handle_custommsg(const u8 *msg)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
static void handle_send_tx_sigs(struct peer *peer, const u8 *msg)
|
||||
{
|
||||
struct wally_psbt *psbt;
|
||||
struct bitcoin_txid txid;
|
||||
|
||||
if (!fromwire_channeld_send_tx_sigs(tmpctx, msg, &psbt))
|
||||
master_badmsg(WIRE_CHANNELD_SEND_TX_SIGS, msg);
|
||||
|
||||
/* Check that we've got the same / correct PSBT */
|
||||
psbt_txid(NULL, psbt, &txid, NULL);
|
||||
if (!bitcoin_txid_eq(&txid, &peer->channel->funding_txid))
|
||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||
"Txid for passed in PSBT does not match"
|
||||
" funding txid for channel. Expected %s, "
|
||||
"received %s",
|
||||
type_to_string(tmpctx, struct bitcoin_txid,
|
||||
&peer->channel->funding_txid),
|
||||
type_to_string(tmpctx, struct bitcoin_txid,
|
||||
&txid));
|
||||
|
||||
tal_wally_start();
|
||||
if (wally_psbt_combine(peer->psbt, psbt) != WALLY_OK) {
|
||||
tal_wally_end(tal_free(peer->psbt));
|
||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||
"Unable to combine PSBTs");
|
||||
}
|
||||
tal_wally_end(tal_steal(peer, peer->psbt));
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
sync_crypto_write(peer->pps,
|
||||
take(psbt_to_tx_sigs_msg(NULL, peer, psbt)));
|
||||
#endif /* EXPERIMENTAL_FEATURES */
|
||||
}
|
||||
|
||||
static void handle_tx_sigs(struct peer *peer, const u8 *msg)
|
||||
{
|
||||
struct channel_id cid;
|
||||
struct bitcoin_txid txid;
|
||||
const struct witness_stack **ws;
|
||||
|
||||
size_t j = 0;
|
||||
enum tx_role their_role = their_tx_role(peer);
|
||||
|
||||
if (!fromwire_tx_signatures(tmpctx, msg, &cid, &txid,
|
||||
cast_const3(
|
||||
struct witness_stack ***,
|
||||
&ws)))
|
||||
peer_failed(peer->pps,
|
||||
&peer->channel_id,
|
||||
"Bad tx_signatures %s",
|
||||
tal_hex(msg, msg));
|
||||
|
||||
/* Maybe they didn't get our funding_locked message ? */
|
||||
if (peer->funding_locked[LOCAL]) {
|
||||
status_broken("Got WIRE_TX_SIGNATURES after funding locked "
|
||||
"for channel %s, ignoring: %s",
|
||||
type_to_string(tmpctx, struct channel_id,
|
||||
&peer->channel_id),
|
||||
tal_hex(tmpctx, msg));
|
||||
return;
|
||||
}
|
||||
|
||||
if (peer->funding_locked[REMOTE])
|
||||
peer_failed(peer->pps,
|
||||
&peer->channel_id,
|
||||
"tx_signatures sent after funding_locked %s",
|
||||
tal_hex(msg, msg));
|
||||
|
||||
if (!peer->psbt) {
|
||||
status_broken("Got WIRE_TX_SIGNATURES with no PSBT "
|
||||
"for channel %s, ignoring: %s",
|
||||
type_to_string(tmpctx, struct channel_id,
|
||||
&peer->channel_id),
|
||||
tal_hex(tmpctx, msg));
|
||||
return;
|
||||
}
|
||||
|
||||
/* This check only works if they've got inputs we need sigs for.
|
||||
* In the case where they send duplicate tx_sigs but have no
|
||||
* sigs, we'll end up re-notifying */
|
||||
if (tal_count(ws) && psbt_side_finalized(peer->psbt, their_role)) {
|
||||
status_info("Got duplicate WIRE_TX_SIGNATURES, "
|
||||
"already have their sigs. Ignoring");
|
||||
return;
|
||||
}
|
||||
|
||||
/* We put the PSBT + sigs all together */
|
||||
for (size_t i = 0; i < peer->psbt->num_inputs; i++) {
|
||||
struct wally_psbt_input *in =
|
||||
&peer->psbt->inputs[i];
|
||||
u64 in_serial;
|
||||
const struct witness_element **elem;
|
||||
|
||||
if (!psbt_get_serial_id(&in->unknowns, &in_serial)) {
|
||||
status_broken("PSBT input %zu missing serial_id %s",
|
||||
i, type_to_string(tmpctx,
|
||||
struct wally_psbt,
|
||||
peer->psbt));
|
||||
return;
|
||||
}
|
||||
if (in_serial % 2 != their_role)
|
||||
continue;
|
||||
|
||||
if (j == tal_count(ws))
|
||||
peer_failed(peer->pps, &peer->channel_id,
|
||||
"Mismatch witness stack count %s",
|
||||
tal_hex(msg, msg));
|
||||
|
||||
elem = cast_const2(const struct witness_element **,
|
||||
ws[j++]->witness_element);
|
||||
psbt_finalize_input(peer->psbt, in, elem);
|
||||
}
|
||||
|
||||
/* Send to the peer controller, who will broadcast the funding_tx
|
||||
* as soon as we've got our sigs */
|
||||
wire_sync_write(MASTER_FD,
|
||||
take(towire_channeld_funding_sigs(NULL, peer->psbt)));
|
||||
}
|
||||
#endif /* EXPERIMENTAL_FEATURES */
|
||||
|
||||
static void handle_unexpected_reestablish(struct peer *peer, const u8 *msg)
|
||||
{
|
||||
struct channel_id channel_id;
|
||||
@ -2052,9 +1896,6 @@ static void peer_in(struct peer *peer, const u8 *msg)
|
||||
handle_peer_shutdown(peer, msg);
|
||||
return;
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
case WIRE_TX_SIGNATURES:
|
||||
handle_tx_sigs(peer, msg);
|
||||
return;
|
||||
case WIRE_INIT_RBF:
|
||||
/* FIXME: handle this here */
|
||||
break;
|
||||
@ -2074,6 +1915,7 @@ static void peer_in(struct peer *peer, const u8 *msg)
|
||||
case WIRE_TX_COMPLETE:
|
||||
case WIRE_OPEN_CHANNEL2:
|
||||
case WIRE_ACCEPT_CHANNEL2:
|
||||
case WIRE_TX_SIGNATURES:
|
||||
case WIRE_BLACKLIST_PODLE:
|
||||
#endif
|
||||
break;
|
||||
@ -2577,15 +2419,6 @@ static void peer_reconnect(struct peer *peer,
|
||||
next_commitment_number,
|
||||
next_revocation_number);
|
||||
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
/* Send our tx_sigs again */
|
||||
if (peer->psbt && psbt_side_finalized(peer->psbt,
|
||||
our_tx_role(peer))
|
||||
&& !peer->funding_locked[REMOTE])
|
||||
sync_crypto_write(peer->pps,
|
||||
take(psbt_to_tx_sigs_msg(NULL, peer, peer->psbt)));
|
||||
#endif /* EXPERIMENTAL_FEATURES */
|
||||
|
||||
/* BOLT #2:
|
||||
*
|
||||
* - if `next_commitment_number` is 1 in both the
|
||||
@ -2785,18 +2618,6 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg)
|
||||
peer->depth_togo = peer->channel->minimum_depth - depth;
|
||||
|
||||
} else {
|
||||
/* We were waiting for them to send us their
|
||||
* `tx_signatures`, but they never did. As a
|
||||
* result we'll still have the psbt */
|
||||
if (peer->psbt && !psbt_side_finalized(peer->psbt,
|
||||
their_tx_role(peer))) {
|
||||
peer_failed(peer->pps, &peer->channel_id,
|
||||
"Funding tx reached funding depth %d "
|
||||
"but we haven't received peer's "
|
||||
"tx_signatures",
|
||||
depth);
|
||||
}
|
||||
|
||||
peer->depth_togo = 0;
|
||||
|
||||
assert(scid);
|
||||
@ -3127,14 +2948,6 @@ static void req_in(struct peer *peer, const u8 *msg)
|
||||
case WIRE_CHANNELD_SEND_ERROR:
|
||||
handle_send_error(peer, msg);
|
||||
return;
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
case WIRE_CHANNELD_SEND_TX_SIGS:
|
||||
handle_send_tx_sigs(peer, msg);
|
||||
return;
|
||||
#else
|
||||
case WIRE_CHANNELD_SEND_TX_SIGS:
|
||||
break;
|
||||
#endif /* !EXPERIMENTAL_FEATURES */
|
||||
#if DEVELOPER
|
||||
case WIRE_CHANNELD_DEV_REENABLE_COMMIT:
|
||||
handle_dev_reenable_commit(peer);
|
||||
@ -3147,7 +2960,6 @@ static void req_in(struct peer *peer, const u8 *msg)
|
||||
case WIRE_CHANNELD_DEV_MEMLEAK:
|
||||
#endif /* DEVELOPER */
|
||||
case WIRE_CHANNELD_INIT:
|
||||
case WIRE_CHANNELD_FUNDING_SIGS:
|
||||
case WIRE_CHANNELD_OFFER_HTLC_REPLY:
|
||||
case WIRE_CHANNELD_SENDING_COMMITSIG:
|
||||
case WIRE_CHANNELD_GOT_COMMITSIG:
|
||||
@ -3369,14 +3181,6 @@ static void init_channel(struct peer *peer)
|
||||
if (fwd_msg)
|
||||
sync_crypto_write(peer->pps, take(fwd_msg));
|
||||
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
/* peer_reconnect does this if needed */
|
||||
if (!reconnected && peer->psbt &&
|
||||
psbt_side_finalized(peer->psbt, our_tx_role(peer)))
|
||||
sync_crypto_write(peer->pps,
|
||||
take(psbt_to_tx_sigs_msg(NULL, peer, peer->psbt)));
|
||||
#endif /* EXPERIMENTAL_FEATURES */
|
||||
|
||||
/* Reenable channel */
|
||||
channel_announcement_negotiate(peer);
|
||||
|
||||
|
@ -75,14 +75,6 @@ msgdata,channeld_init,num_penalty_bases,u32,
|
||||
msgdata,channeld_init,pbases,penalty_base,num_penalty_bases
|
||||
msgdata,channeld_init,psbt,wally_psbt,
|
||||
|
||||
# channeld->master received tx_sigs from peer
|
||||
msgtype,channeld_funding_sigs,1010
|
||||
msgdata,channeld_funding_sigs,signed_psbt,wally_psbt,
|
||||
|
||||
# master->channeld send our tx_sigs to peer
|
||||
msgtype,channeld_send_tx_sigs,1011
|
||||
msgdata,channeld_send_tx_sigs,signed_psbt,wally_psbt,
|
||||
|
||||
# master->channeld funding hit new depth(funding locked if >= lock depth)
|
||||
msgtype,channeld_funding_depth,1002
|
||||
msgdata,channeld_funding_depth,short_channel_id,?short_channel_id,
|
||||
|
Can't render this file because it has a wrong number of fields in line 12.
|
50
channeld/channeld_wiregen.c
generated
50
channeld/channeld_wiregen.c
generated
@ -21,8 +21,6 @@ const char *channeld_wire_name(int e)
|
||||
|
||||
switch ((enum channeld_wire)e) {
|
||||
case WIRE_CHANNELD_INIT: return "WIRE_CHANNELD_INIT";
|
||||
case WIRE_CHANNELD_FUNDING_SIGS: return "WIRE_CHANNELD_FUNDING_SIGS";
|
||||
case WIRE_CHANNELD_SEND_TX_SIGS: return "WIRE_CHANNELD_SEND_TX_SIGS";
|
||||
case WIRE_CHANNELD_FUNDING_DEPTH: return "WIRE_CHANNELD_FUNDING_DEPTH";
|
||||
case WIRE_CHANNELD_OFFER_HTLC: return "WIRE_CHANNELD_OFFER_HTLC";
|
||||
case WIRE_CHANNELD_OFFER_HTLC_REPLY: return "WIRE_CHANNELD_OFFER_HTLC_REPLY";
|
||||
@ -58,8 +56,6 @@ bool channeld_wire_is_defined(u16 type)
|
||||
{
|
||||
switch ((enum channeld_wire)type) {
|
||||
case WIRE_CHANNELD_INIT:;
|
||||
case WIRE_CHANNELD_FUNDING_SIGS:;
|
||||
case WIRE_CHANNELD_SEND_TX_SIGS:;
|
||||
case WIRE_CHANNELD_FUNDING_DEPTH:;
|
||||
case WIRE_CHANNELD_OFFER_HTLC:;
|
||||
case WIRE_CHANNELD_OFFER_HTLC_REPLY:;
|
||||
@ -297,50 +293,6 @@ bool fromwire_channeld_init(const tal_t *ctx, const void *p, const struct chainp
|
||||
return cursor != NULL;
|
||||
}
|
||||
|
||||
/* WIRE: CHANNELD_FUNDING_SIGS */
|
||||
/* channeld->master received tx_sigs from peer */
|
||||
u8 *towire_channeld_funding_sigs(const tal_t *ctx, const struct wally_psbt *signed_psbt)
|
||||
{
|
||||
u8 *p = tal_arr(ctx, u8, 0);
|
||||
|
||||
towire_u16(&p, WIRE_CHANNELD_FUNDING_SIGS);
|
||||
towire_wally_psbt(&p, signed_psbt);
|
||||
|
||||
return memcheck(p, tal_count(p));
|
||||
}
|
||||
bool fromwire_channeld_funding_sigs(const tal_t *ctx, const void *p, struct wally_psbt **signed_psbt)
|
||||
{
|
||||
const u8 *cursor = p;
|
||||
size_t plen = tal_count(p);
|
||||
|
||||
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_FUNDING_SIGS)
|
||||
return false;
|
||||
*signed_psbt = fromwire_wally_psbt(ctx, &cursor, &plen);
|
||||
return cursor != NULL;
|
||||
}
|
||||
|
||||
/* WIRE: CHANNELD_SEND_TX_SIGS */
|
||||
/* master->channeld send our tx_sigs to peer */
|
||||
u8 *towire_channeld_send_tx_sigs(const tal_t *ctx, const struct wally_psbt *signed_psbt)
|
||||
{
|
||||
u8 *p = tal_arr(ctx, u8, 0);
|
||||
|
||||
towire_u16(&p, WIRE_CHANNELD_SEND_TX_SIGS);
|
||||
towire_wally_psbt(&p, signed_psbt);
|
||||
|
||||
return memcheck(p, tal_count(p));
|
||||
}
|
||||
bool fromwire_channeld_send_tx_sigs(const tal_t *ctx, const void *p, struct wally_psbt **signed_psbt)
|
||||
{
|
||||
const u8 *cursor = p;
|
||||
size_t plen = tal_count(p);
|
||||
|
||||
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_SEND_TX_SIGS)
|
||||
return false;
|
||||
*signed_psbt = fromwire_wally_psbt(ctx, &cursor, &plen);
|
||||
return cursor != NULL;
|
||||
}
|
||||
|
||||
/* WIRE: CHANNELD_FUNDING_DEPTH */
|
||||
/* master->channeld funding hit new depth(funding locked if >= lock depth) */
|
||||
u8 *towire_channeld_funding_depth(const tal_t *ctx, const struct short_channel_id *short_channel_id, u32 depth)
|
||||
@ -1096,4 +1048,4 @@ bool fromwire_channeld_send_error_reply(const void *p)
|
||||
return false;
|
||||
return cursor != NULL;
|
||||
}
|
||||
// SHA256STAMP:58b780dc0bd7296e837407e362f2364f70104199c6a6b01382bb9278696688ae
|
||||
// SHA256STAMP:5182d9117cb264ac1142590962c9fc293b2bfee060a47c2f47c894f9d7bee9df
|
||||
|
16
channeld/channeld_wiregen.h
generated
16
channeld/channeld_wiregen.h
generated
@ -23,10 +23,6 @@
|
||||
enum channeld_wire {
|
||||
/* Begin! (passes gossipd-client fd) */
|
||||
WIRE_CHANNELD_INIT = 1000,
|
||||
/* channeld->master received tx_sigs from peer */
|
||||
WIRE_CHANNELD_FUNDING_SIGS = 1010,
|
||||
/* master->channeld send our tx_sigs to peer */
|
||||
WIRE_CHANNELD_SEND_TX_SIGS = 1011,
|
||||
/* master->channeld funding hit new depth(funding locked if >= lock depth) */
|
||||
WIRE_CHANNELD_FUNDING_DEPTH = 1002,
|
||||
/* Tell channel to offer this htlc */
|
||||
@ -93,16 +89,6 @@ bool channeld_wire_is_defined(u16 type);
|
||||
u8 *towire_channeld_init(const tal_t *ctx, const struct chainparams *chainparams, const struct feature_set *our_features, const struct channel_id *channel_id, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshi, u32 minimum_depth, const struct channel_config *our_config, const struct channel_config *their_config, const struct fee_states *fee_states, u32 feerate_min, u32 feerate_max, u32 feerate_penalty, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *per_peer_state, const struct pubkey *remote_fundingkey, const struct basepoints *remote_basepoints, const struct pubkey *remote_per_commit, const struct pubkey *old_remote_per_commit, enum side opener, u32 fee_base, u32 fee_proportional, struct amount_msat local_msatoshi, const struct basepoints *our_basepoints, const struct pubkey *our_funding_pubkey, const struct node_id *local_node_id, const struct node_id *remote_node_id, u32 commit_msec, u16 cltv_delta, bool last_was_revoke, const struct changed_htlc *last_sent_commit, u64 next_index_local, u64 next_index_remote, u64 revocations_received, u64 next_htlc_id, const struct existing_htlc **htlcs, bool local_funding_locked, bool remote_funding_locked, const struct short_channel_id *funding_short_id, bool reestablish, bool send_shutdown, bool remote_shutdown_received, const u8 *final_scriptpubkey, u8 flags, const u8 *init_peer_pkt, bool reached_announce_depth, const struct secret *last_remote_secret, const u8 *their_features, const u8 *upfront_shutdown_script, const secp256k1_ecdsa_signature *remote_ann_node_sig, const secp256k1_ecdsa_signature *remote_ann_bitcoin_sig, bool option_static_remotekey, bool option_anchor_outputs, bool dev_fast_gossip, bool dev_fail_process_onionpacket, const struct penalty_base *pbases, const struct wally_psbt *psbt);
|
||||
bool fromwire_channeld_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct feature_set **our_features, struct channel_id *channel_id, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshi, u32 *minimum_depth, struct channel_config *our_config, struct channel_config *their_config, struct fee_states **fee_states, u32 *feerate_min, u32 *feerate_max, u32 *feerate_penalty, struct bitcoin_signature *first_commit_sig, struct per_peer_state **per_peer_state, struct pubkey *remote_fundingkey, struct basepoints *remote_basepoints, struct pubkey *remote_per_commit, struct pubkey *old_remote_per_commit, enum side *opener, u32 *fee_base, u32 *fee_proportional, struct amount_msat *local_msatoshi, struct basepoints *our_basepoints, struct pubkey *our_funding_pubkey, struct node_id *local_node_id, struct node_id *remote_node_id, u32 *commit_msec, u16 *cltv_delta, bool *last_was_revoke, struct changed_htlc **last_sent_commit, u64 *next_index_local, u64 *next_index_remote, u64 *revocations_received, u64 *next_htlc_id, struct existing_htlc ***htlcs, bool *local_funding_locked, bool *remote_funding_locked, struct short_channel_id *funding_short_id, bool *reestablish, bool *send_shutdown, bool *remote_shutdown_received, u8 **final_scriptpubkey, u8 *flags, u8 **init_peer_pkt, bool *reached_announce_depth, struct secret *last_remote_secret, u8 **their_features, u8 **upfront_shutdown_script, secp256k1_ecdsa_signature **remote_ann_node_sig, secp256k1_ecdsa_signature **remote_ann_bitcoin_sig, bool *option_static_remotekey, bool *option_anchor_outputs, bool *dev_fast_gossip, bool *dev_fail_process_onionpacket, struct penalty_base **pbases, struct wally_psbt **psbt);
|
||||
|
||||
/* WIRE: CHANNELD_FUNDING_SIGS */
|
||||
/* channeld->master received tx_sigs from peer */
|
||||
u8 *towire_channeld_funding_sigs(const tal_t *ctx, const struct wally_psbt *signed_psbt);
|
||||
bool fromwire_channeld_funding_sigs(const tal_t *ctx, const void *p, struct wally_psbt **signed_psbt);
|
||||
|
||||
/* WIRE: CHANNELD_SEND_TX_SIGS */
|
||||
/* master->channeld send our tx_sigs to peer */
|
||||
u8 *towire_channeld_send_tx_sigs(const tal_t *ctx, const struct wally_psbt *signed_psbt);
|
||||
bool fromwire_channeld_send_tx_sigs(const tal_t *ctx, const void *p, struct wally_psbt **signed_psbt);
|
||||
|
||||
/* WIRE: CHANNELD_FUNDING_DEPTH */
|
||||
/* master->channeld funding hit new depth(funding locked if >= lock depth) */
|
||||
u8 *towire_channeld_funding_depth(const tal_t *ctx, const struct short_channel_id *short_channel_id, u32 depth);
|
||||
@ -227,4 +213,4 @@ bool fromwire_channeld_send_error_reply(const void *p);
|
||||
|
||||
|
||||
#endif /* LIGHTNING_CHANNELD_CHANNELD_WIREGEN_H */
|
||||
// SHA256STAMP:58b780dc0bd7296e837407e362f2364f70104199c6a6b01382bb9278696688ae
|
||||
// SHA256STAMP:5182d9117cb264ac1142590962c9fc293b2bfee060a47c2f47c894f9d7bee9df
|
||||
|
@ -332,144 +332,6 @@ static void handle_error_channel(struct channel *channel,
|
||||
forget(channel);
|
||||
}
|
||||
|
||||
struct channel_send {
|
||||
const struct wally_tx *wtx;
|
||||
struct channel *channel;
|
||||
};
|
||||
|
||||
static void sendfunding_done(struct bitcoind *bitcoind UNUSED,
|
||||
bool success, const char *msg,
|
||||
struct channel_send *cs)
|
||||
{
|
||||
struct lightningd *ld = cs->channel->peer->ld;
|
||||
struct channel *channel = cs->channel;
|
||||
const struct wally_tx *wtx = cs->wtx;
|
||||
struct json_stream *response;
|
||||
struct bitcoin_txid txid;
|
||||
struct open_command *oc;
|
||||
struct amount_sat unused;
|
||||
int num_utxos;
|
||||
|
||||
oc = find_open_command(ld, channel);
|
||||
if (!oc && channel->opener == LOCAL) {
|
||||
log_broken(channel->log,
|
||||
"No outstanding command for channel %s,"
|
||||
" funding sent was success? %d",
|
||||
type_to_string(tmpctx, struct channel_id,
|
||||
&channel->cid),
|
||||
success);
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
if (oc)
|
||||
was_pending(command_fail(oc->cmd,
|
||||
FUNDING_BROADCAST_FAIL,
|
||||
"Error broadcasting funding "
|
||||
"tx: %s. Unsent tx discarded "
|
||||
"%s.",
|
||||
msg,
|
||||
type_to_string(tmpctx,
|
||||
struct wally_tx,
|
||||
wtx)));
|
||||
log_unusual(channel->log,
|
||||
"Error broadcasting funding "
|
||||
"tx: %s. Unsent tx discarded "
|
||||
"%s.",
|
||||
msg,
|
||||
type_to_string(tmpctx, struct wally_tx, wtx));
|
||||
tal_free(cs);
|
||||
return;
|
||||
}
|
||||
|
||||
/* This might have spent UTXOs from our wallet */
|
||||
num_utxos = wallet_extract_owned_outputs(ld->wallet,
|
||||
wtx, NULL,
|
||||
&unused);
|
||||
if (num_utxos) {
|
||||
wallet_transaction_add(ld->wallet, wtx, 0, 0);
|
||||
}
|
||||
|
||||
if (oc) {
|
||||
response = json_stream_success(oc->cmd);
|
||||
wally_txid(wtx, &txid);
|
||||
json_add_hex_talarr(response, "tx", linearize_wtx(tmpctx, wtx));
|
||||
json_add_txid(response, "txid", &txid);
|
||||
json_add_string(response, "channel_id",
|
||||
type_to_string(tmpctx, struct channel_id,
|
||||
&channel->cid));
|
||||
was_pending(command_success(oc->cmd, response));
|
||||
}
|
||||
|
||||
tal_free(cs);
|
||||
}
|
||||
|
||||
static void send_funding_tx(struct channel *channel,
|
||||
const struct wally_tx *wtx TAKES)
|
||||
{
|
||||
struct lightningd *ld = channel->peer->ld;
|
||||
struct channel_send *cs;
|
||||
|
||||
cs = tal(channel, struct channel_send);
|
||||
cs->channel = channel;
|
||||
if (taken(wtx))
|
||||
cs->wtx = tal_steal(cs, wtx);
|
||||
else {
|
||||
tal_wally_start();
|
||||
wally_tx_clone_alloc(wtx, 0,
|
||||
cast_const2(struct wally_tx **,
|
||||
&cs->wtx));
|
||||
tal_wally_end(tal_steal(cs, cs->wtx));
|
||||
}
|
||||
|
||||
log_debug(channel->log,
|
||||
"Broadcasting funding tx for channel %s. %s",
|
||||
type_to_string(tmpctx, struct channel_id, &channel->cid),
|
||||
type_to_string(tmpctx, struct wally_tx, cs->wtx));
|
||||
|
||||
bitcoind_sendrawtx(ld->topology->bitcoind,
|
||||
tal_hex(tmpctx, linearize_wtx(tmpctx, cs->wtx)),
|
||||
sendfunding_done, cs);
|
||||
}
|
||||
|
||||
static void peer_tx_sigs_msg(struct channel *channel, const u8 *msg)
|
||||
{
|
||||
struct wally_psbt *psbt;
|
||||
const struct wally_tx *wtx;
|
||||
struct lightningd *ld = channel->peer->ld;
|
||||
|
||||
if (!fromwire_channeld_funding_sigs(tmpctx, msg, &psbt)) {
|
||||
channel_internal_error(channel,
|
||||
"bad channeld_funding_sigs: %s",
|
||||
tal_hex(tmpctx, msg));
|
||||
return;
|
||||
}
|
||||
|
||||
tal_wally_start();
|
||||
if (wally_psbt_combine(channel->psbt, psbt) != WALLY_OK) {
|
||||
channel_internal_error(channel,
|
||||
"Unable to combine PSBTs: %s, %s",
|
||||
type_to_string(tmpctx,
|
||||
struct wally_psbt,
|
||||
channel->psbt),
|
||||
type_to_string(tmpctx,
|
||||
struct wally_psbt,
|
||||
psbt));
|
||||
}
|
||||
tal_wally_end(channel->psbt);
|
||||
|
||||
if (psbt_finalize(cast_const(struct wally_psbt *, channel->psbt))) {
|
||||
wtx = psbt_final_tx(NULL, channel->psbt);
|
||||
if (wtx)
|
||||
send_funding_tx(channel, take(wtx));
|
||||
}
|
||||
|
||||
wallet_channel_save(ld->wallet, channel);
|
||||
|
||||
/* Send notification with peer's signed PSBT */
|
||||
notify_openchannel_peer_sigs(ld, &channel->cid,
|
||||
channel->psbt);
|
||||
}
|
||||
|
||||
void forget_channel(struct channel *channel, const char *why)
|
||||
{
|
||||
channel->error = towire_errorfmt(channel, &channel->cid, "%s", why);
|
||||
@ -494,9 +356,6 @@ static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds)
|
||||
case WIRE_CHANNELD_GOT_COMMITSIG:
|
||||
peer_got_commitsig(sd->channel, msg);
|
||||
break;
|
||||
case WIRE_CHANNELD_FUNDING_SIGS:
|
||||
peer_tx_sigs_msg(sd->channel, msg);
|
||||
break;
|
||||
case WIRE_CHANNELD_GOT_REVOKE:
|
||||
peer_got_revoke(sd->channel, msg);
|
||||
break;
|
||||
@ -523,7 +382,6 @@ static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds)
|
||||
break;
|
||||
/* And we never get these from channeld. */
|
||||
case WIRE_CHANNELD_INIT:
|
||||
case WIRE_CHANNELD_SEND_TX_SIGS:
|
||||
case WIRE_CHANNELD_FUNDING_DEPTH:
|
||||
case WIRE_CHANNELD_OFFER_HTLC:
|
||||
case WIRE_CHANNELD_FULFILL_HTLC:
|
||||
@ -979,97 +837,6 @@ struct command_result *cancel_channel_before_broadcast(struct command *cmd,
|
||||
return command_still_pending(cmd);
|
||||
}
|
||||
|
||||
static struct command_result *json_open_channel_signed(struct command *cmd,
|
||||
const char *buffer,
|
||||
const jsmntok_t *obj UNNEEDED,
|
||||
const jsmntok_t *params)
|
||||
{
|
||||
struct wally_psbt *psbt;
|
||||
const struct wally_tx *wtx;
|
||||
struct uncommitted_channel *uc;
|
||||
struct channel_id *cid;
|
||||
struct channel *channel;
|
||||
struct bitcoin_txid txid;
|
||||
|
||||
if (!param(cmd, buffer, params,
|
||||
p_req("channel_id", param_channel_id, &cid),
|
||||
p_req("signed_psbt", param_psbt, &psbt),
|
||||
NULL))
|
||||
return command_param_failed();
|
||||
|
||||
channel = channel_by_cid(cmd->ld, cid, &uc);
|
||||
if (uc)
|
||||
return command_fail(cmd, LIGHTNINGD,
|
||||
"Commitments for this channel not "
|
||||
"yet secured, see `openchannl_update`");
|
||||
if (!channel)
|
||||
return command_fail(cmd, FUNDING_UNKNOWN_CHANNEL,
|
||||
"Unknown channel");
|
||||
if (channel->psbt && psbt_is_finalized(channel->psbt))
|
||||
return command_fail(cmd, LIGHTNINGD,
|
||||
"Already have a finalized PSBT for "
|
||||
"this channel");
|
||||
|
||||
/* Verify that the psbt's txid matches that of the
|
||||
* funding txid for this channel */
|
||||
psbt_txid(NULL, psbt, &txid, NULL);
|
||||
if (!bitcoin_txid_eq(&txid, &channel->funding_txid))
|
||||
return command_fail(cmd, FUNDING_PSBT_INVALID,
|
||||
"Txid for passed in PSBT does not match"
|
||||
" funding txid for channel. Expected %s, "
|
||||
"received %s",
|
||||
type_to_string(tmpctx, struct bitcoin_txid,
|
||||
&channel->funding_txid),
|
||||
type_to_string(tmpctx, struct bitcoin_txid,
|
||||
&txid));
|
||||
|
||||
/* Go ahead and try to finalize things, or what we can */
|
||||
psbt_finalize(psbt);
|
||||
|
||||
/* Check that all of *our* outputs are finalized */
|
||||
if (!psbt_side_finalized(psbt, TX_INITIATOR))
|
||||
return command_fail(cmd, FUNDING_PSBT_INVALID,
|
||||
"Local PSBT input(s) not finalized");
|
||||
|
||||
/* Now that we've got the signed PSBT, save it */
|
||||
tal_wally_start();
|
||||
if (wally_psbt_combine(cast_const(struct wally_psbt *,
|
||||
channel->psbt),
|
||||
psbt) != WALLY_OK) {
|
||||
tal_wally_end(tal_free(channel->psbt));
|
||||
return command_fail(cmd, FUNDING_PSBT_INVALID,
|
||||
"Failed adding sigs");
|
||||
}
|
||||
tal_wally_end(tal_steal(channel, channel->psbt));
|
||||
|
||||
wallet_channel_save(cmd->ld->wallet, channel);
|
||||
channel_watch_funding(cmd->ld, channel);
|
||||
|
||||
/* Return when the transaction is broadcast */
|
||||
register_open_command(cmd->ld, cmd, channel);
|
||||
|
||||
/* Send our tx_sigs to the peer */
|
||||
subd_send_msg(channel->owner,
|
||||
take(towire_channeld_send_tx_sigs(NULL,
|
||||
channel->psbt)));
|
||||
|
||||
if (psbt_finalize(cast_const(struct wally_psbt *, channel->psbt))) {
|
||||
wtx = psbt_final_tx(NULL, channel->psbt);
|
||||
if (wtx)
|
||||
send_funding_tx(channel, take(wtx));
|
||||
}
|
||||
|
||||
return command_still_pending(cmd);
|
||||
}
|
||||
|
||||
static const struct json_command open_channel_signed_command = {
|
||||
"openchannel_signed",
|
||||
"channels",
|
||||
json_open_channel_signed,
|
||||
"Send our {signed_psbt}'s tx sigs for {channel_id}."
|
||||
};
|
||||
AUTODATA(json_command, &open_channel_signed_command);
|
||||
|
||||
#if DEVELOPER
|
||||
static struct command_result *json_dev_feerate(struct command *cmd,
|
||||
const char *buffer,
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <lightningd/channel_control.h>
|
||||
#include <lightningd/dual_open_control.h>
|
||||
#include <lightningd/hsm_control.h>
|
||||
#include <lightningd/notification.h>
|
||||
#include <lightningd/opening_common.h>
|
||||
#include <lightningd/peer_control.h>
|
||||
#include <lightningd/plugin_hook.h>
|
||||
@ -1032,6 +1033,231 @@ static void accepter_got_offer(struct subd *dualopend,
|
||||
plugin_hook_call_openchannel2(dualopend->ld, payload);
|
||||
}
|
||||
|
||||
struct channel_send {
|
||||
const struct wally_tx *wtx;
|
||||
struct channel *channel;
|
||||
};
|
||||
|
||||
static void sendfunding_done(struct bitcoind *bitcoind UNUSED,
|
||||
bool success, const char *msg,
|
||||
struct channel_send *cs)
|
||||
{
|
||||
struct lightningd *ld = cs->channel->peer->ld;
|
||||
struct channel *channel = cs->channel;
|
||||
const struct wally_tx *wtx = cs->wtx;
|
||||
struct json_stream *response;
|
||||
struct bitcoin_txid txid;
|
||||
struct open_command *oc;
|
||||
struct amount_sat unused;
|
||||
int num_utxos;
|
||||
|
||||
oc = find_open_command(ld, channel);
|
||||
if (!oc && channel->opener == LOCAL) {
|
||||
log_broken(channel->log,
|
||||
"No outstanding command for channel %s,"
|
||||
" funding sent was success? %d",
|
||||
type_to_string(tmpctx, struct channel_id,
|
||||
&channel->cid),
|
||||
success);
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
if (oc)
|
||||
was_pending(command_fail(oc->cmd,
|
||||
FUNDING_BROADCAST_FAIL,
|
||||
"Error broadcasting funding "
|
||||
"tx: %s. Unsent tx discarded "
|
||||
"%s.",
|
||||
msg,
|
||||
type_to_string(tmpctx,
|
||||
struct wally_tx,
|
||||
wtx)));
|
||||
log_unusual(channel->log,
|
||||
"Error broadcasting funding "
|
||||
"tx: %s. Unsent tx discarded "
|
||||
"%s.",
|
||||
msg,
|
||||
type_to_string(tmpctx, struct wally_tx, wtx));
|
||||
tal_free(cs);
|
||||
return;
|
||||
}
|
||||
|
||||
/* This might have spent UTXOs from our wallet */
|
||||
num_utxos = wallet_extract_owned_outputs(ld->wallet,
|
||||
wtx, NULL,
|
||||
&unused);
|
||||
if (num_utxos) {
|
||||
wallet_transaction_add(ld->wallet, wtx, 0, 0);
|
||||
}
|
||||
|
||||
if (oc) {
|
||||
response = json_stream_success(oc->cmd);
|
||||
wally_txid(wtx, &txid);
|
||||
json_add_hex_talarr(response, "tx", linearize_wtx(tmpctx, wtx));
|
||||
json_add_txid(response, "txid", &txid);
|
||||
json_add_string(response, "channel_id",
|
||||
type_to_string(tmpctx, struct channel_id,
|
||||
&channel->cid));
|
||||
was_pending(command_success(oc->cmd, response));
|
||||
}
|
||||
|
||||
tal_free(cs);
|
||||
}
|
||||
|
||||
static void send_funding_tx(struct channel *channel,
|
||||
const struct wally_tx *wtx TAKES)
|
||||
{
|
||||
struct lightningd *ld = channel->peer->ld;
|
||||
struct channel_send *cs;
|
||||
|
||||
cs = tal(channel, struct channel_send);
|
||||
cs->channel = channel;
|
||||
if (taken(wtx))
|
||||
cs->wtx = tal_steal(cs, wtx);
|
||||
else {
|
||||
tal_wally_start();
|
||||
wally_tx_clone_alloc(wtx, 0,
|
||||
cast_const2(struct wally_tx **,
|
||||
&cs->wtx));
|
||||
tal_wally_end(tal_steal(cs, cs->wtx));
|
||||
}
|
||||
|
||||
log_debug(channel->log,
|
||||
"Broadcasting funding tx for channel %s. %s",
|
||||
type_to_string(tmpctx, struct channel_id, &channel->cid),
|
||||
type_to_string(tmpctx, struct wally_tx, cs->wtx));
|
||||
|
||||
bitcoind_sendrawtx(ld->topology->bitcoind,
|
||||
tal_hex(tmpctx, linearize_wtx(tmpctx, cs->wtx)),
|
||||
sendfunding_done, cs);
|
||||
}
|
||||
|
||||
static void peer_tx_sigs_msg(struct subd *dualopend,
|
||||
const u8 *msg)
|
||||
{
|
||||
struct wally_psbt *psbt;
|
||||
const struct wally_tx *wtx;
|
||||
struct lightningd *ld = dualopend->ld;
|
||||
struct channel *channel = dualopend->channel;
|
||||
|
||||
if (!fromwire_dualopend_funding_sigs(tmpctx, msg, &psbt)) {
|
||||
channel_internal_error(channel,
|
||||
"bad dualopend_funding_sigs: %s",
|
||||
tal_hex(tmpctx, msg));
|
||||
return;
|
||||
}
|
||||
|
||||
tal_wally_start();
|
||||
if (wally_psbt_combine(channel->psbt, psbt) != WALLY_OK) {
|
||||
channel_internal_error(channel,
|
||||
"Unable to combine PSBTs: %s, %s",
|
||||
type_to_string(tmpctx,
|
||||
struct wally_psbt,
|
||||
channel->psbt),
|
||||
type_to_string(tmpctx,
|
||||
struct wally_psbt,
|
||||
psbt));
|
||||
return;
|
||||
}
|
||||
tal_wally_end(channel->psbt);
|
||||
|
||||
if (psbt_finalize(cast_const(struct wally_psbt *, channel->psbt))) {
|
||||
wtx = psbt_final_tx(NULL, channel->psbt);
|
||||
if (wtx)
|
||||
send_funding_tx(channel, take(wtx));
|
||||
}
|
||||
|
||||
wallet_channel_save(ld->wallet, channel);
|
||||
|
||||
/* Send notification with peer's signed PSBT */
|
||||
notify_openchannel_peer_sigs(ld, &channel->cid,
|
||||
channel->psbt);
|
||||
}
|
||||
|
||||
|
||||
static struct command_result *json_open_channel_signed(struct command *cmd,
|
||||
const char *buffer,
|
||||
const jsmntok_t *obj UNNEEDED,
|
||||
const jsmntok_t *params)
|
||||
{
|
||||
struct wally_psbt *psbt;
|
||||
const struct wally_tx *wtx;
|
||||
struct uncommitted_channel *uc;
|
||||
struct channel_id *cid;
|
||||
struct channel *channel;
|
||||
struct bitcoin_txid txid;
|
||||
|
||||
if (!param(cmd, buffer, params,
|
||||
p_req("channel_id", param_channel_id, &cid),
|
||||
p_req("signed_psbt", param_psbt, &psbt),
|
||||
NULL))
|
||||
return command_param_failed();
|
||||
|
||||
channel = channel_by_cid(cmd->ld, cid, &uc);
|
||||
if (uc)
|
||||
return command_fail(cmd, LIGHTNINGD,
|
||||
"Commitments for this channel not "
|
||||
"yet secured, see `openchannl_update`");
|
||||
if (!channel)
|
||||
return command_fail(cmd, FUNDING_UNKNOWN_CHANNEL,
|
||||
"Unknown channel");
|
||||
if (channel->psbt && psbt_is_finalized(channel->psbt))
|
||||
return command_fail(cmd, LIGHTNINGD,
|
||||
"Already have a finalized PSBT for "
|
||||
"this channel");
|
||||
|
||||
/* Verify that the psbt's txid matches that of the
|
||||
* funding txid for this channel */
|
||||
psbt_txid(NULL, psbt, &txid, NULL);
|
||||
if (!bitcoin_txid_eq(&txid, &channel->funding_txid))
|
||||
return command_fail(cmd, FUNDING_PSBT_INVALID,
|
||||
"Txid for passed in PSBT does not match"
|
||||
" funding txid for channel. Expected %s, "
|
||||
"received %s",
|
||||
type_to_string(tmpctx, struct bitcoin_txid,
|
||||
&channel->funding_txid),
|
||||
type_to_string(tmpctx, struct bitcoin_txid,
|
||||
&txid));
|
||||
|
||||
/* Go ahead and try to finalize things, or what we can */
|
||||
psbt_finalize(psbt);
|
||||
|
||||
/* Check that all of *our* outputs are finalized */
|
||||
if (!psbt_side_finalized(psbt, TX_INITIATOR))
|
||||
return command_fail(cmd, FUNDING_PSBT_INVALID,
|
||||
"Local PSBT input(s) not finalized");
|
||||
|
||||
/* Now that we've got the signed PSBT, save it */
|
||||
tal_wally_start();
|
||||
if (wally_psbt_combine(cast_const(struct wally_psbt *,
|
||||
channel->psbt),
|
||||
psbt) != WALLY_OK) {
|
||||
tal_wally_end(tal_free(channel->psbt));
|
||||
return command_fail(cmd, FUNDING_PSBT_INVALID,
|
||||
"Failed adding sigs");
|
||||
}
|
||||
tal_wally_end(tal_steal(channel, channel->psbt));
|
||||
|
||||
wallet_channel_save(cmd->ld->wallet, channel);
|
||||
channel_watch_funding(cmd->ld, channel);
|
||||
|
||||
/* Return when the transaction is broadcast */
|
||||
register_open_command(cmd->ld, cmd, channel);
|
||||
|
||||
/* Send our tx_sigs to the peer */
|
||||
subd_send_msg(channel->owner,
|
||||
take(towire_dualopend_send_tx_sigs(NULL, channel->psbt)));
|
||||
|
||||
if (psbt_finalize(cast_const(struct wally_psbt *, channel->psbt))) {
|
||||
wtx = psbt_final_tx(NULL, channel->psbt);
|
||||
if (wtx)
|
||||
send_funding_tx(channel, take(wtx));
|
||||
}
|
||||
|
||||
return command_still_pending(cmd);
|
||||
}
|
||||
|
||||
|
||||
static struct command_result *json_open_channel_update(struct command *cmd,
|
||||
const char *buffer,
|
||||
const jsmntok_t *obj UNNEEDED,
|
||||
@ -1238,6 +1464,8 @@ static unsigned int dual_opend_msg(struct subd *dualopend,
|
||||
const u8 *msg, const int *fds)
|
||||
{
|
||||
enum dualopend_wire t = fromwire_peektype(msg);
|
||||
|
||||
/* FIXME: might be channel? */
|
||||
struct uncommitted_channel *uc = dualopend->channel;
|
||||
|
||||
switch (t) {
|
||||
@ -1274,6 +1502,9 @@ static unsigned int dual_opend_msg(struct subd *dualopend,
|
||||
accepter_commit_received(dualopend,
|
||||
uc, fds, msg);
|
||||
return 0;
|
||||
case WIRE_DUALOPEND_FUNDING_SIGS:
|
||||
peer_tx_sigs_msg(dualopend, msg);
|
||||
return 0;
|
||||
case WIRE_DUALOPEND_FAILED:
|
||||
case WIRE_DUALOPEND_DEV_MEMLEAK_REPLY:
|
||||
|
||||
@ -1283,6 +1514,7 @@ static unsigned int dual_opend_msg(struct subd *dualopend,
|
||||
case WIRE_DUALOPEND_GOT_OFFER_REPLY:
|
||||
case WIRE_DUALOPEND_FAIL:
|
||||
case WIRE_DUALOPEND_PSBT_UPDATED:
|
||||
case WIRE_DUALOPEND_SEND_TX_SIGS:
|
||||
case WIRE_DUALOPEND_DEV_MEMLEAK:
|
||||
break;
|
||||
}
|
||||
@ -1323,9 +1555,17 @@ static const struct json_command open_channel_update_command = {
|
||||
"If {commitments_secured} is true, next call should be to openchannel_signed"
|
||||
};
|
||||
|
||||
static const struct json_command open_channel_signed_command = {
|
||||
"openchannel_signed",
|
||||
"channels",
|
||||
json_open_channel_signed,
|
||||
"Send our {signed_psbt}'s tx sigs for {channel_id}."
|
||||
};
|
||||
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
AUTODATA(json_command, &open_channel_init_command);
|
||||
AUTODATA(json_command, &open_channel_update_command);
|
||||
AUTODATA(json_command, &open_channel_signed_command);
|
||||
#endif /* EXPERIMENTAL_FEATURES */
|
||||
|
||||
void peer_start_dualopend(struct peer *peer,
|
||||
|
@ -86,6 +86,10 @@ OPENINGD_COMMON_OBJS := \
|
||||
gossipd/gossipd_peerd_wiregen.o \
|
||||
lightningd/gossip_msg.o
|
||||
|
||||
ifeq ($(EXPERIMENTAL_FEATURES),1)
|
||||
OPENINGD_COMMON_OBJS += common/psbt_internal.o
|
||||
endif
|
||||
|
||||
lightningd/lightning_openingd: $(OPENINGD_OBJS) $(OPENINGD_COMMON_OBJS) $(WIRE_OBJS) $(BITCOIN_OBJS) $(HSMD_CLIENT_OBJS)
|
||||
|
||||
lightningd/lightning_dualopend: $(DUALOPEND_OBJS) $(OPENINGD_COMMON_OBJS) $(WIRE_OBJS) $(BITCOIN_OBJS) $(HSMD_CLIENT_OBJS)
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include <common/peer_failed.h>
|
||||
#include <common/penalty_base.h>
|
||||
#include <common/per_peer_state.h>
|
||||
#include <common/psbt_internal.h>
|
||||
#include <common/psbt_open.h>
|
||||
#include <common/read_peer_msg.h>
|
||||
#include <common/setup.h>
|
||||
@ -142,6 +143,10 @@ struct state {
|
||||
|
||||
/* Track how many of each tx collab msg we receive */
|
||||
u16 tx_msg_count[NUM_TX_MSGS];
|
||||
|
||||
bool funding_locked[NUM_SIDES];
|
||||
|
||||
struct wally_psbt *psbt;
|
||||
};
|
||||
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
@ -655,6 +660,124 @@ static void dualopend_send_custommsg(struct state *state, const u8 *msg)
|
||||
}
|
||||
#endif
|
||||
|
||||
static u8 *psbt_to_tx_sigs_msg(const tal_t *ctx,
|
||||
struct state *state,
|
||||
const struct wally_psbt *psbt)
|
||||
{
|
||||
const struct witness_stack **ws =
|
||||
psbt_to_witness_stacks(tmpctx, psbt,
|
||||
state->our_role);
|
||||
|
||||
return towire_tx_signatures(ctx, &state->channel_id,
|
||||
&state->funding_txid,
|
||||
ws);
|
||||
}
|
||||
|
||||
static void handle_tx_sigs(struct state *state, const u8 *msg)
|
||||
{
|
||||
struct channel_id cid;
|
||||
struct bitcoin_txid txid;
|
||||
const struct witness_stack **ws;
|
||||
size_t j = 0;
|
||||
enum tx_role their_role = state->our_role == TX_INITIATOR ?
|
||||
TX_ACCEPTER : TX_INITIATOR;
|
||||
|
||||
if (!fromwire_tx_signatures(tmpctx, msg, &cid, &txid,
|
||||
cast_const3(
|
||||
struct witness_stack ***,
|
||||
&ws)))
|
||||
peer_failed(state->pps,
|
||||
&state->channel_id,
|
||||
"Bad tx_signatures %s",
|
||||
tal_hex(msg, msg));
|
||||
|
||||
/* Maybe they didn't get our funding_locked message ? */
|
||||
if (state->funding_locked[LOCAL]) {
|
||||
status_broken("Got WIRE_TX_SIGNATURES after funding locked "
|
||||
"for channel %s, ignoring: %s",
|
||||
type_to_string(tmpctx, struct channel_id,
|
||||
&state->channel_id),
|
||||
tal_hex(tmpctx, msg));
|
||||
return;
|
||||
}
|
||||
|
||||
if (state->funding_locked[REMOTE])
|
||||
peer_failed(state->pps,
|
||||
&state->channel_id,
|
||||
"tx_signatures sent after funding_locked %s",
|
||||
tal_hex(msg, msg));
|
||||
|
||||
/* This check only works if they've got inputs we need sigs for.
|
||||
* In the case where they send duplicate tx_sigs but have no
|
||||
* sigs, we'll end up re-notifying */
|
||||
if (tal_count(ws) && psbt_side_finalized(state->psbt, their_role)) {
|
||||
status_info("Got duplicate WIRE_TX_SIGNATURES, "
|
||||
"already have their sigs. Ignoring");
|
||||
return;
|
||||
}
|
||||
|
||||
/* We put the PSBT + sigs all together */
|
||||
for (size_t i = 0; i < state->psbt->num_inputs; i++) {
|
||||
struct wally_psbt_input *in =
|
||||
&state->psbt->inputs[i];
|
||||
u64 in_serial;
|
||||
const struct witness_element **elem;
|
||||
|
||||
if (!psbt_get_serial_id(&in->unknowns, &in_serial)) {
|
||||
status_broken("PSBT input %zu missing serial_id %s",
|
||||
i, type_to_string(tmpctx,
|
||||
struct wally_psbt,
|
||||
state->psbt));
|
||||
return;
|
||||
}
|
||||
if (in_serial % 2 != their_role)
|
||||
continue;
|
||||
|
||||
if (j == tal_count(ws))
|
||||
peer_failed(state->pps, &state->channel_id,
|
||||
"Mismatch witness stack count %s",
|
||||
tal_hex(msg, msg));
|
||||
|
||||
elem = cast_const2(const struct witness_element **,
|
||||
ws[j++]->witness_element);
|
||||
psbt_finalize_input(state->psbt, in, elem);
|
||||
}
|
||||
|
||||
/* Send to the controller, who will broadcast the funding_tx
|
||||
* as soon as we've got our sigs */
|
||||
wire_sync_write(REQ_FD,
|
||||
take(towire_dualopend_funding_sigs(NULL, state->psbt)));
|
||||
}
|
||||
|
||||
static u8 *handle_send_tx_sigs(struct state *state, const u8 *msg)
|
||||
{
|
||||
struct wally_psbt *psbt;
|
||||
struct bitcoin_txid txid;
|
||||
|
||||
if (!fromwire_dualopend_send_tx_sigs(tmpctx, msg, &psbt))
|
||||
master_badmsg(WIRE_DUALOPEND_SEND_TX_SIGS, msg);
|
||||
|
||||
/* Check that we've got the same / correct PSBT */
|
||||
psbt_txid(NULL, psbt, &txid, NULL);
|
||||
if (!bitcoin_txid_eq(&txid, &state->funding_txid))
|
||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||
"Txid for passed in PSBT does not match"
|
||||
" funding txid for channel. Expected %s, "
|
||||
"received %s",
|
||||
type_to_string(tmpctx, struct bitcoin_txid,
|
||||
&state->funding_txid),
|
||||
type_to_string(tmpctx, struct bitcoin_txid,
|
||||
&txid));
|
||||
|
||||
tal_wally_start();
|
||||
if (wally_psbt_combine(state->psbt, psbt) != WALLY_OK) {
|
||||
tal_wally_end(tal_free(state->psbt));
|
||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||
"Unable to combine PSBTs");
|
||||
}
|
||||
tal_wally_end(tal_steal(state, state->psbt));
|
||||
return psbt_to_tx_sigs_msg(tmpctx, state, psbt);
|
||||
}
|
||||
|
||||
static struct wally_psbt *
|
||||
fetch_psbt_changes(struct state *state, const struct wally_psbt *psbt)
|
||||
@ -2060,8 +2183,11 @@ static u8 *handle_master_in(struct state *state)
|
||||
return NULL;
|
||||
case WIRE_DUALOPEND_OPENER_INIT:
|
||||
return opener_start(state, msg);
|
||||
case WIRE_DUALOPEND_SEND_TX_SIGS:
|
||||
return handle_send_tx_sigs(state, msg);
|
||||
/* mostly handled inline */
|
||||
case WIRE_DUALOPEND_INIT:
|
||||
case WIRE_DUALOPEND_FUNDING_SIGS:
|
||||
case WIRE_DUALOPEND_DEV_MEMLEAK_REPLY:
|
||||
case WIRE_DUALOPEND_FAILED:
|
||||
case WIRE_DUALOPEND_FAIL:
|
||||
@ -2092,7 +2218,7 @@ static u8 *handle_master_in(struct state *state)
|
||||
}
|
||||
|
||||
/*~ Standard "peer sent a message, handle it" demuxer. Though it really only
|
||||
* handles one message, we use the standard form as principle of least
|
||||
* handles a few messages, we use the standard form as principle of least
|
||||
* surprise. */
|
||||
static u8 *handle_peer_in(struct state *state)
|
||||
{
|
||||
@ -2100,10 +2226,12 @@ static u8 *handle_peer_in(struct state *state)
|
||||
enum peer_wire t = fromwire_peektype(msg);
|
||||
struct channel_id channel_id;
|
||||
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
if (t == WIRE_OPEN_CHANNEL2)
|
||||
return accepter_start(state, msg);
|
||||
#endif
|
||||
if (t == WIRE_TX_SIGNATURES) {
|
||||
handle_tx_sigs(state, msg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if DEVELOPER
|
||||
/* Handle custommsgs */
|
||||
|
@ -114,6 +114,14 @@ msgdata,dualopend_opener_init,feerate_per_kw,u32,
|
||||
msgdata,dualopend_opener_init,feerate_per_kw_funding,u32,
|
||||
msgdata,dualopend_opener_init,channel_flags,u8,
|
||||
|
||||
# dualopend->master received tx_sigs from peer
|
||||
msgtype,dualopend_funding_sigs,7010
|
||||
msgdata,dualopend_funding_sigs,signed_psbt,wally_psbt,
|
||||
|
||||
# master->dualopend send our tx_sigs to peer
|
||||
msgtype,dualopend_send_tx_sigs,7011
|
||||
msgdata,dualopend_send_tx_sigs,signed_psbt,wally_psbt,
|
||||
|
||||
# master -> dualopend: do you have a memleak?
|
||||
msgtype,dualopend_dev_memleak,7033
|
||||
|
||||
|
Can't render this file because it has a wrong number of fields in line 11.
|
50
openingd/dualopend_wiregen.c
generated
50
openingd/dualopend_wiregen.c
generated
@ -29,6 +29,8 @@ const char *dualopend_wire_name(int e)
|
||||
case WIRE_DUALOPEND_FAIL: return "WIRE_DUALOPEND_FAIL";
|
||||
case WIRE_DUALOPEND_FAILED: return "WIRE_DUALOPEND_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";
|
||||
case WIRE_DUALOPEND_DEV_MEMLEAK: return "WIRE_DUALOPEND_DEV_MEMLEAK";
|
||||
case WIRE_DUALOPEND_DEV_MEMLEAK_REPLY: return "WIRE_DUALOPEND_DEV_MEMLEAK_REPLY";
|
||||
}
|
||||
@ -49,6 +51,8 @@ bool dualopend_wire_is_defined(u16 type)
|
||||
case WIRE_DUALOPEND_FAIL:;
|
||||
case WIRE_DUALOPEND_FAILED:;
|
||||
case WIRE_DUALOPEND_OPENER_INIT:;
|
||||
case WIRE_DUALOPEND_FUNDING_SIGS:;
|
||||
case WIRE_DUALOPEND_SEND_TX_SIGS:;
|
||||
case WIRE_DUALOPEND_DEV_MEMLEAK:;
|
||||
case WIRE_DUALOPEND_DEV_MEMLEAK_REPLY:;
|
||||
return true;
|
||||
@ -445,6 +449,50 @@ bool fromwire_dualopend_opener_init(const tal_t *ctx, const void *p, struct wall
|
||||
return cursor != NULL;
|
||||
}
|
||||
|
||||
/* WIRE: DUALOPEND_FUNDING_SIGS */
|
||||
/* dualopend->master received tx_sigs from peer */
|
||||
u8 *towire_dualopend_funding_sigs(const tal_t *ctx, const struct wally_psbt *signed_psbt)
|
||||
{
|
||||
u8 *p = tal_arr(ctx, u8, 0);
|
||||
|
||||
towire_u16(&p, WIRE_DUALOPEND_FUNDING_SIGS);
|
||||
towire_wally_psbt(&p, signed_psbt);
|
||||
|
||||
return memcheck(p, tal_count(p));
|
||||
}
|
||||
bool fromwire_dualopend_funding_sigs(const tal_t *ctx, const void *p, struct wally_psbt **signed_psbt)
|
||||
{
|
||||
const u8 *cursor = p;
|
||||
size_t plen = tal_count(p);
|
||||
|
||||
if (fromwire_u16(&cursor, &plen) != WIRE_DUALOPEND_FUNDING_SIGS)
|
||||
return false;
|
||||
*signed_psbt = fromwire_wally_psbt(ctx, &cursor, &plen);
|
||||
return cursor != NULL;
|
||||
}
|
||||
|
||||
/* WIRE: DUALOPEND_SEND_TX_SIGS */
|
||||
/* master->dualopend send our tx_sigs to peer */
|
||||
u8 *towire_dualopend_send_tx_sigs(const tal_t *ctx, const struct wally_psbt *signed_psbt)
|
||||
{
|
||||
u8 *p = tal_arr(ctx, u8, 0);
|
||||
|
||||
towire_u16(&p, WIRE_DUALOPEND_SEND_TX_SIGS);
|
||||
towire_wally_psbt(&p, signed_psbt);
|
||||
|
||||
return memcheck(p, tal_count(p));
|
||||
}
|
||||
bool fromwire_dualopend_send_tx_sigs(const tal_t *ctx, const void *p, struct wally_psbt **signed_psbt)
|
||||
{
|
||||
const u8 *cursor = p;
|
||||
size_t plen = tal_count(p);
|
||||
|
||||
if (fromwire_u16(&cursor, &plen) != WIRE_DUALOPEND_SEND_TX_SIGS)
|
||||
return false;
|
||||
*signed_psbt = fromwire_wally_psbt(ctx, &cursor, &plen);
|
||||
return cursor != NULL;
|
||||
}
|
||||
|
||||
/* WIRE: DUALOPEND_DEV_MEMLEAK */
|
||||
/* master -> dualopend: do you have a memleak? */
|
||||
u8 *towire_dualopend_dev_memleak(const tal_t *ctx)
|
||||
@ -485,4 +533,4 @@ bool fromwire_dualopend_dev_memleak_reply(const void *p, bool *leak)
|
||||
*leak = fromwire_bool(&cursor, &plen);
|
||||
return cursor != NULL;
|
||||
}
|
||||
// SHA256STAMP:435564ffcea3302152e316a659eb30091a72b0d81f0959bea22ecb7e11f23223
|
||||
// SHA256STAMP:b050a7cf375aa2cfbc25f86556d06acaa7f1ed96170adaa912e5ba994a2879c2
|
||||
|
16
openingd/dualopend_wiregen.h
generated
16
openingd/dualopend_wiregen.h
generated
@ -36,6 +36,10 @@ enum dualopend_wire {
|
||||
WIRE_DUALOPEND_FAILED = 7004,
|
||||
/* master->dualopend: hello */
|
||||
WIRE_DUALOPEND_OPENER_INIT = 7200,
|
||||
/* dualopend->master received tx_sigs from peer */
|
||||
WIRE_DUALOPEND_FUNDING_SIGS = 7010,
|
||||
/* master->dualopend send our tx_sigs to peer */
|
||||
WIRE_DUALOPEND_SEND_TX_SIGS = 7011,
|
||||
/* master -> dualopend: do you have a memleak? */
|
||||
WIRE_DUALOPEND_DEV_MEMLEAK = 7033,
|
||||
WIRE_DUALOPEND_DEV_MEMLEAK_REPLY = 7133,
|
||||
@ -98,6 +102,16 @@ bool fromwire_dualopend_failed(const tal_t *ctx, const void *p, wirestring **rea
|
||||
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);
|
||||
bool fromwire_dualopend_opener_init(const tal_t *ctx, const void *p, struct wally_psbt **psbt, struct amount_sat *funding_amount, u8 **local_shutdown_scriptpubkey, u32 *feerate_per_kw, u32 *feerate_per_kw_funding, u8 *channel_flags);
|
||||
|
||||
/* WIRE: DUALOPEND_FUNDING_SIGS */
|
||||
/* dualopend->master received tx_sigs from peer */
|
||||
u8 *towire_dualopend_funding_sigs(const tal_t *ctx, const struct wally_psbt *signed_psbt);
|
||||
bool fromwire_dualopend_funding_sigs(const tal_t *ctx, const void *p, struct wally_psbt **signed_psbt);
|
||||
|
||||
/* WIRE: DUALOPEND_SEND_TX_SIGS */
|
||||
/* master->dualopend send our tx_sigs to peer */
|
||||
u8 *towire_dualopend_send_tx_sigs(const tal_t *ctx, const struct wally_psbt *signed_psbt);
|
||||
bool fromwire_dualopend_send_tx_sigs(const tal_t *ctx, const void *p, struct wally_psbt **signed_psbt);
|
||||
|
||||
/* WIRE: DUALOPEND_DEV_MEMLEAK */
|
||||
/* master -> dualopend: do you have a memleak? */
|
||||
u8 *towire_dualopend_dev_memleak(const tal_t *ctx);
|
||||
@ -109,4 +123,4 @@ bool fromwire_dualopend_dev_memleak_reply(const void *p, bool *leak);
|
||||
|
||||
|
||||
#endif /* LIGHTNING_OPENINGD_DUALOPEND_WIREGEN_H */
|
||||
// SHA256STAMP:435564ffcea3302152e316a659eb30091a72b0d81f0959bea22ecb7e11f23223
|
||||
// SHA256STAMP:b050a7cf375aa2cfbc25f86556d06acaa7f1ed96170adaa912e5ba994a2879c2
|
||||
|
Loading…
Reference in New Issue
Block a user