Skip to content

Commit 46cad2a

Browse files
authored
Merge pull request #49 from lightning-signer/2021-12-wallet-metadata-optional
Cleanup to match 2021-12-wallet-index branch
2 parents 8956898 + c03b767 commit 46cad2a

30 files changed

+203
-145
lines changed

channeld/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ CHANNELD_COMMON_OBJS := \
7474
common/per_peer_state.o \
7575
common/permute_tx.o \
7676
common/ping.o \
77-
common/psbt_internal.o \
77+
common/psbt_keypath.o \
7878
common/psbt_open.o \
7979
common/private_channel_announcement.o \
8080
common/pseudorand.o \

channeld/channeld.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ struct peer {
139139
u32 fee_per_satoshi;
140140

141141
/* The scriptpubkey to use for shutting down. */
142-
u32 final_index;
143-
struct ext_key final_ext_key;
142+
u32 *final_index;
143+
struct ext_key *final_ext_key;
144144
u8 *final_scriptpubkey;
145145

146146
/* If master told us to shut down */
@@ -1848,7 +1848,7 @@ static u8 *got_revoke_msg(struct peer *peer, u64 revoke_num,
18481848
if (pbase) {
18491849
ptx = penalty_tx_create(
18501850
NULL, peer->channel, peer->feerate_penalty,
1851-
peer->final_index, &peer->final_ext_key,
1851+
peer->final_index, peer->final_ext_key,
18521852
peer->final_scriptpubkey, per_commitment_secret,
18531853
&pbase->txid, pbase->outnum, pbase->amount,
18541854
HSM_FD);
@@ -3655,15 +3655,23 @@ static void handle_fail(struct peer *peer, const u8 *inmsg)
36553655

36563656
static void handle_shutdown_cmd(struct peer *peer, const u8 *inmsg)
36573657
{
3658+
u32 *final_index;
3659+
struct ext_key *final_ext_key;
36583660
u8 *local_shutdown_script;
36593661

36603662
if (!fromwire_channeld_send_shutdown(peer, inmsg,
3661-
&peer->final_index,
3662-
&peer->final_ext_key,
3663+
&final_index,
3664+
&final_ext_key,
36633665
&local_shutdown_script,
36643666
&peer->shutdown_wrong_funding))
36653667
master_badmsg(WIRE_CHANNELD_SEND_SHUTDOWN, inmsg);
36663668

3669+
tal_free(peer->final_index);
3670+
peer->final_index = final_index;
3671+
3672+
tal_free(peer->final_ext_key);
3673+
peer->final_ext_key = final_ext_key;
3674+
36673675
tal_free(peer->final_scriptpubkey);
36683676
peer->final_scriptpubkey = local_shutdown_script;
36693677

@@ -3902,6 +3910,8 @@ static void init_channel(struct peer *peer)
39023910
enum side opener;
39033911
struct existing_htlc **htlcs;
39043912
bool reconnected;
3913+
u32 final_index;
3914+
struct ext_key final_ext_key;
39053915
u8 *fwd_msg;
39063916
const u8 *msg;
39073917
struct fee_states *fee_states;
@@ -3964,8 +3974,8 @@ static void init_channel(struct peer *peer)
39643974
&reconnected,
39653975
&peer->send_shutdown,
39663976
&peer->shutdown_sent[REMOTE],
3967-
&peer->final_index,
3968-
&peer->final_ext_key,
3977+
&final_index,
3978+
&final_ext_key,
39693979
&peer->final_scriptpubkey,
39703980
&peer->channel_flags,
39713981
&fwd_msg,
@@ -3983,6 +3993,9 @@ static void init_channel(struct peer *peer)
39833993
master_badmsg(WIRE_CHANNELD_INIT, msg);
39843994
}
39853995

3996+
peer->final_index = tal_dup(peer, u32, &final_index);
3997+
peer->final_ext_key = tal_dup(peer, struct ext_key, &final_ext_key);
3998+
39863999
status_debug("option_static_remotekey = %u, option_anchor_outputs = %u",
39874000
channel_type_has(channel_type, OPT_STATIC_REMOTEKEY),
39884001
channel_type_has(channel_type, OPT_ANCHOR_OUTPUTS));

channeld/channeld_wire.csv

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,11 @@ msgdata,channeld_got_revoke,penalty_tx,?bitcoin_tx,
175175
# (eg. if we sent another commitment_signed, that would implicitly ack).
176176
msgtype,channeld_got_revoke_reply,1122
177177

178+
#include <wally_bip32.h>
178179
# Tell peer to shut down channel.
179180
msgtype,channeld_send_shutdown,1023
180-
msgdata,channeld_send_shutdown,final_index,u32,
181-
msgdata,channeld_send_shutdown,final_ext_key,ext_key,
181+
msgdata,channeld_send_shutdown,final_index,?u32,
182+
msgdata,channeld_send_shutdown,final_ext_key,?ext_key,
182183
msgdata,channeld_send_shutdown,shutdown_len,u16,
183184
msgdata,channeld_send_shutdown,shutdown_scriptpubkey,u8,shutdown_len
184185
msgdata,channeld_send_shutdown,wrong_funding,?bitcoin_outpoint,

channeld/commit_tx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
285285
* `dust_limit_satoshis`, add a [`to_remote`
286286
* output](#to_remote-output).
287287
*/
288-
const u8 *redeem = NULL;
288+
u8 *redeem = NULL;
289289
if (amount_msat_greater_eq_sat(other_pay, dust_limit)) {
290290
struct amount_sat amount = amount_msat_to_sat_round_down(other_pay);
291291
u8 *scriptpubkey;
@@ -325,7 +325,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
325325
scriptpubkey = scriptpubkey_p2wpkh(tmpctx,
326326
&keyset->other_payment_key);
327327
}
328-
pos = bitcoin_tx_add_output(tx, scriptpubkey, (u8 *) redeem, amount);
328+
pos = bitcoin_tx_add_output(tx, scriptpubkey, redeem, amount);
329329
assert(pos == n);
330330
(*htlcmap)[n] = direct_outputs ? dummy_to_remote : NULL;
331331
/* We don't assign cltvs[n]: if we use it, order doesn't matter.

channeld/watchtower.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <common/features.h>
66
#include <common/htlc_tx.h>
77
#include <common/keyset.h>
8-
#include <common/psbt_internal.h>
8+
#include <common/psbt_keypath.h>
99
#include <common/status.h>
1010
#include <common/type_to_string.h>
1111
#include <hsmd/hsmd_wiregen.h>
@@ -17,7 +17,7 @@ const struct bitcoin_tx *
1717
penalty_tx_create(const tal_t *ctx,
1818
const struct channel *channel,
1919
u32 penalty_feerate,
20-
u32 final_index,
20+
u32 *final_index,
2121
struct ext_key *final_ext_key,
2222
u8 *final_scriptpubkey,
2323
const struct secret *revocation_preimage,
@@ -78,7 +78,9 @@ penalty_tx_create(const tal_t *ctx,
7878
NULL, to_them_sats, NULL, wscript);
7979

8080
bitcoin_tx_add_output(tx, final_scriptpubkey, NULL, to_them_sats);
81-
psbt_add_keypath_to_last_output(tx, final_index, final_ext_key);
81+
assert((final_index == NULL) == (final_ext_key == NULL));
82+
if (final_index)
83+
psbt_add_keypath_to_last_output(tx, *final_index, final_ext_key);
8284

8385
/* Worst-case sig is 73 bytes */
8486
weight = bitcoin_tx_weight(tx) + 1 + 3 + 73 + 0 + tal_count(wscript);

channeld/watchtower.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const struct bitcoin_tx *
99
penalty_tx_create(const tal_t *ctx,
1010
const struct channel *channel,
1111
u32 penalty_feerate,
12-
u32 final_index,
12+
u32 *final_index,
1313
struct ext_key *final_ext_key,
1414
u8 *final_scriptpubkey,
1515
const struct secret *revocation_preimage,

closingd/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ CLOSINGD_COMMON_OBJS := \
4848
common/per_peer_state.o \
4949
common/permute_tx.o \
5050
common/ping.o \
51-
common/psbt_internal.o \
51+
common/psbt_keypath.o \
5252
common/psbt_open.o \
5353
common/pseudorand.o \
5454
common/read_peer_msg.o \

closingd/closingd.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static struct bitcoin_tx *close_tx(const tal_t *ctx,
5454
const struct chainparams *chainparams,
5555
struct per_peer_state *pps,
5656
const struct channel_id *channel_id,
57-
u32 local_wallet_index,
57+
u32 *local_wallet_index,
5858
const struct ext_key *local_wallet_ext_key,
5959
u8 *scriptpubkey[NUM_SIDES],
6060
const struct bitcoin_outpoint *funding,
@@ -150,7 +150,7 @@ static void send_offer(struct per_peer_state *pps,
150150
const struct channel_id *channel_id,
151151
const struct pubkey funding_pubkey[NUM_SIDES],
152152
const u8 *funding_wscript,
153-
u32 local_wallet_index,
153+
u32 *local_wallet_index,
154154
const struct ext_key *local_wallet_ext_key,
155155
u8 *scriptpubkey[NUM_SIDES],
156156
const struct bitcoin_outpoint *funding,
@@ -249,7 +249,7 @@ receive_offer(struct per_peer_state *pps,
249249
const struct channel_id *channel_id,
250250
const struct pubkey funding_pubkey[NUM_SIDES],
251251
const u8 *funding_wscript,
252-
u32 local_wallet_index,
252+
u32 *local_wallet_index,
253253
const struct ext_key *local_wallet_ext_key,
254254
u8 *scriptpubkey[NUM_SIDES],
255255
const struct bitcoin_outpoint *funding,
@@ -590,7 +590,7 @@ static size_t closing_tx_weight_estimate(u8 *scriptpubkey[NUM_SIDES],
590590
const struct amount_sat *out,
591591
struct amount_sat funding_sats,
592592
struct amount_sat dust_limit,
593-
u32 local_wallet_index,
593+
u32 *local_wallet_index,
594594
const struct ext_key *local_wallet_ext_key)
595595
{
596596
/* We create a dummy close */
@@ -717,7 +717,7 @@ static void do_quickclose(struct amount_sat offer[NUM_SIDES],
717717
const struct channel_id *channel_id,
718718
const struct pubkey funding_pubkey[NUM_SIDES],
719719
const u8 *funding_wscript,
720-
u32 local_wallet_index,
720+
u32 *local_wallet_index,
721721
const struct ext_key *local_wallet_ext_key,
722722
u8 *scriptpubkey[NUM_SIDES],
723723
const struct bitcoin_outpoint *funding,
@@ -902,8 +902,8 @@ int main(int argc, char *argv[])
902902
u32 min_feerate, initial_feerate, *max_feerate;
903903
struct feerange feerange;
904904
enum side opener;
905-
u32 local_wallet_index;
906-
struct ext_key local_wallet_ext_key;
905+
u32 *local_wallet_index;
906+
struct ext_key *local_wallet_ext_key;
907907
u8 *scriptpubkey[NUM_SIDES], *funding_wscript;
908908
u64 fee_negotiation_step;
909909
u8 fee_negotiation_step_unit;
@@ -957,7 +957,7 @@ int main(int argc, char *argv[])
957957
out, funding_sats,
958958
our_dust_limit,
959959
local_wallet_index,
960-
&local_wallet_ext_key),
960+
local_wallet_ext_key),
961961
min_feerate, initial_feerate, max_feerate,
962962
commitment_fee, funding_sats, opener,
963963
&min_fee_to_accept, &offer[LOCAL], &max_fee_to_accept);
@@ -1015,7 +1015,7 @@ int main(int argc, char *argv[])
10151015
if (whose_turn == LOCAL) {
10161016
send_offer(pps, chainparams,
10171017
&channel_id, funding_pubkey, funding_wscript,
1018-
local_wallet_index, &local_wallet_ext_key,
1018+
local_wallet_index, local_wallet_ext_key,
10191019
scriptpubkey, &funding,
10201020
funding_sats, out, opener,
10211021
our_dust_limit,
@@ -1038,7 +1038,7 @@ int main(int argc, char *argv[])
10381038
&channel_id, funding_pubkey,
10391039
funding_wscript,
10401040
local_wallet_index,
1041-
&local_wallet_ext_key,
1041+
local_wallet_ext_key,
10421042
scriptpubkey, &funding,
10431043
funding_sats,
10441044
out, opener,
@@ -1052,7 +1052,7 @@ int main(int argc, char *argv[])
10521052
do_quickclose(offer,
10531053
pps, &channel_id, funding_pubkey,
10541054
funding_wscript,
1055-
local_wallet_index, &local_wallet_ext_key,
1055+
local_wallet_index, local_wallet_ext_key,
10561056
scriptpubkey,
10571057
&funding,
10581058
funding_sats, out, opener,
@@ -1087,7 +1087,7 @@ int main(int argc, char *argv[])
10871087
send_offer(pps, chainparams, &channel_id,
10881088
funding_pubkey, funding_wscript,
10891089
local_wallet_index,
1090-
&local_wallet_ext_key,
1090+
local_wallet_ext_key,
10911091
scriptpubkey, &funding,
10921092
funding_sats, out, opener,
10931093
our_dust_limit,
@@ -1105,7 +1105,7 @@ int main(int argc, char *argv[])
11051105
funding_pubkey,
11061106
funding_wscript,
11071107
local_wallet_index,
1108-
&local_wallet_ext_key,
1108+
local_wallet_ext_key,
11091109
scriptpubkey, &funding,
11101110
funding_sats,
11111111
out, opener,

closingd/closingd_wire.csv

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <common/htlc_wire.h>
66
#include <common/per_peer_state.h>
77
#include <common/status_wire.h>
8+
#include <wally_bip32.h>
89
# Begin! (passes peer fd, gossipd-client fd)
910
msgtype,closingd_init,2001
1011
msgdata,closingd_init,chainparams,chainparams,
@@ -22,8 +23,8 @@ msgdata,closingd_init,min_feerate_perksipa,u32,
2223
msgdata,closingd_init,preferred_feerate_perksipa,u32,
2324
msgdata,closingd_init,max_feerate_perksipa,?u32,
2425
msgdata,closingd_init,fee_limit_satoshi,amount_sat,
25-
msgdata,closingd_init,local_wallet_index,u32,
26-
msgdata,closingd_init,local_wallet_ext_key,ext_key,
26+
msgdata,closingd_init,local_wallet_index,?u32,
27+
msgdata,closingd_init,local_wallet_ext_key,?ext_key,
2728
msgdata,closingd_init,local_scriptpubkey_len,u16,
2829
msgdata,closingd_init,local_scriptpubkey,u8,local_scriptpubkey_len
2930
msgdata,closingd_init,remote_scriptpubkey_len,u16,

common/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ COMMON_SRC_NOGEN := \
6868
common/peer_failed.c \
6969
common/permute_tx.c \
7070
common/ping.c \
71-
common/psbt_internal.c \
71+
common/psbt_keypath.c \
7272
common/psbt_open.c \
7373
common/private_channel_announcement.c \
7474
common/pseudorand.c \

0 commit comments

Comments
 (0)